Commit 19eb5ef3 authored by Nathan Lovato's avatar Nathan Lovato
Browse files

Backport to Godot 3.0

parent a091c53b
Pipeline #5100 failed with stage
in 1 minute and 26 seconds
extends Node2D
onready var anim_player :AnimationPlayer = $AnimationPlayer
onready var anim_player = $AnimationPlayer
func fade_out():
......
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-License-Identifier: GPL-3.0-or-later
extends Node2D
onready var pillar_spawner := $Foreground/PillarSpawner
onready var score_label :Label = $Background/ScoreLabel
onready var foreground :Node2D = $Foreground
onready var gnu := $Gnu
onready var score_board := $UI/ScoreBoard
onready var pillar_spawner = $Foreground/PillarSpawner
onready var score_label = $Background/ScoreLabel
onready var foreground = $Foreground
onready var gnu = $Gnu
onready var score_board = $UI/ScoreBoard
const ScoreLoader = preload("res://ScoreBoard/ScoreLoader.gd")
var waiting_to_restart :bool = false
var waiting_to_restart = false
func _ready() -> void:
func _ready():
score_label.setup(pillar_spawner)
gnu.connect("died", self, "_on_Gnu_died")
func _unhandled_input(event) -> void:
func _unhandled_input(event):
if waiting_to_restart:
if event.is_action_pressed("ui_accept") or event.is_action_pressed("tap"):
get_tree().reload_current_scene()
......@@ -25,7 +25,7 @@ func _unhandled_input(event) -> void:
get_tree().reload_current_scene()
func _on_Gnu_died() -> void:
func _on_Gnu_died():
"""Play fade out animations, update the score, and show the scoreboard"""
foreground.fade_out()
yield(get_tree().create_timer(0.3), "timeout")
......@@ -35,8 +35,8 @@ func _on_Gnu_died() -> void:
score_label.fade_out()
yield(get_tree().create_timer(0.6), "timeout")
var loader := ScoreLoader.new()
var loader = ScoreLoader.new()
loader.register(score_label.score)
var scores :Array = loader.get_scores()
var scores = loader.get_scores()
score_board.start(scores)
waiting_to_restart = true
extends Camera2D
onready var start_offset := position
onready var start_offset = position
func _ready() -> void:
func _ready():
set_as_toplevel(true)
position = owner.position + start_offset
func _physics_process(delta) -> void:
func _physics_process(delta):
position.x = owner.position.x + start_offset.x
......@@ -2,45 +2,45 @@ extends KinematicBody2D
signal died
onready var tween : Tween = $Tween
onready var anim_player : AnimationPlayer = $AnimationPlayer
onready var sprite : Sprite = $Sprite
onready var collision_shape : CollisionShape2D = $CollisionShape2D
onready var tween = $Tween
onready var anim_player = $AnimationPlayer
onready var sprite = $Sprite
onready var collision_shape = $CollisionShape2D
export var gravity := 4000.0
export var flap_force := 1200.0
export var max_fall_speed := 1200.0
export var max_angular_velocity := PI
export var angular_acceleration := 2.0 * PI
export var speed_horizontal := 280.0
export var gravity = 4000.0
export var flap_force = 1200.0
export var max_fall_speed = 1200.0
export var max_angular_velocity = PI
export var angular_acceleration = 2.0 * PI
export var speed_horizontal = 280.0
var _velocity := Vector2(speed_horizontal, 0.0)
var _angular_velocity := 0.0
var _idle := true setget set_idle
var _target_angle := 0.0
var _velocity = Vector2(speed_horizontal, 0.0)
var _angular_velocity = 0.0
var _idle = true setget set_idle
var _target_angle = 0.0
var _active := true setget _set_active
var _active = true setget _set_active
func _ready() -> void:
func _ready():
self._idle = true
func set_idle(value) -> void:
func set_idle(value):
_idle = value
set_physics_process(not value)
if not _idle:
anim_player.play("idle")
func _unhandled_input(event) -> void:
func _unhandled_input(event):
if event.is_action_pressed("flap"):
if _idle:
self._idle = false
flap()
func flap() -> void:
func flap():
_angular_velocity = 0.0
_velocity.y = -flap_force
_target_angle = -PI / 5.0
......@@ -52,25 +52,25 @@ func flap() -> void:
tween.start()
func _physics_process(delta) -> void:
func _physics_process(delta):
_velocity.y += gravity * delta
_velocity.y = min(_velocity.y, max_fall_speed)
if not tween.is_active() and sprite.rotation < PI / 5.0:
_angular_velocity += angular_acceleration * delta
_angular_velocity = min(_angular_velocity, max_angular_velocity)
sprite.rotate(_angular_velocity * delta)
var motion : Vector2 = _velocity * delta
var motion = _velocity * delta
# Prevent the character from moving too high up
if position.y < -100.0 and motion.y < 0.0:
motion.y = 0.0
var collision := move_and_collide(motion)
var collision = move_and_collide(motion)
if collision:
die()
func die() -> void:
func die():
set_physics_process(false)
set_process_unhandled_input(false)
tween.interpolate_property(
......@@ -83,7 +83,7 @@ func die() -> void:
emit_signal('died')
func _set_active(value) -> void:
func _set_active(value):
_active = value
visible = value
collision_shape.disabled = not value
......@@ -2,12 +2,12 @@ extends StaticBody2D
signal checkpoint_reached
onready var notifier : VisibilityNotifier2D = $VisibilityNotifier2D
onready var checkpoint : Area2D = $Checkpoint
onready var anim_player :AnimationPlayer = $AnimationPlayer
onready var notifier = $VisibilityNotifier2D
onready var checkpoint = $Checkpoint
onready var anim_player = $AnimationPlayer
func _ready() -> void:
func _ready():
var p = global_position
set_as_toplevel(true)
global_position = p
......@@ -16,7 +16,7 @@ func _ready() -> void:
checkpoint.connect("body_entered", self, "_on_Checkpoint_body_entered")
func _on_Checkpoint_body_entered(body) -> void:
func _on_Checkpoint_body_entered(body):
emit_signal("checkpoint_reached")
......
......@@ -3,28 +3,28 @@ extends Node2D
Spawns instances of the Pillar in a vertical area, outside the game's view
Places the Pillars based on their pivot
TODO: To increase the difficulty, we can slowly expand the spawn area,
TODOincrease the difficulty, we can slowly expand the spawn area,
and increase the Gnu's horizontal move speed
"""
signal pillar_checkpoint_reached
onready var spawn_area := $SpawnArea
onready var spawn_area = $SpawnArea
export var spawn_interval := 400.0
export var spawn_interval = 400.0
var pillar_scene := preload("res://Pillar/Pillar.tscn")
var WINDOW_WIDTH : int = ProjectSettings.get('display/window/size/width')
var pillar_scene = preload("res://Pillar/Pillar.tscn")
var WINDOW_WIDTH = ProjectSettings.get('display/window/size/width')
func _ready() -> void:
func _ready():
randomize()
for i in range(3):
spawn_pillar()
func spawn_pillar() -> void:
var pillar := pillar_scene.instance()
func spawn_pillar():
var pillar = pillar_scene.instance()
pillar.global_position = get_random_position()
pillar.connect("tree_exited", self, "spawn_pillar")
pillar.connect("checkpoint_reached", self, "emit_signal", ["pillar_checkpoint_reached"])
......@@ -32,7 +32,7 @@ func spawn_pillar() -> void:
position.x += spawn_interval
func get_random_position() -> Vector2:
func get_random_position():
return Vector2(
position.x + WINDOW_WIDTH,
spawn_area.get_random_vertical_position())
......@@ -2,11 +2,11 @@ tool
extends Node2D
export var min_extents := 100.0 setget set_min_extents
export var max_extents := 400.0 setget set_max_extents
export var min_extents = 100.0 setget set_min_extents
export var max_extents = 400.0 setget set_max_extents
func set_max_extents(value) -> void:
func set_max_extents(value):
max_extents = value
if max_extents < min_extents:
self.min_extents = max_extents
......@@ -14,27 +14,27 @@ func set_max_extents(value) -> void:
update()
func set_min_extents(value) -> void:
func set_min_extents(value):
min_extents = min(value, max_extents)
update()
func get_random_vertical_position(ratio=1.0) -> float:
func get_random_vertical_position(ratio=1.0):
assert ratio >= 0.0 and ratio <= 1.0
var extents : float = lerp(min_extents, max_extents, ratio) / 2.0
var rand_position := rand_range(-extents, extents)
var extents = lerp(min_extents, max_extents, ratio) / 2.0
var rand_position = rand_range(-extents, extents)
return position.y + rand_position
func _draw() -> void:
func _draw():
if not Engine.editor_hint:
return
var window_width : int = ProjectSettings.get('display/window/size/width')
var window_width = ProjectSettings.get('display/window/size/width')
var rectangle_min := Rect2(
var rectangle_min = Rect2(
Vector2(0.0, -min_extents / 2.0),
Vector2(window_width, min_extents))
var rectangle_max := Rect2(
var rectangle_max = Rect2(
Vector2(0.0, -max_extents / 2.0),
Vector2(window_width, max_extents))
......
......@@ -6,10 +6,10 @@ const ROW_COUNT = 3
const ScoreRow = preload("ScoreRow.tscn")
var scores := []
var scores = []
func start(scores:Array) -> void:
func start(scores):
"""Builds a list of ScoreRows and plays their start animation"""
for i in range(ROW_COUNT):
var row = ScoreRow.instance()
......
"""
Saves and loads scores to/from the disk
Each score is a dictionary of the form
{ initials:String, score:int }
{ initials, score }
"""
const SCORES_PATH := "user://scores"
const SCORE_SECTION := "scores"
const SCORES_PATH = "user://scores"
const SCORE_SECTION = "scores"
const DEFAULT_SCORE := {
const DEFAULT_SCORE = {
initials = "RMS",
score = 1,
}
var _scores := [] setget , get_scores
var _scores = [] setget , get_scores
func register(score:int):
func register(score):
if _scores == []:
self.load()
var sorted_scores :Array = _scores
var sorted_scores = _scores
sorted_scores.append({initials='YOU', score=score})
sorted_scores.sort_custom(self, 'sort_scores')
sorted_scores.pop_back()
......@@ -26,20 +26,20 @@ func register(score:int):
save()
static func sort_scores(a:Dictionary, b:Dictionary) -> bool:
static func sort_scores(a, b):
return a['score'] >= b['score']
func save() -> void:
func save():
if _scores.size() != 10:
return
var file := ConfigFile.new()
var file = ConfigFile.new()
for i in range(_scores.size()):
file.set_value(SCORE_SECTION, str(i), _scores[i])
file.save(SCORES_PATH)
func load() -> void:
func load():
"""
Loads scores from the disk and stores them in the _scores variable
"""
......@@ -47,25 +47,25 @@ func load() -> void:
_scores = _get_default_scores()
return
var file := ConfigFile.new()
var file = ConfigFile.new()
if file.load(SCORES_PATH) != OK:
return
_scores = []
for i in range(10):
var score :Dictionary = file.get_value(SCORE_SECTION, str(i), DEFAULT_SCORE)
var score = file.get_value(SCORE_SECTION, str(i), DEFAULT_SCORE)
_scores.append(score)
func get_scores() -> Array:
func get_scores():
return _scores if _scores != [] else _get_default_scores()
func _score_file_exists() -> bool:
func _score_file_exists():
return Directory.new().file_exists(SCORES_PATH)
func _get_default_scores() -> Array:
var scores := []
func _get_default_scores():
var scores = []
for i in range(10):
scores.append(DEFAULT_SCORE)
return scores
extends Control
onready var rank_label := $Rank
onready var score_label := $Score
onready var initials_label := $Initials
onready var animation_player := $AnimationPlayer
onready var rank_label = $Rank
onready var score_label = $Score
onready var initials_label = $Initials
onready var animation_player = $AnimationPlayer
const COLOR_TRANSPARENT = Color('00ffffff')
const COLOR_OPAQUE = Color('00ffffff')
func setup(index:int, score:Dictionary={}) -> void:
func setup(index, score={}):
rank_label.set_rank(index)
score_label.text = "%03d" % score.score
initials_label.text = score.initials
func start() -> void:
func start():
animation_player.play("fade_in")
func _ready() -> void:
func _ready():
modulate = COLOR_TRANSPARENT
......@@ -7,7 +7,7 @@
script/source = "extends Label
func set_rank(index:int) -> void:
func set_rank(index) -> void:
var suffix := \"\"
match index:
0:
......@@ -78,4 +78,3 @@ uppercase = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade_in = SubResource( 2 )
extends Label
onready var tween : Tween = $Tween
onready var tween = $Tween
const WHITE_OPAQUE := Color('aaffffff')
const WHITE_SEMI_TRANSPARENT := Color('44ffffff')
const WHITE_TRANSPARENT := Color('00ffffff')
const WHITE_OPAQUE = Color('aaffffff')
const WHITE_SEMI_TRANSPARENT = Color('44ffffff')
const WHITE_TRANSPARENT = Color('00ffffff')
var score := 0 setget set_score
var score = 0 setget set_score
func setup(pillar_spawner) -> void:
func setup(pillar_spawner):
pillar_spawner.connect("pillar_checkpoint_reached", self, "_on_PillarSpawner_pillar_checkpoint_reached")
func set_score(value) -> void:
func set_score(value):
score = value
text = str(score)
tween.interpolate_property(
......@@ -32,9 +32,9 @@ func fade_out():
tween.start()
func _ready() -> void:
func _ready():
modulate = WHITE_SEMI_TRANSPARENT
func _on_PillarSpawner_pillar_checkpoint_reached() -> void:
func _on_PillarSpawner_pillar_checkpoint_reached():
self.score += 1
......@@ -5,29 +5,29 @@ Repeats a sprite hozitontally infinitely by spawning enough sprites to always
fill the view
"""
onready var spawn_position : Position2D = $SpawnPosition
onready var spawn_position = $SpawnPosition
export var sprite_scene : PackedScene
var WINDOW_WIDTH : float = ProjectSettings.get('display/window/size/width')
var sprite_width := 0.0
var WINDOW_WIDTH = ProjectSettings.get('display/window/size/width')
var sprite_width = 0.0
func _ready() -> void:
func _ready():
assert sprite_scene
if Engine.editor_hint:
spawn_position.add_child(sprite_scene.instance())
else:
var sprite : Sprite = sprite_scene.instance()
var sprite = sprite_scene.instance()
sprite_width = sprite.texture.get_width() * sprite.scale.x
var amount_to_fill_screen = ceil(WINDOW_WIDTH / sprite_width)
for i in range(amount_to_fill_screen + 2):
spawn_sprite()
func spawn_sprite() -> void:
func spawn_sprite():
"""Offsets the spawner node and spawns a new sprite"""
var sprite : Sprite = sprite_scene.instance()
var sprite = sprite_scene.instance()
sprite.connect("tree_exited", self, "spawn_sprite")
sprite.position = spawn_position.position
call_deferred("add_child", sprite) # to avoid error on reload
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment