Player gun, bullet and its collisiions. Refactor.
This commit is contained in:
parent
0dd3f24030
commit
ffb7c8bf99
28 changed files with 562 additions and 131 deletions
9
metroidvania/Scenes/Enemies/Enemy.gd
Normal file
9
metroidvania/Scenes/Enemies/Enemy.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
export (int) var MAX_SPEED = 15
|
||||
|
||||
var motion = Vector2.ZERO
|
||||
|
||||
|
||||
func _on_Hurtbox_hit(_damage):
|
||||
queue_free()
|
19
metroidvania/Scenes/Enemies/Enemy.tscn
Normal file
19
metroidvania/Scenes/Enemies/Enemy.tscn
Normal file
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Enemies/Enemy.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Scenes/Objects/Hurtbox.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="Enemy" type="KinematicBody2D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
|
||||
[node name="Collider" type="CollisionShape2D" parent="."]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 2 )]
|
||||
collision_mask = 8
|
||||
[connection signal="hit" from="Hurtbox" to="." method="_on_Hurtbox_hit"]
|
32
metroidvania/Scenes/Enemies/WalkingEnemy.gd
Normal file
32
metroidvania/Scenes/Enemies/WalkingEnemy.gd
Normal file
|
@ -0,0 +1,32 @@
|
|||
extends "res://Scenes/Enemies/Enemy.gd"
|
||||
|
||||
enum DIRECTION {LEFT = -1, RIGHT = 1}
|
||||
|
||||
export (DIRECTION) var WALKING_DIRECTION = DIRECTION.RIGHT
|
||||
|
||||
var state
|
||||
|
||||
onready var sprite = $Sprite
|
||||
onready var floor_left = $FloorLeft
|
||||
onready var floor_right = $FloorRight
|
||||
onready var wall_right = $WallRight
|
||||
onready var wall_left = $WallLeft
|
||||
|
||||
func _ready():
|
||||
motion.y = 8
|
||||
state = WALKING_DIRECTION
|
||||
|
||||
func _physics_process(_delta):
|
||||
match state:
|
||||
DIRECTION.RIGHT:
|
||||
motion.x = MAX_SPEED
|
||||
if not floor_right.is_colliding() or wall_right.is_colliding():
|
||||
state = DIRECTION.LEFT
|
||||
|
||||
DIRECTION.LEFT:
|
||||
motion.x = -MAX_SPEED
|
||||
if not floor_left.is_colliding() or wall_left.is_colliding():
|
||||
state = DIRECTION.RIGHT
|
||||
|
||||
sprite.scale.x = sign(motion.x)
|
||||
motion = move_and_slide_with_snap(motion, Vector2.DOWN * 4, Vector2.UP, true, 4, deg2rad(46))
|
79
metroidvania/Scenes/Enemies/WalkingEnemy.tscn
Normal file
79
metroidvania/Scenes/Enemies/WalkingEnemy.tscn
Normal file
|
@ -0,0 +1,79 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Enemies/WalkingEnemy.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Assets/Enemies/WalkingEnemy.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Scenes/Enemies/Enemy.tscn" type="PackedScene" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 2, 6 )
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
resource_name = "Walking"
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("../WalkingEnemy/Sprite:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.5 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ 0, 1 ]
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 7, 6 )
|
||||
|
||||
[node name="WalkingEnemy" instance=ExtResource( 3 )]
|
||||
script = ExtResource( 1 )
|
||||
MAX_SPEED = 15
|
||||
|
||||
[node name="Sprite" parent="." index="0"]
|
||||
position = Vector2( 0, -9 )
|
||||
texture = ExtResource( 2 )
|
||||
flip_h = true
|
||||
hframes = 2
|
||||
|
||||
[node name="Collider" parent="." index="1"]
|
||||
position = Vector2( 0, -6 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" parent="." index="2"]
|
||||
autoplay = "Walking"
|
||||
anims/Walking = SubResource( 2 )
|
||||
|
||||
[node name="FloorRight" type="RayCast2D" parent="." index="3"]
|
||||
position = Vector2( 2, -1 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, 7 )
|
||||
collision_mask = 2
|
||||
|
||||
[node name="FloorLeft" type="RayCast2D" parent="." index="4"]
|
||||
position = Vector2( -2, -1 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, 7 )
|
||||
collision_mask = 2
|
||||
|
||||
[node name="WallRight" type="RayCast2D" parent="." index="5"]
|
||||
position = Vector2( 0, -8 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 6, 0 )
|
||||
collision_mask = 2
|
||||
|
||||
[node name="WallLeft" type="RayCast2D" parent="." index="6"]
|
||||
position = Vector2( 0, -8 )
|
||||
enabled = true
|
||||
cast_to = Vector2( -6, 0 )
|
||||
collision_mask = 2
|
||||
|
||||
[node name="Hurtbox" parent="." index="7"]
|
||||
collision_layer = 8
|
||||
collision_mask = 0
|
||||
|
||||
[node name="Collider" parent="Hurtbox" index="0"]
|
||||
position = Vector2( 0, -7 )
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[editable path="Hurtbox"]
|
Loading…
Add table
Add a link
Reference in a new issue