Week6, Game Manager, Data objects

This commit is contained in:
bip committed 2024-08-19 21:18:41 -04:00
1 parent 21253ccc12
commit b73c6f882f
148 files changed
+794 -92

No files matched your search

+17 -6
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
@@ -24,11 +27,9 @@ 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 living_status():
return living
func die():
print("kill the player")
currentPlaying = "death"
animated_sprite.play("death")
living = false
@@ -79,11 +80,14 @@ 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():
@@ -111,3 +115,10 @@ 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":
print("Animation is Finished")
deathComplete.emit()
+24
View File
@@ -0,0 +1,24 @@
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!")
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
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
+6
View File
@@ -0,0 +1,6 @@
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://gq7wgc8p4582"]
[ext_resource type="Script" path="res://scripts/Resources/character_stats.gd" id="1_b8trt"]
[resource]
script = ExtResource("1_b8trt")
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://bfoxlbp2n4cr7"]
[ext_resource type="Script" path="res://scripts/Resources/character_stats.gd" id="1_vykut"]
[resource]
script = ExtResource("1_vykut")
max_health = 50
starting_health = 50
health = 50
+5 -4
View File
@@ -1,4 +1,4 @@
extends Area2D
class_name badguy extends Area2D
const speed = 60
var direction = -1
@@ -6,10 +6,11 @@ var direction = -1
@onready var left_cast = $LeftCast
@onready var right_floor_cast = $RightFloorCast
@onready var left_floor_cast = $LeftFloorCast
@onready var game = %GameController
@onready var player = $"../CharacterBody2D"
signal playerDamage
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
@@ -32,5 +33,5 @@ func _process(delta):
func _on_body_entered(body):
if body.is_in_group("player") and player.living_status():
game.playerDeath()
if body.is_in_group("player"):
playerDamage.emit()
+3 -13
View File
@@ -1,19 +1,9 @@
extends Area2D
@onready var game_controller = %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_controller.coinCollected()
coinCollected.emit()
queue_free()
+33 -7
View File
@@ -4,9 +4,26 @@ var crate = preload("res://scenes/crate.tscn")
@onready var boxtrap = $"../crates/boxtrap"
@onready var timer = $Timer
@onready var player = $"../CharacterBody2D"
@onready var coins = $"../Coins"
@onready var enemies = $"../Enemies"
@onready var ui = $"../CanvasLayer/UI"
func _ready():
GameManager.resetPlayer()
ui.coinsUpdate(GameManager.coinCollectedTotal)
ui.healthUpdate(GameManager.player.health)
for n in coins.get_children():
if n is Coin:
n.coinCollected.connect(_on_area_2d_3_coin_collected)
for n in enemies.get_children():
if n is badguy:
n.playerDamage.connect(_on_badguy_player_damage)
func _process(delta):
if GameManager.player.health <= 0 and player.living:
player.die()
var totalCoins = 0
func _on_area_2d_areatrigger(effect, body):
print("Game Controller sees the trigger "+effect)
@@ -22,15 +39,24 @@ func _on_area_2d_areatrigger(effect, body):
"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_area_2d_3_coin_collected():
print("SceneManager sees new coin")
GameManager.coinCollected()
ui.coinsUpdate(GameManager.coinCollectedTotal)
func _on_badguy_player_damage():
print("run into bad guy")
GameManager.playerDamage()
ui.healthUpdate(GameManager.player.health)
func _on_death_complete():
#This is where we reset the world
timer.start(0.5)
+9
View File
@@ -0,0 +1,9 @@
extends Control
@onready var health = $VBoxContainer/HBoxContainer/MarginContainer/Health
@onready var coins = $VBoxContainer/HBoxContainer/MarginContainer2/Coins
func healthUpdate(amt):
health.text = "Health : " + str(amt)
func coinsUpdate(amt):
coins.text = "Coins : " + str(amt)