generated from hertog/godot-module-template
2d template pushed
This commit is contained in:
parent
aa8cc49f4d
commit
4da7e28cb5
73 changed files with 3120 additions and 11 deletions
87
project/enemy/enemy.gd
Normal file
87
project/enemy/enemy.gd
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
class_name Enemy
|
||||
extends RigidBody2D
|
||||
|
||||
|
||||
const WALK_SPEED = 50
|
||||
|
||||
enum State {
|
||||
WALKING,
|
||||
DYING,
|
||||
}
|
||||
|
||||
var _state := State.WALKING
|
||||
|
||||
var direction := -1
|
||||
var anim := ""
|
||||
|
||||
@onready var rc_left := $RaycastLeft as RayCast2D
|
||||
@onready var rc_right := $RaycastRight as RayCast2D
|
||||
|
||||
|
||||
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
|
||||
var velocity := state.get_linear_velocity()
|
||||
var new_anim := anim
|
||||
|
||||
if _state == State.DYING:
|
||||
new_anim = "explode"
|
||||
elif _state == State.WALKING:
|
||||
new_anim = "walk"
|
||||
|
||||
var wall_side := 0.0
|
||||
|
||||
for collider_index in state.get_contact_count():
|
||||
var collider := state.get_contact_collider_object(collider_index)
|
||||
var collision_normal := state.get_contact_local_normal(collider_index)
|
||||
|
||||
if collider is Bullet and not (collider as Bullet).disabled:
|
||||
_bullet_collider.call_deferred(collider, state, collision_normal)
|
||||
break
|
||||
|
||||
if collision_normal.x > 0.9:
|
||||
wall_side = 1.0
|
||||
elif collision_normal.x < -0.9:
|
||||
wall_side = -1.0
|
||||
|
||||
if wall_side != 0 and wall_side != direction:
|
||||
direction = -direction
|
||||
($Sprite2D as Sprite2D).scale.x = -direction
|
||||
if direction < 0 and not rc_left.is_colliding() and rc_right.is_colliding():
|
||||
direction = -direction
|
||||
($Sprite2D as Sprite2D).scale.x = -direction
|
||||
elif direction > 0 and not rc_right.is_colliding() and rc_left.is_colliding():
|
||||
direction = -direction
|
||||
($Sprite2D as Sprite2D).scale.x = -direction
|
||||
|
||||
velocity.x = direction * WALK_SPEED
|
||||
|
||||
if anim != new_anim:
|
||||
anim = new_anim
|
||||
($AnimationPlayer as AnimationPlayer).play(anim)
|
||||
|
||||
state.set_linear_velocity(velocity)
|
||||
|
||||
|
||||
func _die() -> void:
|
||||
queue_free()
|
||||
|
||||
|
||||
func _pre_explode() -> void:
|
||||
#make sure nothing collides against this
|
||||
$Shape1.queue_free()
|
||||
$Shape2.queue_free()
|
||||
$Shape3.queue_free()
|
||||
|
||||
($SoundExplode as AudioStreamPlayer2D).play()
|
||||
|
||||
|
||||
func _bullet_collider(
|
||||
collider: Bullet,
|
||||
state: PhysicsDirectBodyState2D,
|
||||
collision_normal: Vector2
|
||||
) -> void:
|
||||
_state = State.DYING
|
||||
|
||||
state.set_angular_velocity(signf(collision_normal.x) * 33.0)
|
||||
physics_material_override.friction = 1
|
||||
collider.disable()
|
||||
($SoundHit as AudioStreamPlayer2D).play()
|
||||
BIN
project/enemy/enemy.png
Normal file
BIN
project/enemy/enemy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 817 B |
34
project/enemy/enemy.png.import
Normal file
34
project/enemy/enemy.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://crrmmbu8k46tl"
|
||||
path="res://.godot/imported/enemy.png-1891d9038eeed672a2459bc4e7db5910.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://enemy/enemy.png"
|
||||
dest_files=["res://.godot/imported/enemy.png-1891d9038eeed672a2459bc4e7db5910.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
|
||||
202
project/enemy/enemy.tscn
Normal file
202
project/enemy/enemy.tscn
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://daqqtote00syu"]
|
||||
|
||||
[ext_resource type="Script" path="res://enemy/enemy.gd" id="1_hjwkx"]
|
||||
[ext_resource type="Texture2D" uid="uid://crrmmbu8k46tl" path="res://enemy/enemy.png" id="2_org2d"]
|
||||
[ext_resource type="Texture2D" uid="uid://7sv64orewgmb" path="res://player/bullet.png" id="3_7unrb"]
|
||||
[ext_resource type="AudioStream" uid="uid://cfssio7r2t7wq" path="res://audio/sound_hit.wav" id="4_5rkwm"]
|
||||
[ext_resource type="AudioStream" uid="uid://bulmr2lpb7y4h" path="res://audio/sound_explode.wav" id="5_t2e2f"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_eyxlk"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_a7qal"]
|
||||
resource_name = "RESET"
|
||||
length = 0.01
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sprite2D:self_modulate")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="2"]
|
||||
length = 6.0
|
||||
step = 0.0
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [4]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Explosion:emitting")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(1),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/2/type = "method"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath(".")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(1.04, 2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"values": [{
|
||||
"args": [],
|
||||
"method": &"_pre_explode"
|
||||
}, {
|
||||
"args": [],
|
||||
"method": &"_die"
|
||||
}]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("Sprite2D:self_modulate")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
"times": PackedFloat32Array(0.5, 1.1),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="3"]
|
||||
length = 6.75
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.75, 1.5, 2.25, 3, 3.75, 4.5, 5.25, 6, 6.75),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [5, 6, 5, 6, 5, 6, 7, 6, 7, 5]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="4"]
|
||||
length = 0.5
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1, 2, 3, 4, 0]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ay0tp"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_a7qal"),
|
||||
"explode": SubResource("2"),
|
||||
"idle": SubResource("3"),
|
||||
"walk": SubResource("4")
|
||||
}
|
||||
|
||||
[sub_resource type="CircleShape2D" id="5"]
|
||||
radius = 7.0
|
||||
|
||||
[sub_resource type="Gradient" id="6"]
|
||||
offsets = PackedFloat32Array(0.5, 1)
|
||||
colors = PackedColorArray(1, 1, 1, 0.501961, 0, 0, 0, 0)
|
||||
|
||||
[node name="Enemy" type="RigidBody2D"]
|
||||
physics_material_override = SubResource("PhysicsMaterial_eyxlk")
|
||||
lock_rotation = true
|
||||
max_contacts_reported = 4
|
||||
contact_monitor = true
|
||||
script = ExtResource("1_hjwkx")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_ay0tp")
|
||||
}
|
||||
|
||||
[node name="SoundExplode" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = ExtResource("5_t2e2f")
|
||||
|
||||
[node name="SoundHit" type="AudioStreamPlayer2D" parent="."]
|
||||
position = Vector2(0, -1)
|
||||
stream = ExtResource("4_5rkwm")
|
||||
|
||||
[node name="VisibleOnScreenEnabler2D" type="VisibleOnScreenEnabler2D" parent="."]
|
||||
rect = Rect2(-150, -100, 300, 200)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_org2d")
|
||||
hframes = 8
|
||||
|
||||
[node name="Shape1" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-0.54036, -1.08072)
|
||||
shape = SubResource("5")
|
||||
|
||||
[node name="Shape2" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(3.24216, 1.62108)
|
||||
shape = SubResource("5")
|
||||
|
||||
[node name="Shape3" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-6.2475, 1.76707)
|
||||
shape = SubResource("5")
|
||||
|
||||
[node name="RaycastLeft" type="RayCast2D" parent="."]
|
||||
position = Vector2(-14, -4.672)
|
||||
|
||||
[node name="RaycastRight" type="RayCast2D" parent="."]
|
||||
position = Vector2(11, -4.672)
|
||||
|
||||
[node name="Explosion" type="CPUParticles2D" parent="."]
|
||||
modulate = Color(1, 1, 1, 0.685843)
|
||||
emitting = false
|
||||
amount = 32
|
||||
lifetime = 0.5
|
||||
one_shot = true
|
||||
speed_scale = 1.2
|
||||
explosiveness = 0.76
|
||||
texture = ExtResource("3_7unrb")
|
||||
emission_shape = 1
|
||||
emission_sphere_radius = 8.0
|
||||
spread = 180.0
|
||||
gravity = Vector2(0, 0)
|
||||
color_ramp = SubResource("6")
|
||||
Loading…
Add table
Add a link
Reference in a new issue