Author Topic: My first Lua project: Galaga  (Read 1077 times)

0 Members and 1 Guest are viewing this topic.

Offline njaddison

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 176
  • Rating: +24/-27
    • View Profile
My first Lua project: Galaga
« on: November 11, 2011, 04:57:15 pm »
Hey guys, I finally decided to be a man, and show my self worth. I'm creating a clone of Galaga for the nspire. But, my creation of the game is paused until i can make the spacefighter move with the arrow keys, and the animate the galaga. For example, how do I make an explosion animation if the spacefighter is hit by a enemy shot or a galaga? and, how do I keep the file size from becoming too large? please help. I will post my progress online when i get to my laptop at home.
« Last Edit: November 11, 2011, 08:46:35 pm by Qwerty.55 »
<a href="http://www.nerdtests.com/ft_nt2.php">
<img src="http://www.nerdtests.com/images/badge/nt2/5f42ec78e054645d.png" alt="NerdTests.com says I'm a Highly Dorky Nerd God.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!">
</a>


Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: MY FIRST LUA PROJECT IN THE MAKING! GALAGA!
« Reply #1 on: November 11, 2011, 08:43:27 pm »
did you already started making the real game, or is this just the beginning of the project?
If you have just started, i recommend to not think about the animation of the explosion yet, first get your basic game idea ready, and then start adding new features like the animation.
for the arrowkeys, use the code bellow, with fighter
  • as x-value and fighter[y] as y value of the spacefighter.
Code: [Select]
function on.arrowLeft()
     if fighter[x]>(min x-value here, eg. 0) then
          fighter[x] = fighter[x]-1
     end
     platform.window:invalidate()
end

function on.arrowRight()
     if fighter[x]<(max x-value here, eg. 300)
          fighter[x]=fighter[x]+1
     end
     platform.window:invalidate()
end


if you work with a platform.window:invalidate() called from a timer.start function, you don't have to put it there (if your period is small enough at least), otherwise you have to put it there to redraw the fighter on the new position.

and for the filesize, avoid using TI.images in the file, it makes it slower and larger. But if you'd like to use them to draw the spacefighter, you shouldn't hesitate, cause it's quite small.
i think you should first start programming everything you want, and clean it afterwards, otherwise you'll spend more time on thinking how to program something small instead of programming something good. once you know how it works, you can start cleaning it an certainly reduce the filesize
« Last Edit: November 11, 2011, 08:46:06 pm by Nick »

Offline DJ Omnimaga

  • Retired Omnimaga founder (no longer admin) and former news
  • Editor
  • LV15 Omnimagician (Next: --)
  • ***************
  • Posts: 55013
  • Rating: +3135/-231
  • Retired Omnimaga founder (No longer admin)
    • View Profile
    • Omnimaga
Re: MY FIRST LUA PROJECT IN THE MAKING! GALAGA!
« Reply #2 on: November 11, 2011, 08:44:23 pm »
Erm... caps-lock much? ???
Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)
Do not PM me for support. I'm not admin/mod.



Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1580
  • Rating: +228/-16
    • View Profile
    • TI-Planet
Re: My first Lua project: Galaga
« Reply #3 on: November 12, 2011, 04:56:38 am »
This is what I did for my blockbreaker : it handles a basic linear acceleration/deceleration (the "dx" part)
This allows the paddle (or whatever is moving) to have a smooth scrolling.

Code: [Select]
the paddleStuff function gets called when the ball(s) move(s) via a timer, from on.paint, basically)   

    ...

    function on.arrowKey(key)
        if key == "right" and paddle.x < platform.window:width()-20-XLimit then
            paddle.dx = 8
        elseif key == "left" and paddle.x >= 25 then
            paddle.dx = -8
        end
    end
    ...

    function paddleStuff(gc)
       if paddle.dx > 0 then
           paddle.x = paddle.x + paddle.dx
           paddle.dx = paddle.dx - 1 -- more if on-calc
       elseif paddle.dx < 0 then
           paddle.x = paddle.x + paddle.dx
           paddle.dx = paddle.dx + 1 -- more if on-calc
       end
    end
« Last Edit: November 12, 2011, 05:04:36 am by adriweb »

TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline njaddison

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 176
  • Rating: +24/-27
    • View Profile
Re: My first Lua project: Galaga
« Reply #4 on: November 12, 2011, 12:06:52 pm »
thanks guys! i will be online for a while, so tell me if you have any good ideas for my project.
And guys, I have already started. I made the title screen, and assigned the enter key to start the game. Now, I am drawing sprites.
Guys, I have another question. I won't be doing this any time soon, but what do I use to raycast? Another user explained to me the basic concept of it, but I don't know what materials I need. I hope I don't have to buy anything (I don't like lying to my parents about stuff that costs money)
<a href="http://www.nerdtests.com/ft_nt2.php">
<img src="http://www.nerdtests.com/images/badge/nt2/5f42ec78e054645d.png" alt="NerdTests.com says I'm a Highly Dorky Nerd God.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!">
</a>


Offline njaddison

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 176
  • Rating: +24/-27
    • View Profile
Re: My first Lua project: Galaga
« Reply #5 on: November 12, 2011, 07:26:30 pm »
Hey, guys, I want to know something. I can't figure out how to draw things, so I found the smallest image of a spacefighter on google images that I could. I used ti-nspire scripting tools to convert it to a TI-Image. Nick, I tried using your script(The script you gave me is correct). But, when I defined the picture "spacefighter" as the TI-Image string, and then ran the script in nspire student software, the title screen shows, but after I press enter, the picture doesn't show. I didn't get an error message, so I obviously typed valid program syntaxes and arguments.
« Last Edit: November 12, 2011, 07:29:14 pm by njaddison »
<a href="http://www.nerdtests.com/ft_nt2.php">
<img src="http://www.nerdtests.com/images/badge/nt2/5f42ec78e054645d.png" alt="NerdTests.com says I'm a Highly Dorky Nerd God.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!">
</a>


Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3720
  • Rating: +276/-12
  • Survivor of Apocalypse
    • View Profile
Re: My first Lua project: Galaga
« Reply #6 on: November 12, 2011, 07:57:24 pm »
:D
good luck XD
Project Redemption....

My project progresses:HERE
My Pastebin stuffs:HERE
Check your rate: HERE
My Animations: HERE
Spoiler For Images :D:

ノ◕ヮ◕)ノ:・゚ PENGUIN WAVE!!:„ø¤º°¨ ¨°º¤KEEP THE PENGUIN GOING ¸„ø¤º°¨ ¨°º¤øº LETS GO PENGUIN !¤¤º°¨¨°º¤øº¤ø„¸¸ø¤º°¨„ ø¤º°¨¨°º

Offline DJ Omnimaga

  • Retired Omnimaga founder (no longer admin) and former news
  • Editor
  • LV15 Omnimagician (Next: --)
  • ***************
  • Posts: 55013
  • Rating: +3135/-231
  • Retired Omnimaga founder (No longer admin)
    • View Profile
    • Omnimaga
Re: My first Lua project: Galaga
« Reply #7 on: December 25, 2011, 10:03:18 pm »
You should cross-post your questions in the Lua help sub-forum. You migth get some help faster there.
Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)
Do not PM me for support. I'm not admin/mod.



Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1580
  • Rating: +228/-16
    • View Profile
    • TI-Planet
Re: My first Lua project: Galaga
« Reply #8 on: December 26, 2011, 05:17:36 am »
Hey, guys, I want to know something. I can't figure out how to draw things, so I found the smallest image of a spacefighter on google images that I could. I used ti-nspire scripting tools to convert it to a TI-Image. Nick, I tried using your script(The script you gave me is correct). But, when I defined the picture "spacefighter" as the TI-Image string, and then ran the script in nspire student software, the title screen shows, but after I press enter, the picture doesn't show. I didn't get an error message, so I obviously typed valid program syntaxes and arguments.

your picture = image.new("....") has to be put at the very end of your program, for example, not in any functions.
your gc:drawImage(picture,x,y) has to be put in the on.paint(gc) function (or any other function where gc is passed)

Then, each time the screen gets refreshed, on.paint(gc) will draw your image.

TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation