Now sound isn't working...

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

Moderators: Shine, Insert_witty_name

Post Reply
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Now sound isn't working...

Post by DiabloTerrorGF »

Code: Select all

--[[DiabloTerrorGF]]
--System.usbDiskModeActivate()

--load graphics
yourShipImage = Image.load("yourShip.png")
enemyShipImage = Image.load("enemy1.png")
yourBulletImage = Image.load("bullet.png")
enemyBulletImage = Image.load("enemyBullet.png")
--explosionImage1 = Image.load("explosion1.png")
--explosionImage2 = Image.load("explosion2.png")
--explosionImage3 = Image.load("explosion3.png")
background = Image.load("background.png")
--gameOver = Image.load("gameOver.png")

--load sounds
bulletFire = Sound.load("PHOTON.wav")

--set bounds
YSBoundX = 0
YSBoundY = 0
YSBoundMX = 18
YSBoundMY = 11
YSBoundCMX = 0
YSBoundCMY = 0

ES1BoundX = 0
ES1BoundY = 0
ES1BoundCMX = 0
ES1BoundCMY = 0
ESBoundMX = 17
ESBoundMY = 21

--set globals
score = 0
GameRun = 0
loopNum = 0
bulletNotFired = true

function testFireSound()
if GameRun==1 then
if Controls.read():cross() then
if bulletNotFired==true then
bulletFire:play()
bulletNotFired=false
end
end
end
end

function moveMyShip()
if GameRun==1 then
if Controls.read():right() then
YSBoundX = YSBoundX+10
end
if Controls.read():left() then
YSBoundX = YSBoundX-10
end
if Controls.read():up() then
YSBoundY = YSBoundY-10
end
if Controls.read():down() then
YSBoundY = YSBoundY+10
end
end
end

GameRun = 1
if GameRun==1 then
while not Controls.read():start() do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen:blit(YSBoundX, YSBoundY, yourShipImage)
testFireSound()
moveMyShip()
screen.flip()
screen.waitVblankStart()
bulletNotFire=true
end
end



--System.usbDiskModeDeactivate()
Moving seems laggy and slow on the psp, any ideas?
Last edited by DiabloTerrorGF on Tue Aug 23, 2005 1:16 pm, edited 1 time in total.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Controls.read() needs some time. Save the value returned from this function and call the test functions on the return value (e.g. pad=Controls.read(); if pad:right() ... if pad:top() ...)
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

rawr, that helped, thanks.
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

My sound only seems to play once now... what did I do?

Code: Select all

--[[DiabloTerrorGF]]
System.usbDiskModeActivate()

--load graphics
yourShipImage = Image.load("yourShip.png")
enemyShipImage = Image.load("enemy1.png")
yourBulletImage = Image.load("bullet.png")
enemyBulletImage = Image.load("enemyBullet.png")
--explosionImage1 = Image.load("explosion1.png")
--explosionImage2 = Image.load("explosion2.png")
--explosionImage3 = Image.load("explosion3.png")
background = Image.load("background.png")
--gameOver = Image.load("gameOver.png")

--load sounds
bulletFire = Sound.load("PHOTON.wav")

--set bounds
YSBoundX = 0
YSBoundY = 0
YSBoundMX = 18
YSBoundMY = 11
YSBoundCMX = 0
YSBoundCMY = 0

ES1BoundX = 0
--[[ES2BoundX = 0
ES3BoundX = 0
ES4BoundX = 0
ES5BoundX = 0
ES6BoundX = 0
ES7BoundX = 0
ES8BoundX = 0
ES9BoundX = 0
ES10BoundX = 0
ES11BoundX = 0
ES12BoundX = 0]]
ES1BoundY = 0
--[[ES2BoundY = 0
ES3BoundY = 0
ES4BoundY = 0
ES5BoundY = 0
ES6BoundY = 0
ES7BoundY = 0
ES8BoundY = 0
ES9BoundY = 0
ES10BoundY = 0
ES11BoundY = 0
ES12BoundY = 0]]
ES1BoundCMX = 0
--[[ES2BoundCMX = 0
ES3BoundCMX = 0
ES4BoundCMX = 0
ES5BoundCMX = 0
ES6BoundCMX = 0
ES7BoundCMX = 0
ES8BoundCMX = 0
ES9BoundCMX = 0
ES10BoundCMX = 0
ES11BoundCMX = 0
ES12BoundCMX = 0]]
ES1BoundCMY = 0
--[[ES2BoundCMY = 0
ES3BoundCMY = 0
ES4BoundCMY = 0
ES5BoundCMY = 0
ES6BoundCMY = 0
ES7BoundCMY = 0
ES8BoundCMY = 0
ES9BoundCMY = 0
ES10BoundCMY = 0
ES11BoundCMY = 0
ES12BoundCMY = 0]]
ESBoundMX = 17
ESBoundMY = 21

--set globals
score = 0
GameRun = 0
loopNum = 0
bulletNotFired = true
pad = 0


function moveMyShip()
if GameRun==1 then
pad=Controls.read()
if pad:right() then
YSBoundX = YSBoundX+10
end
if pad:left() then
YSBoundX = YSBoundX-10
end
if pad:up() then
YSBoundY = YSBoundY-10
end
if pad:down() then
YSBoundY = YSBoundY+10
end
if pad:cross() then
if bulletNotFired then
  bulletFire:play()
  bulletNotFired=false
 end
end
if pad:start() then
loopNum = 0
end
end
end

GameRun = 1
loopNum = 1
if GameRun==1 then
while loopNum==1 do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen:blit(YSBoundX, YSBoundY, yourShipImage)
bulletNotFire=true
moveMyShip()
screen.flip()
screen.waitVblankStart()
end
end

System.usbDiskModeDeactivate()
dofile("index.lua")
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

(solved this with gf over aim)

Just a general advice, one that Shine also recommends often: If you have weird problems with your code, look through it the way it would be interpreted, follow the thread of execution. In the above example, one would see that the if statement checks for a certain boolean. Following the thread of execution through the main loop, one would see that that boolean is never reset to true, because of a spelling mistake. (doing a search through the document for the offending variable would work too. This is a good idea in Lua, as it's not an error to set a previously undeclared variable (that is, a misspelled one) to a value.)
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

Yeah, thanks a lot. I'm now setting up Eclipse for my own LUA IDE that will prevent this >_<
Post Reply