Death implemented, added money spent, pause screen

This commit is contained in:
Andrew Lee 2023-06-25 15:43:55 -04:00
parent dbb42c99e0
commit a4f737b2be
Signed by: andrew
GPG key ID: 4DCE67C47836D125
10 changed files with 140 additions and 77 deletions

5
.gitignore vendored
View file

@ -1,5 +1,7 @@
# Godot-specific ignores # Godot 4+ specific ignores
.godot/ .godot/
# Godot-specific ignores
.import/ .import/
export.cfg export.cfg
export_presets.cfg export_presets.cfg
@ -10,3 +12,4 @@ export_presets.cfg
# Mono-specific ignores # Mono-specific ignores
.mono/ .mono/
data_*/ data_*/
mono_crash.*.json

8
game/Game.gd Normal file
View file

@ -0,0 +1,8 @@
extends Node2D
func _input(event):
if event.is_action_pressed("pause"):
var new_pause_state = not get_tree().paused
get_tree().paused = new_pause_state
visible = new_pause_state
$Pause.show()

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,6 @@
extends CharacterBody2D extends CharacterBody2D
const JUMP_VELOCITY = -500.0
@export var SPEED = 300.0
var JUMP_VELOCITY = -400.0
# Get the gravity from the project settings to be synced with RigidBody nodes. # Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@ -14,15 +12,15 @@ func _physics_process(delta):
velocity.y += gravity * delta velocity.y += gravity * delta
# Handle Jump. # 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 velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration. # Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions. # As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("left", "right") velocity.x = 1 * Stats.playerspeed
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide() move_and_slide()
if Stats.playerdead == true:
queue_free()
get_tree().paused = true
$"../Game Over".show()

View file

@ -1,40 +1,14 @@
[gd_scene load_steps=4 format=3 uid="uid://l0lnby3rm6fj"] [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"] [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"] [sub_resource type="RectangleShape2D" id="1"]
size = Vector2(16, 16) size = Vector2(16, 16)
[node name="Player" type="CharacterBody2D"] [node name="Player" type="CharacterBody2D"]
position = Vector2(50, 600) position = Vector2(8, 8)
script = SubResource("GDScript_mix1s") script = ExtResource("1_a5mv4")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2") texture = ExtResource("2")

View file

@ -1,11 +1,16 @@
extends CharacterBody2D extends CharacterBody2D
var SPEED = 100 var SPEED = 100
const JUMP_VELOCITY = -500.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var player var player
var chase = true
func _physics_process(delta): func _physics_process(delta):
velocity.y += gravity * delta velocity.y += gravity * delta
if chase == true:
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
player = get_node("../Player") player = get_node("../Player")
var direction = (player.position - self.position).normalized() var direction = (player.position - self.position).normalized()
velocity.x = direction.x * SPEED velocity.x = direction.x * SPEED
@ -15,4 +20,5 @@ func _physics_process(delta):
func _on_player_collision_body_entered(body): func _on_player_collision_body_entered(body):
if body.name == "Player": if body.name == "Player":
print("Killed player") print("Killed player")
Stats.playerdead == true chase = false
Stats.playerdead = true

21
game/objects/Shop.gd Normal file
View file

@ -0,0 +1,21 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_area_2d_body_entered(body):
if body.name == "Player":
Stats.money += 5
var popuptween = create_tween()
popuptween.tween_property($"../MoneySpent", "position", position - Vector2(888,0), 0.2)
print("Oh no! Victor spent some money!")
Stats.victorannoyed += 1
self.queue_free()

View file

@ -1,11 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://dhb4sjfe6w3uh"] [gd_scene load_steps=4 format=3 uid="uid://dhb4sjfe6w3uh"]
[ext_resource type="Texture2D" uid="uid://bac68xxoapn2c" path="res://assets/images/green.png" id="1"] [ext_resource type="Texture2D" uid="uid://bac68xxoapn2c" path="res://assets/images/green.png" id="1"]
[ext_resource type="Script" path="res://game/objects/Shop.gd" id="1_qgosu"]
[sub_resource type="RectangleShape2D" id="1"] [sub_resource type="RectangleShape2D" id="1"]
size = Vector2(16, 16) size = Vector2(12, 12)
[node name="Shop" type="Node2D"] [node name="Shop" type="Node2D"]
script = ExtResource("1_qgosu")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1") texture = ExtResource("1")
@ -14,3 +16,6 @@ texture = ExtResource("1")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("1") shape = SubResource("1")
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]

View file

@ -1,5 +1,7 @@
extends Node extends Node
var money = 0 var money = 0
var initspeed = 10 var playerspeed = 110
var playerdead = false var playerdead = false
var victorannoyed = 0
var cutscene = false

View file

@ -7,7 +7,6 @@
[sub_resource type="GDScript" id="GDScript_kjhan"] [sub_resource type="GDScript" id="GDScript_kjhan"]
script/source = "extends Control script/source = "extends Control
func _on_Play_button_up(): func _on_Play_button_up():
if get_tree().change_scene_to_file(\"res://game/Game.tscn\") != OK: if get_tree().change_scene_to_file(\"res://game/Game.tscn\") != OK:
print(\"There was an error trying to load the scene...\") print(\"There was an error trying to load the scene...\")