Some logic work on gdscripts

This commit is contained in:
Stephen Seo 2024-04-13 16:46:00 +09:00
parent 36cc125c7c
commit 9ff2eb1867
2 changed files with 68 additions and 40 deletions

View file

@ -57,6 +57,8 @@ var diamonds_gone = false
var music_file var music_file
var gander
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
if not state_dict.has("state"): if not state_dict.has("state"):
@ -103,7 +105,15 @@ func _process(delta):
music_player.stream = AudioStreamMP3.new() music_player.stream = AudioStreamMP3.new()
music_file = FileAccess.open("res://audio/LD55_1.mp3", FileAccess.READ) 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.data = music_file.get_buffer(music_file.get_length())
music_player.stream.loop = true
music_player.play() 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: StateT.Introduction_00:
update_stop_diamonds(delta) update_stop_diamonds(delta)
update_text(intro_text_00, StateT.Introduction_00_post) update_text(intro_text_00, StateT.Introduction_00_post)
@ -141,6 +151,12 @@ func _process(delta):
pass pass
_: _:
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): func _unhandled_input(event):
if event.is_pressed() and event.is_action("Confirm"): if event.is_pressed() and event.is_action("Confirm"):
@ -250,8 +266,8 @@ func update_start_diamonds(delta):
state_dict["start_diamonds"]["dist"] = diamond_min_dist state_dict["start_diamonds"]["dist"] = diamond_min_dist
state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate
if state_dict["start_diamonds"]["angle"] > PI * 2.0: if state_dict["start_diamonds"]["angle"] > TAU:
state_dict["start_diamonds"]["angle"] -= PI * 2.0 state_dict["start_diamonds"]["angle"] -= TAU
diamond_position_update() diamond_position_update()
@ -268,7 +284,7 @@ func update_stop_diamonds(delta):
earth_diamond.get_parent().remove_child(earth_diamond) earth_diamond.get_parent().remove_child(earth_diamond)
state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate state_dict["start_diamonds"]["angle"] += delta * diamond_angle_rate
if state_dict["start_diamonds"]["angle"] > PI * 2.0: if state_dict["start_diamonds"]["angle"] > TAU:
state_dict["start_diamonds"]["angle"] -= PI * 2.0 state_dict["start_diamonds"]["angle"] -= TAU
diamond_position_update() diamond_position_update()

View file

@ -1,5 +1,15 @@
extends CharacterBody2D 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 @onready var animated = $AnimatedSprite2D
const SPEED = 150.0 const SPEED = 150.0
@ -7,42 +17,44 @@ const ANIM_DEADZONE = 0.3
func _physics_process(delta): func _physics_process(delta):
var vec2 = Vector2() var vec2 = Vector2()
if Input.is_action_pressed("Left"): if player_controlled:
vec2.x = -1.0 if Input.is_action_pressed("Left"):
elif Input.is_action_pressed("Right"): vec2.x = -1.0
vec2.x = 1.0 elif Input.is_action_pressed("Right"):
if Input.is_action_pressed("Up"): vec2.x = 1.0
vec2.y = -1.0 if Input.is_action_pressed("Up"):
elif Input.is_action_pressed("Down"): vec2.y = -1.0
vec2.y = 1.0 elif Input.is_action_pressed("Down"):
vec2.y = 1.0
if vec2.length() > 0.1: if vec2.length() > 0.1:
vec2 = vec2.normalized() vec2 = vec2.normalized()
else: else:
vec2.x = 0.0 vec2.x = 0.0
vec2.y = 0.0 vec2.y = 0.0
if vec2.x > ANIM_DEADZONE: if vec2.x > ANIM_DEADZONE:
animated.play("walking_right") animated.play("walking_right")
elif vec2.x < -ANIM_DEADZONE: elif vec2.x < -ANIM_DEADZONE:
animated.play("walking_left") animated.play("walking_left")
elif vec2.y > ANIM_DEADZONE: elif vec2.y > ANIM_DEADZONE:
animated.play("walking_front") animated.play("walking_front")
elif vec2.y < -ANIM_DEADZONE: elif vec2.y < -ANIM_DEADZONE:
animated.play("walking_back") animated.play("walking_back")
else: else:
match animated.animation: match animated.animation:
"walking_right": "walking_right":
animated.play("facing_right") animated.play("facing_right")
"walking_left": "walking_left":
animated.play("facing_left") animated.play("facing_left")
"walking_front": "walking_front":
animated.play("facing_front") animated.play("facing_front")
"walking_back": "walking_back":
animated.play("facing_back") animated.play("facing_back")
_: _:
pass pass
velocity = vec2 * SPEED
velocity = vec2 * SPEED elif animated.animation != auto_control_action:
animated.play(auto_control_action)
move_and_slide() move_and_slide()