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
|
||||
|
|
@ -8,8 +8,9 @@ class_name Entity
|
|||
## Optional spawn layer for grid interactions
|
||||
@export var layer : StringName = ""
|
||||
## Current amount of health points of an entity. Cannot be below 0 or [code]max_hp[/code]
|
||||
var hp : float = max_hp
|
||||
|
||||
@onready var hp : float = max_hp
|
||||
##
|
||||
var disabled : bool = false
|
||||
|
||||
signal damaged
|
||||
## Emitted when damage is taken
|
||||
|
|
@ -20,6 +21,21 @@ signal healed(context : HealedContext)
|
|||
signal hp_changed(context : HPChangedContext)
|
||||
## Emitted when kill is requested
|
||||
signal killed(context : KilledContext)
|
||||
##
|
||||
signal toggled(disabled : bool)
|
||||
|
||||
|
||||
##
|
||||
func disable():
|
||||
if disabled: return
|
||||
disabled = true
|
||||
toggled.emit(disabled)
|
||||
|
||||
##
|
||||
func enable():
|
||||
if disabled == false: return
|
||||
disabled = false
|
||||
toggled.emit(disabled)
|
||||
|
||||
## Properly deal damage to entity
|
||||
func deal_damage(amount : float, source : Entity):
|
||||
|
|
@ -42,7 +58,6 @@ func deal_damage(amount : float, source : Entity):
|
|||
hp = 0
|
||||
kill(source)
|
||||
|
||||
|
||||
## Properly heal entity
|
||||
func heal(amount : float, source : Entity):
|
||||
var context = HealedContext.new()
|
||||
|
|
@ -61,7 +76,6 @@ func heal(amount : float, source : Entity):
|
|||
if hp > max_hp:
|
||||
hp = max_hp
|
||||
|
||||
|
||||
## Invoked when an entity is killed by damage.
|
||||
func kill(source : Entity):
|
||||
var context = KilledContext.new()
|
||||
|
|
@ -72,9 +86,6 @@ func kill(source : Entity):
|
|||
LevelEventBus.entity_killed.emit(context)
|
||||
if not layer.is_empty():
|
||||
LevelEventBus.layer_entity_killed.emit(context)
|
||||
|
||||
deconstruct()
|
||||
|
||||
|
||||
## Method used to properly deconstruct entity
|
||||
func deconstruct():
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
extends CanvasGroup
|
||||
extends Node2D
|
||||
|
||||
@export var entity_container : LayeredEntityContainer
|
||||
var can_plant : bool = false
|
||||
|
|
@ -24,13 +24,16 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
if held_packet != null and can_plant and event.is_action_pressed("primary_action"):
|
||||
for child in get_children():
|
||||
child.enable()
|
||||
child.reparent(get_tree().current_scene.get_node("%Plants"))
|
||||
LevelEventBus.packet_placed.emit(held_packet)
|
||||
held_packet = null
|
||||
visible = false
|
||||
|
||||
func on_seedpacket_selected(packet : SeedpacketResource) -> void:
|
||||
add_child(packet.scene.instantiate())
|
||||
var instantiated = packet.scene.instantiate()
|
||||
add_child(instantiated)
|
||||
instantiated.disable()
|
||||
held_packet = packet
|
||||
visible = true
|
||||
|
||||
|
|
|
|||
18
scripts/projectiles/linear_projectile.gd
Normal file
18
scripts/projectiles/linear_projectile.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends Area2D
|
||||
|
||||
var source : Entity
|
||||
|
||||
@export var speed : float
|
||||
@export var damage : float
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(on_area_entered)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
global_position += global_transform.x * speed * delta
|
||||
|
||||
func on_area_entered(area : Area2D):
|
||||
if area.get_parent() != null:
|
||||
area.get_parent().deal_damage(damage, source)
|
||||
queue_free()
|
||||
1
scripts/projectiles/linear_projectile.gd.uid
Normal file
1
scripts/projectiles/linear_projectile.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://fgdhvaq4dek2
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
extends AnimationTree
|
||||
|
||||
|
||||
func on_speed_changed(speed : float):
|
||||
set("parameters/speed/scale",speed)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cbmavbe4xd0j2
|
||||
16
scripts/speed_controlled/speed_controlled_timer.gd
Normal file
16
scripts/speed_controlled/speed_controlled_timer.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends Timer
|
||||
|
||||
|
||||
var old_speed : float
|
||||
|
||||
func on_speed_changed(speed : float):
|
||||
var ratio = speed / old_speed
|
||||
var old_wait_time = wait_time
|
||||
var old_time_left = time_left
|
||||
|
||||
if old_time_left > 0:
|
||||
start(old_time_left * ratio)
|
||||
|
||||
wait_time = old_wait_time * ratio
|
||||
|
||||
old_speed = speed
|
||||
1
scripts/speed_controlled/speed_controlled_timer.gd.uid
Normal file
1
scripts/speed_controlled/speed_controlled_timer.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bk1twclmpvalk
|
||||
Loading…
Add table
Add a link
Reference in a new issue