forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LUA Lights out

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Debug



Joined: 06 Oct 2005
Posts: 16

PostPosted: Sun Jun 25, 2006 1:01 pm    Post subject: LUA Lights out Reply with quote

I had this almost done in C++ when my hard drive crashed, so here's a quick lua version that I wrote in about 20 minues. If anyone is interested I'll continue the project, if not, then who knows. Enjoy :)


Code:
--LUA Lights out by Debug
w = Color.new(255,255,255)
bl = Color.new(0,0,100)
bk = Color.new(0,0,0)
yl = Color.new(255,255,100)
buffer = Image.createEmpty(480,272)
grid = {}

for y=0,6 do
   grid[y] = {}
   for x=0,6 do
      grid[y][x]=math.random(0,1)
   end
end

x = 3
y = 3


function DrawGrid()
   for b=1,5 do
      for a=1,5 do
         if grid[b][a] == 1 then
                buffer:fillRect(a*30,b*30,28,28,yl)
            else
               buffer:fillRect(a*30,b*30,28,28,bl)
            end
      end
   end
end

function DrawCursor()
   buffer:fillRect(x*30+8,y*30+8,12,12,bk)
   buffer:fillRect(x*30+10,y*30+10,8,8,w)
end

function Check()
c=0
   for a=1,5 do
      for b=1,5 do
         c=(c+grid[a][b])
      end
   end
   if c<1 then
      
      while true do
         buffer:clear(bk)
         buffer:print(200,120,"You Win!!!!!!",yl)
         screen:blit(0,0,buffer)
         screen.waitVblankStart()
         screen.flip()
      end
   end
end

function Click()
   grid[y][x]=math.abs(grid[y][x]-1)
   grid[y-1][x]=math.abs(grid[y-1][x]-1)
   grid[y+1][x]=math.abs(grid[y+1][x]-1)
   grid[y][x-1]=math.abs(grid[y][x-1]-1)
   grid[y][x+1]=math.abs(grid[y][x+1]-1)

   moves=moves+1
end
moves=0
while true do
   pad = Controls.read()
   if pad~=temp then
      if pad:up() then y=y-1 end
      if pad:down() then y=y+1 end
      if pad:left() then x=x-1 end
      if pad:right() then x=x+1 end
      if x<1 then x=1 end
      if x>5 then x=5 end
      if y<1 then y=1 end
      if y>5 then y=5 end
      if pad:cross() then Click() end
      Check()   
      temp=pad
   end
   buffer:clear(bk)
   buffer:print(210,15,"Current Position: ("..x..","..y..")", w)
   buffer:print(210,25,"Moves: "..moves,w)
   DrawGrid()
   DrawCursor()
   screen:blit(0,0,buffer)
   screen.waitVblankStart()
   screen.flip()
end

_________________
Code:

catch(IOException e){
//oh crap
}
Back to top
View user's profile Send private message AIM Address
flattspott



Joined: 22 Aug 2005
Posts: 22

PostPosted: Mon Jul 03, 2006 2:06 am    Post subject: Reply with quote

I already did this a while ago.

http://www.maxconsole.net/?mode=news&newsid=5031
Back to top
View user's profile Send private message
Debug



Joined: 06 Oct 2005
Posts: 16

PostPosted: Mon Jul 03, 2006 5:20 am    Post subject: Reply with quote

oh. well, thanks anyway.
_________________
Code:

catch(IOException e){
//oh crap
}
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group