This commit is contained in:
firefighter198
2021-08-11 00:26:20 +02:00
parent 7424309dac
commit 7146b2639c
44 changed files with 867 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
using Godot;
using System;
public class Ground : Area2D
{
private void _on_Ground_player_entered(object body)
{
if (body is Player)
{
Player player = body as Player;
player.die();
}
}
}
+13
View File
@@ -0,0 +1,13 @@
using Godot;
using System;
public class Menu : Control
{
public override void _Process(float delta)
{
if (Input.IsActionJustPressed("Click"))
{
GetTree().ChangeScene("res://World.tscn");
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using Godot;
using System;
public class Obstacle : Area2D
{
private const float moveSpeed = 145f;
private void _on_Pipe_player_entered(object body)
{
if (body is Player)
{
Player player = body as Player;
player.die();
}
}
private void _on_Obstacle_player_exited(object body)
{
if (body is Player)
{
Player player = body as Player;
player.score_increase();
}
}
public override void _PhysicsProcess(float delta)
{
Translate(new Vector2(-moveSpeed * delta, 0));
if (Position.x < -200)
{
QueueFree();
}
}
}
+52
View File
@@ -0,0 +1,52 @@
using Godot;
using System;
public class Player : RigidBody2D
{
private const float jumpForce = -225f;
private bool alive = true;
private int score = 0;
private Label labelScore;
private ulong timeDied = 0;
private const int respawnTime = 3;
private Sprite spriteGameOver;
public override void _Ready()
{
labelScore = GetNode<Label>("../Overlay/Score");
spriteGameOver = GetNode<Sprite>("../GameOver");
}
public override void _PhysicsProcess(float delta)
{
if (Input.IsActionJustPressed("Click") && alive)
{
LinearVelocity = new Vector2(0, jumpForce);
}
if (!alive && OS.GetUnixTime() - timeDied > respawnTime)
{
GetTree().ChangeScene("res://Menu.tscn");
}
}
public void die()
{
if(alive)
{
alive = false;
GravityScale = 0;
timeDied = OS.GetUnixTime();
spriteGameOver.Visible = true;
}
}
public void score_increase()
{
if(alive)
{
score++;
labelScore.Text = score.ToString();
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using Godot;
using System;
using Object = Godot.Object;
public class World : Node2D
{
//-260 240
private Sprite spriteBackground;
private PackedScene prefabObstacle = GD.Load<PackedScene>("res://Obstacle.tscn");
private Random random = new Random();
public override void _Ready()
{
spriteBackground = GetNode<Sprite>("Background");
}
private void _on_Timer_timeout()
{
Area2D instance = prefabObstacle.Instance() as Area2D;
instance.Position = new Vector2(instance.Position.x, random.Next(-260, 140));
spriteBackground.AddChild(instance);
}
}