Skip to content

Commit

Permalink
HUD with buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Cod3lta committed Oct 11, 2021
1 parent 7095c70 commit 92d1db1
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 167 deletions.
78 changes: 72 additions & 6 deletions src/actors/player.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,84 @@
extends Node2D

"""########################################
VARIABLES
########################################"""

# Declare member variables here.
enum gender_enum {BOY, GIRL}
enum team_enum {RED, BLACK}
enum gender_e {BOY=0, GIRL=1}
enum team_e {RED=0, BLACK=1}

onready var gender = null

var velocity = Vector2.ZERO
var speed = 500
var gender = null
var team = null
var flip_h = false
var current_animation = "idle"

"""########################################
INIT
########################################"""

func _init():
self.gender = gender_e.BOY
self.team = team_e.BLACK


func init_animated_sprite():
for sprite in $Sprites.get_children():
var sprite_as = sprite as AnimatedSprite
sprite_as.hide()
get_sprite_node().show()


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
init_animated_sprite()

"""########################################
PROCESS
########################################"""

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _process(delta):
run()
animate()
position += velocity * delta


func run():
var player_input_x = Input.get_action_strength("right") - Input.get_action_strength("left")
var player_input_y = Input.get_action_strength("down") - Input.get_action_strength("up")
velocity.x = player_input_x
velocity.y = player_input_y
velocity = velocity.normalized() * speed


"""########################################
ANIMATIONS
########################################"""


func animate():
current_animation = get_animation()
var node = str(self.gender) + '_' + str(self.team)
var animated_node = get_sprite_node()
animated_node.animation = get_animation()
animated_node.flip_h = flip_h
if abs(velocity.x) > 0:
flip_h = velocity.x < 0


func get_sprite_node():
if gender == gender_e.BOY and team == team_e.RED: return $Sprites/BoyRed
if gender == gender_e.BOY and team == team_e.BLACK: return $Sprites/BoyBlack
if gender == gender_e.GIRL and team == team_e.RED: return $Sprites/GirlRed
if gender == gender_e.GIRL and team == team_e.BLACK: return $Sprites/GirlBlack
print("No animation defined")
assert(false)

func get_animation():
if abs(velocity.x) > 0 || abs(velocity.y) > 0:
return "run"
return "idle"
Loading

0 comments on commit 92d1db1

Please sign in to comment.