Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instruction preview #58

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions microgame_example/my_cool_microgame.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
script = ExtResource( 1 )
name = "My Cool Microgame"
scene = ExtResource( 2 )
hint_verb = "Mash!"
1 change: 1 addition & 0 deletions microgames/cupcake_game/Cupcake.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
script = ExtResource( 1 )
name = "Cupcake"
scene = ExtResource( 2 )
hint_verb = "Decorate!"
1 change: 0 additions & 1 deletion microgames/cupcake_game/cupcake_game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ animation = "closed"

[node name="cherry" type="Area2D" parent="hand"]
position = Vector2( 69.3333, 80.6667 )
scale = Vector2( 1, 1 )
script = ExtResource( 6 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="hand/cherry"]
Expand Down
1 change: 1 addition & 0 deletions microgames/hotdog_game/Hotdog.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
script = ExtResource( 1 )
name = "Hotdog"
scene = ExtResource( 2 )
hint_verb = "Catch!"
1 change: 1 addition & 0 deletions microgames/pixelart/Pixelart.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
script = ExtResource( 1 )
name = "Pixelart"
scene = ExtResource( 2 )
hint_verb = "Pick the Color!"
1 change: 0 additions & 1 deletion microgames/pixelart/src/pixelart_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ func _on_Pencil_drawing_done() -> void:
$Camera2D, "zoom", $Camera2D.zoom, $FinalCamera.zoom, 0.4, Tween.TRANS_BACK, Tween.EASE_OUT
)
$CameraTween.start()
yield(get_tree().create_timer(0.5), "timeout")
1 change: 1 addition & 0 deletions microgames/press_key/PressKey.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
script = ExtResource( 1 )
name = "Press Key"
scene = ExtResource( 2 )
hint_verb = "Press!"
2 changes: 1 addition & 1 deletion src/core/game_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export var speed: float = 1
export var level_up_interval: int = 10
export var speed_up_interval: int = 3

var current_score : int = 0
var current_score : int = 0
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=8 format=2]

[ext_resource path="res://fonts/Wariowareincv2-2OOBw.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://src/microgame/mg_instructions.gd" type="Script" id=2]
[ext_resource path="res://src/core/intermission/instructions.gd" type="Script" id=2]

[sub_resource type="DynamicFont" id=17]
size = 64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ extends Control

signal intermission_completed

onready var instructions_scene = preload("res://src/core/intermission/instructions.tscn")

onready var timer : Timer = $Timer
onready var score_display: RichTextLabel = $ScoreDisplay
onready var status_up: AnimatedSprite = $StatusUp
onready var sfx_success: AudioStreamPlayer2D = $SuccessSFX
onready var sfx_failure: AudioStreamPlayer2D = $FailureSFX
onready var sfx_start: AudioStreamPlayer2D = $StartSFX
onready var instructions_layer : CanvasLayer = $Instructions
onready var instructions_timer : Timer = $InstructionsTimer

var current_microgame_def : MicrogameDefinition


func _ready() -> void:
Expand All @@ -24,6 +30,7 @@ func _ready() -> void:
if game_state.lives <= 0:
Engine.time_scale = 1
timer.wait_time = 5
instructions_timer.wait_time = 1
$GameOver.visible = true
timer.start()
sfx_failure.play()
Expand All @@ -48,13 +55,24 @@ func _ready() -> void:

sfx_start.play()
timer.start()
instructions_timer.start()


func on_Timer_timeout() -> void:
emit_signal("intermission_completed")
emit_signal("intermission_completed", current_microgame_def)


func _show_modifier_update(type: String) -> void:
status_up.animation = type
status_up.visible = true
timer.wait_time *= 2
instructions_timer.wait_time *= 2


func _on_InstructionsTimer_timeout():
current_microgame_def = Utility.get_random_microgame(Session.microgame_pool)
# wait for instructions to finish showing before adding timer
var instructions = instructions_scene.instance()
instructions_layer.add_child(instructions)
instructions.prompt.text = current_microgame_def.hint_verb
instructions.start()
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
[gd_scene load_steps=18 format=2]

[ext_resource path="res://graphics/icon.png" type="Texture" id=1]
[ext_resource path="res://graphics/level_up_spritesheet.png" type="Texture" id=2]
[ext_resource path="res://audio/tat-tat-92592.wav" type="AudioStream" id=3]
[ext_resource path="res://graphics/speed_up_spritesheet.png" type="Texture" id=4]
[ext_resource path="res://graphics/game_over_spritesheet.png" type="Texture" id=5]
[ext_resource path="res://audio/tada-fanfare-a-6313.wav" type="AudioStream" id=6]
[ext_resource path="res://audio/failfare-86009.wav" type="AudioStream" id=7]
[ext_resource path="res://src/core/life.gd" type="Script" id=8]
[ext_resource path="res://src/core/intermission.gd" type="Script" id=9]

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 2 )
[ext_resource path="res://audio/failfare-86009.wav" type="AudioStream" id=1]
[ext_resource path="res://graphics/game_over_spritesheet.png" type="Texture" id=2]
[ext_resource path="res://audio/tada-fanfare-a-6313.wav" type="AudioStream" id=3]
[ext_resource path="res://graphics/icon.png" type="Texture" id=4]
[ext_resource path="res://graphics/speed_up_spritesheet.png" type="Texture" id=5]
[ext_resource path="res://audio/tat-tat-92592.wav" type="AudioStream" id=6]
[ext_resource path="res://src/core/life.gd" type="Script" id=7]
[ext_resource path="res://src/core/intermission/intermission.gd" type="Script" id=8]
[ext_resource path="res://graphics/level_up_spritesheet.png" type="Texture" id=9]

[sub_resource type="AtlasTexture" id=9]
atlas = ExtResource( 9 )
region = Rect2( 0, 0, 512, 128 )

[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 2 )
[sub_resource type="AtlasTexture" id=10]
atlas = ExtResource( 9 )
region = Rect2( 512, 0, 512, 128 )

[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 4 )
[sub_resource type="AtlasTexture" id=11]
atlas = ExtResource( 5 )
region = Rect2( 0, 0, 512, 128 )

[sub_resource type="AtlasTexture" id=4]
atlas = ExtResource( 4 )
[sub_resource type="AtlasTexture" id=12]
atlas = ExtResource( 5 )
region = Rect2( 512, 0, 512, 128 )

[sub_resource type="SpriteFrames" id=5]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ) ],
"frames": [ SubResource( 9 ), SubResource( 10 ) ],
"loop": true,
"name": "level_up",
"speed": 5.0
}, {
"frames": [ SubResource( 3 ), SubResource( 4 ) ],
"frames": [ SubResource( 11 ), SubResource( 12 ) ],
"loop": true,
"name": "speed_up",
"speed": 5.0
} ]

[sub_resource type="AtlasTexture" id=6]
atlas = ExtResource( 5 )
[sub_resource type="AtlasTexture" id=13]
atlas = ExtResource( 2 )
region = Rect2( 0, 0, 512, 256 )

[sub_resource type="AtlasTexture" id=7]
atlas = ExtResource( 5 )
[sub_resource type="AtlasTexture" id=14]
atlas = ExtResource( 2 )
region = Rect2( 512, 0, 512, 256 )

[sub_resource type="SpriteFrames" id=8]
animations = [ {
"frames": [ SubResource( 6 ), SubResource( 7 ) ],
"frames": [ SubResource( 13 ), SubResource( 14 ) ],
"loop": true,
"name": "default",
"speed": 5.0
Expand All @@ -60,7 +60,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 3.0
margin_bottom = 3.0
script = ExtResource( 9 )
script = ExtResource( 8 )

[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_left = 0.5
Expand All @@ -82,9 +82,9 @@ size_flags_horizontal = 3
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/HBoxContainer/MarginContainer"]
margin_right = 94.0
margin_bottom = 64.0
texture = ExtResource( 1 )
texture = ExtResource( 4 )
stretch_mode = 6
script = ExtResource( 8 )
script = ExtResource( 7 )

[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 98.0
Expand All @@ -95,9 +95,9 @@ size_flags_horizontal = 3
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/HBoxContainer/MarginContainer2"]
margin_right = 95.0
margin_bottom = 64.0
texture = ExtResource( 1 )
texture = ExtResource( 4 )
stretch_mode = 6
script = ExtResource( 8 )
script = ExtResource( 7 )
index = 1

[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
Expand All @@ -109,9 +109,9 @@ size_flags_horizontal = 3
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/HBoxContainer/MarginContainer3"]
margin_right = 94.0
margin_bottom = 64.0
texture = ExtResource( 1 )
texture = ExtResource( 4 )
stretch_mode = 6
script = ExtResource( 8 )
script = ExtResource( 7 )
index = 2

[node name="MarginContainer4" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
Expand All @@ -123,9 +123,9 @@ size_flags_horizontal = 3
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/HBoxContainer/MarginContainer4"]
margin_right = 95.0
margin_bottom = 64.0
texture = ExtResource( 1 )
texture = ExtResource( 4 )
stretch_mode = 6
script = ExtResource( 8 )
script = ExtResource( 7 )
index = 3

[node name="ScoreDisplay" type="RichTextLabel" parent="."]
Expand All @@ -143,7 +143,7 @@ one_shot = true

[node name="StatusUp" type="AnimatedSprite" parent="."]
visible = false
position = Vector2( 528, 248 )
position = Vector2( 528, 184 )
frames = SubResource( 5 )
animation = "level_up"
playing = true
Expand All @@ -157,17 +157,24 @@ playing = true

[node name="SuccessSFX" type="AudioStreamPlayer2D" parent="."]
position = Vector2( 518, 279 )
stream = ExtResource( 6 )
stream = ExtResource( 3 )
bus = "Session"

[node name="FailureSFX" type="AudioStreamPlayer2D" parent="."]
position = Vector2( 518, 279 )
stream = ExtResource( 7 )
stream = ExtResource( 1 )
bus = "Session"

[node name="StartSFX" type="AudioStreamPlayer2D" parent="."]
position = Vector2( 518, 279 )
stream = ExtResource( 3 )
stream = ExtResource( 6 )
bus = "Session"

[node name="InstructionsTimer" type="Timer" parent="."]
one_shot = true

[node name="Instructions" type="CanvasLayer" parent="."]
layer = 2

[connection signal="timeout" from="Timer" to="." method="on_Timer_timeout"]
[connection signal="timeout" from="InstructionsTimer" to="." method="_on_InstructionsTimer_timeout"]
1 change: 1 addition & 0 deletions src/core/modes/mode_standard.tres
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[ext_resource path="res://src/core/game_state.gd" type="Script" id=1]

[resource]
resource_local_to_scene = true
script = ExtResource( 1 )
name = "standard"
lives = 4
Expand Down
19 changes: 8 additions & 11 deletions src/core/session.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const GAME_MODE : Dictionary = {
"STANDARD": preload("res://src/core/modes/mode_standard.tres"),
"DEBUG": preload("res://src/core/modes/mode_debug.tres"),
}
const INTERMISSION_SCENE: PackedScene = preload("res://src/core/intermission.tscn")
const INTERMISSION_SCENE: PackedScene = preload("res://src/core/intermission/intermission.tscn")
const MENU_SCENE : PackedScene = preload("res://src/menu/menu.tscn")

var game_state : GameState
Expand All @@ -21,13 +21,13 @@ func _ready():
connect("speed_up_requested", self, "_on_speed_up_requested")

# if microgame is being previewed directly, loop it
var microgame_scene: String = ""
var microgame_def: String = ""
for arg in OS.get_cmdline_args():
if arg.begins_with("res://") and arg.ends_with(".tscn"):
microgame_scene = arg
if microgame_scene.length() > 0 or not OS.has_feature("editor"):
if arg.begins_with("res://") and arg.ends_with(".tres"):
microgame_def = arg
if microgame_def.length() > 0 or not OS.has_feature("editor"):
game_state = GAME_MODE.DEBUG
microgame_pool = [load(microgame_scene)]
microgame_pool = [microgame_def]


func start_mode(game_mode : GameState):
Expand All @@ -41,14 +41,11 @@ func _play_intermission() -> void:
get_tree().change_scene_to(INTERMISSION_SCENE)


func _on_intermission_completed() -> void:
func _on_intermission_completed(new_microgame : MicrogameDefinition) -> void:
if game_state.lives > 0:
get_tree().change_scene_to(
Utility.get_random_microgame(microgame_pool)
)
get_tree().change_scene_to(new_microgame.scene)
else:
Scores.save_score_for(game_state.name, game_state.current_score)
queue_free()
get_tree().change_scene_to(MENU_SCENE)


Expand Down
10 changes: 5 additions & 5 deletions src/core/utility.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class_name Utility
# Common helper functions


static func get_random_microgame(microgame_scenes : Array) -> PackedScene:
return microgame_scenes[randi() % microgame_scenes.size()]
static func get_random_microgame(microgame_definitions : Array) -> MicrogameDefinition:
return microgame_definitions[randi() % microgame_definitions.size()]


static func find_by_class(node: Node, className: String, result: Array) -> void:
Expand All @@ -15,14 +15,14 @@ static func find_by_class(node: Node, className: String, result: Array) -> void:


static func get_microgames() -> Array:
var microgame_scenes := []
var microgame_defs := []

for file in find_microgame_definitions():
var definition: Resource = load(file)
if definition is MicrogameDefinition:
microgame_scenes.append(definition.scene)
microgame_defs.append(definition)

return microgame_scenes
return microgame_defs


static func find_microgame_definitions() -> Array:
Expand Down
1 change: 1 addition & 0 deletions src/microgame/mg_definition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ class_name MicrogameDefinition

export var name: String
export var scene: PackedScene
export var hint_verb : String
8 changes: 0 additions & 8 deletions src/microgame/microgame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class_name Microgame
# Custom microgames should extend this

const UI_SCENES : Dictionary = {
"Instructions": preload("res://src/microgame/mg_instructions.tscn"),
"Timer": preload("res://src/microgame/mg_timer.tscn"),
}

Expand Down Expand Up @@ -39,15 +38,8 @@ func _ready() -> void:

# add additional UI elements
var timer = UI_SCENES.Timer.instance()
var instructions = UI_SCENES.Instructions.instance()
var ui_parent = CanvasLayer.new()
add_child(ui_parent)

# wait for instructions to finish showing before adding timer
ui_parent.add_child(instructions)
instructions.prompt.text = hint_verb
instructions.start()
yield(instructions, "timeout")
timer.connect("timeout", self, "_on_Timer_timeout")
ui_parent.add_child(timer)
is_timer_running = true
Expand Down