Some logic work on gdscripts
This commit is contained in:
parent
36cc125c7c
commit
9ff2eb1867
2 changed files with 68 additions and 40 deletions
26
MainLogic.gd
26
MainLogic.gd
|
@ -57,6 +57,8 @@ var diamonds_gone = false
|
|||
|
||||
var music_file
|
||||
|
||||
var gander
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
if not state_dict.has("state"):
|
||||
|
@ -103,7 +105,15 @@ func _process(delta):
|
|||
music_player.stream = AudioStreamMP3.new()
|
||||
music_file = FileAccess.open("res://audio/LD55_1.mp3", FileAccess.READ)
|
||||
music_player.stream.data = music_file.get_buffer(music_file.get_length())
|
||||
music_player.stream.loop = true
|
||||
music_player.play()
|
||||
var gander_scene = preload("res://gander_schwartz.tscn")
|
||||
gander = gander_scene.instantiate()
|
||||
add_child(gander)
|
||||
gander.position.x = 800
|
||||
gander.position.y = 50
|
||||
gander.velocity.x = -gander.SPEED
|
||||
gander.auto_control_action = "walking_left"
|
||||
StateT.Introduction_00:
|
||||
update_stop_diamonds(delta)
|
||||
update_text(intro_text_00, StateT.Introduction_00_post)
|
||||
|
@ -141,7 +151,13 @@ func _process(delta):
|
|||
pass
|
||||
_:
|
||||
pass
|
||||
|
||||
if gander is MainCharacter and not gander.player_controlled and gander.current_scene_type == gander.GanderSceneT.Introduction:
|
||||
if gander.velocity.x < 0.0:
|
||||
if gander.position.x <= 0.0:
|
||||
gander.velocity.x = 0.0
|
||||
gander.auto_control_action = "facing_front"
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event.is_pressed() and event.is_action("Confirm"):
|
||||
match state_dict["state"]:
|
||||
|
@ -250,8 +266,8 @@ func update_start_diamonds(delta):
|
|||
state_dict["start_diamonds"]["dist"] = diamond_min_dist
|
||||
state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate
|
||||
|
||||
if state_dict["start_diamonds"]["angle"] > PI * 2.0:
|
||||
state_dict["start_diamonds"]["angle"] -= PI * 2.0
|
||||
if state_dict["start_diamonds"]["angle"] > TAU:
|
||||
state_dict["start_diamonds"]["angle"] -= TAU
|
||||
|
||||
diamond_position_update()
|
||||
|
||||
|
@ -268,7 +284,7 @@ func update_stop_diamonds(delta):
|
|||
earth_diamond.get_parent().remove_child(earth_diamond)
|
||||
state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate
|
||||
|
||||
if state_dict["start_diamonds"]["angle"] > PI * 2.0:
|
||||
state_dict["start_diamonds"]["angle"] -= PI * 2.0
|
||||
if state_dict["start_diamonds"]["angle"] > TAU:
|
||||
state_dict["start_diamonds"]["angle"] -= TAU
|
||||
|
||||
diamond_position_update()
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
class_name MainCharacter
|
||||
|
||||
var player_controlled = false
|
||||
enum GanderSceneT {
|
||||
Introduction,
|
||||
Gameplay,
|
||||
}
|
||||
var current_scene_type = GanderSceneT.Introduction
|
||||
var auto_control_action = "facing_front"
|
||||
|
||||
@onready var animated = $AnimatedSprite2D
|
||||
|
||||
const SPEED = 150.0
|
||||
|
@ -7,42 +17,44 @@ const ANIM_DEADZONE = 0.3
|
|||
|
||||
func _physics_process(delta):
|
||||
var vec2 = Vector2()
|
||||
if Input.is_action_pressed("Left"):
|
||||
vec2.x = -1.0
|
||||
elif Input.is_action_pressed("Right"):
|
||||
vec2.x = 1.0
|
||||
if Input.is_action_pressed("Up"):
|
||||
vec2.y = -1.0
|
||||
elif Input.is_action_pressed("Down"):
|
||||
vec2.y = 1.0
|
||||
if player_controlled:
|
||||
if Input.is_action_pressed("Left"):
|
||||
vec2.x = -1.0
|
||||
elif Input.is_action_pressed("Right"):
|
||||
vec2.x = 1.0
|
||||
if Input.is_action_pressed("Up"):
|
||||
vec2.y = -1.0
|
||||
elif Input.is_action_pressed("Down"):
|
||||
vec2.y = 1.0
|
||||
|
||||
if vec2.length() > 0.1:
|
||||
vec2 = vec2.normalized()
|
||||
else:
|
||||
vec2.x = 0.0
|
||||
vec2.y = 0.0
|
||||
|
||||
if vec2.x > ANIM_DEADZONE:
|
||||
animated.play("walking_right")
|
||||
elif vec2.x < -ANIM_DEADZONE:
|
||||
animated.play("walking_left")
|
||||
elif vec2.y > ANIM_DEADZONE:
|
||||
animated.play("walking_front")
|
||||
elif vec2.y < -ANIM_DEADZONE:
|
||||
animated.play("walking_back")
|
||||
else:
|
||||
match animated.animation:
|
||||
"walking_right":
|
||||
animated.play("facing_right")
|
||||
"walking_left":
|
||||
animated.play("facing_left")
|
||||
"walking_front":
|
||||
animated.play("facing_front")
|
||||
"walking_back":
|
||||
animated.play("facing_back")
|
||||
_:
|
||||
pass
|
||||
if vec2.length() > 0.1:
|
||||
vec2 = vec2.normalized()
|
||||
else:
|
||||
vec2.x = 0.0
|
||||
vec2.y = 0.0
|
||||
|
||||
velocity = vec2 * SPEED
|
||||
if vec2.x > ANIM_DEADZONE:
|
||||
animated.play("walking_right")
|
||||
elif vec2.x < -ANIM_DEADZONE:
|
||||
animated.play("walking_left")
|
||||
elif vec2.y > ANIM_DEADZONE:
|
||||
animated.play("walking_front")
|
||||
elif vec2.y < -ANIM_DEADZONE:
|
||||
animated.play("walking_back")
|
||||
else:
|
||||
match animated.animation:
|
||||
"walking_right":
|
||||
animated.play("facing_right")
|
||||
"walking_left":
|
||||
animated.play("facing_left")
|
||||
"walking_front":
|
||||
animated.play("facing_front")
|
||||
"walking_back":
|
||||
animated.play("facing_back")
|
||||
_:
|
||||
pass
|
||||
velocity = vec2 * SPEED
|
||||
elif animated.animation != auto_control_action:
|
||||
animated.play(auto_control_action)
|
||||
|
||||
move_and_slide()
|
||||
|
|
Loading…
Reference in a new issue