1 Commits
Author SHA1 Message Date
OddlyTimbot 8d19d25a75 bullet factory better, state machine for player, simple NPC 2026-03-16 14:05:53 -04:00
23 changed files with 117 additions and 512 deletions

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 568 B

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cljdn8xafgbr3"
path="res://.godot/imported/bgcolor.png-e2c7f69bed4e086fc6803aa99b5afd90.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/bg/bgcolor.png"
dest_files=["res://.godot/imported/bgcolor.png-e2c7f69bed4e086fc6803aa99b5afd90.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 2.2 KiB

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bci2ejdugybxi"
path="res://.godot/imported/foreground.png-c487090c461fdde2851cfe897d5ae0df.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/bg/foreground.png"
dest_files=["res://.godot/imported/foreground.png-c487090c461fdde2851cfe897d5ae0df.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 1.5 KiB

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dvj4b1ku3fdwa"
path="res://.godot/imported/midground.png-395e3b40bd65c312dc5fc7afb2b9bcda.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/bg/midground.png"
dest_files=["res://.godot/imported/midground.png-395e3b40bd65c312dc5fc7afb2b9bcda.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 5.8 KiB

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://u7jn2uupwh84"
path="res://.godot/imported/plane.png-2123d8756656030b687b5854ee45ac74.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/stuff/plane.png"
dest_files=["res://.godot/imported/plane.png-2123d8756656030b687b5854ee45ac74.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 12 KiB

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cgfmfshcgk32h"
path="res://.godot/imported/Terrain (32x32).png-3bf12044c27f645f7b3ccaa417d9adb1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/terrains/Terrain (32x32).png"
dest_files=["res://.godot/imported/Terrain (32x32).png-3bf12044c27f645f7b3ccaa417d9adb1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 2.7 KiB

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c1gqnwp5pq37g"
path="res://.godot/imported/mushroom_32x64.png-029639574d0e250658cc399b22fc1a79.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/veggies/mushroom_32x64.png"
dest_files=["res://.godot/imported/mushroom_32x64.png-029639574d0e250658cc399b22fc1a79.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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.

Before

Width:  |  Height:  |  Size: 675 B

@@ -1,40 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bxsc7u8bupxeq"
path="res://.godot/imported/veg_32x32.png-f9cf09bd889241b79dfda92291ada574.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/environment/veggies/veg_32x32.png"
dest_files=["res://.godot/imported/veg_32x32.png-f9cf09bd889241b79dfda92291ada574.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
+2 -2
View File
@@ -17,8 +17,8 @@ config/icon="res://icon.svg"
[display]
window/size/viewport_width=480
window/size/viewport_height=270
window/size/viewport_width=320
window/size/viewport_height=180
window/size/window_width_override=960
window/size/window_height_override=540
window/stretch/mode="viewport"
+17 -154
View File
@@ -1,127 +1,14 @@
[gd_scene format=4 uid="uid://cqk2rgy3m1chs"]
[gd_scene format=3 uid="uid://cqk2rgy3m1chs"]
[ext_resource type="Script" uid="uid://dxubdt7nh5s1j" path="res://scripts/gameController.gd" id="1_lnu2h"]
[ext_resource type="Script" uid="uid://ch2id76i14srx" path="res://scripts/scene_manager.gd" id="2_iywne"]
[ext_resource type="PackedScene" uid="uid://b6lw2go5mwk3h" path="res://scenes/crate.tscn" id="2_lnu2h"]
[ext_resource type="PackedScene" uid="uid://s0utas3jmhjk" path="res://scenes/player.tscn" id="3_iywne"]
[ext_resource type="Texture2D" uid="uid://cgfmfshcgk32h" path="res://assets/graphics/environment/terrains/Terrain (32x32).png" id="3_u5sy4"]
[ext_resource type="Texture2D" uid="uid://bxsc7u8bupxeq" path="res://assets/graphics/environment/veggies/veg_32x32.png" id="4_0tnpc"]
[ext_resource type="PackedScene" uid="uid://bf50mxdma8wq4" path="res://scenes/trigger.tscn" id="4_lbhrr"]
[ext_resource type="Texture2D" uid="uid://c1gqnwp5pq37g" path="res://assets/graphics/environment/veggies/mushroom_32x64.png" id="5_vtaks"]
[ext_resource type="PackedScene" uid="uid://bgi18lbutp5ui" path="res://scenes/npc_character.tscn" id="6_u5sy4"]
[ext_resource type="Texture2D" uid="uid://cljdn8xafgbr3" path="res://assets/graphics/environment/bg/bgcolor.png" id="10_vtaks"]
[ext_resource type="Texture2D" uid="uid://dvj4b1ku3fdwa" path="res://assets/graphics/environment/bg/midground.png" id="11_kvpfn"]
[ext_resource type="Texture2D" uid="uid://bci2ejdugybxi" path="res://assets/graphics/environment/bg/foreground.png" id="12_dinhu"]
[ext_resource type="PackedScene" uid="uid://bgi18lbutp5ui" path="res://scenes/npc_character.tscn" id="6_p57ef"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_gee14"]
texture = ExtResource("3_u5sy4")
texture_region_size = Vector2i(32, 32)
0:0/0 = 0
1:0/0 = 0
2:0/0 = 0
4:0/0 = 0
4:0/0/terrain_set = 0
4:0/0/terrain = 0
4:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:0/0/terrains_peering_bit/bottom_side = 0
6:0/0 = 0
7:0/0 = 0
9:0/0 = 0
10:0/0 = 0
12:0/0 = 0
13:0/0 = 0
15:0/0 = 0
0:1/0 = 0
1:1/0 = 0
2:1/0 = 0
4:1/0 = 0
4:1/0/terrain_set = 0
4:1/0/terrain = 0
4:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:1/0/terrains_peering_bit/bottom_side = 0
4:1/0/terrains_peering_bit/top_side = 0
6:1/0 = 0
7:1/0 = 0
9:1/0 = 0
10:1/0 = 0
12:1/0 = 0
13:1/0 = 0
15:1/0 = 0
16:1/0 = 0
0:2/0 = 0
1:2/0 = 0
2:2/0 = 0
4:2/0 = 0
4:2/0/terrain_set = 0
4:2/0/terrain = 0
4:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
4:2/0/terrains_peering_bit/top_side = 0
6:3/0 = 0
7:3/0 = 0
9:3/0 = 0
10:3/0 = 0
12:3/0 = 0
13:3/0 = 0
15:3/0 = 0
16:3/0 = 0
0:4/0 = 0
0:4/0/terrain_set = 0
0:4/0/terrain = 0
0:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
0:4/0/terrains_peering_bit/right_side = 0
1:4/0 = 0
1:4/0/terrain_set = 0
1:4/0/terrain = 0
1:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
1:4/0/terrains_peering_bit/right_side = 0
1:4/0/terrains_peering_bit/left_side = 0
2:4/0 = 0
2:4/0/terrain_set = 0
2:4/0/terrain = 0
2:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
2:4/0/terrains_peering_bit/left_side = 0
4:4/0 = 0
4:4/0/terrain_set = 0
4:4/0/terrain = 0
4:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
6:4/0 = 0
7:4/0 = 0
9:4/0 = 0
10:4/0 = 0
12:4/0 = 0
13:4/0 = 0
15:4/0 = 0
16:4/0 = 0
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_kvpfn"]
texture = ExtResource("4_0tnpc")
texture_region_size = Vector2i(32, 32)
0:0/0 = 0
0:0/0/terrain_set = 0
0:0/0/terrain = 1
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_dinhu"]
texture = ExtResource("5_vtaks")
texture_region_size = Vector2i(32, 32)
0:0/0 = 0
0:0/0/terrain_set = 0
0:0/0/terrains_peering_bit/bottom_side = 1
0:1/0 = 0
0:1/0/terrain_set = 0
0:1/0/terrain = 1
0:1/0/terrains_peering_bit/top_side = 1
[sub_resource type="TileSet" id="TileSet_0tnpc"]
tile_size = Vector2i(32, 32)
physics_layer_0/collision_layer = 1
terrain_set_0/mode = 0
terrain_set_0/terrain_0/name = "LeafyDirt"
terrain_set_0/terrain_0/color = Color(0.5, 0.34375, 0.25, 1)
terrain_set_0/terrain_1/name = "Veg"
terrain_set_0/terrain_1/color = Color(0.5, 0.4375, 0.25, 1)
sources/0 = SubResource("TileSetAtlasSource_gee14")
sources/1 = SubResource("TileSetAtlasSource_kvpfn")
sources/2 = SubResource("TileSetAtlasSource_dinhu")
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
size = Vector2(74, 20)
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_lbhrr"]
@@ -132,37 +19,8 @@ script = ExtResource("1_lnu2h")
unique_name_in_owner = true
script = ExtResource("2_iywne")
[node name="FarSky" type="Parallax2D" parent="." unique_id=1670161639]
repeat_size = Vector2(480, 270)
[node name="Sprite2D" type="Sprite2D" parent="FarSky" unique_id=939473192]
texture = ExtResource("10_vtaks")
offset = Vector2(240, 135)
[node name="Midground" type="Parallax2D" parent="." unique_id=1879206139]
repeat_size = Vector2(480, 0)
[node name="Sprite2D" type="Sprite2D" parent="Midground" unique_id=945851306]
texture_filter = 1
texture = ExtResource("11_kvpfn")
offset = Vector2(240, 300)
[node name="Foreground" type="Parallax2D" parent="." unique_id=968148700]
scroll_scale = Vector2(1.5, 1)
repeat_size = Vector2(480, 0)
[node name="Sprite2D" type="Sprite2D" parent="Foreground" unique_id=693353172]
texture_filter = 1
texture = ExtResource("12_dinhu")
offset = Vector2(240, 300)
[node name="TileMapLayer" type="TileMapLayer" parent="." unique_id=555266141]
texture_filter = 1
tile_map_data = PackedByteArray("AAAQAA0AAAAAAAQAAAARAA0AAAABAAQAAAASAA0AAAABAAQAAAATAA0AAAABAAQAAAAUAA0AAAACAAQAAAAOAA0AAAAEAAQAAAAUAAwAAQAAAAAAAAARAAwAAQAAAAAAAAAVAAwAAQAAAAAAAAAWAAwAAgAAAAEAAAAWAAsAAgAAAAAAAAATAAwAAgAAAAEAAAATAAsAAgAAAAAAAAA=")
tile_set = SubResource("TileSet_0tnpc")
[node name="Player" parent="." unique_id=161143934 instance=ExtResource("3_iywne")]
position = Vector2(524, 400)
position = Vector2(597, 416)
[node name="Triggers" type="Node2D" parent="." unique_id=1411399015]
@@ -180,20 +38,25 @@ effect = "powerup"
[node name="Crates" type="Node2D" parent="." unique_id=1983554973]
[node name="Crate" parent="Crates" unique_id=1307809047 instance=ExtResource("2_lnu2h")]
position = Vector2(657.99994, 382.99994)
[node name="Crate2" parent="Crates" unique_id=1988562966 instance=ExtResource("2_lnu2h")]
position = Vector2(627.99994, 350)
position = Vector2(660.9999, 413.99994)
[node name="Crate3" parent="Crates" unique_id=1771442258 instance=ExtResource("2_lnu2h")]
position = Vector2(575, 255)
[node name="Crate4" parent="Crates" unique_id=34543093 instance=ExtResource("2_lnu2h")]
position = Vector2(622.99994, 388.99997)
position = Vector2(633.99994, 411)
[node name="Level" type="Node2D" parent="." unique_id=1225714734]
[node name="StaticBody2D" type="StaticBody2D" parent="Level" unique_id=2062716976]
position = Vector2(591, 442)
scale = Vector2(2, 1)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Level/StaticBody2D" unique_id=1655047088]
shape = SubResource("RectangleShape2D_8cj0n")
[node name="StaticBody2D2" type="StaticBody2D" parent="Level" unique_id=426786591]
position = Vector2(601, 622)
metadata/_edit_group_ = true
@@ -201,5 +64,5 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Level/StaticBody2D2" unique_id=895098891]
shape = SubResource("WorldBoundaryShape2D_lbhrr")
[node name="NPCCharacter" parent="." unique_id=597270257 instance=ExtResource("6_u5sy4")]
position = Vector2(474, 404)
[node name="NPCCharacter" parent="." unique_id=847055918 instance=ExtResource("6_p57ef")]
position = Vector2(536, 415)
+5 -5
View File
@@ -2,11 +2,11 @@
[ext_resource type="Script" uid="uid://gutmbv5ff4u4" path="res://scripts/npc_character.gd" id="1_xtrxv"]
[sub_resource type="CircleShape2D" id="CircleShape2D_aykgk"]
[sub_resource type="CircleShape2D" id="CircleShape2D_5hyqr"]
[node name="NPCCharacter" type="CharacterBody2D" unique_id=597270257]
[node name="NPCCharacter" type="CharacterBody2D" unique_id=847055918]
script = ExtResource("1_xtrxv")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=895564969]
shape = SubResource("CircleShape2D_aykgk")
debug_color = Color(0.9234807, 0.19196323, 0.5046088, 0.41960785)
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=351834440]
shape = SubResource("CircleShape2D_5hyqr")
debug_color = Color(0.91631323, 0.13193849, 0.63224995, 0.41960785)
+4 -5
View File
@@ -191,14 +191,13 @@ position = Vector2(15, -3)
[node name="LeftTarget" type="Marker2D" parent="." unique_id=212282016]
position = Vector2(-15, -3)
[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=726229378]
[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=368198734]
texture_filter = 1
position = Vector2(1, -7)
position = Vector2(0, -6)
sprite_frames = SubResource("SpriteFrames_jej6c")
animation = &"falling"
animation = &"jumping"
autoplay = "idle"
[node name="Camera2D" type="Camera2D" parent="." unique_id=600604016]
offset = Vector2(0, -30)
[node name="Camera2D" type="Camera2D" parent="." unique_id=1107348196]
[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"]
+7 -3
View File
@@ -1,17 +1,21 @@
class_name Bullet extends Area2D
var speed:float = 700
signal bulletDamageSignal(body, bullet)
signal bulletDamageSignal(body: Node2D, bullet:Bullet)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func setSpeed(value)->void:
speed = value
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
position += transform.x * speed *delta
func setSpeed(value:float)->void:
speed = value
func _on_body_entered(body: Node2D) -> void:
print("Bullet hit something")
bulletDamageSignal.emit(body, self)
+6 -4
View File
@@ -29,8 +29,9 @@ func _process(delta: float) -> void:
pass
#Signals from Triggers!
func _on_trigger(body: Variant, effect, trigger) -> void:
print("GC knows trigger...."+effect)
#Crate triggers
if body is Crate:
match effect:
"destroy":
@@ -38,7 +39,7 @@ func _on_trigger(body: Variant, effect, trigger) -> void:
"teleport":
print("GC teleport an object")
teleportSignal.emit(body)
#Player triggers
if body is Player:
match effect:
"powerup":
@@ -48,13 +49,14 @@ func _on_trigger(body: Variant, effect, trigger) -> void:
func crateUpdate(cratesAmount)->void:
crateTotal = cratesAmount
print("GC updated crates: "+str(crateTotal))
if crateTotal <=0:
print("You WON!!!")
levelChangeSignal.emit(currentScene)
func bulletDamage(body:Node2D, bullet:Bullet)->void:
print("GC knows bullet hit")
if body is Crate:
#destroy crate
#destroy the crate?
destroySignal.emit(body)
#destroy the bullet?
destroySignal.emit(bullet)
+13 -3
View File
@@ -1,12 +1,22 @@
class_name NPCCharacter extends CharacterBody2D
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
handle_movement(delta)
move_and_slide()
handle_collisions()
func handle_movement(_delta)->void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * _delta
func knockBack(direction, duration:float=0.2):
velocity = direction
await get_tree().create_timer(duration).timeout
velocity = Vector2.ZERO
func handle_collisions()->void:
for i in get_slide_collision_count():
var collision = get_slide_collision(i)
var collider = collision.get_collider()
# Check the collider's group or type
if collider is Player:
print("NPC hit by player")
+50 -49
View File
@@ -10,32 +10,22 @@ const JUMP_VELOCITY = -400.0
const BUMP_POWER = 50
enum FaceDirection{LEFT, RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
var direction
enum PlayerState{IDLE,RUNNING, JUMPING, FALLING}
#states for player
enum PlayerState{IDLE,RUNNING,JUMPING, FALLING}
var current_player_state:PlayerState = PlayerState.IDLE
var jumpUp:bool = false
var upJump:bool = false
func _physics_process(delta: float) -> void:
handle_input()
handle_movement(delta)
handle_state()
handle_animation()
handle_update_states()
handle_update_animation()
move_and_slide()
handle_collisions()
#organize the game loop
func handle_input()->void:
direction = Input.get_axis("ui_left", "ui_right")
if direction <0:
player_graphic.flip_h = true
if direction >0:
player_graphic.flip_h = false
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
current_player_state = PlayerState.JUMPING
jumpUp = true
# Handle Shoot
if Input.is_action_just_pressed("shoot"):
print("Player wants to shoot")
@@ -46,55 +36,66 @@ func handle_input()->void:
FaceDirection.LEFT:
print("Shoot to the left")
%SceneManager.makeBullet(left_target.global_transform, -700)
func handle_state()->void:
match current_player_state:
PlayerState.IDLE when velocity.x !=0:
#change to running!!
current_player_state = PlayerState.RUNNING
PlayerState.RUNNING when velocity.x == 0:
current_player_state = PlayerState.IDLE
PlayerState.JUMPING when velocity.y > 0:
current_player_state = PlayerState.FALLING
PlayerState.FALLING when is_on_floor():
if velocity.x ==0:
current_player_state = PlayerState.IDLE
else:
current_player_state = PlayerState.RUNNING
func handle_animation()->void:
match current_player_state:
PlayerState.IDLE:
player_graphic.play("idle")
PlayerState.RUNNING:
player_graphic.play("running")
PlayerState.JUMPING:
if jumpUp:
player_graphic.play("jumping")
PlayerState.FALLING:
player_graphic.play("falling")
func handle_movement(delta)->void:
# 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
current_player_state = PlayerState.JUMPING
upJump = true
# 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 direction:
velocity.x = direction * SPEED
if direction <0:
facing=FaceDirection.LEFT
player_graphic.flip_h = true
if direction >0:
facing=FaceDirection.RIGHT
player_graphic.flip_h = false
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
func handle_movement(_delta)->void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * _delta
func handle_collisions()->void:
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_POWER)
if c.get_collider() is NPCCharacter:
var myCharacter:NPCCharacter = c.get_collider()
var direction = -c.get_normal()*BUMP_POWER
myCharacter.knockBack(direction)
c.get_collider().knockBack(direction)
func handle_update_states()->void:
match current_player_state:
PlayerState.IDLE when velocity.x !=0:
current_player_state = PlayerState.RUNNING
PlayerState.RUNNING when velocity.x ==0:
current_player_state = PlayerState.IDLE
PlayerState.JUMPING when velocity.y >0:
current_player_state = PlayerState.FALLING
PlayerState.FALLING when is_on_floor():
if velocity.x == 0:
current_player_state = PlayerState.IDLE
else:
current_player_state = PlayerState.RUNNING
func handle_update_animation()->void:
match current_player_state:
PlayerState.IDLE:
player_graphic.play("idle")
PlayerState.RUNNING:
player_graphic.play("running")
PlayerState.JUMPING:
if upJump:
player_graphic.play("jumping")
PlayerState.FALLING:
player_graphic.play("falling")
func _on_animation_finished() -> void:
match current_player_state:
PlayerState.JUMPING:
jumpUp = false
upJump = false
+13 -7
View File
@@ -4,8 +4,11 @@ class_name SceneManager extends Node2D
@onready var level: Node2D = $"../Level"
@onready var game: GameController = $".."
#preloads for dynamic instantiation
var bullet = preload("res://scenes/bullet.tscn")
#array to keep track of bullets
var bulletArray:Array[Bullet] = []
#total number of bullets allowed to exist
var totalAllowedBullets:int = 7
# Called when the node enters the scene tree for the first time.
@@ -47,7 +50,7 @@ func updateCrates()->void:
func destroy(body)->void:
if body is Bullet:
stashBullet(body)
bulletStash(body)
return
body.queue_free()
func teleport(body)->void:
@@ -60,29 +63,32 @@ func teleport(body)->void:
func loadLevel(level:String)->void:
get_tree().call_deferred("change_scene_to_file", level)
func stashBullet(bullet:Bullet)->void:
var stashPosition:Vector2 = Vector2(-100,100)
func bulletStash(bullet:Bullet)->void:
var stashPosition:Vector2 = Vector2(-100,-100)
bullet.position = stashPosition
bullet.setSpeed(0)
bullet.set_process(false)
func bulletFactory()->Bullet :
func bulletFactory()->Bullet:
var myBullet:Bullet
#how many bullets have been made?
if bulletArray.size() <= totalAllowedBullets:
#make a new bullet
myBullet = bullet.instantiate()
#connect to the game controller
if not myBullet.bulletDamageSignal.is_connected(game.bulletDamage):
myBullet.bulletDamageSignal.connect(game.bulletDamage)
game.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func makeBullet(targetPosition, speed)->void:
print("Make a bullet!")
print("bullets created: "+str( bulletArray.size() ))
var myBullet:Bullet = bulletFactory()
myBullet.transform = targetPosition
myBullet.setSpeed(speed)
myBullet.set_process(true)