Skip to content

Commit

Permalink
Merge branch 'master' into update-1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JCash committed Mar 11, 2024
2 parents 1edb7d8 + d2e85df commit 4c8f047
Show file tree
Hide file tree
Showing 7 changed files with 535 additions and 3 deletions.
22 changes: 20 additions & 2 deletions examples/_main/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,9 @@ embedded_components {
}
}
embedded_components {
id: "material/vertexcolor"
id: "collection/timestep"
type: "collectionproxy"
data: "collection: \"/examples/material/vertexcolor/vertexcolor.collection\"\n"
data: "collection: \"/examples/collection/timestep/timestep.collection\"\n"
"exclude: false\n"
""
position {
Expand All @@ -1126,3 +1126,21 @@ embedded_components {
w: 1.0
}
}
embedded_components {
id: "material/vertexcolor"
type: "collectionproxy"
data: "collection: \"/examples/material/vertexcolor/vertexcolor.collection\"\n"
"exclude: false\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
}
2 changes: 1 addition & 1 deletion examples/_main/menu.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function init(self)
self.index["sound"] = { "music", "fade_in_out", "panning" }
self.index["render"] = { "camera", "screen_to_world" }
self.index["debug"] = { "physics", "profile" }
self.index["collection"] = { "proxy", "splash" }
self.index["collection"] = { "proxy", "splash", "timestep" }
self.index["sprite"] = { "size", "tint", "flip", "bunnymark" }
self.index["file"] = { "sys_save_load" }
self.index["tilemap"] = { "collisions", "get_set_tile" }
Expand Down
35 changes: 35 additions & 0 deletions examples/collection/timestep/controller.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- speed of the time in the collection proxy
go.property("speed", 1)

function init(self)
-- acquire input for this script
msg.post(".", "acquire_input_focus")
-- load the collection proxy
msg.post("#gameproxy", "async_load")
end

function update(self, dt)
-- update the time step of the proxy each frame since it might be animated
msg.post("#gameproxy", "set_time_step", { factor = self.speed, mode = 0 })
label.set_text("#label", tostring(self.speed))
end

function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
msg.post(sender, "enable")
elseif message_id == hash("animate_speed") then
-- cancel any current animation of the speed property
go.cancel_animations("#", "speed")
-- start animation of the speed property
local to = message.to
local change = math.abs(self.speed - to)
local rate_of_change = 2
local duration = change / rate_of_change
go.animate("#", "speed", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, duration)
elseif message_id == hash("change_speed") then
-- cancel any current animation of the speed property
go.cancel_animations("#", "speed")
-- make sure speed never goes below 0
self.speed = math.max(self.speed + message.amount, 0)
end
end
254 changes: 254 additions & 0 deletions examples/collection/timestep/game.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
name: "game"
scale_along_z: 0
embedded_instances {
id: "game"
data: "components {\n"
" id: \"game\"\n"
" component: \"/examples/collection/timestep/game.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
" property_decls {\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "enemy1"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"enemyBlack1\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/assets/sprites.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 589.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "player"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"playerShip1_red\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/assets/sprites.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 360.0
y: 100.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "enemy2"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"enemyBlack1\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/assets/sprites.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 494.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "enemy3"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"enemyBlack1\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/assets/sprites.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 397.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "enemy4"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"enemyBlack1\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/assets/sprites.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 294.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
22 changes: 22 additions & 0 deletions examples/collection/timestep/game.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function init(self)
-- get input to this script
msg.post(".", "acquire_input_focus")

-- animate some game objects
go.animate("enemy1", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 0)
go.animate("enemy2", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 0.5)
go.animate("enemy3", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 1)
go.animate("enemy4", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 1.5)
end

function on_input(self, action_id, action)
if action_id == hash("left") then
msg.post("timestep:/controller", "change_speed", { amount = -0.01 })
elseif action_id == hash("right") then
msg.post("timestep:/controller", "change_speed", { amount = 0.01 })
elseif action_id == hash("action") and action.pressed then
-- flip self.to between 0 and 3 each time
self.to = 3 - (self.to or 0)
msg.post("timestep:/controller", "animate_speed", { to = self.to })
end
end
Loading

0 comments on commit 4c8f047

Please sign in to comment.