game manager and data objects

This commit is contained in:
winniewk committed 2024-08-19 21:11:17 -04:00
1 parent d4b5181c01
commit 6fcd33bb18
43 files changed
+582 -145

No files matched your search

+17 -8
View File
@@ -13,6 +13,9 @@ extends CharacterBody2D
@onready var animated_sprite = $AnimatedSprite2D
signal deathComplete
var currentPlaying = "idle"
var faceLeft = false
var pushLeftEnabled = false
var pushRightEnabled = false
@@ -23,9 +26,10 @@ var bullet = preload("res://scenes/bullet.tscn")
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func die():
print("kill the player")
animated_sprite.play("death")
currentPlaying = "death"
animated_sprite.play(currentPlaying)
living = false
func _physics_process(delta):
@@ -73,27 +77,27 @@ func _physics_process(delta):
velocity.x = move_toward(velocity.x, 0, SPEED)
if is_on_floor():
if direction==0:
animated_sprite.play("idle")
currentPlaying = "idle"
animated_sprite.play(currentPlaying)
else:
animated_sprite.play("run")
currentPlaying = "run"
animated_sprite.play(currentPlaying)
else:
animated_sprite.play("jump")
currentPlaying = "jump"
animated_sprite.play(currentPlaying)
move_and_slide()
if right_ray.is_colliding():
print("right ray is colliding")
var collider = right_ray.get_collider()
#what did we hit?
if collider is Node:
if collider.is_in_group("boxes"):
print("This is a pushable box")
pushRightEnabled = true
pushTarget = collider
else:
pushRightEnabled = false
if left_ray.is_colliding():
print("left ray is colliding")
var collider = left_ray.get_collider()
if collider is Node:
if collider.is_in_group("boxes"):
@@ -107,3 +111,8 @@ func _physics_process(delta):
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal()* BUMP_FORCE)
func _on_animation_finished():
if currentPlaying == "death":
deathComplete.emit()
+21
View File
@@ -0,0 +1,21 @@
extends Node
var player: Resource
var coinCollectedTotal:int = 0
# Called when the node enters the scene tree for the first time.
func _ready():
print("GameManager is here, queer, get used to it!")
player = load("res://scripts/resources/player_stats.tres")
func coinCollected():
coinCollectedTotal += 1
print("coins collected"+str(coinCollectedTotal))
func playerDamage():
player.health -= 20
print("Player health is now"+str(player.health))
func resetPlayer():
player.health = player.max_health
func _process(delta):
pass
+5 -4
View File
@@ -1,4 +1,4 @@
extends Area2D
class_name BadGuy extends Area2D
const speed = 60
var direction = 1
@@ -7,7 +7,9 @@ var direction = 1
@onready var right_floor_cast = $rightFloorCast
@onready var left_floor_cast = $leftFloorCast
@onready var sprite = $AnimatedSprite2D
@onready var game = %GameController
signal playerDamage
# Called when the node enters the scene tree for the first time.
func _ready():
@@ -34,7 +36,6 @@ func _process(delta):
func _on_body_entered(body):
print("something hit the bad guy")
if body.is_in_group("player"):
game.playerDeath()
playerDamage.emit()
+3 -13
View File
@@ -1,19 +1,9 @@
extends Area2D
@onready var game = %GameController
# 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
class_name Coin extends Area2D
signal coinCollected
func _on_body_entered(body):
if body.is_in_group("player"):
print("something hit the coin")
game.coinCollected()
coinCollected.emit()
queue_free()
+28 -13
View File
@@ -4,18 +4,24 @@ var myBox = preload("res://scenes/crate.tscn")
@onready var box_trap = $"../BoxTrap"
@onready var timer = $Timer
@onready var player = $"../CharacterBody2D"
@onready var coins = $"../Coins"
@onready var enemies = $"../enemies"
@onready var ui = $"../CanvasLayer/UI"
var totalCoins = 0
# 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.
GameManager.resetPlayer()
for n in coins.get_children():
if n is Coin:
#wire up our listener
n.coinCollected.connect(_on_coin_coin_collected)
for n in enemies.get_children():
if n is BadGuy:
n.playerDamage.connect(playerDamage)
func _process(delta):
pass
if GameManager.player.health <= 0 && player.living:
player.die()
func _on_area_2d_areatrigger(effect, body):
@@ -31,12 +37,21 @@ func _on_area_2d_areatrigger(effect, body):
box.position = box_trap.position
"powerup":
print("you got power")
func coinCollected():
totalCoins += 1
print("game controller will add coin" + str(totalCoins) )
func playerDeath():
player.die()
timer.start()
func resetWorld():
get_tree().reload_current_scene()
func _on_coin_coin_collected():
GameManager.coinCollected()
ui.coinUpdate(GameManager.coinCollectedTotal)
func playerDamage():
GameManager.playerDamage()
ui.healthUpdate(GameManager.player.health)
func _on_death_complete():
#This is where we reset the world
timer.start(.5)
+5
View File
@@ -0,0 +1,5 @@
class_name Character extends Resource
@export var max_health: int = 100
@export var starting_health: int = 100
@export var health: int = 100
+9
View File
@@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="Character" load_steps=2 format=3 uid="uid://c0n0yean36qm3"]
[ext_resource type="Script" path="res://scripts/resources/character_stats.gd" id="1_q0ae6"]
[resource]
script = ExtResource("1_q0ae6")
max_health = 100
starting_health = 100
health = 100
+9
View File
@@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="Character" load_steps=2 format=3 uid="uid://dbn3ku6rpqrbh"]
[ext_resource type="Script" path="res://scripts/resources/character_stats.gd" id="1_1s65d"]
[resource]
script = ExtResource("1_1s65d")
max_health = 50
starting_health = 50
health = 50
+11
View File
@@ -0,0 +1,11 @@
extends Control
@onready var health = $VBoxContainer/HBoxContainer/MarginContainer/Health
@onready var coins = $VBoxContainer/HBoxContainer/MarginContainer2/Coins
func _ready():
coinUpdate(GameManager.coinCollectedTotal)
healthUpdate(GameManager.player.health)
func healthUpdate(amt):
health.text = "Health : "+str(amt)
func coinUpdate(amt):
coins.text = "Coins : "+str(amt)