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,6 +17,7 @@ const ANIM_DEADZONE = 0.3
func _physics_process(delta): func _physics_process(delta):
var vec2 = Vector2() var vec2 = Vector2()
if player_controlled:
if Input.is_action_pressed("Left"): if Input.is_action_pressed("Left"):
vec2.x = -1.0 vec2.x = -1.0
elif Input.is_action_pressed("Right"): elif Input.is_action_pressed("Right"):
@ -42,7 +53,8 @@ func _physics_process(delta):
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()