1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added the 3D effect

Works nice, but can burn your eyes.
Warning: the example can actually burn your eyes.
This commit is contained in:
Firew0lf 2015-08-20 01:26:21 +02:00
parent 1c92eb22c3
commit 58309b39c2
2 changed files with 26 additions and 2 deletions

View file

@ -1,12 +1,15 @@
local gfx = require("ctr.gfx")
local hid = require("ctr.hid")
local ctr = require("ctr")
local x = 0
local y = 0
local d = 4
local angle = 0
gfx.color.setBackground(gfx.color.RGBA8(200, 200, 200))
gfx.set3D(true)
while os.run() do
local keys = hid.keys()
@ -18,7 +21,10 @@ while os.run() do
if keys.held.up then y = y - 1 end
if keys.held.down then y = y + 1 end
gfx.startFrame(gfx.GFX_TOP)
if keys.held.cstickUp then d = d + 1 end
if keys.held.cstickDown then d = d - 1 end
gfx.startFrame(gfx.GFX_TOP, gfx.GFX_LEFT)
gfx.color.setDefault(0xFF0000FF)
gfx.rectangle(x, y, 10, 10, angle)
@ -34,11 +40,18 @@ while os.run() do
gfx.endFrame()
gfx.startFrame(gfx.GFX_TOP, gfx.GFX_RIGHT)
gfx.circle(125+d, 125, 16)
gfx.endFrame()
gfx.startFrame(gfx.GFX_BOTTOM)
gfx.color.setDefault(0, 0, 0)
gfx.text(5, 7, "FPS: "..math.ceil(gfx.getFPS()))
gfx.text(5, 20, "Hello world, from Lua !", 20)
gfx.text(5, 30, "Time: "..os.date())
gfx.endFrame()

View file

@ -39,6 +39,16 @@ static int gfx_getFPS(lua_State *L) {
return 1;
}
static int gfx_set3D(lua_State *L) {
bool enable = false;
if (lua_isboolean(L, 1))
enable = lua_toboolean(L, 1);
gfxSet3D(enable);
return 1;
}
static int gfx_line(lua_State *L) {
int x1 = luaL_checkinteger(L, 1);
int y1 = luaL_checkinteger(L, 2);
@ -112,6 +122,7 @@ static const struct luaL_Reg gfx_lib[] = {
{ "endFrame", gfx_endFrame },
{ "render", gfx_render },
{ "getFPS", gfx_getFPS },
{ "set3D", gfx_set3D },
{ "line", gfx_line },
{ "point", gfx_point },
{ "rectangle", gfx_rectangle },