Skip to content

Commit

Permalink
Improve examples. Add wasm binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
jyaif committed Sep 19, 2020
1 parent 951a6e1 commit bd8c17f
Show file tree
Hide file tree
Showing 17 changed files with 12,418 additions and 53 deletions.
10 changes: 10 additions & 0 deletions content/dynamic/examples/advanced_graphics/level.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pewpew.set_level_size(500fx, 500fx)

local background1 = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(background1, "/dynamic/examples/advanced_graphics/polar_graphic.lua", 0)

local background2 = pewpew.new_customizable_entity(200fx, 200fx)
pewpew.customizable_entity_set_mesh(background2, "/dynamic/examples/advanced_graphics/polar_graphic.lua", 1)


pewpew.new_player_ship(100fx, 100fx, 0)
40 changes: 40 additions & 0 deletions content/dynamic/examples/advanced_graphics/polar_graphic.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


function f1(angle)
return 100 * (1.0 - math.cos(angle) * math.sin(3 * angle))
end

function f2(angle)
return 200 * (math.cos(angle) + math.sin(4 * angle))
end

function mesh_from_polar_function(f)
computed_vertexes = {}

local index = 0
local line = {}
for angle = 0, math.pi * 2, 0.05 do
local radius = f(angle)
local x = math.cos(angle) * radius
local y = math.sin(angle) * radius
table.insert(computed_vertexes, {x, y})
table.insert(line, index)
index = index + 1
end

-- Close the loop
table.insert(line, 0)

return {
vertexes = computed_vertexes,
segments = {line},
}
end



meshes = {
mesh_from_polar_function(f1),
mesh_from_polar_function(f2),
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pewpew.set_level_size(width, height)

-- Create an entity at position (0,0) that will hold the background mesh.
local background = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(background, "/dynamic/examples/complex_level/rectangles_graphic.lua", 0)
pewpew.customizable_entity_set_mesh(background, "/dynamic/examples/advanced_level/rectangles_graphic.lua", 0)

-- Configure the player, with 2 shields.
pewpew.configure_player(0, {shield = 2})
Expand Down
6 changes: 0 additions & 6 deletions content/dynamic/examples/complex_graphics/level.lua

This file was deleted.

31 changes: 0 additions & 31 deletions content/dynamic/examples/complex_graphics/polar_graphic.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
meshes = {
{
vertexes = {{0,0}, {500,0}, {500,500}, {0,500}},
colors = {0xffffffff, 0xffff00ff, 0xff00ffff, 0x00ff0000},
segments = {{0,1,2,3,0}}
}
}
29 changes: 29 additions & 0 deletions content/dynamic/examples/sounds/level.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local width = 500fx
local height = 500fx
pewpew.set_level_size(width, height)

local time = 0

local background = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(background, "/dynamic/examples/sounds/square500x500_graphic.lua", 0)

pewpew.new_player_ship(250fx, 250fx, 0)

function level_tick()
if time % 30 == 0 then
local x = 100fx
local y = 100fx
pewpew.play_sound("/dynamic/examples/sounds/sounds.lua", 0, x, y)
pewpew.create_explosion(x, y, 0xff0000ff, 1fx, 50)
end
if time % 30 == 15 then
local x = 400fx
local y = 400fx
pewpew.play_sound("/dynamic/examples/sounds/sounds.lua", 1, x, y)
pewpew.create_explosion(x, y, 0x00ffffff, 1fx, 50)
end
time = time + 1
end

-- Register the `level_tick` function to be called at every game tick.
pewpew.add_update_callback(level_tick)
12 changes: 12 additions & 0 deletions content/dynamic/examples/sounds/sounds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sounds = {
{
frequency = 1000,
decay = 0.5,
waveform = "tangent",
},
{
frequency = 500,
decay = 0.5,
waveform = "triangle",
}
}
6 changes: 6 additions & 0 deletions content/dynamic/examples/sounds/square500x500_graphic.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
meshes = {
{
vertexes = {{0,0}, {500,0}, {500,500}, {0,500}},
segments = {{0,1,2,3,0}}
}
}
2 changes: 1 addition & 1 deletion content/dynamic/examples/tutorial/box_graphics.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local gfx = require("dynamic/other/tutorial/graphics_helpers.lua")
local gfx = require("dynamic/examples/tutorial/graphics_helpers.lua")

meshes = {gfx.new_mesh(), gfx.new_mesh()}

Expand Down
12 changes: 6 additions & 6 deletions content/dynamic/examples/tutorial/cage_graphics.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local gfx = require("dynamic/other/tutorial/graphics_helpers.lua")
local gfx = require("dynamic/examples/tutorial/graphics_helpers.lua")

function make_cage_mesh()
local mesh = gfx.new_mesh()
local color = 0x40ffffff
for i = 200 - 20, 200 + 20, 5 do
gfx.add_line_to_mesh(mesh, {{i, 200 - 20, -50}, {i, 200 - 20, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{i, 200 + 20, -50}, {i, 200 + 20, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{200 - 20, i, -50}, {200 - 20, i, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{200 + 20, i, -50}, {200 + 20, i, 50}}, {color, color})
for i = - 20, 20, 5 do
gfx.add_line_to_mesh(mesh, {{i, -20, -50}, {i, -20, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{i, 20, -50}, {i, 20, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{-20, i, -50}, {-20, i, 50}}, {color, color})
gfx.add_line_to_mesh(mesh, {{20, i, -50}, {20, i, 50}}, {color, color})
end
return mesh
end
Expand Down
4 changes: 4 additions & 0 deletions content/dynamic/examples/tutorial/graphics_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ function helper.make_color(r, g, b, a)
return color
end

function helper.print()
pewpew.print("it works!")
end

return helper
14 changes: 7 additions & 7 deletions content/dynamic/examples/tutorial/level.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local boxes = require("dynamic/other/tutorial/box_template.lua")
local boxes = require("dynamic/examples/tutorial/box_template.lua")

function clamp(v, min, max)
if v < min then
Expand All @@ -9,16 +9,16 @@ function clamp(v, min, max)
return v
end

local box_outer_mesh_info = {"/dynamic/other/tutorial/box_graphics.lua", 0}
local box_inner_mesh_info = {"/dynamic/other/tutorial/box_graphics.lua", 1}
local box_outer_mesh_info = {"/dynamic/examples/tutorial/box_graphics.lua", 0}
local box_inner_mesh_info = {"/dynamic/examples/tutorial/box_graphics.lua", 1}

local w = 400fx
local h = 400fx
local margin = 50fx
pewpew.set_level_size(w, h)

local id = pewpew.new_customizable_entity(0, 0)
pewpew.customizable_entity_set_mesh(id, "/dynamic/other/tutorial/level_graphics.lua", 0)
local id = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(id, "/dynamic/examples/tutorial/level_graphics.lua", 0)

ship = pewpew.new_player_ship(w / 2fx, h / 2fx, 0)
local camera_distance = -15fx
Expand Down Expand Up @@ -62,8 +62,8 @@ function level_tick()
function()
mode_shoot = true
mode_shoot_time = 0
local cage = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(cage, "/dynamic/other/tutorial/cage_graphics.lua", 0)
local cage = pewpew.new_customizable_entity(w / 2fx, h / 2fx)
pewpew.customizable_entity_set_mesh(cage, "/dynamic/examples/tutorial/cage_graphics.lua", 0)
pewpew.configure_player_ship_weapon(ship, {frequency = 4, cannon = pewpew.CannonType.DOUBLE})
local up_angle = fmath.tau() * fmath.from_fraction(1, 4)
local down_angle = fmath.tau() * fmath.from_fraction(3, 4)
Expand Down
4 changes: 3 additions & 1 deletion content/dynamic/examples/tutorial/level_graphics.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local gfx = require("dynamic/other/tutorial/graphics_helpers.lua")
local gfx = require("dynamic/examples/tutorial/graphics_helpers.lua")

gfx.print()

function make_level_mesh()
local mesh = gfx.new_mesh()
Expand Down
Loading

0 comments on commit bd8c17f

Please sign in to comment.