Finish Trash Can Enemy And Fix Drops

main
Luna Brovchuk 2023-09-30 22:48:27 +02:00
parent f2112b296d
commit 43d693450e
15 changed files with 247 additions and 36 deletions

View File

@ -8,6 +8,16 @@
config_version=4 config_version=4
_global_script_classes=[ {
"base": "EditorVCSInterface",
"class": "GitAPI",
"language": "NativeScript",
"path": "res://addons/godot-git-plugin/git_api.gdns"
} ]
_global_script_class_icons={
"GitAPI": ""
}
[application] [application]
config/name="LD54" config/name="LD54"

View File

@ -1,21 +1,20 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://src/models/enemies/trash_can/sprites/trash_can.png" type="Texture" id=1]
[ext_resource path="res://src/models/enemies/trash_can/trash_can.gd" type="Script" id=2] [ext_resource path="res://src/models/enemies/trash_can/trash_can.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8.5 ) extents = Vector2( 6, 7 )
[node name="TrashCan" type="KinematicBody2D"] [node name="TrashCan" type="KinematicBody2D"]
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."] [node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 0.25, 0.25 )
texture = ExtResource( 1 ) texture = ExtResource( 1 )
centered = false centered = false
[node name="EnemyCollider" type="Area2D" parent="."] [node name="EnemyCollider" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollider"] [node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollider"]
position = Vector2( 8, 8.5 ) position = Vector2( 6, 7 )
shape = SubResource( 1 ) shape = SubResource( 1 )

View File

@ -1,12 +1,20 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://src/models/enemies/trash_can/drop/drop.png" type="Texture" id=1]
[ext_resource path="res://src/models/enemies/trash_can/drop/trash_drop.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 6, 6 ) extents = Vector2( 4, 4 )
[node name="TrashDrop" type="StaticBody2D"] [node name="TrashDrop" type="StaticBody2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
centered = false
[node name="Area2D" type="Area2D" parent="."] [node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 6, 6 ) position = Vector2( 4, 4 )
shape = SubResource( 1 ) shape = SubResource( 1 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/drop.png-43903b6c0b365d394fc3a965a28edba7.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://src/models/enemies/trash_can/drop/drop.png"
dest_files=[ "res://.import/drop.png-43903b6c0b365d394fc3a965a28edba7.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,10 @@
extends StaticBody2D
var alive_timer = .0
func _physics_process(delta):
alive_timer += delta
if alive_timer > 2:
$Sprite.modulate.a = 3 - alive_timer
if alive_timer > 3:
self.call_deferred("free")

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/horizontal.png-274e119b44df77eddc16fb5f657c855e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://src/models/enemies/trash_can/sprites/path/horizontal.png"
dest_files=[ "res://.import/horizontal.png-274e119b44df77eddc16fb5f657c855e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/vertical.png-8da31b1b3e77a0754e060d4d1c008980.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://src/models/enemies/trash_can/sprites/path/vertical.png"
dest_files=[ "res://.import/vertical.png-8da31b1b3e77a0754e060d4d1c008980.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/trash_can.png-0987d8f67e93f5b32fac39729f87305a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://src/models/enemies/trash_can/sprites/trash_can.png"
dest_files=[ "res://.import/trash_can.png-0987d8f67e93f5b32fac39729f87305a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -7,42 +7,86 @@ var velocity
var start_timer = .0 var start_timer = .0
var drop_timer = .0 var drop_timer = .0
var last_x
var last_y
var drop_preload = preload("res://src/models/enemies/trash_can/drop/TrashDrop.tscn")
var path_sprite = Sprite.new()
var horizontal_speed = 160 var horizontal_speed = 160
var vertical_speed = 60 var vertical_speed = 60
func _ready(): func _ready():
path_sprite.name = "trash_path"
randomize() randomize()
movement_type = ["horizontal", "vertical"][randi()%2] movement_type = ["horizontal", "vertical"][randi()%2]
if movement_type == "vertical": if movement_type == "vertical":
movement_start = "top" movement_start = "top"
global_position.x = randi()&268 + 20 # 320 - 12 - 20 randomize()
global_position.x = randi()%248 + 40 # 320 - 12 - 40
global_position.y = -20 global_position.y = -20
path_sprite.texture = load("res://src/models/enemies/trash_can/sprites/path/vertical.png")
path_sprite.global_position.y = 21
path_sprite.global_position.x = self.global_position.x
else: else:
randomize()
movement_start = ["left", "right"][randi()%2] movement_start = ["left", "right"][randi()%2]
randomize()
global_position.y = randi()%60 + 20 global_position.y = randi()%60 + 20
global_position.x = 360 if movement_start == "right" else -20 global_position.x = 360 if movement_start == "right" else -20
path_sprite.texture = load("res://src/models/enemies/trash_can/sprites/path/horizontal.png")
path_sprite.global_position.y = self.global_position.y
path_sprite.global_position.x = 26
last_x = self.global_position.x
last_y = self.global_position.y
path_sprite.centered = false
path_sprite.modulate.a = 1
get_parent().call_deferred("add_child", path_sprite)
func drop_trash(): func drop_trash():
pass var trash_drop = drop_preload.instance()
trash_drop.global_position = self.global_position
get_parent().call_deferred("add_child", trash_drop)
func _physics_process(delta): func _physics_process(delta):
if start_timer < 2: if start_timer < 2:
path_sprite.modulate.a = 2 - start_timer
start_timer += delta start_timer += delta
return return
drop_timer += delta drop_timer += delta
if drop_timer > .5:
drop_timer = 0
drop_trash()
velocity = Vector2.ZERO velocity = Vector2.ZERO
if movement_type == "horizontal": if movement_type == "horizontal":
if movement_start == "left": if movement_start == "left":
velocity.x += horizontal_speed velocity.x += horizontal_speed
if self.global_position.x > 360:
path_sprite.call_deferred("free")
self.call_deferred("free")
if self.global_position.x > last_x + 7:
last_x = self.global_position.x
drop_trash()
else: else:
velocity.x -= horizontal_speed velocity.x -= horizontal_speed
if self.global_position.x < 0:
path_sprite.call_deferred("free")
self.call_deferred("free")
if self.global_position.x < last_x - 7:
last_x = self.global_position.x
drop_trash()
else: else:
velocity.y += vertical_speed velocity.y += vertical_speed
if self.global_position.y > 160:
path_sprite.call_deferred("free")
self.call_deferred("free")
if self.global_position.y > last_y + 7:
last_y = self.global_position.y
drop_trash()
velocity = move_and_slide(velocity) velocity = move_and_slide(velocity)

View File

@ -4,7 +4,7 @@
[ext_resource path="res://src/models/player/player.gd" type="Script" id=2] [ext_resource path="res://src/models/player/player.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7, 11 ) extents = Vector2( 4, 5.5 )
[sub_resource type="RectangleShape2D" id=2] [sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 7, 11 ) extents = Vector2( 7, 11 )

View File

@ -44,28 +44,6 @@ centered = false
region_enabled = true region_enabled = true
region_rect = Rect2( 0, 0, 320, 180 ) region_rect = Rect2( 0, 0, 320, 180 )
[node name="Houses" type="StaticBody2D" parent="View/Background"]
[node name="Sprite" type="Sprite" parent="View/Background/Houses"]
texture = ExtResource( 2 )
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="View/Background/Houses"]
position = Vector2( 10, 60 )
shape = SubResource( 2 )
[node name="CollisionShape2D2" type="CollisionShape2D" parent="View/Background/Houses"]
position = Vector2( 310, 60 )
shape = SubResource( 2 )
[node name="CollisionShape2D3" type="CollisionShape2D" parent="View/Background/Houses"]
position = Vector2( 160, 10.25 )
shape = SubResource( 3 )
[node name="CollisionShape2D4" type="CollisionShape2D" parent="View/Background/Houses"]
position = Vector2( 160, 109.875 )
shape = SubResource( 3 )
[node name="Player" parent="View" instance=ExtResource( 5 )] [node name="Player" parent="View" instance=ExtResource( 5 )]
position = Vector2( 46, 42 ) position = Vector2( 46, 42 )
@ -73,6 +51,28 @@ position = Vector2( 46, 42 )
margin_right = 40.0 margin_right = 40.0
margin_bottom = 40.0 margin_bottom = 40.0
[node name="Houses" type="StaticBody2D" parent="UI"]
[node name="Sprite" type="Sprite" parent="UI/Houses"]
texture = ExtResource( 2 )
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="UI/Houses"]
position = Vector2( 10, 60 )
shape = SubResource( 2 )
[node name="CollisionShape2D2" type="CollisionShape2D" parent="UI/Houses"]
position = Vector2( 310, 60 )
shape = SubResource( 2 )
[node name="CollisionShape2D3" type="CollisionShape2D" parent="UI/Houses"]
position = Vector2( 160, 10.25 )
shape = SubResource( 3 )
[node name="CollisionShape2D4" type="CollisionShape2D" parent="UI/Houses"]
position = Vector2( 160, 109.875 )
shape = SubResource( 3 )
[node name="Background" type="TextureRect" parent="UI"] [node name="Background" type="TextureRect" parent="UI"]
margin_top = 120.0 margin_top = 120.0
margin_right = 320.0 margin_right = 320.0