diff options
author | Indrajith K L | 2022-04-15 02:08:49 +0530 |
---|---|---|
committer | Indrajith K L | 2022-04-15 02:08:49 +0530 |
commit | 31089507aae1d35d0deeb2c412cfa311e7a57563 (patch) | |
tree | 65f773c23eaa44df8dbb8423e020fb79d3ded47a /entities/chicken/chicken.gd | |
parent | aef396151234aa21af4a658ea11f03ea9434961c (diff) | |
download | gamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.tar.gz gamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.tar.bz2 gamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.zip |
Adds Chicken Enemy
Animation Tree - In-Progress
Diffstat (limited to 'entities/chicken/chicken.gd')
-rw-r--r-- | entities/chicken/chicken.gd | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/entities/chicken/chicken.gd b/entities/chicken/chicken.gd new file mode 100644 index 0000000..2ab309d --- /dev/null +++ b/entities/chicken/chicken.gd @@ -0,0 +1,26 @@ +extends KinematicBody2D +const UP = Vector2(0, -1) +const GRAVITY = 1200 +const SPEED = 200 +const health = 10 +var motion = Vector2() +var left = Vector2(-1, 0) +var right = Vector2(1, 0) +var direction = left +onready var sprite = $AnimatedSprite +func _physics_process(delta): + motion.y += GRAVITY * delta + motion.x = direction.x * SPEED + motion = move_and_slide(motion, UP) + $AnimatedSprite.play("run") + if is_on_wall(): + if direction == left: + sprite.flip_h = true + direction = right + elif direction == right: + sprite.flip_h = false + direction = left + for index in get_slide_count(): + var collision = get_slide_collision(index) + if collision.collider.is_in_group("player"): + SignalBus.emit_signal("on_hit",health) |