Calculator Community > Lua

Lua Q&A

<< < (40/42) > >>

LDStudios:

--- Quote from: njaddison on February 15, 2014, 09:15:16 am ---Yes I'm guessing that trigonometry is essential if I want to learn to program games. I learned basic trig in Geometry, how can I apply that to programming? It's something I've been wondering for a very long time, as i want to program my first game in lua, on the nspire.
EDIT:
Not actually ON the nspire, just for it.

--- End quote ---

Trig isnt really essential, unless you are going to work with rotating around a fixed point, or I guess if you are making some sort of 3D environment like DJ Omnimaga said

njaddison:
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:

--- Code: ---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
--- End code ---
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: ---while true do
--- End code ---
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.

LDStudios:
Well, I'm not really an expert, but here are some things:
You can use on.activate() so that every time u open it up it returns to the title screen. In on.activate, i would call a function to reset it to the title screen, and you can call the same function in your on.escapeKey() function.

To make the screen black:

gc:setColorRGB(0,0,0)
gc:fillRect(0,0,w,h)

LD_Chimpman:
Hi, I wanted to know how to go about mirroring an image locally in lua. I have a bunch of images for character animations and I need copies of them mirrored horizontally but instead of inserting them in as seperate mirrored images I'd like to make mirrored copies of them within my code.

The first thing I tried was using image:copy() to copy them and make the width negative, however that gave an error since lua requires the width value to be >0.

Next I studied the way the image strings are made and figured out how I could potentially switch certain parts of an image's string to mirror it. However, I tried to make a function that would manipulate parts of an image's string and got errors, because the foreward slash that is used in the strings doesn't function like a normal string value, and it overally screws up everything you try to do with it (I tried using "\\" too, but then it didn't think that "\" in the image string = "\\").

So before I go crazy searching further for a really complex way to manipulate image strings, is there a simpler way to mirror images in lua?
Please help!  ???

Jonius7:
I'm not so sure about mirroring images within the Lua code itself, but if you have the original image (.gif, .png etc) you could mirror it and convert it to image code.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version