Lua Help

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

Moderators: Shine, Insert_witty_name

Post Reply
Spirit
Posts: 1
Joined: Mon Apr 03, 2006 8:15 am

Lua Help

Post by Spirit »

Hello, I'm new to this forum, so sorry if this is the wrong section, or something along the line.
I have a Lua script(http://home.comcast.net/~nickpaoletti/lj2.lua) thats nearing completion, but has a couple bugs that need a little fix-up.
The first bug is that when the player chooses "scissors" the enemy may not choose something, but still get hit and lose health. His graphic does not show either when he is hit. (Video HERE
My second bug is that when the player is not standing, it seems he can still make a choice. (I'll upload a video soon if anyone would like to see.)

Anyway, thanks for any help :)... oh and take the IMG folder from this archive if you want to test the game. The script is outdated, so that dosen't matter.
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

This could be further simplified, but...

Code: Select all

math.randomseed(os.time())
math.random();math.random();math.random()
black = Color.new(0, 0, 0)
title = Image.load("img/title.png")
vs = Image.load("img/vs.png")
jimmystand = Image.load("img/stand.png")
jimmyrock = Image.load("img/rock.png")
jimmypaper = Image.load("img/paper.png")
jimmyscissors = Image.load("img/scissors.png")
jimmyhit = Image.load("img/hit.png")
enemystand = Image.load("img/estand.png")
enemyrock = Image.load("img/erock.png")
enemypaper = Image.load("img/epaper.png")
enemyscissors = Image.load("img/escissors.png")
enemyhit = Image.load("img/ehit.png")

enemyrps = 0
jimmyhealth = 24
enemyhealth = 24
jimmypos = 0
enemypos = 0

showTitle = true
varJimmy = 0
varEnemy = 0

timer = Timer.new()

while true do
	screen:clear()
	pad = Controls.read()

	if showTitle then
		screen:blit(0, 0, title)
		if pad:start() and pad ~= oldpad then showTitle = false end
	else
		screen:blit(0, 0, vs)

		screen:print(2, 256, "Jimmy 's HP: " .. jimmyhealth, black)
		screen:print(365, 256, "Enemy's HP: " .. enemyhealth, black)
		screen:print(180, 104, "Jimmy " .. jimmypos, black)
		screen:print(160, 154, "The enemy " .. enemypos, black)

		if pad:up() and pad ~= oldpad then
			if varJimmy == 0 then 
			varJimmy = 1
			varEnemy = math.random(1,3)
			timer:start()
			end
		end
		
		if pad:right() and pad ~= oldpad then
			if varJimmy == 0 then 
			varJimmy = 2
			varEnemy = math.random(1,3)
			timer:start()
			end
		end
		
		if pad:down() and pad ~= oldpad then
			if varJimmy == 0 then 
			varJimmy = 3
			varEnemy = math.random(1,3)
			timer:start()
			end
		end

		if timer:time() > 2005 then
			varJimmy = 0
			varEnemy = 0
			timer:stop()
			timer:reset()
		end

			if varJimmy == 1 and varEnemy == 2 then
				varEnemy = 4
				enemyhealth = enemyhealth - 4
			elseif varJimmy == 1 and varEnemy == 3 then 
				varJimmy = 4
				jimmyhealth = jimmyhealth - 4
			elseif varJimmy == 2 and varEnemy == 1 then 
				varJimmy = 4
				jimmyhealth = jimmyhealth - 4
			elseif varJimmy == 2 and varEnemy == 3 then 
				varEnemy = 4
				enemyhealth = enemyhealth - 4
			elseif varJimmy == 3 and varEnemy == 1 then 
				varEnemy = 4
				enemyhealth = enemyhealth - 4
			elseif varJimmy == 3 and varEnemy == 2 then 
				varJimmy = 4
				jimmyhealth = jimmyhealth - 4
			end


			if varJimmy == 1 then jimmypos = "chose PAPER"
				screen:blit(0, 0, jimmypaper)
			elseif varJimmy == 2 then jimmypos = "chose ROCK"
				screen:blit(0, 0, jimmyrock)
			elseif varJimmy == 3 then jimmypos = "chose SCISSORS"
				screen:blit(0, 0, jimmyscissors)
			elseif varJimmy == 4 then jimmypos = "got HIT"
				screen:blit(0, 0, jimmyhit)
			else
				jimmypos = "is STANDING"
				screen:blit(0, 0, jimmystand)
			end

			if varEnemy == 1 then enemypos = "chose PAPER"
				screen:blit(346, 0, enemypaper)
			elseif varEnemy == 2 then enemypos = "chose ROCK"
				screen:blit(346, 0, enemyrock)
			elseif varEnemy == 3 then enemypos = "chose SCISSORS"
				screen:blit(346, 0, enemyscissors)
			elseif varEnemy == 4 then enemypos = "got HIT"
				screen:blit(346, 0, enemyhit)
			else
				enemypos = "is STANDING"
				screen:blit(346, 0, enemystand)
			end
		end

	oldpad = pad
	screen.flip()
	screen.waitVblankStart()
end
Sorry for the long post. ^^;
Post Reply