enemies, game controller, playerdeath, coins, player hurt

This commit is contained in:
konzy 2024-12-16 21:14:40 -05:00
parent 082386ee29
commit 8966ac2165
21 changed files with 718 additions and 88 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cshrbm2roxdfc"
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cxil0e8gvkg18"
path="res://.godot/imported/coin.png-f0b33289d8d72c34d5a0c76da4c0f19c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/pickups/coin.png"
dest_files=["res://.godot/imported/coin.png-f0b33289d8d72c34d5a0c76da4c0f19c.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://4hq64jj4kprc"
path="res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/death/Player Death 64x64.png"
dest_files=["res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bibmmytjgw0nl"
path="res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/hurt/Player Hurt 48x48.png"
dest_files=["res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.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

View File

@ -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://scripts/game_controller.gd"
[display]
window/size/viewport_width=320

View File

@ -0,0 +1,77 @@
[gd_scene load_steps=9 format=3 uid="uid://bfex451nb78lt"]
[ext_resource type="Script" path="res://scripts/badguy.gd" id="1_vier3"]
[ext_resource type="Texture2D" uid="uid://cshrbm2roxdfc" path="res://assets/graphics/enemies/slime_green.png" id="1_x0bq5"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1yklg"]
size = Vector2(12.6615, 13.5659)
[sub_resource type="AtlasTexture" id="AtlasTexture_nlkx5"]
atlas = ExtResource("1_x0bq5")
region = Rect2(0, 24, 24, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_imbiq"]
atlas = ExtResource("1_x0bq5")
region = Rect2(24, 24, 24, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_46pxa"]
atlas = ExtResource("1_x0bq5")
region = Rect2(48, 24, 24, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_xkbu6"]
atlas = ExtResource("1_x0bq5")
region = Rect2(72, 24, 24, 24)
[sub_resource type="SpriteFrames" id="SpriteFrames_yljrg"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_nlkx5")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_imbiq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_46pxa")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xkbu6")
}],
"loop": true,
"name": &"idle",
"speed": 12.0
}]
[node name="Area2D" type="Area2D"]
script = ExtResource("1_vier3")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(5.96046e-08, -0.5)
scale = Vector2(1.10571, 1.10571)
shape = SubResource("RectangleShape2D_1yklg")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
position = Vector2(0, -5)
sprite_frames = SubResource("SpriteFrames_yljrg")
animation = &"idle"
autoplay = "idle"
frame = 2
frame_progress = 0.395087
[node name="CastRight" type="RayCast2D" parent="."]
target_position = Vector2(13, 0)
[node name="CastLeft" type="RayCast2D" parent="."]
target_position = Vector2(-13, 0)
[node name="CastFloorRight" type="RayCast2D" parent="."]
position = Vector2(7, 1)
target_position = Vector2(0, 8)
[node name="CastFloorLeft" type="RayCast2D" parent="."]
position = Vector2(-7, 1)
target_position = Vector2(0, 8)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,6 +1,8 @@
[gd_scene load_steps=28 format=3 uid="uid://b6vk2imhuhv0j"]
[gd_scene load_steps=44 format=3 uid="uid://b6vk2imhuhv0j"]
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_esbkk"]
[ext_resource type="Texture2D" uid="uid://4hq64jj4kprc" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_bws84"]
[ext_resource type="Texture2D" uid="uid://bibmmytjgw0nl" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="2_gm3uu"]
[ext_resource type="Texture2D" uid="uid://da3mdnk0s8bxc" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_jvkyl"]
[ext_resource type="Texture2D" uid="uid://cfmrxvwojl071" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_nnfwu"]
[ext_resource type="Texture2D" uid="uid://lk01unajxhx0" path="res://assets/graphics/player/run/player run 48x48.png" id="3_qml56"]
@ -8,6 +10,62 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_drde1"]
radius = 15.0
[sub_resource type="AtlasTexture" id="AtlasTexture_36q7i"]
atlas = ExtResource("2_bws84")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_j4tb0"]
atlas = ExtResource("2_bws84")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_wghdt"]
atlas = ExtResource("2_bws84")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_bh361"]
atlas = ExtResource("2_bws84")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_7wfdh"]
atlas = ExtResource("2_bws84")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_o0mvc"]
atlas = ExtResource("2_bws84")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_p2eca"]
atlas = ExtResource("2_bws84")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_jc1nd"]
atlas = ExtResource("2_bws84")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_q1uk6"]
atlas = ExtResource("2_bws84")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_gqkgi"]
atlas = ExtResource("2_bws84")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_6lqi3"]
atlas = ExtResource("2_gm3uu")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_sserb"]
atlas = ExtResource("2_gm3uu")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_tkl74"]
atlas = ExtResource("2_gm3uu")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_7br0y"]
atlas = ExtResource("2_gm3uu")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_v6vtg"]
atlas = ExtResource("2_jvkyl")
region = Rect2(0, 0, 48, 48)
@ -96,6 +154,58 @@ region = Rect2(336, 0, 48, 48)
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_36q7i")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_j4tb0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_wghdt")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_bh361")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_7wfdh")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_o0mvc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_p2eca")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jc1nd")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_q1uk6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_gqkgi")
}],
"loop": false,
"name": &"death",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_6lqi3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_sserb")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_tkl74")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_7br0y")
}],
"loop": false,
"name": &"hurt",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_v6vtg")
}, {
"duration": 1.0,
@ -198,8 +308,10 @@ position = Vector2(-16, -5)
texture_filter = 1
position = Vector2(0, -1)
sprite_frames = SubResource("SpriteFrames_xt5u3")
animation = &"idle"
animation = &"death"
autoplay = "idle"
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(0, -40)
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]

View File

@ -0,0 +1,113 @@
[gd_scene load_steps=17 format=3 uid="uid://bc6587qq8v636"]
[ext_resource type="Texture2D" uid="uid://cxil0e8gvkg18" path="res://assets/graphics/pickups/coin.png" id="1_gau74"]
[ext_resource type="Script" path="res://scripts/coin.gd" id="1_ydk8w"]
[sub_resource type="CircleShape2D" id="CircleShape2D_7tg8h"]
radius = 5.0
[sub_resource type="AtlasTexture" id="AtlasTexture_7r3qr"]
atlas = ExtResource("1_gau74")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_fsm1g"]
atlas = ExtResource("1_gau74")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_34y51"]
atlas = ExtResource("1_gau74")
region = Rect2(32, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_r3sgi"]
atlas = ExtResource("1_gau74")
region = Rect2(48, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_3oltj"]
atlas = ExtResource("1_gau74")
region = Rect2(64, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_p6mss"]
atlas = ExtResource("1_gau74")
region = Rect2(80, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_oj8qo"]
atlas = ExtResource("1_gau74")
region = Rect2(96, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_iorej"]
atlas = ExtResource("1_gau74")
region = Rect2(112, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_xhjtr"]
atlas = ExtResource("1_gau74")
region = Rect2(128, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_dpmih"]
atlas = ExtResource("1_gau74")
region = Rect2(144, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_cnmdp"]
atlas = ExtResource("1_gau74")
region = Rect2(160, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_qxp47"]
atlas = ExtResource("1_gau74")
region = Rect2(176, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_dbf75"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_7r3qr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fsm1g")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_34y51")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_r3sgi")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3oltj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_p6mss")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_oj8qo")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_iorej")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xhjtr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dpmih")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_cnmdp")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qxp47")
}],
"loop": true,
"name": &"default",
"speed": 12.0
}]
[node name="Area2D" type="Area2D"]
script = ExtResource("1_ydk8w")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_7tg8h")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
sprite_frames = SubResource("SpriteFrames_dbf75")
autoplay = "default"
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=4 uid="uid://dmk3hbsrqhgad"]
[gd_scene load_steps=18 format=4 uid="uid://dmk3hbsrqhgad"]
[ext_resource type="Texture2D" uid="uid://dv6amvxucgy0g" path="res://assets/graphics/enviroment/terrain/Terrain (32x32).png" id="1_ab3a4"]
[ext_resource type="PackedScene" uid="uid://flumvyk8tafw" path="res://scenes/box.tscn" id="1_ixp3c"]
@ -9,6 +9,8 @@
[ext_resource type="Texture2D" uid="uid://bihm8chupdlu2" path="res://assets/graphics/enviroment/background/stratosphere.png" id="2_l8kko"]
[ext_resource type="Texture2D" uid="uid://lj1cipgutadw" path="res://assets/graphics/enviroment/background/midground.png" id="2_w7c1m"]
[ext_resource type="PackedScene" uid="uid://e4o5ja1w0gph" path="res://scenes/bullet.tscn" id="4_7436f"]
[ext_resource type="PackedScene" uid="uid://bc6587qq8v636" path="res://scenes/coin.tscn" id="10_akvym"]
[ext_resource type="PackedScene" uid="uid://bfex451nb78lt" path="res://scenes/badguy.tscn" id="11_387qc"]
[sub_resource type="TileMapPattern" id="TileMapPattern_fkdsw"]
tile_data = PackedInt32Array(0, 262144, 0, 65536, 262144, 1, 131072, 262144, 2)
@ -430,10 +432,10 @@ shape = SubResource("RectangleShape2D_0jo0r")
debug_color = Color(0.774214, 0.233911, 0.917118, 0.42)
[node name="RigidBody2D" parent="." instance=ExtResource("1_ixp3c")]
position = Vector2(399, 48)
position = Vector2(466, 45)
[node name="RigidBody2D2" parent="." instance=ExtResource("1_ixp3c")]
position = Vector2(525, 46)
position = Vector2(546, 45)
[node name="RigidBody2D3" parent="." instance=ExtResource("1_ixp3c")]
position = Vector2(634, 44)
@ -457,4 +459,23 @@ repeat_size = Vector2(320, 0)
position = Vector2(180, 120)
texture = ExtResource("2_w7c1m")
[node name="Coins" type="Node" parent="."]
[node name="Coin" parent="Coins" instance=ExtResource("10_akvym")]
position = Vector2(79, 80)
[node name="Coin2" parent="Coins" instance=ExtResource("10_akvym")]
position = Vector2(143, 18)
[node name="Coin3" parent="Coins" instance=ExtResource("10_akvym")]
position = Vector2(143, -43)
[node name="Coin4" parent="Coins" instance=ExtResource("10_akvym")]
position = Vector2(47, -50)
[node name="enemies" type="Node" parent="."]
[node name="Area2D3" parent="enemies" instance=ExtResource("11_387qc")]
position = Vector2(391, 122)
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]

View File

@ -0,0 +1,41 @@
class_name BadGuy extends Area2D
signal playerDamage
var direction = 1
const speed = 60
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@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
# 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
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()

View File

@ -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()

View File

@ -17,97 +17,123 @@ var pushTarget
var pushLeftEnabled = 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 hurt")
animPlaying = "hurt"
playerSprite.play("hurt")
func killPlayer():
print("Characters know it is the end")
if living:
living = false
animPlaying = "death"
playerSprite.play(animPlaying)
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) * PUSH_FORCE * 2)
pushRightEnabled = false
if Input.is_action_just_pressed("shove") && faceLeft == true && pushLeftEnabled == true:
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2)
pushLeftEnabled = false
if Input.is_action_just_pressed("shoot"):
print("shoot a bullet")
var mybullet = %SceneManager.bulletFactory()
if not faceLeft:
mybullet.transform = right_target.global_transform
mybullet.setSpeed(400)
if faceLeft:
mybullet.transform = left_target.global_transform
mybullet.setSpeed(-400)
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
# 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) * PUSH_FORCE * 2)
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("This is a pushable box")
pushTarget = collider
pushLeftEnabled = true
else:
pushLeftEnabled = false
if Input.is_action_just_pressed("shove") && faceLeft == true && pushLeftEnabled == true:
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2)
pushLeftEnabled = 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)
if Input.is_action_just_pressed("shoot"):
print("shoot a bullet")
var mybullet = %SceneManager.bulletFactory()
if not faceLeft:
mybullet.transform = right_target.global_transform
mybullet.setSpeed(400)
if faceLeft:
mybullet.transform = left_target.global_transform
mybullet.setSpeed(-400)
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")
if faceLeft:
var collider = left_ray.get_collider()
if collider is Node:
if collider.is_in_group("box"):
print("This is a pushable box")
pushTarget = collider
pushLeftEnabled = true
else:
pushLeftEnabled = 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 == "death":
## emita custom signal
playerDead.emit()

View File

@ -0,0 +1,34 @@
extends Node
var coinsCollected:int = 0
var player:Resource
signal playerHurt(amt)
signal playerDeath()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
player = load("res://scripts/res/playerstats.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 collecte " + 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

View File

@ -0,0 +1,6 @@
class_name CharacterStats extends Resource
@export var max_health:int = 100
@export var starting_health: int = 100
@export var health: int = 100

View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://cuqtpu3cm6xgo"]
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_in2m2"]
[resource]
script = ExtResource("1_in2m2")
max_health = 50
starting_health = 50
health = 50

View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://d26och4kddhoe"]
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_yty15"]
[resource]
script = ExtResource("1_yty15")
max_health = 100
starting_health = 100
health = 100

View File

@ -3,9 +3,30 @@ extends Node
var bulletsFiredTotal := 0
var bulletsMadeTotal := 0
var bulletArray:Array = []
@onready var coins: Node = $"../Coins"
@onready var enemies: Node = $"../enemies"
@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)
## enemy loop
for n in enemies.get_children():
print("enemy found")
n.playerDamage.connect(GameController.playerDamage)
## wire up game controller 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
@ -29,3 +50,13 @@ func onBulletHit(bullet, body):
if body.is_in_group("shootable"):
print("explode this thing")
body.queue_free()
func hurtPlayer(amt):
player.hurtPlayer(amt)
func killPlayer():
player.killPlayer()
func deadPlayer():
GameController.reset()
get_tree().reload_current_scene()