From 9a70b862ec4c58d421e67df4c72a16a03e97e966 Mon Sep 17 00:00:00 2001 From: KieranScott Date: Mon, 30 Sep 2024 21:14:46 -0400 Subject: [PATCH] we add simple enemy ai and added gamemanager --- .../Assets/Graphics/Enemies/slime_green.png | Bin 0 -> 908 bytes .../Graphics/Enemies/slime_green.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 ++++++ august26godotcompkieran/Scenes/Coin.tscn | 113 ++++++++++++++++++ august26godotcompkieran/Scenes/Game.tscn | 34 +++++- august26godotcompkieran/Scenes/Player.tscn | 86 ++++++++++++- august26godotcompkieran/Scenes/Slime.tscn | 75 ++++++++++++ .../Sripts/Resources/character_stats.gd | 5 + .../Sripts/Resources/player.tres | 9 ++ .../Sripts/Resources/slime.tres | 9 ++ august26godotcompkieran/Sripts/coin.gd | 17 +++ .../Sripts/game_controller.gd | 24 ++++ august26godotcompkieran/Sripts/player.gd | 6 +- .../Sripts/scene_manager.gd | 25 ++++ august26godotcompkieran/Sripts/slime.gd | 39 ++++++ august26godotcompkieran/project.godot | 4 + 19 files changed, 540 insertions(+), 8 deletions(-) create mode 100644 august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png create mode 100644 august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png.import create mode 100644 august26godotcompkieran/Assets/Graphics/Pickups/coin.png create mode 100644 august26godotcompkieran/Assets/Graphics/Pickups/coin.png.import create mode 100644 august26godotcompkieran/Assets/Graphics/Player/Death/Player Death 64x64.png create mode 100644 august26godotcompkieran/Assets/Graphics/Player/Death/Player Death 64x64.png.import create mode 100644 august26godotcompkieran/Scenes/Coin.tscn create mode 100644 august26godotcompkieran/Scenes/Slime.tscn create mode 100644 august26godotcompkieran/Sripts/Resources/character_stats.gd create mode 100644 august26godotcompkieran/Sripts/Resources/player.tres create mode 100644 august26godotcompkieran/Sripts/Resources/slime.tres create mode 100644 august26godotcompkieran/Sripts/coin.gd create mode 100644 august26godotcompkieran/Sripts/game_controller.gd create mode 100644 august26godotcompkieran/Sripts/slime.gd diff --git a/august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png b/august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png new file mode 100644 index 0000000000000000000000000000000000000000..a21cb6fa253a2142be9bdad248238299dce6e695 GIT binary patch literal 908 zcmeAS@N?(olHy`uVBq!ia0vp^2|(<@!3HEb(?2AGr~;43Vg?3oVGw3ym^DX&fq~i1 z)5S5QV$Rz+)_J!b1lrmiqe6M+oJ(NX&NN4Phv|b`z4{NYP5+>JWrs--17qeTsRD5g z!(g=zZP^CRNrf+-+NH@KR$Td0s&mngVw3+xu0?EXcCBM}?K8i`C}Wk?V1NhZ=gNnL znwH6IezGFZ!~9a6?RHUyhPV4>Uu{?_FnfW>zS{qPKK*<4uVTZ$ce_63>1Q2~5psEW zx_|#J@#X97|9=sRdr@7gG^K>%S{q!=tk;zc{umA757CW^gF~?Y* zzL@Q4_FeSScBuyG05^_0b=8H-_E|RV`0{(oCG+JLF?=tr`x)+BFt>laYl`#E_4#US z^)8yV;ydQc)Lt=IzWv`O|NWa{=kBflzObA3)w^Aa^ZVqko^^cn|Ic5O3*}M*OaJxH zkT2-?mBRcbPJn+~%B^6jY(87p9(Mo#>Q7(h~rm&XFcnS2%Pu(#j4I<=R1EbeZ((y;O5o?wIy5Q|G$2J-k$H; z`tsE}e}z7FZ&xe&&T>;Ie$t&EuHB#RoL~6BudegQ(e6(xj^8Zaa&Il$W#4ySE~~5m zTfmt7%O>)U?6I5hEH)mc^Zy7i2AYE5_cS8+Pd zEL*XBwVBru|99M6hFkZ|y>aAN9DmO}@fM%8>yNRi-8VbG`yY1_&*gmzOfw=rUyaF+ zc6a>UWOJqT@=>+Yz0nhwE57CCn(*tmRI)?YzOxPXujg|0Ui|Qj8JN8oJYD@<);T3K F0RY5^vzq__ literal 0 HcmV?d00001 diff --git a/august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png.import b/august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png.import new file mode 100644 index 0000000..03b8d90 --- /dev/null +++ b/august26godotcompkieran/Assets/Graphics/Enemies/slime_green.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://lpbq4n22w1ig" +path="res://.godot/imported/slime_green.png-ebdb998e3765d428d6dd56d872c89a71.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Enemies/slime_green.png" +dest_files=["res://.godot/imported/slime_green.png-ebdb998e3765d428d6dd56d872c89a71.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/august26godotcompkieran/Assets/Graphics/Pickups/coin.png b/august26godotcompkieran/Assets/Graphics/Pickups/coin.png new file mode 100644 index 0000000000000000000000000000000000000000..01ae33d70b398db7f1f7bcafe883a0a469805201 GIT binary patch literal 500 zcmV^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=uy!A4;g>*6iCRL!wF!o{9{X0YM%Mf@U=DvM2}Kx zY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i{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: + pass + + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("Player"): + coincollected.emit() + queue_free() diff --git a/august26godotcompkieran/Sripts/game_controller.gd b/august26godotcompkieran/Sripts/game_controller.gd new file mode 100644 index 0000000..720b329 --- /dev/null +++ b/august26godotcompkieran/Sripts/game_controller.gd @@ -0,0 +1,24 @@ +extends Node + +var coinscollected:int = 0 +var player:Resource + +signal playerdeath +func _ready() -> void: + print("Game Controller is on") + player = load("res://Sripts/Resources/player.tres") + +func coincollected(): + coinscollected +=1 + print("Gamecontroller Coin Collected : "+str(coinscollected) ) +func resetplayer(): + player.current_health = player.max_health + +func playerdamaged(): + player.current_health -= 20 + print("player health is : "+str(player.current_health)) + # is player dead + if player.current_health <=0: + #Death + playerdeath.emit() + diff --git a/august26godotcompkieran/Sripts/player.gd b/august26godotcompkieran/Sripts/player.gd index 7c1d2de..1633a64 100644 --- a/august26godotcompkieran/Sripts/player.gd +++ b/august26godotcompkieran/Sripts/player.gd @@ -19,7 +19,11 @@ var pushTarget var bullet = preload("res://Scenes/Bullet.tscn") - +func killplayer(): + print("dying") + #play death + playerSprite.play("Death") + func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): diff --git a/august26godotcompkieran/Sripts/scene_manager.gd b/august26godotcompkieran/Sripts/scene_manager.gd index df8bceb..b9cf5e1 100644 --- a/august26godotcompkieran/Sripts/scene_manager.gd +++ b/august26godotcompkieran/Sripts/scene_manager.gd @@ -5,6 +5,10 @@ var bulletPool:Array = [] # crate pool thing 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 deathdelay: Timer = $Timer func _ready() -> void: # pool crates @@ -12,6 +16,18 @@ func _ready() -> void: if obj.is_in_group("Pushable"): cratePool.push_back(obj) print("Total crate in play: "+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.playerdamaged) + # gamecontroller signals + GameController.playerdeath.connect(killplayer) + func boxTrap(): print("boxTrap active") @@ -46,3 +62,12 @@ func crateFactory(): var myCrate = crate.instantiate() myCrate.add_to_group("Pushable") return myCrate + +func killplayer(): + print("kill player") + player.killplayer() + deathdelay.start(1) + +func resetworld(): + GameController.resetplayer() + get_tree().reload_current_scene() diff --git a/august26godotcompkieran/Sripts/slime.gd b/august26godotcompkieran/Sripts/slime.gd new file mode 100644 index 0000000..29f55b4 --- /dev/null +++ b/august26godotcompkieran/Sripts/slime.gd @@ -0,0 +1,39 @@ +class_name Enemy extends Area2D + +signal playerdamage +@onready var cast_right: RayCast2D = $CastRight +@onready var cast_left: RayCast2D = $CastLeft +@onready var cast_floor_right: RayCast2D = $CastFloorRight +@onready var cast_floor_left: RayCast2D = $CastFloorLeft +const speed = 60 +var direction = 1 +@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D + +# 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: + if cast_right.is_colliding(): + if not cast_right.get_collider().is_in_group("Player"): + direction = -1 + sprite.flip_h = true + position.x += direction * speed * delta + 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 + + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("Player"): + playerdamage.emit() + diff --git a/august26godotcompkieran/project.godot b/august26godotcompkieran/project.godot index 18ebfaa..8cf2fad 100644 --- a/august26godotcompkieran/project.godot +++ b/august26godotcompkieran/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://Scenes/Game.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +GameController="*res://Sripts/game_controller.gd" + [display] window/size/viewport_width=320