Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Chockosta on June 03, 2011, 02:56:02 pm

Title: [Lua] Space Invaders
Post by: Chockosta on June 03, 2011, 02:56:02 pm
Hello everybody !

That's my first post here, so I'll try to introduce myself.
First, I'm French. I am a very bad English speaker (well, I'm fifteen and our English teacher sucks) so I apologize for all the nonsenses and mistakes that I'll do.
I was a member of TI-Bank, and I left this website because of all the troubles (fights between admins, etc)
So the most interesting website about calculators was Omnimaga, and I registered.
I have a TI-83+ and a TI-Nspire (Non-CAS & clickpad), and I code in Axe, in C for Nspire and in Lua. I also program in C with OpenGL on my PC, but that's not really interesting.
Well, I think I've enough talked about myself.

I made this post because I wanted feedbacks (not sure about this word) for my newest project, a Space Invaders game in Lua.
It looks like the original game, excepted that there's only one kind of enemies, and there's no "houses". Also, the enemies doesn't go faster as they go down, but the speed increases with the level.

The player can shoot with the up arrow, but that's not really convenient. If you had any better idea...
Also, I've never tried it on a calc. I don't have any CX and I use the OS 2.0.1 on my clickpad. If you could try it on your calc (and post your hi-score !)
EDIT : final version, updated.

Thank you,
Chockosta (Loic Pujet)

Lua code (Edited, final version):
Code: [Select]
function on.charIn(ch)
if ch=="r" then
blocks={5,5,5,5,5,5,5,5,5,5,5,5}
blockAttacked=0
game="notfinished"
score=0
player=100
shotX=0
shotY=0
level=1
wait=0.04
aliensDir="right"
down="no"
aliensX={}
aliensY={}
shotsX={}
shotsY={}
lives=3
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
if ch=="c" then
originalColors=not originalColors
end
end

function blocktest(x,y)
blockAttacked=0
if y>170 and y<177 then
if x>30 and x<40 and blocks[1]>0 then
blockAttacked=1
elseif x>40 and x<=50 and blocks[2]>0 then
blockAttacked=2
elseif x>50 and x<=60 and blocks[3]>0 then
blockAttacked=3
elseif x>60 and x<=70 and blocks[4]>0 then
blockAttacked=4
elseif x>140 and x<=150 and blocks[5]>0 then
blockAttacked=5
elseif x>150 and x<=160 and blocks[6]>0 then
blockAttacked=6
elseif x>160 and x<=170 and blocks[7]>0 then
blockAttacked=7
elseif x>170 and x<=180 and blocks[8]>0 then
blockAttacked=8
elseif x>250 and x<=260 and blocks[9]>0 then
blockAttacked=9
elseif x>260 and x<=270 and blocks[10]>0 then
blockAttacked=10
elseif x>270 and x<=280 and blocks[11]>0 then
blockAttacked=11
elseif x>280 and x<=290 and blocks[12]>0 then
blockAttacked=12
end
end
end


on.charIn("r")


function on.arrowLeft()
if player>0 then
player=player-10
end
end
function on.arrowRight()
if player<290 then
player=player+10
end
end
function on.tabKey()
if shotY<=0 then
shotY=195
shotX=player+13
end
end


function on.paint(gc)
if originalColors then
gc:setColorRGB(0,0,0)
gc:fillRect(0,0,platform.window:width(),platform.window:height())
end

if not originalColors then gc:setColorRGB(0,0,0)
else gc:setColorRGB(255,255,255) end
gc:setPen("thin","smooth")
gc:setFont("sansserif","r",8)
gc:drawString("Lua Alien Invaders - Par Loic Pujet",10,200,"top")

if game=="notfinished" then
if not originalColors then gc:setColorRGB(200,0,0)
else gc:setColorRGB(255,255,255) end
for i=1,21,1 do
if aliensY[i]~=0 then
gc:drawArc(aliensX[i]+4,aliensY[i]-9,10,10,0,360)
gc:fillArc(aliensX[i]-5,aliensY[i]-4,28,8,0,360)
end
end

if not originalColors then gc:setColorRGB(0,0,200)
else gc:setColorRGB(255,255,0) end
for i=1,21,1 do
if shotsY[i]<200 then
gc:fillRect(shotsX[i],shotsY[i],2,5)
end
end
if shotY>0 then
gc:fillRect(shotX,shotY,4,6)
end

if not originalColors then gc:setColorRGB(100,0,255)
else gc:setColorRGB(0,255,0) end
gc:fillRect(player,195,30,10)
gc:fillRect(player+13,191,4,4)
gc:setFont("sansserif","r",10)
gc:drawString("Lives:"..tostring(lives).." Score:"..tostring(score).." Level:"..tostring(level),0,0,"top")

if not originalColors then add=3
else add=0 end
for i=1,12,1 do
if blocks[i]>0 then
gc:fillRect(i*10+math.floor((i-1)/4)*70+20,180-blocks[i]*2,10,blocks[i]*2)
end
end
else
if var.recall("highscore")==nil then
var.store("highscore",0)
else
if var.recall("highscore")<score then
var.store("highscore",score)
document.markChanged()
end
end
if not originalColors then gc:setColorRGB(0,0,0)
else gc:setColorRGB(255,255,255) end
gc:setFont("sansserif","b",15)
gc:drawString("Score : "..tostring(score).."        High score : "..tostring(var.recall("highscore")),50,50, "top")
if not originalColors then gc:setColorRGB(0,0,255) end
if locale.name()=="fr" then
gc:drawString("Appuyez sur R pour rejouer",50,150,"top")
else
gc:drawString("Press R to try again",80,150,"top")
end
end

if wait>0.01 then
timer.start(wait)
else
timer.start(0.01)
end

end


function on.timer()
timer.stop()

if game=="notfinished" then
if aliensDir=="right" then
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]+1
end
end
else
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]-1
end
end
end

if aliensDir=="right" then
for i=1,21,1 do
if aliensX[i]>295 then
down="yes"
end
end
else
for i=1,21,1 do
if aliensX[i]<5 then
down="yes"
end
end
end

if down=="yes" then
down="no"
for i=1,21,1 do
if aliensY[i]>0 then
aliensY[i]=aliensY[i]+25
end
end
if aliensDir=="left" then
aliensDir="right"
else
aliensDir="left"
end
end

for i=1,21,1 do
if aliensY[i]>180 then
game="finished"
end

if shotsY[i]>=200 and aliensY[i]~=0 then
if math.random(1,100)==5 then
shotsY[i]=aliensY[i]+math.random(1,10)
shotsX[i]=aliensX[i]
end
else
shotsY[i]=shotsY[i]+3
end

blocktest(shotsX[i],shotsY[i])
if blockAttacked>0 then
shotsY[i]=201
blocks[blockAttacked]=blocks[blockAttacked]-1
end

if shotsY[i]<200 then
if shotsY[i]>195 and shotsX[i]>player and shotsX[i]<player+30 then
lives=lives-1
shotsY[i]=200
end
end

if shotY>0 and shotY>aliensY[i]-5 and shotY<aliensY[i]+5 and shotX>aliensX[i]-10 and shotX<aliensX[i]+21 then
aliensY[i]=0
aliensX[i]=100
shotY=0
score=score+1
end
end

blocktest(shotX,shotY)
if blockAttacked>0 then
shotY=-1
blocks[blockAttacked]=blocks[blockAttacked]-1
end

if shotY>=0 then
shotY=shotY-5
end

if lives<=0 then
game="finished"
end


wintest=0
for i=1,21,1 do
wintest=wintest+aliensY[i]
end

if wintest==0 then
if wait>0.01 then
wait=wait-0.005
end
level=level+1
aliensDir="right"
down="no"
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
end

platform.window:invalidate()
end

I attached the .tns It works on OS 3.0.1 and OS 3.0.2 (edited : bug fixed)
Title: Re: [Lua] Space Invaders
Post by: JosJuice on June 03, 2011, 03:00:02 pm
Welcome to Omnimaga! Have you uploaded your game yet so that others can play it? I think you can't upload it as an attachment in an Omnimaga post before you've made a certain amount of posts, so maybe you could try a file sharing site like mediafire.com.

Also, your English seems to be fine. :)
Title: Re: [Lua] Space Invaders
Post by: Jim Bauwens on June 03, 2011, 03:06:12 pm
Hey, and welcome Chockosta!
Its nice to see another Lua programmer :)

I just tried your game on my touchpad, but for some reason I immediately die :/

Quote
The player can shoot with the up arrow, but that's not really convenient. If you had any better idea...
Maybe the TAB key is better?
Title: Re: [Lua] Space Invaders
Post by: Keoni29 on June 03, 2011, 03:09:12 pm
Hello everybody !
Hi there :)

That's my first post here, so I'll try to introduce myself.
Welcome!

First, I'm French. I am a very bad English speaker (well, I'm fifteen and our English teacher sucks) so I apologize for all the nonsenses and mistakes that I'll do.
That ain't a problem. There are people who can't speak English at all. We have a French board for those n00bs :)

I was a member of TI-Bank, and I left this website because of all the troubles (fights between admins, etc)
Oh God. They play The Game too?

So the most interesting website about calculators was Omnimaga, and I registered.

I have a TI-83+ and a TI-Nspire (Non-CAS & clickpad), and I code in Axe, in C for Nspire and in Lua. I also program in C with OpenGL on my PC, but that's not really interesting.
I have a TI 84 + myself.

Well, I think I've enough talked about myself.

I made this post because I wanted feedbacks (not sure about this word) for my newest project, a Space Invaders game in Lua.
Feedback (It's already plural)

It looks like the original game, excepted that there's only one kind of enemies, and there's no "houses". Also, the enemies doesn't go faster as they go down, but the speed increases with the level.
You did that because it was easier to make or because you wanted to alter these things?

The player can shoot with the up arrow, but that's not really convenient. If you had any better idea...
Also, I've never tried it on a calc. I don't have any CX and I use the OS 2.0.1 on my clickpad. If you could try it on your calc (and post your hi-score !)
I don't have a Nspire :(

Thank you,
Chockosta (Loic Pujet)
:)
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 03, 2011, 03:18:00 pm
Sounds good I use OS 2.0.1 so unfortunately I won't be able to play this. I refuse to upgrade to 3 till downgrading and Ndless become possible.
You should start an introduction topic in the intro board so you can get your peanuts to make your calc run faster.
Your English seems almost as good as mine and I live in America and thats my first language.
Title: Re: [Lua] Space Invaders
Post by: Jim Bauwens on June 03, 2011, 03:18:46 pm
I have looked for the bug, and this is what I found

Code: [Select]
         for i=1,21,1 do
            if aliensY>0 then
               aliensY=aliensY+25
            end
         end

For some reason you put for loops arround every check, while it is not necessary.
This piece of code will loop 21 times, which means that aliensY=aliensY+525 .
And that is why you die.
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 03, 2011, 03:37:34 pm
Strange... It works perfectly on my emulator. (Nspire_emu)
Oooooh i understood !
The "spoiler" option suppress all the '[i ]'  of tables ! Let's try it with "code"
Code: [Select]
function on.charIn(ch)
if ch=="r" then
game="notfinished"
score=0
player=100
shotX=0
shotY=0
wait=0.04
aliensDir="right"
down="no"
aliensX={}
aliensY={}
shotsX={}
shotsY={}
lives=3
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
end


on.charIn("r")


function on.arrowLeft()
if player>0 then
player=player-10
end
end
function on.arrowRight()
if player<290 then
player=player+10
end
end
function on.arrowUp()
if shotY<=0 then
shotY=195
shotX=player+13
end
end


function on.paint(gc)
gc:setColorRGB(0,0,0)
gc:setPen("thin","smooth")
gc:setFont("sansserif","r",8)
gc:drawString("Lua Alien Invaders - Par Loic Pujet",10,200,"top")

if game=="notfinished" then
gc:setColorRGB(200,0,0)
for i=1,21,1 do
if aliensY[i]~=0 then
gc:drawArc(aliensX[i]+4,aliensY[i]-9,10,10,0,360)
gc:fillArc(aliensX[i]-5,aliensY[i]-4,28,8,0,360)
end
end

gc:setColorRGB(0,0,200)
for i=1,21,1 do
if shotsY[i]<200 then
gc:fillRect(shotsX[i],shotsY[i],2,5)
end
end
if shotY>0 then
gc:fillRect(shotX,shotY,4,6)
end

gc:setColorRGB(100,0,255)
gc:fillRect(player,195,30,10)
gc:fillRect(player+13,191,4,4)
gc:setFont("sansserif","r",10)
gc:drawString("vies:"..tostring(lives).." score:"..tostring(score),0,0,"top")
else
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","b",15)
gc:drawString("Score : "..tostring(score),100,50, "top")
gc:setColorRGB(0,0,255)
gc:drawString("Appuyez sur R pour rejouer",50,150,"top")
end

timer.start(wait)
end


function on.timer()
timer.stop()

if game=="notfinished" then
if aliensDir=="right" then
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]+1
end
end
else
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]-1
end
end
end

if aliensDir=="right" then
for i=1,21,1 do
if aliensX[i]>305 then
down="yes"
end
end
else
for i=1,21,1 do
if aliensX[i]<15 then
down="yes"
end
end
end

if down=="yes" then
down="no"
for i=1,21,1 do
if aliensY[i]>0 then
aliensY[i]=aliensY[i]+25
end
end
if aliensDir=="left" then
aliensDir="right"
else
aliensDir="left"
end
end

for i=1,21,1 do
if aliensY[i]>200 then
game="finished"
end
end

for i=1,21,1 do
if shotsY[i]>=200 and aliensY[i]~=0 then
if math.random(1,100)==5 then
shotsY[i]=aliensY[i]+math.random(1,10)
shotsX[i]=aliensX[i]
end
else
shotsY[i]=shotsY[i]+3
end
end
if shotY>=0 then
shotY=shotY-5
end

for i=1,21,1 do
if shotsY[i]<200 then
if shotsY[i]>195 and shotsX[i]>player and shotsX[i]<player+30 then
lives=lives-1
shotsY[i]=200
end
end
end
if lives==0 then
game="finished"
end

if shotY>0 then
for i=1,21,1 do
if shotY>0 and shotY>aliensY[i]-5 and shotY<aliensY[i]+5 and shotX>aliensX[i]-15 and shotX<aliensX[i]+15 then
aliensY[i]=0
aliensX[i]=100
shotY=0
score=score+1
end
end
end

wintest=0
for i=1,21,1 do
wintest=wintest+aliensY[i]
end
if wintest==0 then
if wait>0.02 then
wait=wait-0.005
end
aliensDir="right"
down="no"
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
end

platform.window:invalidate()
end


function on.arrowKey(key)
platform.window:invalidate()
end

Yay, it works !
I join a screenie :
(http://i25.servimg.com/u/f25/11/25/11/26/screen18.jpg) (http://www.servimg.com/image_preview.php?i=82&u=11251126)
Translate it to English if you want.

BTW, I saw that we could join pictures. How can I do that ?


Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 03:38:54 pm
I looked through some of your code, and I noticed a few things wrong with it:

- unoptimized math commands.  While it's not huge, using player+=10 is a lot better than player=player+10.
- what's the deal with all of the for loops?  I don't see the point in many of them.
- you should chain if statements together more, it'll remove the need for much of the redundancies and might even half your code size.
- why do you assign different functions to keys instead of just making a checkKeys() function or just putting all checks inline?  Or are you overriding previously existing functions provided by an NLua module?
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 03, 2011, 03:40:20 pm
you use the drawimage function with the image screen. Thats the limit of my knowledge unfortunately
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 03, 2011, 03:41:19 pm
I looked through some of your code, and I noticed a few things wrong with it:

- unoptimized math commands.  While it's not huge, using player+=10 is a lot better than player=player+10.
- what's the deal with all of the for loops?  I don't see the point in many of them.
- you should chain if statements together more, it'll remove the need for much of the redundancies and might even half your code size.
- why do you assign different functions to keys instead of just making a checkKeys() function or just putting all checks inline?  Or are you overriding previously existing functions provided by an NLua module?

I just started in LUA...
The '+=' works ? Omg I was fed up with all the 'player=player+10'
I will check all the other things tomorrow...
Title: Re: [Lua] Space Invaders
Post by: Levak on June 03, 2011, 03:44:05 pm
It looks like the original game, excepted that there's only one kind of enemies, and there's no "houses". Also, the enemies doesn't go faster as they go down, but the speed increases with the level.
Only one thing (don't have the time) : In the real game, the ennemy speed increases when they were less only because it was a performance lack. More ennemy there were, more the game was laggy !
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 03:44:18 pm
I looked through some of your code, and I noticed a few things wrong with it:

- unoptimized math commands.  While it's not huge, using player+=10 is a lot better than player=player+10.
- what's the deal with all of the for loops?  I don't see the point in many of them.
- you should chain if statements together more, it'll remove the need for much of the redundancies and might even half your code size.
- why do you assign different functions to keys instead of just making a checkKeys() function or just putting all checks inline?  Or are you overriding previously existing functions provided by an NLua module?

I just started in LUA...
The '+=' works ? Omg I was fed up with all the 'player=player+10'
I will check all the other things tomorrow...

I can help you rewrite if you want, I think I could probably cut out ~60 lines of code if I do it correctly.  Also, for a beginning Lua programmer, it's actually not bad, and you should be proud ;)

Most double math commands like +=, -=, and the like usually work in lua, with exceptions of a few good ones like ++, --, and depending on the platform and what version was ported, the bitwise shifting ops.
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 03, 2011, 03:58:05 pm
I believe this code should run a little faster. I haven't tested it yet though
Spoiler For Hopefully faster non buggy code:
Code: [Select]
function on.charIn(ch)
   if ch=="r" then
      game="notfinished"
      score=0
      player=100
      shotX=0
      shotY=0
      wait=0.04
      aliensDir="right"
      down="no"
      aliensX={}
      aliensY={}
      shotsX={}
      shotsY={}
      lives=3
      for i=1,21,1 do
         aliensX=(i-1)%7*31+1
         aliensY=math.floor((i-1)/7)*25+10
         shotsX=aliensX
         shotsY=200
      end
   end
end


on.charIn("r")


function on.arrowLeft()
   if player>0 then
      player=player-10
   end
end
function on.arrowRight()
   if player<290 then
      player=player+10
   end
end
function on.arrowUp()
   if shotY<=0 then
      shotY=195
      shotX=player+13
   end
end


function on.paint(gc)
   gc:setColorRGB(0,0,0)
   gc:setPen("thin","smooth")
   gc:setFont("sansserif","r",8)
   gc:drawString("Lua Alien Invaders - Par Loic Pujet",10,200,"top")

   if game=="notfinished" then
      gc:setColorRGB(200,0,0)
      if aliensY~=0 then
         gc:drawArc(aliensX+4,aliensY-9,10,10,0,360)
         gc:fillArc(aliensX-5,aliensY-4,28,8,0,360)
      end

      gc:setColorRGB(0,0,200)
      if shotsY<200 then
         gc:fillRect(shotsX,shotsY,2,5)
      end
      if shotY>0 then
         gc:fillRect(shotX,shotY,4,6)
      end

      gc:setColorRGB(100,0,255)
      gc:fillRect(player,195,30,10)
      gc:fillRect(player+13,191,4,4)
      gc:setFont("sansserif","r",10)
      gc:drawString("vies:"..tostring(lives).." score:"..tostring(score),0,0,"top")
   else
      gc:setColorRGB(0,0,0)
      gc:setFont("sansserif","b",15)
      gc:drawString("Score : "..tostring(score),100,50, "top")
      gc:setColorRGB(0,0,255)
      gc:drawString("Appuyez sur R pour rejouer",50,150,"top")
   end

   timer.start(wait)
end


function on.timer()
   timer.stop()
   
   if game=="notfinished" then
      if aliensDir=="right" then
         if aliensY>0 then
            aliensX+=1
         end
      else
         if aliensY>0 then
            aliensX-=1
         end
      end

      if aliensDir=="right" then
         if aliensX>305 then
            down="yes"
         end
      else
         if aliensX<15 then
            down="yes"
         end
      end

      if down=="yes" then
         down="no"
         if aliensY>0 then
            aliensY+=25
         end
         if aliensDir=="left" then
            aliensDir="right"
         else
            aliensDir="left"
         end
      end

      if aliensY>200 then
         game="finished"
      end

      if shotsY>=200 and aliensY~=0 then
         if math.random(1,100)==5 then
            shotsY=aliensY+math.random(1,10)
            shotsX=aliensX
         end
      else
          shotsY+=3
      end
      if shotY>=0 then
         shotY-=5
      end

      if shotsY<200 then
         if shotsY>195 and shotsX>player and shotsX<player+30 then
            lives-=1
            shotsY=200
         end
      end
      if lives==0 then
         game="finished"
      end
     
      if shotY>0 then
         if shotY>0 and shotY>aliensY-5 and shotY<aliensY+5 and shotX>aliensX-15 and shotX<aliensX+15 then
            aliensY=0
            aliensX=100
            shotY=0
            score+=1
         end
      end

      wintest=0
      wintest=wintest+aliensY
      if wintest==0 then
         if wait>0.02 then
            wait-=0.005
         end
         aliensDir="right"
         down="no"
         for i=1,21,1 do
            aliensX=(i-1)%7*31+1
            aliensY=math.floor((i-1)/7)*25+10
            shotsX=aliensX
            shotsY=200
         end
      end
   end

function on.arrowKey(key)
   platform.window:invalidate()
end
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 04:08:29 pm
I went through really quickly and tried to cut off as much as I could in ~5 minutes.  Here's what I did in a nutshell:

-I put together the X and Y lists for less loops in the for statements, should double their speed
-I optimized math
-I took out a few logic things that weren't nessicary

I think there's still huge potential to optimize with this further, but make the rest of your game before it becomes unreadable! ;)

Code: [Select]
function on.charIn(ch)
if ch=="r" then
game="notfinished"
score=0
player=100
shotX=0;shotY=0
wait=0.04
aliensDir="right"
down="no"
aliensXY={}
shotsXY={}
lives=3
for i=1,21,2 do
aliensXY[i]=(math.ceil(i/2)-1)%7*31+1
aliensXY[i+1]=math.floor((math.ceil(i+1/2)-1)/7)*25+10
shotsXY[i]=aliensX[i]
shotsXY[i+1]=200
end
end
end


on.charIn("r")


function on.arrowLeft()
if player~=0 then
player-=10
end
end
function on.arrowRight()
if player<290 then
player+=10
end
end
function on.arrowUp()
if shotY <= 0 then
shotY=195
shotX+=13
end
end


function on.paint(gc)
gc:setColorRGB(0,0,0)
gc:setPen("thin","smooth")
gc:setFont("sansserif","r",8)
gc:drawString("Lua Alien Invaders - Par Loic Pujet",10,200,"top")

if game=="notfinished" then
gc:setColorRGB(200,0,0)
for i=1,21,2 do
if aliensXY[i+1]~=0 then
gc:drawArc(aliensXY[i]+4,aliensXY[i+1]-9,10,10,0,360)
gc:fillArc(aliensXY[i]-5,aliensXY[i+1]-4,28,8,0,360)
end
end

gc:setColorRGB(0,0,200)
for i=1,21,2 do
if shotsXY[i+1]<200 then
gc:fillRect(shotsXY[i],shotsxY[i+1],2,5)
end
end
if shotY>0 then
gc:fillRect(shotX,shotY,4,6)
end

gc:setColorRGB(100,0,255)
gc:fillRect(player,195,30,10)
gc:fillRect(player+13,191,4,4)
gc:setFont("sansserif","r",10)
gc:drawString("vies:"..tostring(lives).." score:"..tostring(score),0,0,"top")
else
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","b",15)
gc:drawString("Score : "..tostring(score),100,50, "top")
gc:setColorRGB(0,0,255)
gc:drawString("Appuyez sur R pour rejouer",50,150,"top")
end

timer.start(wait)
end


function on.timer()
timer.stop()

if game=="notfinished" then
if aliensDir=="right" then
for i=1,21,2 do
if aliensXY[i+1]>0 then
aliensXY[i]+=1
end
end
else
for i=1,21,2 do
if aliensXY[i+1]>0 then
aliensXY[i]-=1
end
end
end

if aliensDir=="right" then
for i=1,21,2 do
if aliensXY[i]>305 then
down="yes"
end
end
else
for i=1,21,2 do
if aliensXY[i]<15 then
down="yes"
end
end
end

if down=="yes" then
down="no"
for i=1,21,2 do
if aliensXY[i+1]>0 then
aliensXY[i+1]+=25
end
end
if aliensDir=="left" then
aliensDir="right"
else
aliensDir="left"
end
end

for i=1,21,2 do
if aliensXY[i+1]>200 then
game="finished"
end
end

for i=1,21,2 do
if shotsXY[i+1]>=200 and aliensXY[i+1]~=0 then
if math.random(1,100)==5 then
shotsXY[i+1]=aliensXY[i+1]+math.random(1,10)
shotsXY[i]=aliensXY[i]
end
else
shotsXY[i+1]+=3
end
end
if shotY>=0 then
shotY-=5
end

for i=1,21,2 do
if shotsXY[i+]<200 then
if shotsXY[i+1]>195 and shotsXY[i]>player and shotsXY[i]<player+30 then
lives-=1
shotsXY[i+1]=200
end
end
end
if lives==0 then
game="finished"
end

if shotY ~= 0 then
for i=1,21,2 do
if shotY~=0 and shotY>aliensXY[i+1]-5 and shotY<aliensXY[i+1]+5
   and shotX>aliensXY[i]-15 and shotX<aliensXY[i]+15 then
aliensXY[i+1]=0
aliensXY[i]=100
shotY=0
score+=1
end
end
end

wintest=0
for i=1,21,2 do
wintest+=aliensXY[i+1]
end
if wintest==0 and
if wait>0.02 then
wait-=0.005
end
aliensDir="right"
down="no"
for i=1,21,2 do
aliensXY[i]=(math.ceil(i/2)-1)%7*31+1
aliensXY[i+1]=math.floor((math.ceil(i+1/2)-1)/7)*25+10
shotsXY[i]=aliensX[i]
shotsXY[i+1]=200
end
end
end

platform.window:invalidate()
end


function on.arrowKey(key)
platform.window:invalidate()
end


EDIT: suggested new optimizations:

- there are some areas where do in pairs loops would be beneficial.
- using numbers for directions rather than strings.
- instead of using built in shape methods to draw your objects, I'm sure using sprite data would be a faster choice.
Title: Re: [Lua] Space Invaders
Post by: Levak on June 03, 2011, 04:31:48 pm
Most double math commands like +=, -=, and the like usually work in lua, with exceptions of a few good ones like ++, --, and depending on the platform and what version was ported, the bitwise shifting ops.

Good try, but ... you're wrong.
On the TI-Nspire Lua langage you can't do that.
Example of the given error :
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 04:42:25 pm
That means TI put an old version of Lua on the Nspire.  I say the first thing they need to improve is the version number.

Well, 80% of the speed optimizations were actually with the merged tables, so that should still increase the speed significantly :)
Title: Re: [Lua] Space Invaders
Post by: Levak on June 03, 2011, 04:58:37 pm
If it could help you to understand :

Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 03, 2011, 04:59:16 pm
that looks evil Levak
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 05:00:04 pm
Hmm, it actually seems as though they DO have 5.1.4 on it O.o  No idea why the += operators aren't working then.  I explicitly remember being able to use them when I used Lua a few years ago, and I've seen code examples with double ops in them.
Title: Re: [Lua] Space Invaders
Post by: BrownyTCat on June 03, 2011, 05:02:30 pm
Ooooh, I like this. Perhaps try exchanging the geometric drawing for original sprites.
Title: Re: [Lua] Space Invaders
Post by: Levak on June 03, 2011, 05:08:53 pm
Hmm, it actually seems as though they DO have 5.1.4 on it O.o  No idea why the += operators aren't working then.  I explicitly remember being able to use them when I used Lua a few years ago, and I've seen code examples with double ops in them.

Well, in the official Manual, " += " appears only one time, in the C integration part :
http://www.lua.org/manual/5.1/manual.html#lua_CFunction
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 03, 2011, 05:10:27 pm
Hmm, it actually seems as though they DO have 5.1.4 on it O.o  No idea why the += operators aren't working then.  I explicitly remember being able to use them when I used Lua a few years ago, and I've seen code examples with double ops in them.

Well, in the official Manual, " += " appears only one time, in the C integration part :
http://www.lua.org/manual/5.1/manual.html#lua_CFunction

Hmm, I guess I just remember that from when I embedded Lua into a C program a few times.  False alarm then.  In that case, Lua itself needs to improve.
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 04, 2011, 03:21:17 am
Thanks for your helping, Ashbad.  :)

For the '+=' operators, I was thinking that I've already tried it.
But I don't really understand the :
Code: [Select]
for i=1,21,2 do
aliensXY[i]=(math.ceil(i/2)-1)%7*31+1
aliensXY[i+1]=math.floor((math.ceil(i+1/2)-1)/7)*25+10
shotsXY[i]=aliensX[i]
shotsXY[i+1]=200
end
Wasn't it supposed to be :
Code: [Select]
for i=1,21,2 do
aliensXY[i]=(math.ceil(i/2)-1)%7*31+1
aliensXY[i+21]=math.floor((math.ceil(i+1/2)-1)/7)*25+10javascript:void(0);
shotsXY[i]=aliensXY[i]
shotsXY[i+21]=200
end
And all your "aliensXY[i+1]" shouldn't be changed in "aliensXY[i+21]" ? Because there are 21 aliens, and the table should content first their X position, and after their Y pos.

Quote from: Ashbad
- using numbers for directions rather than strings.
Is it really faster ? I think that it will not really increase the speed...

PS:Well, it is 9:20 in France, but in USA, it may be very early... I will not get any answers until a few hours, I think   :D
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 04, 2011, 08:19:12 am
Strings take more memory so yeah ti would probably be faster to use numbers
Title: Re: [Lua] Space Invaders
Post by: ztrumpet on June 04, 2011, 11:42:26 am
PS:Well, it is 9:20 in France, but in USA, it may be very early... I will not get any answers until a few hours, I think   :D
Yup, France is about 6-9 hours ahead of the US, so a lot of activity will happen at night in the US, when you're sleeping,and some of your activity will happen when most people in the US are sleeping.  That being said, we do have a few other members from Europe. :)
Welcome to Omnimaga, Chockosta.  This project looks great. :D
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 04, 2011, 11:57:18 am
Some people like me though will commonly stay up all night here in the US and be on
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 04, 2011, 02:10:23 pm
I updated the first post with a playable version, screenies, and a link to the .tns (unfortunately the website where I uploaded it has a lot of ads)
This may be the final version, because the game is finished and the gameplay seems good for me.
Some optimizations still can be done, but the speed is fast enough. (If you think that it's too slow, try to reach 100 points ;) )

EDIT : I just saw we could attach files ;D No more ads, now.
Title: Re: [Lua] Space Invaders
Post by: ruler501 on June 04, 2011, 02:35:37 pm
Yay it works. now need to get the emulator set up so i can play it
Title: Re: [Lua] Space Invaders
Post by: Jim Bauwens on June 04, 2011, 03:23:17 pm
Good job! Congratulations!
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 04, 2011, 03:35:20 pm
If it could help you to understand :


Wait... you can read that thing?

Great! Can't wait to play the game.

P.S.- I lost the game.
Title: Re: [Lua] Space Invaders
Post by: Levak on June 04, 2011, 03:53:19 pm
If it could help you to understand :
Wait... you can read that thing?
Where is the problem ? We can do this since a while ... The more important thing to know is that the data base part (like strings, keys of strings, and the Lua part) are readable without dissassembly procedure.
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 04, 2011, 04:02:31 pm
Never mind, thought you were able to read the gobbledegook above the Lua part.
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 05, 2011, 08:17:15 am
For pianoman :
The important thing is not all the weird characters, but the highlighted word in the last line and the following words... It says the Lua version is 5.1.4

To go back to the topic, my hi-score is 94. Can you beat it ? :)
Title: Re: [Lua] Space Invaders
Post by: Ashbad on June 05, 2011, 08:18:29 am
For pianoman :
The important thing is not all the weird characters, but the highlighted word in the last line and the following words... It says the Lua version is 5.1.4

To go back to the topic, my hi-score is 94. Can you beat it ? :)

I think I'll try it later on today with the official Nspire document player.  It seems as if you did a great job with this, I commend you :) did the optimizations [that worked] help speed at all?
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 05, 2011, 09:59:23 am
Well, the speed without optimizations was already adapted to the game. I tried the optimizations like one table instead of two for X and Y, but I couldn't see the speed changing. I think that the difference exist, but it's too small.
I will post the final version in a few hours including a first page which contains explanations (keys, etc)
Title: Re: [Lua] Space Invaders
Post by: Hot_Dog on June 05, 2011, 12:05:35 pm
Welcome to Omnimaga, Chockosta!

And I must say, amazing game design so far.
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 05, 2011, 01:30:18 pm
The final version is here !
I attach it in the first post, and in this post too.
It works on OS 3.0.2, as I used the official TI scripting tool, with the 30-days trial.
So thank you for all your help and replies, and I forgot to thank you for all your welcoming posts :)
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 05, 2011, 01:35:49 pm
The final version is here !
I attach it in the first post, and in this post too.
It works on OS 3.0.2, as I used the official TI scripting tool, with the 30-days trial.
So thank you for all your help and replies, and I forgot to thank you for all your welcoming posts :)
Wait, 30-day trial?
Title: Re: [Lua] Space Invaders
Post by: Levak on June 05, 2011, 01:41:47 pm
The final version is here !
I attach it in the first post, and in this post too.
It works on OS 3.0.2, as I used the official TI scripting tool, with the 30-days trial.
So thank you for all your help and replies, and I forgot to thank you for all your welcoming posts :)
Wait, 30-day trial?

He used the official TI scripting tool. To use it you need TI Nspire Computer Software. But since TI-Nspire Computer Software is under licence and we need to pay for it, Chockosta used the trial version of TI-Nspire Computer Software. But one thing is that it is not a 30-days trial, but a 90-days trial =)
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 05, 2011, 01:42:21 pm
Got it. Thanks!
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 05, 2011, 01:42:38 pm
30-days trial of Nspire computer software :)
(For the moment) the official scripting tool is unlimited...

EDIT : Ninja'd
Title: Re: [Lua] Space Invaders
Post by: Spyro543 on June 05, 2011, 01:58:36 pm
So that means to link out Nspire to the computer we can only do it for 30 days for free??? The computer software doesn't come with the Nspire?
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 05, 2011, 01:59:52 pm
Touchpad comes for free, I'd assume CX does too. Clickpad does not.
Title: Re: [Lua] Space Invaders
Post by: Spyro543 on June 05, 2011, 02:00:45 pm
Oh I get it. Chockosta has a clickpad, then?
Title: Re: [Lua] Space Invaders
Post by: pianoman on June 05, 2011, 02:01:22 pm
Says that in his profile.
Title: Re: [Lua] Space Invaders
Post by: BrownyTCat on June 06, 2011, 09:45:56 am
The final version is here !
I attach it in the first post, and in this post too.
It works on OS 3.0.2, as I used the official TI scripting tool, with the 30-days trial.
So thank you for all your help and replies, and I forgot to thank you for all your welcoming posts :)
Wait, 30-day trial?

He used the official TI scripting tool. To use it you need TI Nspire Computer Software. But since TI-Nspire Computer Software is under licence and we need to pay for it, Chockosta used the trial version of TI-Nspire Computer Software. But one thing is that it is not a 30-days trial, but a 90-days trial =)
Student software just says "Invalid 7Zip Archive" for me, If I manually extract the EXE, nothing happens still. It'll probably fix on my WinXP computer.
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 06, 2011, 02:52:49 pm
I tried this and it's quite nice actually. I wonder if adding a star background or more complex sprites would slow it down too much?
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 07, 2011, 09:22:53 am
Thank you for putting my game in the news ! :)

For the star background or more complex sprites, I'm not sure it's a really good idea.
Yes it would maybe look prettier, but I like minimalist graphics...

But if you really think that it would be better, I could try.
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 08, 2011, 01:20:56 am
AAh ok, it's up to you then. Else, another idea is to just make the background plain black. Also adding blocks at the bottom to hide yourself from shots like in the original game would be nice (maybe as option)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 10, 2011, 07:15:25 am
Great ideas !
Sorry, I didn't noticed your post before yesterday.
Well, I've added a new option : when you press the "c" key, the colors change. Actually, there are two themes : the first one that we can see in the first screenshots, and the second one which looks like the original game. (I attach a screenie) Moreover, the second one looks nicer on a CX, and the first one is more adapted for a clickpad (or touchpad)

I also fixed a bug : when the player had just 1 life, if he "caught" two shots exactly at the same time, he had -1 lives, and became invincible.
I will try to add blocks soon.
Title: Re: [Lua] Space Invaders
Post by: Jim Bauwens on June 10, 2011, 07:16:18 am
Looks very pretty!
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 10, 2011, 07:33:08 am
Thank you !
(And for the .tns, I will post it when I have added the shield blocks)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 11, 2011, 07:24:20 am
(Sorry for the double post)

I've added the blocks, which hide the player.  Three shots destroy a block. (There are 12 blocks)
Do you think that it's better if the player can shoot through blocks or not ?

I attach a new screenshot
Title: Re: [Lua] Space Invaders
Post by: ztrumpet on June 11, 2011, 09:37:25 am
This is looking great. :D
Do you think that it's better if the player can shoot through blocks or not ?
I think the player should not be able to shoot through blocks, as that means that he has too much protection.  Make it so if the player does shoot the blocks that it counts as one of each blocks' three shots-to-destroy. ;)
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 11, 2011, 02:35:01 pm
Wow nice! And I like the new colors: It looks even closer to the original :D

(http://upload.wikimedia.org/wikipedia/en/2/20/SpaceInvaders-Gameplay.gif)
Title: Re: [Lua] Space Invaders
Post by: Kjelddy on June 11, 2011, 04:15:46 pm
do u already know when you release the one with blocks. and where could i download it then?
Title: Re: [Lua] Space Invaders
Post by: BrownyTCat on June 12, 2011, 02:55:29 am
Wow nice! And I like the new colors: It looks even closer to the original :D

(http://upload.wikimedia.org/wikipedia/en/2/20/SpaceInvaders-Gameplay.gif)
/me is crossing his fingers for possible sprites.
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 12, 2011, 02:57:49 am
do u already know when you release the one with blocks. and where could i download it then?
I'm not sure if the version with blocks is available yet.
Title: Re: [Lua] Space Invaders
Post by: Kjelddy on June 12, 2011, 04:20:48 am
do u already know when you release the one with blocks. and where could i download it then?
I'm not sure if the version with blocks is available yet.
that was my question :)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 12, 2011, 05:07:49 am
No, not yet.
I have to forbid the player to shoot trough blocks, and to do some optimizations.
I will probably post the new release today (well, in my French day).

And sadly, I tried with sprites, and it became awfully slow.
Title: Re: [Lua] Space Invaders
Post by: Kjelddy on June 12, 2011, 05:15:49 am
too bad for the sprites ...
but good for the release :)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 12, 2011, 06:52:15 am
Okay, I think my game is finished. I attach the last release.
Please test this, and post here if you find any bug or problem. (By the way, the 3 shots to destroy a block are increased, now it's 5 shots)

EDIT : I removed the attachment. If you're looking for the game, see below.
Title: Re: [Lua] Space Invaders
Post by: Adriweb on June 12, 2011, 06:56:11 am
looks pretty good !

Haven't found a bug so far (well I played only a little:P)

Mind to share the .lua ?

;)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 12, 2011, 07:04:35 am
Sure !
Here it is :
Code: [Select]
function on.charIn(ch)
if ch=="r" then
blocks={5,5,5,5,5,5,5,5,5,5,5,5}
blockAttacked=0
game="notfinished"
score=0
player=100
shotX=0
shotY=0
level=1
wait=0.04
aliensDir="right"
down="no"
aliensX={}
aliensY={}
shotsX={}
shotsY={}
lives=3
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
if ch=="c" then
originalColors=not originalColors
end
end

function blocktest(x,y)
blockAttacked=0
if y>170 and y<177 then
if x>30 and x<40 and blocks[1]>0 then
blockAttacked=1
elseif x>40 and x<=50 and blocks[2]>0 then
blockAttacked=2
elseif x>50 and x<=60 and blocks[3]>0 then
blockAttacked=3
elseif x>60 and x<=70 and blocks[4]>0 then
blockAttacked=4
elseif x>140 and x<=150 and blocks[5]>0 then
blockAttacked=5
elseif x>150 and x<=160 and blocks[6]>0 then
blockAttacked=6
elseif x>160 and x<=170 and blocks[7]>0 then
blockAttacked=7
elseif x>170 and x<=180 and blocks[8]>0 then
blockAttacked=8
elseif x>250 and x<=260 and blocks[9]>0 then
blockAttacked=9
elseif x>260 and x<=270 and blocks[10]>0 then
blockAttacked=10
elseif x>270 and x<=280 and blocks[11]>0 then
blockAttacked=11
elseif x>280 and x<=290 and blocks[12]>0 then
blockAttacked=12
end
end
end


on.charIn("r")


function on.arrowLeft()
if player>0 then
player=player-10
end
end
function on.arrowRight()
if player<290 then
player=player+10
end
end
function on.tabKey()
if shotY<=0 then
shotY=195
shotX=player+13
end
end


function on.paint(gc)
if originalColors then
gc:setColorRGB(0,0,0)
gc:fillRect(0,0,platform.window:width(),platform.window:height())
end

if not originalColors then gc:setColorRGB(0,0,0)
else gc:setColorRGB(255,255,255) end
gc:setPen("thin","smooth")
gc:setFont("sansserif","r",8)
gc:drawString("Lua Alien Invaders - Par Loic Pujet",10,200,"top")

if game=="notfinished" then
if not originalColors then gc:setColorRGB(200,0,0)
else gc:setColorRGB(255,255,255) end
for i=1,21,1 do
if aliensY[i]~=0 then
gc:drawArc(aliensX[i]+4,aliensY[i]-9,10,10,0,360)
gc:fillArc(aliensX[i]-5,aliensY[i]-4,28,8,0,360)
end
end

if not originalColors then gc:setColorRGB(0,0,200)
else gc:setColorRGB(255,255,0) end
for i=1,21,1 do
if shotsY[i]<200 then
gc:fillRect(shotsX[i],shotsY[i],2,5)
end
end
if shotY>0 then
gc:fillRect(shotX,shotY,4,6)
end

if not originalColors then gc:setColorRGB(100,0,255)
else gc:setColorRGB(0,255,0) end
gc:fillRect(player,195,30,10)
gc:fillRect(player+13,191,4,4)
gc:setFont("sansserif","r",10)
gc:drawString("Vies:"..tostring(lives).." Score:"..tostring(score).." Niveau:"..tostring(level),0,0,"top")

if not originalColors then add=3
else add=0 end
for i=1,12,1 do
if blocks[i]>0 then
gc:fillRect(i*10+math.floor((i-1)/4)*70+20,180-blocks[i]*2,10,blocks[i]*2)
end
end
else
if not originalColors then gc:setColorRGB(0,0,0)
else gc:setColorRGB(255,255,255) end
gc:setFont("sansserif","b",15)
gc:drawString("Score : "..tostring(score),100,50, "top")
if not originalColors then gc:setColorRGB(0,0,255) end
gc:drawString("Appuyez sur R pour rejouer",50,150,"top")
end

timer.start(wait)
end


function on.timer()
timer.stop()

if game=="notfinished" then
if aliensDir=="right" then
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]+1
end
end
else
for i=1,21,1 do
if aliensY[i]>0 then
aliensX[i]=aliensX[i]-1
end
end
end

if aliensDir=="right" then
for i=1,21,1 do
if aliensX[i]>305 then
down="yes"
end
end
else
for i=1,21,1 do
if aliensX[i]<15 then
down="yes"
end
end
end

if down=="yes" then
down="no"
for i=1,21,1 do
if aliensY[i]>0 then
aliensY[i]=aliensY[i]+25
end
end
if aliensDir=="left" then
aliensDir="right"
else
aliensDir="left"
end
end

for i=1,21,1 do
if aliensY[i]>180 then
game="finished"
end

if shotsY[i]>=200 and aliensY[i]~=0 then
if math.random(1,100)==5 then
shotsY[i]=aliensY[i]+math.random(1,10)
shotsX[i]=aliensX[i]
end
else
shotsY[i]=shotsY[i]+3
end

blocktest(shotsX[i],shotsY[i])
if blockAttacked>0 then
shotsY[i]=201
blocks[blockAttacked]=blocks[blockAttacked]-1
end

if shotsY[i]<200 then
if shotsY[i]>195 and shotsX[i]>player and shotsX[i]<player+30 then
lives=lives-1
shotsY[i]=200
end
end

if shotY>0 and shotY>aliensY[i]-5 and shotY<aliensY[i]+5 and shotX>aliensX[i]-10 and shotX<aliensX[i]+21 then
aliensY[i]=0
aliensX[i]=100
shotY=0
score=score+1
end
end

blocktest(shotX,shotY)
if blockAttacked>0 then
shotY=-1
blocks[blockAttacked]=blocks[blockAttacked]-1
end

if shotY>=0 then
shotY=shotY-5
end

if lives<=0 then
game="finished"
end


wintest=0
for i=1,21,1 do
wintest=wintest+aliensY[i]
end

if wintest==0 then
if wait>0.01 then
wait=wait-0.005
end
level=level+1
aliensDir="right"
down="no"
for i=1,21,1 do
aliensX[i]=(i-1)%7*31+1
aliensY[i]=math.floor((i-1)/7)*25+10
shotsX[i]=aliensX[i]
shotsY[i]=200
end
end
end

platform.window:invalidate()
end
I think that my code is pretty awful, good luck when reading it :)
(I know, I should add comments)
Title: Re: [Lua] Space Invaders
Post by: Kjelddy on June 12, 2011, 07:42:25 am
it really looks nice ;D(http://www.omnimaga.org/Themes/default/images/gpbp_arrow_up.gif)

edit: on my CX with the different colours :) almost like the original


@below  when u press c non stop it looks like a disco :P
maybe I will make a video but I am not sure if I got enough time
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 13, 2011, 03:03:06 pm
Nice, someone with a CX should make a video ;D

Also guys if you use an emu or an actual CX, don't keep mashing the C key non stop O.O (seizure, much? :P)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 15, 2011, 02:19:10 pm
Space Invaders 0.8 is already in my calc and it's pretty great. However, I'd still like an English version and highscores :) I really like it though.

That's done !
Now the game language is the same as your TI-Nspire's language.
And for the high scores, now the game displays the high score when you loose the game. If you beat it, you have to save the document.

Thats the third "final version" of my game  :D
(I also edit the first post)
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 22, 2011, 06:54:46 am
Bug fixed ! If you went to the level 7, there was an error message.
For the ones who still care of my game, I attach it to this post. (And to the first post)
It's the fourth "final version" of my space invaders  :)
Title: Re: [Lua] Space Invaders
Post by: DJ Omnimaga on June 22, 2011, 03:11:36 pm
Cool to hear. :)

As for the game language, I assume it's in French and English, right? I wonder what happens if someone choose chinese or german as language? Does it default to English in the game?
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 23, 2011, 05:20:18 am
Yes, so the French becomes a bit useless, because a lot of French people (including me) have their calc in English.
And yes, English is the default language.
Title: Re: [Lua] Space Invaders
Post by: Levak on June 23, 2011, 10:06:30 am
because a lot of French people (including me) have their calc in English..

Wait wait wait .... what ??
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 23, 2011, 10:08:20 am
Er... I think so.
(I mean their calc language is English, not that they use their calc in English class :P )
Title: Re: [Lua] Space Invaders
Post by: Levak on June 23, 2011, 10:37:47 am
When you launch the OS the first time, you can choose your language. I'm sure most of French pupils select French language instead of English one.
Title: Re: [Lua] Space Invaders
Post by: Chockosta on June 29, 2011, 03:11:50 am
Little modification, quite useless...
When the var "highscore" doesn't exist, it is created. It can be useful if you delete this var (strange, but why not ?) or if you open the scratchpad (strange too...)

So you can download it, but if you already have the last version, it's useless.

PS : I also edited the first post.