From 42eb81d7d479e307a49123aa1ed222db0dfbcbad Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Tue, 1 Oct 2024 06:04:10 -0400 Subject: [PATCH] week 5 --- .../assets/graphics/enemies/slime_purple.png | Bin 0 -> 1030 bytes .../graphics/enemies/slime_purple.png.import | 34 ++++++ .../assets/graphics/pickups/coin.png | Bin 0 -> 500 bytes .../assets/graphics/pickups/coin.png.import | 34 ++++++ .../player/death/Player Death 64x64.png | Bin 0 -> 1584 bytes .../death/Player Death 64x64.png.import | 34 ++++++ augustgamecourse/project.godot | 4 + augustgamecourse/scenes/badguy.tscn | 74 ++++++++++++ augustgamecourse/scenes/coin.tscn | 114 ++++++++++++++++++ augustgamecourse/scenes/game.tscn | 32 ++++- augustgamecourse/scenes/player.tscn | 80 +++++++++++- augustgamecourse/scripts/badguy.gd | 38 ++++++ augustgamecourse/scripts/coin.gd | 18 +++ augustgamecourse/scripts/game_controller.gd | 27 +++++ augustgamecourse/scripts/player.gd | 6 +- .../scripts/resources/character_stats.gd | 5 + .../scripts/resources/player.tres | 9 ++ augustgamecourse/scripts/resources/slime.tres | 9 ++ augustgamecourse/scripts/scene_manager.gd | 25 ++++ 19 files changed, 537 insertions(+), 6 deletions(-) create mode 100644 augustgamecourse/assets/graphics/enemies/slime_purple.png create mode 100644 augustgamecourse/assets/graphics/enemies/slime_purple.png.import create mode 100644 augustgamecourse/assets/graphics/pickups/coin.png create mode 100644 augustgamecourse/assets/graphics/pickups/coin.png.import create mode 100644 augustgamecourse/assets/graphics/player/death/Player Death 64x64.png create mode 100644 augustgamecourse/assets/graphics/player/death/Player Death 64x64.png.import create mode 100644 augustgamecourse/scenes/badguy.tscn create mode 100644 augustgamecourse/scenes/coin.tscn create mode 100644 augustgamecourse/scripts/badguy.gd create mode 100644 augustgamecourse/scripts/coin.gd create mode 100644 augustgamecourse/scripts/game_controller.gd create mode 100644 augustgamecourse/scripts/resources/character_stats.gd create mode 100644 augustgamecourse/scripts/resources/player.tres create mode 100644 augustgamecourse/scripts/resources/slime.tres diff --git a/augustgamecourse/assets/graphics/enemies/slime_purple.png b/augustgamecourse/assets/graphics/enemies/slime_purple.png new file mode 100644 index 0000000000000000000000000000000000000000..76f564e1d18d3f4b59c032ee8233ebf4665af431 GIT binary patch literal 1030 zcmeAS@N?(olHy`uVBq!ia0vp^2|(<@!3HEb(?2AGr~;43Vg?3oVGw3ym^DX&fq{94 zr;B4q#hkZu_UB)A5IH_yFgSBs)oT$}vmn=*zw9@ptqPdBe?d}nV{fk>$4CBvg?)Ed z_vO50>IiWPSm-r%m!<3^wh~P~_4RS~ zpI=Gub+-QhIeq%h`RaxX{5TJNc>dLzfkEQSwe9u4|AzdIT*^2{!A86~-QWe|7ymwB zC>Ti{|81}_`+UPPl@+TN=sEg&On58UrMgnvLQXF0_ys@bQ1@EdnLWo=s>t&5b6*sD zcFMcwU?tm(D_Xg)W-Wc$-E!h}Crjk()1K3gUwWA?xq;Wdw18cHo3k~Zx-$Fb`AU$*-@DD zmGPf?jG6V$dCTQj>{2>(Zt>F0fcfj}50vb4xa*Xko3|y%e%9UPUyOMTg5ncDvEEv- z-pIj{ckVgygWdnMA2Z(bzqjb#^{`seQ^pPQ$9_6a&90O2#S*<mC1;UMyZZkxfN& z@uKHWkGnrH91Z`H^EmwCk41a3FUGWg-!^5J_|wx1K5Uz!#D3x7Zw}ELVrNTt9P8IR z_1(WOXsY%rc>^6i*W&vj&+HC_UuW8s@vbNLPX_a^r!6hi!Wct>kSmw76A*+mkqIDVjdDL!Rb}5E?Td;C@2y9S zHih2xK(yTWh+gXdrTqK8Uwx^_$MoI4V|67Hn26^Qp-rJ*c_3P5d_*tx|6%^yEznE& zeE6^KHvJ|vI7934d=L#ytZIR)9hxaN1Jm8sZ6_j{Yx1#nTWt!D2<;1?{VNX?M*l~R zzukKP+i+D+FAlB;7qkOXfaGA?&h>EX&+$Oxqgs>{d4C#zhd05hUS`kO@{&+Bb`?-H zKXwYn7Ms9B!`F}PQh%-o65r;4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yt;sd@Om-+idk7Xb#UH{=Le13eompX2x~$9Y-!IgB68~B zyi{J#W;{RWh$LfR<KYVZZqWO8bH?sI@P$~?|dU0L)`^qi#E7$tnRVqHt&p#k4+|J8itGi6`?;Vjl zpOKL{5zF>D;r#Dh{lkce6E%P!f8(`U{=)6N6z;@7-Yvdj;cGcfwZ+%9BX{>hB>MZV$nuSDQ@E3N7X|*9mX4Yo5s`dbL6(2DdxRLn z%dhdsUC5ucs-FKg7T?MM!rRCA4gfsfX#w9wcEVRIt6YF5ZGK9_ix~OK8l6As9B{qu zSlcEsg}29acP_^cDlB{(QsD0yIxjCjy#9St!_$@1_XNH)!Gj0000 void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + if cast_right.is_colliding(): + if not cast_right.get_collider().is_in_group("player"): + direction = -1 + sprite.flip_h = true + if cast_left.is_colliding(): + if not cast_left.get_collider().is_in_group("player"): + direction = 1 + sprite.flip_h = false + if not cast_floor_right.is_colliding(): + direction = -1 + sprite.flip_h = true + if not cast_floor_left.is_colliding(): + direction = 1 + sprite.flip_h = false + position.x += direction * speed * delta + + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("player"): + playerDamage.emit() diff --git a/augustgamecourse/scripts/coin.gd b/augustgamecourse/scripts/coin.gd new file mode 100644 index 0000000..f9240c0 --- /dev/null +++ b/augustgamecourse/scripts/coin.gd @@ -0,0 +1,18 @@ +extends Area2D + +signal coinCollected + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("player"): + coinCollected.emit() + queue_free() diff --git a/augustgamecourse/scripts/game_controller.gd b/augustgamecourse/scripts/game_controller.gd new file mode 100644 index 0000000..02656ee --- /dev/null +++ b/augustgamecourse/scripts/game_controller.gd @@ -0,0 +1,27 @@ +extends Node + +var coinsCollected:int = 0 +var player:Resource + +signal playerDeath + +func _ready() -> void: + print("Game controller is ready") + player = load("res://scripts/resources/player.tres") + + +func coinCollected(): + coinsCollected +=1 + print("Game Controller Coin Collected : "+str(coinsCollected)) + +func resetPlayer(): + player.health = player.max_health + +func playerDamage(): + player.health -= 20 + print("Player health is : "+str(player.health) ) + #is the player dead? + if player.health <= 0: + #kill him + playerDeath.emit() + diff --git a/augustgamecourse/scripts/player.gd b/augustgamecourse/scripts/player.gd index 0fb7453..ea67ed5 100644 --- a/augustgamecourse/scripts/player.gd +++ b/augustgamecourse/scripts/player.gd @@ -19,7 +19,11 @@ var pushTarget var bullet = preload("res://scenes/bullet.tscn") - +func killPlayer(): + print("kill the player") + #play death animation + playerSprite.play("death") + func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): diff --git a/augustgamecourse/scripts/resources/character_stats.gd b/augustgamecourse/scripts/resources/character_stats.gd new file mode 100644 index 0000000..d34f911 --- /dev/null +++ b/augustgamecourse/scripts/resources/character_stats.gd @@ -0,0 +1,5 @@ +class_name CharacterStats extends Resource + +@export var max_health:int = 100 +@export var starting_health: int = 100 +@export var health: int = 100 diff --git a/augustgamecourse/scripts/resources/player.tres b/augustgamecourse/scripts/resources/player.tres new file mode 100644 index 0000000..651b6a3 --- /dev/null +++ b/augustgamecourse/scripts/resources/player.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://koxvwi31cjtf"] + +[ext_resource type="Script" path="res://scripts/resources/character_stats.gd" id="1_mwxs7"] + +[resource] +script = ExtResource("1_mwxs7") +max_health = 100 +starting_health = 100 +health = 100 diff --git a/augustgamecourse/scripts/resources/slime.tres b/augustgamecourse/scripts/resources/slime.tres new file mode 100644 index 0000000..98ab6aa --- /dev/null +++ b/augustgamecourse/scripts/resources/slime.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://edb4xjspowwc"] + +[ext_resource type="Script" path="res://scripts/resources/character_stats.gd" id="1_6yxqy"] + +[resource] +script = ExtResource("1_6yxqy") +max_health = 50 +starting_health = 50 +health = 50 diff --git a/augustgamecourse/scripts/scene_manager.gd b/augustgamecourse/scripts/scene_manager.gd index aa88beb..da43279 100644 --- a/augustgamecourse/scripts/scene_manager.gd +++ b/augustgamecourse/scripts/scene_manager.gd @@ -5,6 +5,10 @@ var bulletPool:Array = [] # crate stuff var cratePool:Array = [] @onready var box_trap_target: Node2D = $"../BoxTrapTarget" +@onready var coins: Node = $"../coins" +@onready var enemies: Node = $"../enemies" +@onready var player: CharacterBody2D = $"../CharacterBody2D" +@onready var timer: Timer = $Timer # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -13,6 +17,17 @@ func _ready() -> void: if obj.is_in_group("pushables"): cratePool.push_back(obj) print("Total crates on screen : "+str(cratePool.size() ) ) + for n in coins.get_children(): + #hook up the coinCollected signal + print("coin found") + n.coinCollected.connect(GameController.coinCollected) + # Enemy routine + for n in enemies.get_children(): + if n is Enemy: + #wire up the signal + n.playerDamage.connect(GameController.playerDamage) + #GameController signals + GameController.playerDeath.connect(killPlayer) func boxTrap(): print("Trigger a box trap!") @@ -47,3 +62,13 @@ func crateFactory(): var myCrate = crate.instantiate() myCrate.add_to_group("pushables") return myCrate + +func killPlayer(): + print("kill the player now") + player.killPlayer() + timer.start(3) + + +func resetWorld(): + GameController.resetPlayer() + get_tree().reload_current_scene()