sprites, character animations

This commit is contained in:
GabriellePipo 2025-01-20 20:44:30 -05:00
parent 8adfc2b674
commit 6650e5ae9d
21 changed files with 554 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b283wfk58dltk"
path="res://.godot/imported/crate.png-91961d6f3a0764bc8758ad055606c6d0.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/destructables/crate.png"
dest_files=["res://.godot/imported/crate.png-91961d6f3a0764bc8758ad055606c6d0.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.8 KiB

View File

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

View File

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

View File

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

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bk0aakyo6grve"
path="res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/projectiles/pixel_bullet.png"
dest_files=["res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.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: 12 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c7gfcwmohp6th"
path="res://.godot/imported/Terrain (32x32).png-7361ca574569f6e5ff16ef11d25a8904.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/terrains/Terrain (32x32).png"
dest_files=["res://.godot/imported/Terrain (32x32).png-7361ca574569f6e5ff16ef11d25a8904.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,14 @@ run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"
[display]
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"
[input]
right={

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://c7v063yofnirp"]
[gd_scene load_steps=4 format=3 uid="uid://c7v063yofnirp"]
[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_au5n7"]
[ext_resource type="Texture2D" uid="uid://bk0aakyo6grve" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_pcjo1"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hrjpd"]
size = Vector2(14, 6)
@ -12,4 +13,11 @@ script = ExtResource("1_au5n7")
shape = SubResource("RectangleShape2D_hrjpd")
debug_color = Color(0.92607, 0.250785, 0.273463, 0.42)
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
position = Vector2(-5, -3)
rotation = 3.14159
scale = Vector2(0.117753, 0.117753)
texture = ExtResource("2_pcjo1")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,11 +1,19 @@
[gd_scene load_steps=2 format=3 uid="uid://63qb2drh1l33"]
[gd_scene load_steps=3 format=3 uid="uid://63qb2drh1l33"]
[ext_resource type="Texture2D" uid="uid://b283wfk58dltk" path="res://assets/graphics/destructables/crate.png" id="1_hy1ys"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jflwv"]
[node name="RigidBody2D" type="RigidBody2D" groups=["box", "destructable"]]
rotation = -2.29882
rotation = -3.14159
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_jflwv")
debug_color = Color(0.968627, 0.117647, 0.345098, 0.419608)
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
position = Vector2(-8.74228e-08, 1)
scale = Vector2(0.0686591, 0.0686591)
texture = ExtResource("1_hy1ys")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://cxnmaxykhbgaq"]
[gd_scene load_steps=13 format=3 uid="uid://cxnmaxykhbgaq"]
[ext_resource type="PackedScene" uid="uid://63qb2drh1l33" path="res://scenes/crate.tscn" id="1_0wmww"]
[ext_resource type="Script" path="res://scripts/gamecontroller.gd" id="1_5dy8j"]
@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://c1cuiluq1fcpk" path="res://scenes/player.tscn" id="3_w28al"]
[ext_resource type="PackedScene" uid="uid://c7v063yofnirp" path="res://scenes/bullet.tscn" id="5_drh85"]
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="6_duuox"]
[ext_resource type="Texture2D" uid="uid://c7gfcwmohp6th" path="res://assets/graphics/terrains/Terrain (32x32).png" id="7_ogiiy"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_f1luk"]
size = Vector2(172, 20)
@ -15,6 +16,61 @@ size = Vector2(172, 20)
[sub_resource type="CircleShape2D" id="CircleShape2D_wdyhk"]
radius = 34.1321
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_06fpy"]
texture = ExtResource("7_ogiiy")
texture_region_size = Vector2i(32, 32)
0:0/0 = 0
1:0/0 = 0
2:0/0 = 0
4:0/0 = 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
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
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
1:4/0 = 0
2:4/0 = 0
4:4/0 = 0
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="TileSet" id="TileSet_51dbi"]
tile_size = Vector2i(32, 32)
sources/0 = SubResource("TileSetAtlasSource_06fpy")
[node name="game" type="Node2D"]
script = ExtResource("1_5dy8j")
@ -25,14 +81,6 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
shape = SubResource("RectangleShape2D_f1luk")
[node name="RigidBody2D" parent="." instance=ExtResource("1_0wmww")]
position = Vector2(297, 129)
rotation = 0.688747
[node name="RigidBody2D2" parent="." instance=ExtResource("1_0wmww")]
position = Vector2(391, 64)
rotation = 0.358379
[node name="CharacterBody2D" parent="." instance=ExtResource("3_w28al")]
[node name="StaticBody2D2" type="StaticBody2D" parent="."]
@ -51,9 +99,6 @@ metadata/_edit_group_ = true
shape = SubResource("CircleShape2D_wdyhk")
debug_color = Color(0.466667, 0.592157, 0, 0.419608)
[node name="RigidBody2D3" parent="." instance=ExtResource("1_0wmww")]
position = Vector2(256, 39)
[node name="Area2D" parent="." instance=ExtResource("5_drh85")]
position = Vector2(49, 305)
@ -61,5 +106,21 @@ position = Vector2(49, 305)
unique_name_in_owner = true
script = ExtResource("6_duuox")
[node name="crates" type="Node2D" parent="."]
[node name="RigidBody2D3" parent="crates" instance=ExtResource("1_0wmww")]
position = Vector2(256, 39)
[node name="RigidBody2D" parent="crates" instance=ExtResource("1_0wmww")]
position = Vector2(297, 129)
rotation = 0.688747
[node name="RigidBody2D2" parent="crates" instance=ExtResource("1_0wmww")]
position = Vector2(391, 64)
rotation = 0.358379
[node name="TileMapLayer" type="TileMapLayer" parent="."]
tile_set = SubResource("TileSet_51dbi")
[connection signal="alert" from="Trigger" to="." method="_on_trigger_alert"]
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]

View File

@ -1,9 +1,177 @@
[gd_scene load_steps=3 format=3 uid="uid://c1cuiluq1fcpk"]
[gd_scene load_steps=28 format=3 uid="uid://c1cuiluq1fcpk"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_s1kdl"]
[ext_resource type="Texture2D" uid="uid://cv2rxkxb3qt8d" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_h20by"]
[ext_resource type="Texture2D" uid="uid://cnya66cp8q1jw" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_fr7w2"]
[ext_resource type="Texture2D" uid="uid://ds0ii0prt3pij" path="res://assets/graphics/player/run/player run 48x48.png" id="3_gom75"]
[sub_resource type="CircleShape2D" id="CircleShape2D_y4y41"]
[sub_resource type="AtlasTexture" id="AtlasTexture_mww1u"]
atlas = ExtResource("2_h20by")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ok4l7"]
atlas = ExtResource("2_h20by")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_tusxt"]
atlas = ExtResource("2_h20by")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_gdc6u"]
atlas = ExtResource("2_h20by")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_235hx"]
atlas = ExtResource("2_h20by")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_cy5k4"]
atlas = ExtResource("2_h20by")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_g3wxi"]
atlas = ExtResource("2_h20by")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_aec4t"]
atlas = ExtResource("2_h20by")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_3ht28"]
atlas = ExtResource("2_h20by")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_5ntut"]
atlas = ExtResource("2_h20by")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_8hdk6"]
atlas = ExtResource("3_fr7w2")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4ddi8"]
atlas = ExtResource("3_fr7w2")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ndifq"]
atlas = ExtResource("3_fr7w2")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_0rpev"]
atlas = ExtResource("3_gom75")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_w0u7q"]
atlas = ExtResource("3_gom75")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_csrrm"]
atlas = ExtResource("3_gom75")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_n4feg"]
atlas = ExtResource("3_gom75")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_eje62"]
atlas = ExtResource("3_gom75")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_5yqty"]
atlas = ExtResource("3_gom75")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_s7y8g"]
atlas = ExtResource("3_gom75")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_kg71y"]
atlas = ExtResource("3_gom75")
region = Rect2(336, 0, 48, 48)
[sub_resource type="SpriteFrames" id="SpriteFrames_gcr48"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_mww1u")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ok4l7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_tusxt")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_gdc6u")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_235hx")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_cy5k4")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_g3wxi")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_aec4t")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3ht28")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5ntut")
}],
"loop": true,
"name": &"idle",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_8hdk6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4ddi8")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ndifq")
}],
"loop": false,
"name": &"jump",
"speed": 6.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0rpev")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_w0u7q")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_csrrm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_n4feg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_eje62")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5yqty")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_s7y8g")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_kg71y")
}],
"loop": true,
"name": &"run",
"speed": 12.0
}]
[node name="CharacterBody2D" type="CharacterBody2D" groups=["player"]]
script = ExtResource("1_s1kdl")
metadata/_edit_group_ = true
@ -13,14 +181,24 @@ shape = SubResource("CircleShape2D_y4y41")
debug_color = Color(0.752941, 0.211765, 0.984314, 0.419608)
[node name="RightRay" type="RayCast2D" parent="."]
target_position = Vector2(15, 0)
target_position = Vector2(20, 0)
collide_with_areas = true
[node name="LeftRay" type="RayCast2D" parent="."]
target_position = Vector2(-15, 0)
target_position = Vector2(-21, 0)
[node name="RightTarget" type="Node2D" parent="."]
position = Vector2(10, -5)
[node name="LeftTarget" type="Node2D" parent="."]
position = Vector2(-10, -5)
[node name="Camera2D" type="Camera2D" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
sprite_frames = SubResource("SpriteFrames_gcr48")
animation = &"jump"
autoplay = "jump"
frame = 2
frame_progress = 1.0

View File

@ -1,6 +1,9 @@
class_name Bullet extends Area2D
@onready var bulletGraphic: Sprite2D = $Sprite2D
var speed = 700
signal hit
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@ -15,9 +18,13 @@ func _physics_process(delta: float) -> void:
func setSpeed(value):
speed = value
if speed <0:
bulletGraphic.flip_h = true
else:
bulletGraphic.flip_h= false
func _on_body_entered(body: Node2D) -> void:
print("hit")
if not body.is_in_group("player"):
hit.emit(body)
hit.emit(self, body)

View File

@ -2,6 +2,10 @@ extends Node2D
var totalBoxes = 3
var timer:= Timer.new()
var countdown = 10
var totalCrates = 0
signal destroyBox(body)
# Called when the node enters the scene tree for the first time.
func _ready():
add_child(timer)
@ -31,4 +35,7 @@ func _on_trigger_alert(body):
func bulletHit(body):
print("game controller knows bullet hit something")
if body.is_in_group("destructable"):
body.queue_free()
destroyBox.emit(body)
func coutnCrates(value):
totalCrates = value

View File

@ -4,6 +4,7 @@ extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@export var BUMP_FORCE = 90
@onready var animation: AnimatedSprite2D = $AnimatedSprite2D
# Shove attack
@onready var right_ray: RayCast2D = $RightRay
@ -22,14 +23,18 @@ var bullet = preload("res://scenes/bullet.tscn")
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var isJumping = false
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
else:
isJumping = false
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
animation.play("jump")
isJumping = true
# shove attack
if Input.is_action_just_pressed("shove"):
@ -41,10 +46,18 @@ func _physics_process(delta):
if direction:
velocity.x = direction * SPEED
if direction<0:
if not isJumping:
animation.play("run")
faceleft = true
animation.flip_h = true
if direction>0:
if not isJumping:
animation.play("run")
faceleft = false
animation.flip_h = false
else:
if not isJumping:
animation.play("idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
@ -52,12 +65,13 @@ func _physics_process(delta):
if Input.is_action_just_pressed("shoot"):
# make bullet
var myBullet = %SceneManager.bulletFactory()
owner.add_child(myBullet)
myBullet.transform = right_target.global_transform
if faceleft:
myBullet.transform = left_target.global_transform
myBullet.setSpeed(-700)
#owner.add_child(myBullet)
#myBullet.transform = right_target.global_transform
if faceleft == true:
var myBullet = %SceneManager.makeBullet(left_target.global_transform,-700)
if faceleft == false:
var myBullet = %SceneManager.makeBullet(right_target.global_transform,700)
move_and_slide()
if right_ray.is_colliding():

View File

@ -1,11 +1,20 @@
extends Node
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../crates"
var bullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array = []
var bulletMadeTotal:= 0
var totalCrates := 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
game.destroyBox.connect(boxDestroy)
for obj in crates.get_children():
if obj.is_in_group("destructable"):
#increase box counter
totalCrates +=1
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -14,10 +23,29 @@ func _process(delta: float) -> void:
func bulletFactory():
print("factory will make a bullet")
var myBullet = bullet.instantiate()
myBullet.connect("hit", onBulletHit)
var myBullet
if bulletArray.size() < 4:
myBullet = bullet.instantiate()
myBullet.connect("hit", onBulletHit)
owner.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func onBulletHit(body):
func makeBullet(position, speed):
var myBullet = bulletFactory()
myBullet.transform = position
myBullet.setSpeed(speed)
return myBullet
func onBulletHit(bullet, body):
bullet.position = Vector2(-100,-100)
bullet.setSpeed(0)
print("Scene manager knows bullet hit")
game.bulletHit(body)
func boxDestroy(body):
body.queue_free()