Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kickflip-games/github_game_off_2024
Browse files Browse the repository at this point in the history
  • Loading branch information
avivajpeyi committed Nov 2, 2024
2 parents 4f767fb + 29d577d commit 47676ff
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 289 deletions.
54 changes: 46 additions & 8 deletions enemy/Enemy.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
extends Node
extends CharacterBody2D

@onready var animation := $AnimatedSprite2D
@onready var walk_timer := $Timer

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
enum STATE {IDLE, ATTACK, DEATH}
var current_state: STATE = STATE.IDLE

const SPEED = 100.0
const WALK_DURATION: float = 3.0
const WAIT_DURATION: float = 2.0

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var is_walking: bool = true
var direction: int = 1 # 1 is right, -1 is left

func _ready():
pass

func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta

func _physics_process(delta):
pass
# State handling
match current_state:
STATE.IDLE:
handle_idle(delta)
walk_timer.start() # Two second timer
STATE.ATTACK:
print("Enemy attacks.")
STATE.DEATH:
print("Enemy dies.")

move_and_slide()

func handle_idle(delta: float) -> void:
if direction == -1:
animation.flip_h = true
else:
animation.flip_h = false

if(is_walking):
animation.play("walk")
velocity.x = direction * SPEED
else:
animation.play("idle")
velocity.x = 0




func _on_timer_timeout() -> void:
direction *= -1 # After timer ends, flip direction
Loading

0 comments on commit 47676ff

Please sign in to comment.