-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:kickflip-games/github_game_off_2024
- Loading branch information
Showing
3 changed files
with
83 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.