1
Lua / Re: Lua Q&A
« on: February 15, 2014, 09:24:12 pm »
OK, so I'm programming my first game in Nspire Lua, and I have a lot of questions, but first let me deal with problems I've had so far.
The game is a simple pong clone. Here is the code so far:
Also, how would I go about making the title screen background black? I want it to look a bit like the original pong, and also, you can't see the "Simple pong clone by njaddison" if the screen is white because the text is white.
EDIT:
Also, an animation of pong in the background of the title screen would be nice, like with the lua clone of Cubefield.
The game is a simple pong clone. Here is the code so far:
Code: [Select]
function on.paint(gc)
local screen = platform.window
local h=screen:height()
local w=screen:width()
gc:setFont("sansserif", "b", 24)
gc:setColorRGB(255,193,37)
local sw = gc:getStringWidth("Pong")
local sh = gc:getStringHeight("Pong")
gc:drawString("Pong",w/2-sw/2,h/16+sh/16)
gc:setFont("sansserif", "r", 12)
gc:setColorRGB(255,255,255)
local s2w = gc:getStringWidth("Simple Pong clone by njaddison")
local s2h = gc:getStringHeight("Simple Pong clone by njaddison")
gc:drawString("Simple Pong clone by njaddison",w/2-s2w/2,h/2+s2h/2)
end
function on.enterKey()
screen:invalidate()
end
So far I've finished the title screen (subject to change) and that's pretty much it. I'm trying to make it so once you press the escape key after the game starts (game starts by pressing enter key), it will restart the code, or at least recall the title screen function. I think this is possible with Code: [Select]
while true do
loop, but I kept running into errors, and I don't even know if I can recall a function that is in a loop with a function that is outside of one.Also, how would I go about making the title screen background black? I want it to look a bit like the original pong, and also, you can't see the "Simple pong clone by njaddison" if the screen is white because the text is white.
EDIT:
Also, an animation of pong in the background of the title screen would be nice, like with the lua clone of Cubefield.