Forum    News    Downloads    Saved Games


Help me?

<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Thu Jul 17, 2008 11:44 am

Help me?

Are there any Lua coders around? Help me out with this game.

I'm making a port of asteroids, and the code I'm using for collision won't define the ship and the Ammo at the same time :(

  Code:
green=Color.new(0,255,0)
white = Color.new(255,255,255)

pd = Image.load("ShipD.png")
pr = Image.load("ShipR.png")
pl = Image.load("ShipL.png")
player = Image.load("Ship.png")
pu = Image.load("Ship.png")

block = Image.createEmpty(32,32)
block:clear(green)

shot = Image.load("sht.png")

Player = { x = 30, y = 100 }
Sht = { x = 55, y = 115}

shotHeight = 5
shotWidth = 5

playerHeight = 32
playerWidth = 32

Block = {}
Block[1] = { x = 100, y = 80, height = block:height(), width = block:width() }
Block[2] = { x = 300, y = 30, height = block:height(), width = block:width() }
Block[3] = { x = 200, y = 58, height = block:height(), width = block:width() }

function movePlayer()

pad = Controls.read()

if pad:left() then
player = pl
Player.x = Player.x - 3
Sht.x = Sht.x - 3
end

if pad:right() then
player = pr
Player.x = Player.x + 3
Sht.x = Sht.x + 3
end

if pad:up() then
player = pu
Player.y = Player.y - 3
Sht.y = Sht.y - 3
end

if pad:down() then
player = pd
Player.y = Player.y + 3
Sht.y = Sht.y + 3
end
end

pad = Controls.read()

if pad:cross() then
Sht.x = oldx
Sht.y = oldy
end

if pad:cross() and player == pu then

while oldy > 0 do
shtoldy = shtoldy + 3
end
end

function collisionCheck(object)
if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then
Player.x = oldx
Player.y = oldy
end
end

function collisionCheck(object)

if (Sht.x + shotWidth > object.x) and (Sht.x < object.x + object.width) and (Sht.y + shotHeight > object.y) and (Sht.y < object.y + object.height) then
Sht.x = shtoldx
Sht.y = shtoldy
end
end

while true do

oldx = Player.x
oldy = Player.y
screen:clear()

shtoldx = Sht.x
shtoldy = Sht.y
screen:clear()

movePlayer()

collisionCheck(Block[1])
collisionCheck(Block[2])
collisionCheck(Block[3])


screen:blit(Sht.x,Sht.y,shot)
screen:blit(Player.x,Player.y,player)


for a = 1,3 do
screen:blit(Block[a].x,Block[a].y,block)
end

screen.waitVblankStart()
screen.flip()
end


Whats wrong with my code?

EDIT: DL the full pack here.
5.00M33-6
Image
Image Veemon
Image
Image
<<

crait

User avatar

Brewology Administrator
Brewology Administrator

Posts: 6488

Joined: August 11 2006

Location: Narnia!

Thanks given: 195 times

Thanks received: 51 times

Post Thu Jul 17, 2008 12:02 pm

Okay, I think this may be the problem....
You create the function collisionCheck(object) twice.
Whenever you do that, you overwrite the previous. (I'm a little rusty on LUA, but I'm pretty sure I remember that correctly...)
You should probably change one to collisionPlayer and the other to CollisionSht

Hope this helps you out some. ;)
<<

BKFraiders7

User avatar

Brewology Administrator
Brewology Administrator

Posts: 4248

Joined: January 23 2010

Location: On COD:BO2 iPhone User:5 Mac User: Macbook Pro Mtn Lion

Thanks given: 13 times

Thanks received: 31 times

Post Thu Jul 17, 2008 2:05 pm

seanpaul can help u on this im sure.
Watch me stream on MIXER or follow on Youtube at ChA0TiCxDR3AMS

Image Image
<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Fri Jul 18, 2008 5:13 am

Got it fixed.

Here are the new lines:
  Code:
function collisionCheck(object)
if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then
Player.x = oldx
Player.y = oldy

if (Sht.x + shotWidth > object.x) and (Sht.x < object.x + object.width) and (Sht.y + shotHeight > object.y) and (Sht.y < object.y + object.height) then
Sht.x = shtoldx
Sht.y = shtoldy
end
end
end
5.00M33-6
Image
Image Veemon
Image
Image
<<

crait

User avatar

Brewology Administrator
Brewology Administrator

Posts: 6488

Joined: August 11 2006

Location: Narnia!

Thanks given: 195 times

Thanks received: 51 times

Post Fri Jul 18, 2008 8:03 am

roxfox64 wrote:Got it fixed.

Here are the new lines:
  Code:
function collisionCheck(object)
if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then
Player.x = oldx
Player.y = oldy

if (Sht.x + shotWidth > object.x) and (Sht.x < object.x + object.width) and (Sht.y + shotHeight > object.y) and (Sht.y < object.y + object.height) then
Sht.x = shtoldx
Sht.y = shtoldy
end
end
end


Nice, you made them into one instead of keeping them seperate functions.
Glad I could help! :D
<<

roxfox64

User avatar

Brew Guru
Brew Guru

Posts: 2287

Joined: June 12 2007

Location: Smyrna, GA Current Status: Its true... I am a fur.

Thanks given: 0

Thanks received: 2 times

Post Fri Jul 18, 2008 9:09 am

Yeah crait. Thanks!
5.00M33-6
Image
Image Veemon
Image
Image

Return to PSP Help

Who is online

Users browsing this forum: Google [Bot] and 87 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for blacklist.org.