diff options
Diffstat (limited to 'game/characters')
| -rw-r--r-- | game/characters/player/Player.gd | 18 | ||||
| -rw-r--r-- | game/characters/player/Player.tscn | 32 | ||||
| -rw-r--r-- | game/characters/victor/Victor.gd | 16 |
3 files changed, 22 insertions, 44 deletions
diff --git a/game/characters/player/Player.gd b/game/characters/player/Player.gd index 862a0a1..56a60d0 100644 --- a/game/characters/player/Player.gd +++ b/game/characters/player/Player.gd @@ -1,8 +1,6 @@ extends CharacterBody2D - -@export var SPEED = 300.0 -var JUMP_VELOCITY = -400.0 +const JUMP_VELOCITY = -500.0 # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -14,15 +12,15 @@ func _physics_process(delta): velocity.y += gravity * delta # Handle Jump. - if Input.is_action_just_pressed("jump") and is_on_floor(): + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. - var direction = Input.get_axis("left", "right") - if direction: - velocity.x = direction * SPEED - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - + velocity.x = 1 * Stats.playerspeed move_and_slide() + + if Stats.playerdead == true: + queue_free() + get_tree().paused = true + $"../Game Over".show() diff --git a/game/characters/player/Player.tscn b/game/characters/player/Player.tscn index f1d831e..34035f6 100644 --- a/game/characters/player/Player.tscn +++ b/game/characters/player/Player.tscn @@ -1,40 +1,14 @@ [gd_scene load_steps=4 format=3 uid="uid://l0lnby3rm6fj"] +[ext_resource type="Script" path="res://game/characters/player/Player.gd" id="1_a5mv4"] [ext_resource type="Texture2D" uid="uid://d1gf8ked7ik4l" path="res://assets/images/white.png" id="2"] -[sub_resource type="GDScript" id="GDScript_mix1s"] -script/source = "extends CharacterBody2D - -const JUMP_VELOCITY = -500.0 - -# Get the gravity from the project settings to be synced with RigidBody nodes. -var gravity = ProjectSettings.get_setting(\"physics/2d/default_gravity\") - - -func _physics_process(delta): - # Add the gravity. - if not is_on_floor(): - velocity.y += gravity * delta - - # Handle Jump. - if Input.is_action_just_pressed(\"ui_accept\") and is_on_floor(): - velocity.y = JUMP_VELOCITY - - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - velocity.x = 1 * Stats.initspeed - move_and_slide() - - if Stats.playerdead == true: - queue_free() -" - [sub_resource type="RectangleShape2D" id="1"] size = Vector2(16, 16) [node name="Player" type="CharacterBody2D"] -position = Vector2(50, 600) -script = SubResource("GDScript_mix1s") +position = Vector2(8, 8) +script = ExtResource("1_a5mv4") [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("2") diff --git a/game/characters/victor/Victor.gd b/game/characters/victor/Victor.gd index 725babe..55b3d32 100644 --- a/game/characters/victor/Victor.gd +++ b/game/characters/victor/Victor.gd @@ -1,18 +1,24 @@ extends CharacterBody2D var SPEED = 100 +const JUMP_VELOCITY = -500.0 var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var player +var chase = true func _physics_process(delta): velocity.y += gravity * delta - player = get_node("../Player") - var direction = (player.position - self.position).normalized() - velocity.x = direction.x * SPEED - move_and_slide() + if chase == true: + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + player = get_node("../Player") + var direction = (player.position - self.position).normalized() + velocity.x = direction.x * SPEED + move_and_slide() func _on_player_collision_body_entered(body): if body.name == "Player": print("Killed player") - Stats.playerdead == true + chase = false + Stats.playerdead = true |
