LUA Lights out

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Debug
Posts: 16
Joined: Thu Oct 06, 2005 4:16 am

LUA Lights out

Post by Debug »

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: Select all

--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&#58;clear&#40;bk&#41;
			buffer&#58;print&#40;200,120,"You Win!!!!!!",yl&#41;
			screen&#58;blit&#40;0,0,buffer&#41;
			screen.waitVblankStart&#40;&#41;
			screen.flip&#40;&#41;
		end
	end
end

function Click&#40;&#41;
	grid&#91;y&#93;&#91;x&#93;=math.abs&#40;grid&#91;y&#93;&#91;x&#93;-1&#41;
	grid&#91;y-1&#93;&#91;x&#93;=math.abs&#40;grid&#91;y-1&#93;&#91;x&#93;-1&#41;
	grid&#91;y+1&#93;&#91;x&#93;=math.abs&#40;grid&#91;y+1&#93;&#91;x&#93;-1&#41;
	grid&#91;y&#93;&#91;x-1&#93;=math.abs&#40;grid&#91;y&#93;&#91;x-1&#93;-1&#41;
	grid&#91;y&#93;&#91;x+1&#93;=math.abs&#40;grid&#91;y&#93;&#91;x+1&#93;-1&#41;

	moves=moves+1
end
moves=0
while true do
	pad = Controls.read&#40;&#41;
	if pad~=temp then
		if pad&#58;up&#40;&#41; then y=y-1 end
		if pad&#58;down&#40;&#41; then y=y+1 end
		if pad&#58;left&#40;&#41; then x=x-1 end
		if pad&#58;right&#40;&#41; 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&#58;cross&#40;&#41; then Click&#40;&#41; end
		Check&#40;&#41;	
		temp=pad
	end
	buffer&#58;clear&#40;bk&#41;
	buffer&#58;print&#40;210,15,"Current Position&#58; &#40;"..x..","..y.."&#41;", w&#41;
	buffer&#58;print&#40;210,25,"Moves&#58; "..moves,w&#41;
	DrawGrid&#40;&#41;
	DrawCursor&#40;&#41;
	screen&#58;blit&#40;0,0,buffer&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
end

Code: Select all

catch&#40;IOException e&#41;&#123;
//oh crap
&#125;
flattspott
Posts: 22
Joined: Mon Aug 22, 2005 4:06 am

Post by flattspott »

I already did this a while ago.

http://www.maxconsole.net/?mode=news&newsid=5031
Debug
Posts: 16
Joined: Thu Oct 06, 2005 4:16 am

Post by Debug »

oh. well, thanks anyway.

Code: Select all

catch&#40;IOException e&#41;&#123;
//oh crap
&#125;
Post Reply