Create Trash Can Enemy

main
Luna Brovchuk 2023-09-30 21:09:52 +02:00
parent 58bc799cb9
commit f54e70173c
6 changed files with 102 additions and 7 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"
@ -38,7 +48,7 @@ version_control_plugin_name="GitAPI"
[gdnative] [gdnative]
singletons=[ ] singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ]
[global] [global]

View File

@ -0,0 +1,21 @@
[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/trash_can.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8.5 )
[node name="TrashCan" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 0.25, 0.25 )
texture = ExtResource( 1 )
centered = false
[node name="EnemyCollider" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyCollider"]
position = Vector2( 8, 8.5 )
shape = SubResource( 1 )

View File

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 6, 6 )
[node name="TrashDrop" type="StaticBody2D"]
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 6, 6 )
shape = SubResource( 1 )

View File

@ -0,0 +1,48 @@
extends KinematicBody2D
var movement_type # horizontal or vertical
var movement_start # top left or right
var velocity
var start_timer = .0
var drop_timer = .0
var horizontal_speed = 160
var vertical_speed = 60
func _ready():
randomize()
movement_type = ["horizontal", "vertical"][randi()%2]
if movement_type == "vertical":
movement_start = "top"
global_position.x = randi()&268 + 20 # 320 - 12 - 20
global_position.y = -20
else:
movement_start = ["left", "right"][randi()%2]
global_position.y = randi()%60 + 20
global_position.x = 360 if movement_start == "right" else -20
func drop_trash():
pass
func _physics_process(delta):
if start_timer < 2:
start_timer += delta
return
drop_timer += delta
if drop_timer > .5:
drop_timer = 0
drop_trash()
velocity = Vector2.ZERO
if movement_type == "horizontal":
if movement_start == "left":
velocity.x += horizontal_speed
else:
velocity.x -= horizontal_speed
else:
velocity.y += vertical_speed
velocity = move_and_slide(velocity)

View File

@ -1,7 +1,7 @@
extends KinematicBody2D extends KinematicBody2D
var velocity = Vector2.ZERO var velocity = Vector2.ZERO
var speed = 120 var speed = 100
func get_input(): func get_input():
var input_direction = Input.get_vector("left", "right", "up", "down") var input_direction = Input.get_vector("left", "right", "up", "down")

View File

@ -1,13 +1,17 @@
[gd_scene load_steps=13 format=2] [gd_scene load_steps=17 format=2]
[ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1]
[ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2]
[ext_resource path="res://src/scenes/game/spell_holder.gd" type="Script" id=3] [ext_resource path="res://src/scenes/game/spell_holder.gd" type="Script" id=3]
[ext_resource path="res://res/fonts/silkscreen/Silkscreen-Regular.ttf" type="DynamicFontData" id=4] [ext_resource path="res://res/fonts/silkscreen/Silkscreen-Regular.ttf" type="DynamicFontData" id=4]
[ext_resource path="res://src/models/player/Player.tscn" type="PackedScene" id=5] [ext_resource path="res://src/models/player/Player.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/scenes/game/sprites/ui_background.png" type="Texture" id=6] [ext_resource path="res://src/scenes/game/sprites/health/3.png" type="Texture" id=6]
[ext_resource path="res://src/scenes/game/sprites/health/1.png" type="Texture" id=7]
[ext_resource path="res://src/scenes/game/sprites/health/2.png" type="Texture" id=8]
[ext_resource path="res://src/scenes/game/sprites/health/0.png" type="Texture" id=9]
[ext_resource path="res://icon.png" type="Texture" id=10] [ext_resource path="res://icon.png" type="Texture" id=10]
[ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11] [ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11]
[ext_resource path="res://src/scenes/game/sprites/ui_background.png" type="Texture" id=12]
[sub_resource type="RectangleShape2D" id=2] [sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 10, 60 ) extents = Vector2( 10, 60 )
@ -21,7 +25,7 @@ font_data = ExtResource( 4 )
[sub_resource type="SpriteFrames" id=4] [sub_resource type="SpriteFrames" id=4]
animations = [ { animations = [ {
"frames": [ null, null, null, null ], "frames": [ ExtResource( 9 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 6 ) ],
"loop": true, "loop": true,
"name": "default", "name": "default",
"speed": 5.0 "speed": 5.0
@ -69,11 +73,11 @@ position = Vector2( 46, 42 )
margin_right = 40.0 margin_right = 40.0
margin_bottom = 40.0 margin_bottom = 40.0
[node name="UIBackground" 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
margin_bottom = 180.0 margin_bottom = 180.0
texture = ExtResource( 6 ) texture = ExtResource( 12 )
expand = true expand = true
[node name="SpellHolder" type="Control" parent="UI"] [node name="SpellHolder" type="Control" parent="UI"]