From 5ca3a193d19bfef66315a896db63eae20afe5c6d Mon Sep 17 00:00:00 2001 From: fabianainu Date: Mon, 16 Dec 2024 21:16:05 -0500 Subject: [PATCH] enemies, gamecontroller, playerdeath, coins --- .../assets/graphics/enemies/slime_green.png | Bin 0 -> 908 bytes .../graphics/enemies/slime_green.png.import | 34 ++++ fabigame/assets/graphics/pickups/coin.png | Bin 0 -> 500 bytes .../assets/graphics/pickups/coin.png.import | 34 ++++ .../player/dead/Player Death 64x64.png | Bin 0 -> 1584 bytes .../player/dead/Player Death 64x64.png.import | 34 ++++ .../player/hurt/Player Hurt 48x48.png | Bin 0 -> 1448 bytes .../player/hurt/Player Hurt 48x48.png.import | 34 ++++ fabigame/project.godot | 4 + fabigame/scenes/badguy.tscn | 73 +++++++ fabigame/scenes/coin.tscn | 113 +++++++++++ fabigame/scenes/dude.tscn | 116 ++++++++++- fabigame/scenes/game.tscn | 46 ++++- fabigame/scripts/badguy.gd | 40 ++++ fabigame/scripts/coin.gd | 11 + fabigame/scripts/dudecontroller.gd | 189 ++++++++++-------- fabigame/scripts/game_controller.gd | 34 ++++ fabigame/scripts/res/characterstats.gd | 6 + fabigame/scripts/res/dudestats.tres | 9 + fabigame/scripts/res/enemystats.tres | 9 + fabigame/scripts/scene_manager.gd | 37 +++- 21 files changed, 732 insertions(+), 91 deletions(-) create mode 100644 fabigame/assets/graphics/enemies/slime_green.png create mode 100644 fabigame/assets/graphics/enemies/slime_green.png.import create mode 100644 fabigame/assets/graphics/pickups/coin.png create mode 100644 fabigame/assets/graphics/pickups/coin.png.import create mode 100644 fabigame/assets/graphics/player/dead/Player Death 64x64.png create mode 100644 fabigame/assets/graphics/player/dead/Player Death 64x64.png.import create mode 100644 fabigame/assets/graphics/player/hurt/Player Hurt 48x48.png create mode 100644 fabigame/assets/graphics/player/hurt/Player Hurt 48x48.png.import create mode 100644 fabigame/scenes/badguy.tscn create mode 100644 fabigame/scenes/coin.tscn create mode 100644 fabigame/scripts/badguy.gd create mode 100644 fabigame/scripts/coin.gd create mode 100644 fabigame/scripts/game_controller.gd create mode 100644 fabigame/scripts/res/characterstats.gd create mode 100644 fabigame/scripts/res/dudestats.tres create mode 100644 fabigame/scripts/res/enemystats.tres diff --git a/fabigame/assets/graphics/enemies/slime_green.png b/fabigame/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/fabigame/assets/graphics/enemies/slime_green.png.import b/fabigame/assets/graphics/enemies/slime_green.png.import new file mode 100644 index 0000000..efd3c2d --- /dev/null +++ b/fabigame/assets/graphics/enemies/slime_green.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://grew2f48lbpx" +path="res://.godot/imported/slime_green.png-5261ffd1254c816fe62b35227a9aa11d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/enemies/slime_green.png" +dest_files=["res://.godot/imported/slime_green.png-5261ffd1254c816fe62b35227a9aa11d.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/fabigame/assets/graphics/pickups/coin.png b/fabigame/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#A;!e+4Y{Qh#m^NPMe5dkcj0f5`ZIy8@JYG2kpkh}LrU76{dHI?&Z}2LKX(>v1MX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kDtboV<8V;MH!JO{H}IM6?a#tYT1}N>;J~47D#d1F-pfZZ#j@ zZ3Hq8&1@O%^NpfyqeJX|TF~7H>u?&uZD4yb*P?B7XrF;AMJPXoaAJ&LlK;{Cd}PW) z)RKShrw{h^Z4{D!Bsrn{Dw#1cWa5}j1>dj;i%^~etgkJ&gqq}!0w#%~mi&H1F$S-R z+eU|6CN8%LWZ>4FSbiKUbdha!@ z?QwYZo8uN4{ZRfGN}2+h 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/fabigame/scripts/coin.gd b/fabigame/scripts/coin.gd new file mode 100644 index 0000000..096849b --- /dev/null +++ b/fabigame/scripts/coin.gd @@ -0,0 +1,11 @@ +class_name Coin extends Area2D + +signal coinCollected + + + + +func _on_body_entered(body: Node2D) -> void: + if body.is_in_group("player"): + coinCollected.emit() + queue_free() diff --git a/fabigame/scripts/dudecontroller.gd b/fabigame/scripts/dudecontroller.gd index 6cb76f4..06917d6 100644 --- a/fabigame/scripts/dudecontroller.gd +++ b/fabigame/scripts/dudecontroller.gd @@ -16,92 +16,119 @@ var pushTarget var pushLefEnabled = false var pushRightEnabled = false var isJumping = false + +var animPlaying = "idle" +var living = true + +signal playerDead + @onready var right_target: Node2D = $RightTarget @onready var left_target: Node2D = $LeftTarget +func hurtPlayer(amt): + print("Character knows it should be hurt") + animPlaying = "hurt" + playerSprite.play("Hurt") + +func killPlayer(): + if living: + living = false + print("MORRIDO") + animPlaying = "dead" + playerSprite.play("Dead") func _physics_process(delta: float) -> void: - # Add the gravity. - if not is_on_floor(): - velocity += get_gravity() * delta + if living and not animPlaying =="hurt": + # Add the gravity. + if not is_on_floor(): + velocity += get_gravity() * delta - # Handle jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY + # 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. - var direction := Input.get_axis("ui_left", "ui_right") - if Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft == false: - print("Shove a box") - pushTarget.apply_central_impulse(Vector2(1,0) * PUSHFORCE * 2) - pushRightEnabled = false - - if Input.is_action_just_pressed("shove") && faceLeft == true && pushLefEnabled == true: - pushTarget.apply_central_impulse(Vector2(-1,0) * PUSHFORCE * 2) - pushLefEnabled = false - - if Input.is_action_just_pressed("shoot"): - print("I'm an owl: Shoot shoot") - var myBullet = %SceneManager.bulletFactory() - if not faceLeft: - myBullet.transform = right_target.global_transform - myBullet.setSpeed(750) - if faceLeft == true: - myBullet.transform = left_target.global_transform - myBullet.setSpeed(-750) - - if direction: - velocity.x = direction * SPEED - if direction >0: - faceLeft = false - if direction <0: - faceLeft = true - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - - if faceLeft: - playerSprite.flip_h = true - else: - playerSprite.flip_h = false - - if is_on_floor(): - isJumping = false - if direction == 0: - playerSprite.play("Idle") - else: - playerSprite.play("Run") - else: - if not isJumping: - playerSprite.play("Jump") - isJumping = true - - move_and_slide() - if right_ray.is_colliding(): - print("Something is on my right") - if not faceLeft: - var collider = right_ray.get_collider() - if collider is Node: - if collider.is_in_group("box"): - print("This is a pushable box") - pushTarget = collider - pushRightEnabled = true - else: - pushRightEnabled = false - - if left_ray.is_colliding(): - print("Something is on my left") + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var direction := Input.get_axis("ui_left", "ui_right") + if Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft == false: + print("Shove a box") + pushTarget.apply_central_impulse(Vector2(1,0) * PUSHFORCE * 2) + pushRightEnabled = false + + if Input.is_action_just_pressed("shove") && faceLeft == true && pushLefEnabled == true: + pushTarget.apply_central_impulse(Vector2(-1,0) * PUSHFORCE * 2) + pushLefEnabled = false + + if Input.is_action_just_pressed("shoot"): + print("I'm an owl: Shoot shoot") + var myBullet = %SceneManager.bulletFactory() + if not faceLeft: + myBullet.transform = right_target.global_transform + myBullet.setSpeed(750) + if faceLeft == true: + myBullet.transform = left_target.global_transform + myBullet.setSpeed(-750) + + if direction: + velocity.x = direction * SPEED + if direction >0: + faceLeft = false + if direction <0: + faceLeft = true + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + if faceLeft: - var collider = left_ray.get_collider() - if collider is Node: - if collider.is_in_group("box"): - print("I can shove this box") - pushTarget = collider - pushLefEnabled = true - else: - pushLefEnabled = false - - for i in get_slide_collision_count(): - var c = get_slide_collision(i) - if c.get_collider() is RigidBody2D: - c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_FORCE) + playerSprite.flip_h = true + else: + playerSprite.flip_h = false + + if is_on_floor(): + isJumping = false + if direction == 0: + playerSprite.play("Idle") + else: + playerSprite.play("Run") + else: + if not isJumping: + playerSprite.play("Jump") + isJumping = true + + move_and_slide() + if right_ray.is_colliding(): + print("Something is on my right") + if not faceLeft: + var collider = right_ray.get_collider() + if collider is Node: + if collider.is_in_group("box"): + print("This is a pushable box") + pushTarget = collider + pushRightEnabled = true + else: + pushRightEnabled = false + + if left_ray.is_colliding(): + print("Something is on my left") + if faceLeft: + var collider = left_ray.get_collider() + if collider is Node: + if collider.is_in_group("box"): + print("I can shove this box") + pushTarget = collider + pushLefEnabled = true + else: + pushLefEnabled = false + + for i in get_slide_collision_count(): + 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() -> void: + if animPlaying == "hurt": + animPlaying ="idle" + if animPlaying == "dead": + ### emit a custom signal + playerDead.emit() + diff --git a/fabigame/scripts/game_controller.gd b/fabigame/scripts/game_controller.gd new file mode 100644 index 0000000..3cb1707 --- /dev/null +++ b/fabigame/scripts/game_controller.gd @@ -0,0 +1,34 @@ +extends Node + +var coinsCollected:int = 0 +var player:Resource + +signal playerHurt() +signal playerDeath() + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + player = load("res://scripts/res/dudestats.tres") + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + +func coinCollected(): + coinsCollected +=1 + print("Total coins collected "+str(coinsCollected) ) + +func playerDamage(): + if player.health > 0: + player.health -= 20 + if player.health <=0: + ##kill him + playerDeath.emit() + else: + ##damage him + playerHurt.emit(20) +func reset(): + player.health = player.max_health + coinsCollected = 0 + diff --git a/fabigame/scripts/res/characterstats.gd b/fabigame/scripts/res/characterstats.gd new file mode 100644 index 0000000..89ec76a --- /dev/null +++ b/fabigame/scripts/res/characterstats.gd @@ -0,0 +1,6 @@ +class_name CharacterStats extends Resource + + +@export var max_health:int = 100 +@export var starting_heatlh: int = 100 +@export var health: int = 100 diff --git a/fabigame/scripts/res/dudestats.tres b/fabigame/scripts/res/dudestats.tres new file mode 100644 index 0000000..1882f31 --- /dev/null +++ b/fabigame/scripts/res/dudestats.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://bo060uupgs5s0"] + +[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_8xb6q"] + +[resource] +script = ExtResource("1_8xb6q") +max_health = 100 +starting_heatlh = 100 +health = 100 diff --git a/fabigame/scripts/res/enemystats.tres b/fabigame/scripts/res/enemystats.tres new file mode 100644 index 0000000..0ed6cf6 --- /dev/null +++ b/fabigame/scripts/res/enemystats.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://dqihgguptx2it"] + +[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_qhki2"] + +[resource] +script = ExtResource("1_qhki2") +max_health = 50 +starting_heatlh = 50 +health = 50 diff --git a/fabigame/scripts/scene_manager.gd b/fabigame/scripts/scene_manager.gd index 56178d6..350bd0d 100644 --- a/fabigame/scripts/scene_manager.gd +++ b/fabigame/scripts/scene_manager.gd @@ -3,9 +3,32 @@ extends Node var bulletsFiredTotal := 0 var bulletsMadeTotal := 0 var bulletArray:Array = [] +@onready var coins: Node = $"../Coins" +@onready var bad_guys: Node = $"../BadGuys" + +@onready var player: CharacterBody2D = $"../CharacterBody2D" + + var bullet = preload("res://scenes/bullet.tscn") +func _ready() -> void: + ### coins loop + for n in coins.get_children(): + print("coin found") + n.coinCollected.connect(GameController.coinCollected) + ### enemies loop + for n in bad_guys.get_children(): + print("enemy found") + n.playerDamage.connect(GameController.playerDamage) + + ### wire up GameController signals to Player + GameController.playerHurt.connect(hurtPlayer) + GameController.playerDeath.connect(killPlayer) + + player.playerDead.connect(deadPlayer) + + func bulletFactory(): print("Make a bullet at the factory") var mybullet @@ -21,11 +44,21 @@ func bulletFactory(): bulletArray.push_front(mybullet) bulletsMadeTotal += 1 return mybullet - + func onBulletHit(bullet, body): print("Scene Manager knows a bullet hit something") bullet.setSpeed(0) if body.is_in_group("shootable"): print("RIP") body.queue_free() - + +func hurtPlayer(amt): + player.hurtPlayer(amt) + +func killPlayer(): + player.killPlayer() + +func deadPlayer(): + GameController.reset() + get_tree().reload_current_scene() +