Lua Player for PSP

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

Moderators: Shine, Insert_witty_name

Post Reply
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Thanks shine, I'll update my game at lunch time at work and add some sounds to it then up a new version.

G
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

http://haggar.pocketheaven.com/preview.zip <- Updated for the new API.


Don't post news about this updated Dr. Mario though (if any psp news site ppl are watching) ;)
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

I have it all updated with the new API. Adding sounds now. Is there any way to get a wav file to loop?
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

nice work shine, are you still chugging away on the program so we can run lua scripts on the computer to test instead of uploading it to my psp everytime?
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

SnowSurfer wrote:nice work shine, are you still chugging away on the program so we can run lua scripts on the computer to test instead of uploading it to my psp everytime?
That would be nice.

And um... would be nice with music/sound pause.
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

VgSlag wrote:I have it all updated with the new API. Adding sounds now. Is there any way to get a wav file to loop?
I guess you could do this:

Code: Select all

if not mysound&#58;playing&#40;&#41; then
  mysound&#58;play&#40;&#41;
end
hm... or maybe not
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

I didn't see that listed in the functions.txt.. only said it was available for Music and voice.

Will give it a shot incase they missed it out.

EDIT: Sorry, I think I was misreading the file.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:I have it all updated with the new API. Adding sounds now. Is there any way to get a wav file to loop?
Hmm... Mikmod has the ability, I'll have to write a wrapper. Gimme a while.

If you want to do it with the current API, it's possible with a loop:

Code: Select all

sound = Sound.load&#40;"whatever.wav"&#41;
voice =  sound.play&#40;&#41;
while true do
  game loop...
  if not voice&#58;playing&#40;&#41; then
    voice = sound&#58;play&#40;&#41;
  end
end
Note the distinction between the data of a soundfile and a currently playing voice (sort of an "instance" of a sound)


Can't do music pausing, sorry. It's a bug in mikmod. [Edit: Or maybe.... If I... Hmm... I'll look into it.]

Sound pausing, I'll look into it.
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

nevyn wrote:
VgSlag wrote:I have it all updated with the new API. Adding sounds now. Is there any way to get a wav file to loop?
Hmm... Mikmod has the ability, I'll have to write a wrapper. Gimme a while.

If you want to do it with the current API, it's possible with a loop:

Code: Select all

sound = Sound.load&#40;"whatever.wav"&#41;
voice =  sound.play&#40;&#41;
while true do
  game loop...
  if not voice&#58;playing&#40;&#41; then
    voice = sound&#58;play&#40;&#41;
  end
end
Note the distinction between the data of a soundfile and a currently playing voice (sort of an "instance" of a sound)


Can't do music pausing, sorry. It's a bug in mikmod. [Edit: Or maybe.... If I... Hmm... I'll look into it.]

Sound pausing, I'll look into it.

They added mikmod to psp media center I think, and you can pause the music there... Maybe you could take a look at the media center code or something? if they've released the source that is...
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

nevyn wrote:

Code: Select all

sound = Sound.load&#40;"whatever.wav"&#41;
voice =  sound.play&#40;&#41;
while true do
  game loop...
  if not voice&#58;playing&#40;&#41; then
    voice = sound&#58;play&#40;&#41;
  end
end
This is not a good idea, because if you want to play "looped" sounds, you will hear a gap between two plays. If Mikmod supports it, this should be used and called from Lua.
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

I've got it working with the above code but you have your true and false mixed up that the function returns.

voice:playing() returns true when it's not playing, and false when it is or at least it seems that way.

With:

Code: Select all

	-- Has the sound finished?
	if sound_torch_playing&#58;playing&#40;&#41; == false then

		-- Yes, restart it
		sound_torch_playing = sound_torch&#58;play&#40;&#41;
	end
The above causes the sound to keep starting over itself where as:

Code: Select all

	-- Has the sound finished?
	if sound_torch_playing&#58;playing&#40;&#41; == true then

		-- Yes, restart it
		sound_torch_playing = sound_torch&#58;play&#40;&#41;
	end
The above makes it work.

G
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

I agree with Shine, my solution isn't exactly beautiful. There's no actual need to resort to these hacks anyway, as the release version of 0.7 WILL contain code to properly loop sounds.

Edit: Yes, I saw the bug with Sound:playing(), it'll be fixed... (forgot to negate a result)

Edit again: I managed to ugly-hack past the mikmod bug to allow pausing through Music.pause() and Music.resume(). Next up: pausing and looping of samples...
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Nicwe one Nev... wasn't hassling, just saying. I realise it's a nightmare when people start mentioning bugs with a beta release :)

Cheers for your work Nev and Shine.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:Nicwe one Nev... wasn't hassling, just saying. I realise it's a nightmare when people start mentioning bugs with a beta release :)

Cheers for your work Nev and Shine.
That's exactly what beta releases are for, so no worries :P Thanks for your feedback, it's very helpful :) If any more bugs crop up, please tell!
indianajonesilm
Posts: 15
Joined: Tue Feb 08, 2005 6:36 pm

Post by indianajonesilm »

Hello all! I'm attempting to make an air hockey game, but I've noticed a small problem with my paddles. Sometimes they appear corrupted when I start the game.
Image
It happens about once every four times I start the game. I was wondering if it's something I'm doing wrong. Any advice would be appreciated. Thank you.

Here is a normal screen shot:
Image
Here is the script and stuff:
http://webpages.charter.net/aldanafx/st ... hockey.zip

P.S.
Thank you Shine and all who are contributing to Lua Player, I'm having so much fun learning to program. Thanks again.
emumaniac
Posts: 79
Joined: Sun May 08, 2005 12:22 am

Post by emumaniac »

im a major air hockey fan, cant wait for a fully playable version :)
the-dan
Posts: 7
Joined: Thu Jul 21, 2005 8:56 am
Contact:

Post by the-dan »

hah nice indianajoneslim. for some reason i noticed that it locked up for a second with the controls and wouldnt move briefly, maybe a sound locking issue who knows.. but speaking of sound i like it, especially the yahoo! all this lua stuff makes me want to get back into it hehe. keep it up man =D also, would there be hard slap shots that would knock the disc/puck off the table? that could be some interesting play lol

- Dan
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Updated luaplayer at the repository. 0.7b7 adds music and sample looping, and music pausing and resuming. I tried sample pausing, but the resuming would crash the psp. Without a debugger, I don't feel like giving that one another try...

(It's hard to find time over to write code after my girlfriend came over for an extended visit :P I plan to fix Lowser tomorrow though, and add usb mode to Lowser... I have a great idea for a new Lowser interface, having a Dasher-like UI using the analog stick. Wish I had time to implement it...)
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Are there any way to rotate text 90 degrees right or left? I'm thinking about doing some vertical games and stuff.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

MikeHaggar wrote:Are there any way to rotate text 90 degrees right or left? I'm thinking about doing some vertical games and stuff.
Nope, not at the moment, sorry... I'd like to add rotozooming, but graphics is not my department... *makes a hinting gesture towards Shine* :P
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

MikeHaggar wrote:Are there any way to rotate text 90 degrees right or left? I'm thinking about doing some vertical games and stuff.
Thanks for this idea, there were some bugs which prevented you from doing this in Lua, so a new version can be downloaded, where these bugs are fixed and the changes from Nevyn are included: luaplayer-0.7b7.zip

Now it is possible to write your rotate function in Lua without problems, see the rotate.lua in the samples folder.

Image
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

indianajonesilm wrote:Hello all! I'm attempting to make an air hockey game.
I sorta dislike rigid movement, so I couldn't help but to add acceleration to your game :P Hope you like it :)
(Lowser-adapted it while at it, too)
http://ncoder.nevyn.nu/psp/pspairhockey.zip
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Some more Lua for fun

Code: Select all

-- change this to select the view area
depth = 32
x0 = -0.65
y0 = -0.7
x1 = -0.5
y1 = -0.6

-- some nice palette
palette = &#123;&#125;
for i=0,depth do
	b = math.floor&#40;i / depth * 1024&#41;
	if b > 255 then
		b = 255
	end
	g = math.floor&#40;&#40;i - depth / 3&#41; / depth * 1024&#41;
	if g > 255 then
		g = 255
	end
	if g < 0 then
		g = 0
	end
	r = math.floor&#40;&#40;i - depth / 3 * 2&#41; / depth * 1024&#41;
	if r > 255 then
		r = 255
	end
	if r < 0 then
		r = 0
	end
	palette&#91;i&#93; = Color.new&#40;r, g, b&#41;
end
palette&#91;depth-1&#93; = Color.new&#40;0, 0, 0&#41;

-- draw mandelbrot fractal
w = 480
h = 272
image = Image.createEmpty&#40;w, h&#41;
dx = x1 - x0
dy = y1 - y0
for y=0,h-1 do
	for x=0,w-1 do
		r = 0; n = 0; b = x / w * dx + x0; e = y / h * dy + y0; i = 0
		while i < depth-1 and r * r < 4 do
			d = r; r = r * r - n * n + b; n = 2 * d * n + e; i = i + 1
		end
		image&#58;pixel&#40;x, y, palette&#91;i&#93;&#41;
	end
	screen&#58;blit&#40;0, 0, image&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
end

screen&#58;save&#40;"screenshot.tga"&#41;

while true do
	screen.waitVblankStart&#40;&#41;
end
This needs some 2 minutes to draw the picture, because it is not optimized, but it is worth the time:

Image
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Shine wrote: Now it is possible to write your rotate function in Lua without problems, see the rotate.lua in the samples folder.
Big thanks!
jambox
Posts: 3
Joined: Thu Aug 11, 2005 6:24 am

Post by jambox »

edit: oops, double post
Last edited by jambox on Thu Aug 11, 2005 6:39 am, edited 1 time in total.
jambox
Posts: 3
Joined: Thu Aug 11, 2005 6:24 am

Post by jambox »

nevyn wrote: Updated luaplayer at the repository. 0.7b7 ... I plan to fix Lowser tomorrow though, and add usb mode to Lowser...
I tried the included 1.5 eboots and, although I'm not sure if I set it up right, was unable to load the Lowser script. Is that normal? The error is: attempt to call global 'getColorNumber' (a nil value).
I wasn't sure if that's expected with this version or not. (This is my first time to try Lua Player.)
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

jambox wrote:
nevyn wrote: Updated luaplayer at the repository. 0.7b7 ... I plan to fix Lowser tomorrow though, and add usb mode to Lowser...
I tried the included 1.5 eboots and, although I'm not sure if I set it up right, was unable to load the Lowser script. Is that normal? The error is: attempt to call global 'getColorNumber' (a nil value).
I wasn't sure if that's expected with this version or not. (This is my first time to try Lua Player.)
This is entirely expected. The 0.7b7 is, as you can tell by the 'b', a beta. Lowser isn't updated to work with the new version yet. I recommend that, if you just want to try out LuaPlayer, you download version 0.6 from www.frank-buss.de/luaplayer/ . The non-beta version of 0.7 will be out in a few days.
jambox
Posts: 3
Joined: Thu Aug 11, 2005 6:24 am

Post by jambox »

nevyn wrote:
jambox wrote:
nevyn wrote: Updated luaplayer at the repository. 0.7b7 ... I plan to fix Lowser tomorrow though, and add usb mode to Lowser...
I tried the included 1.5 eboots and, although I'm not sure if I set it up right, was unable to load the Lowser script. Is that normal? The error is: attempt to call global 'getColorNumber' (a nil value).
I wasn't sure if that's expected with this version or not. (This is my first time to try Lua Player.)
This is entirely expected. The 0.7b7 is, as you can tell by the 'b', a beta. Lowser isn't updated to work with the new version yet. I recommend that, if you just want to try out LuaPlayer, you download version 0.6 from www.frank-buss.de/luaplayer/ . The non-beta version of 0.7 will be out in a few days.
Great! Thanks for the quick response. I'm looking forward to getting back into programming (even if it is the easy route :)..
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

I've updated Lowser to work with the new API. Activate USB mode by pressing L inside Lowser.

Everything seems to be in order now... Should we release this as the real 0.7?

btw shine, love that song you have in Snake! Jeoren Tel rocks :)
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

For some reason there's a typo in graphics.c line 22 of the latest commit. It's trivial to fix, but annoying.
Post Reply