Cleanup Code

This commit is contained in:
Snoweuph 2023-04-08 17:17:48 +02:00
parent edb4265367
commit 08a134d2fc
2 changed files with 8 additions and 10 deletions

View file

@ -8,12 +8,12 @@ var team : int
var on_death_callbacks : Array var on_death_callbacks : Array
func damage(damage : int): func damage(damage : int):
health -= health health -= damage
if(health <= 0): on_death() if(health <= 0): on_death()
pass pass
func heal(health : int): func heal(health : int):
health += health self.health += health
pass pass
func on_death(): func on_death():

View file

@ -6,20 +6,17 @@ extends Area2D
@export_flags_2d_physics var map_collision_layer : int @export_flags_2d_physics var map_collision_layer : int
@export_flags_2d_physics var bunny_collision_layer : int @export_flags_2d_physics var bunny_collision_layer : int
const bunny_script = preload("res://Scripts/EntitySystem/Bunny.gd")
func _process(delta): func _process(delta):
self.translate(Vector2(cos(self.rotation), sin(self.rotation)) * speed * delta) self.translate(Vector2(cos(self.rotation), sin(self.rotation)) * speed * delta)
pass pass
func _on_collision(body): func _on_collision(body):
var collision_layer = null; var collision_layer = null;
match body.get_class():
"TileMap": if body.get_class() == "TileMap":
collision_layer = body.tile_set.get_physics_layer_collision_layer(0) collision_layer = body.tile_set.get_physics_layer_collision_layer(0)
_: if(body.has_method("get_collision_layer")):
if(body.has_method("get_collision_layer")): collision_layer = body.get_collision_layer() collision_layer = body.get_collision_layer()
if collision_layer & map_collision_layer: if collision_layer & map_collision_layer:
queue_free() queue_free()
@ -27,3 +24,4 @@ func _on_collision(body):
var bunny = body as Bunny var bunny = body as Bunny
bunny.damage(damage) bunny.damage(damage)
queue_free() queue_free()
pass