Peashooters
This commit is contained in:
parent
161f87da75
commit
68cfe89f1d
47 changed files with 1571 additions and 279 deletions
|
|
@ -0,0 +1,33 @@
|
|||
extends Node
|
||||
|
||||
const projectile := preload("uid://ciqhjwh4sfe3u")
|
||||
|
||||
@export var projectile_transform : Marker2D
|
||||
|
||||
var detected : bool = false
|
||||
var can_shoot : bool = true
|
||||
|
||||
@onready var timer := $Timer
|
||||
@onready var entity : Entity = get_parent()
|
||||
|
||||
func is_shooting():
|
||||
return detected and can_shoot and entity.disabled == false
|
||||
|
||||
func _on_generic_hurtbox_collision_start() -> void:
|
||||
detected = true
|
||||
|
||||
func _on_generic_hurtbox_collision_end() -> void:
|
||||
detected = false
|
||||
|
||||
func shoot():
|
||||
if can_shoot == false:
|
||||
return
|
||||
can_shoot = false
|
||||
timer.start()
|
||||
var proj = projectile.instantiate()
|
||||
get_tree().current_scene.get_node("%Projectiles").add_child(proj)
|
||||
proj.global_transform = projectile_transform.global_transform
|
||||
proj.source = entity
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
can_shoot = true
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b0ka8lb5kl1fd
|
||||
29
scripts/components/controllers/zombies/basic_controller.gd
Normal file
29
scripts/components/controllers/zombies/basic_controller.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node
|
||||
|
||||
var eating:
|
||||
get:
|
||||
return is_eating()
|
||||
var walking:
|
||||
get:
|
||||
return is_walking()
|
||||
|
||||
@export var hurtbox : GenericHurtbox
|
||||
@export var damage : float
|
||||
@onready var disablable := get_parent()
|
||||
|
||||
var killed := false
|
||||
|
||||
func _on_entity_killed(_context: RefCounted) -> void:
|
||||
if killed: return
|
||||
$"../AnimationTree"["parameters/main/playback"].travel("death")
|
||||
killed = true
|
||||
|
||||
func is_eating() -> bool:
|
||||
return hurtbox.is_colliding() and disablable.disabled == false
|
||||
|
||||
func is_walking() -> bool:
|
||||
return disablable.disabled == false
|
||||
|
||||
func bite() -> void:
|
||||
if hurtbox.is_colliding() == false: return
|
||||
hurtbox.get_colliding_entity().deal_damage(damage,get_parent())
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bg88vb74hinkj
|
||||
4
scripts/components/field_segment_shape.gd
Normal file
4
scripts/components/field_segment_shape.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends CollisionShape2D
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
shape.b = Vector2(FieldParams.field_rect.end.x-global_position.x+FieldParams.TILE.x,0)
|
||||
1
scripts/components/field_segment_shape.gd.uid
Normal file
1
scripts/components/field_segment_shape.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cjulv0bt6deps
|
||||
15
scripts/components/generic_collider.gd
Normal file
15
scripts/components/generic_collider.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Area2D
|
||||
|
||||
## Base class for generic colliders.
|
||||
|
||||
class_name GenericCollider
|
||||
|
||||
## Contact layer. Used to check
|
||||
enum Layers
|
||||
{
|
||||
NORMAL = 1,
|
||||
LOW = 2,
|
||||
HIGH = 4
|
||||
}
|
||||
|
||||
@export var layer : Layers = Layers.NORMAL
|
||||
1
scripts/components/generic_collider.gd.uid
Normal file
1
scripts/components/generic_collider.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://be5rfbbl5xgeh
|
||||
45
scripts/components/generic_hurtbox.gd
Normal file
45
scripts/components/generic_hurtbox.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
extends Area2D
|
||||
|
||||
class_name GenericHurtbox
|
||||
|
||||
@export_flags("NORMAL:1","LOW:2","HIGH:4") var lookup_layers : int = 0
|
||||
var entities : Array[Entity] = []
|
||||
|
||||
signal entity_added(entity : Entity)
|
||||
signal entity_removed(entity : Entity)
|
||||
signal collision_start
|
||||
signal collision_end
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(on_area_entered)
|
||||
area_exited.connect(on_area_exited)
|
||||
|
||||
func on_area_entered(area: Area2D):
|
||||
if area is GenericCollider:
|
||||
if lookup_layers & area.layer != 0:
|
||||
add_entity(area.get_parent())
|
||||
|
||||
func on_area_exited(area: Area2D):
|
||||
if area is GenericCollider:
|
||||
if lookup_layers & area.layer != 0:
|
||||
remove_entity(area.get_parent())
|
||||
|
||||
func add_entity(entity : Entity):
|
||||
entities.append(entity)
|
||||
entity_added.emit(entity)
|
||||
if entities.size() == 1:
|
||||
collision_start.emit()
|
||||
|
||||
func remove_entity(entity : Entity):
|
||||
entities.erase(entity)
|
||||
entity_removed.emit(entity)
|
||||
if entities.size() == 0:
|
||||
collision_end.emit()
|
||||
|
||||
func get_colliding_entity() -> Entity:
|
||||
if entities.size() == 0:
|
||||
return null
|
||||
return entities[0]
|
||||
|
||||
func is_colliding() -> bool:
|
||||
return entities.size() > 0
|
||||
1
scripts/components/generic_hurtbox.gd.uid
Normal file
1
scripts/components/generic_hurtbox.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cbudgx741oxtc
|
||||
10
scripts/components/mover.gd
Normal file
10
scripts/components/mover.gd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
extends Node
|
||||
|
||||
@export_range(0,2,0.001,"or_greater","hide_slider","suffix:tiles/second") var speed : float = 0.2
|
||||
# Used by animation players to control zombie's movement
|
||||
@export var speed_control : float = 0.0
|
||||
|
||||
@onready var parent : Node2D = get_parent()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
parent.global_position += -parent.global_transform.x * speed_control * speed * delta * FieldParams.TILE.x
|
||||
1
scripts/components/mover.gd.uid
Normal file
1
scripts/components/mover.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bdacurei5fp02
|
||||
5
scripts/components/plant_death_handler.gd
Normal file
5
scripts/components/plant_death_handler.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func _on_killed(context: RefCounted) -> void:
|
||||
get_parent().deconstruct()
|
||||
1
scripts/components/plant_death_handler.gd.uid
Normal file
1
scripts/components/plant_death_handler.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d17rkta3k73jx
|
||||
5
scripts/components/zombie_death_handler.gd
Normal file
5
scripts/components/zombie_death_handler.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends Node
|
||||
|
||||
func _on_animation_tree_animation_finished(anim_name: StringName) -> void:
|
||||
if anim_name.split("/")[1] == "death":
|
||||
get_parent().deconstruct()
|
||||
1
scripts/components/zombie_death_handler.gd.uid
Normal file
1
scripts/components/zombie_death_handler.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dfnyam1pvkb73
|
||||
Loading…
Add table
Add a link
Reference in a new issue