Author Topic: [Lua] Space Invaders  (Read 29151 times)

0 Members and 1 Guest are viewing this topic.

Offline Kjelddy

  • LV3 Member (Next: 100)
  • ***
  • Posts: 80
  • Rating: +2/-1
    • View Profile
Re: [Lua] Space Invaders
« Reply #60 on: June 12, 2011, 05:15:49 am »
too bad for the sprites ...
but good for the release :)
KJ
in need of omnoms ? check this out :P
http://img.removedfromgame.com/imgs/0-omnom.png

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #61 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.
« Last Edit: June 15, 2011, 02:14:57 pm by Chockosta »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Lua] Space Invaders
« Reply #62 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 ?

;)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #63 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)

Offline Kjelddy

  • LV3 Member (Next: 100)
  • ***
  • Posts: 80
  • Rating: +2/-1
    • View Profile
Re: [Lua] Space Invaders
« Reply #64 on: June 12, 2011, 07:42:25 am »
it really looks nice ;D

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
« Last Edit: June 13, 2011, 04:34:03 pm by Kjelddy »
KJ
in need of omnoms ? check this out :P
http://img.removedfromgame.com/imgs/0-omnom.png

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Space Invaders
« Reply #65 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)

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #66 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)
« Last Edit: June 22, 2011, 06:52:04 am by Chockosta »

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #67 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  :)
« Last Edit: June 29, 2011, 03:08:54 am by Chockosta »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Space Invaders
« Reply #68 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?

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #69 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.

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: [Lua] Space Invaders
« Reply #70 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 ??
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #71 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 )
« Last Edit: June 23, 2011, 10:09:14 am by Chockosta »

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: [Lua] Space Invaders
« Reply #72 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.
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Space Invaders
« Reply #73 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.
« Last Edit: June 29, 2011, 03:13:41 am by Chockosta »