-
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.
- Loading branch information
Showing
6 changed files
with
480 additions
and
167 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,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" |
Oops, something went wrong.