Lua Player for PSP
Moderators: Shine, Insert_witty_name
For successful debugging imperative programs (if you would like to write it in Prolog, it would be more correct like you've done it) you have to simulate the program flow in your brain or on paper. This is what your program does:F34R wrote:Now this doesnt move the smiley at all.
1. usb active, image loading
2. blit background to offscreen
3. set start position
4. check pad and update position
5. goto 4
6. blit smiley to offscreen and flip visible screen and offscreen
7. exit, if start was pressed
8. goto 2
Perhaps now you can correct your program.
Yes, this is possible. There was a discussion on #pspdev on freenode and ooPo suggested to use libart. It has some nice vector operations, and could be built on top of the current graphics.c. Then you can use the old API, but if you want something more, which may be slower, you can use the libart functions, too.Nils wrote:Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
F34R, add a fillrect with black color in the main while loop, in order to erase previous smiley
Shine > seems interesting :)
" Libart has full support for RGB and RGBA image operations, including rotation, scaling, skewing, and alpha compositing."
Yay !
Shine > seems interesting :)
" Libart has full support for RGB and RGBA image operations, including rotation, scaling, skewing, and alpha compositing."
Yay !
Puzzle Bobble - The arcade port!
You don't need this. There are two reasons against it: If you want to clear the screen, call the clear function, it is faster. And in step 2 of my program flow explanation the background is blitted without alpha, so assuming the background image is 480x272, the whole display is already reseted to the background pixels.Nils wrote:F34R, add a fillrect with black color in the main while loop, in order to erase previous smiley
Ok, now we only need someone who ports this to PSP and integrates it in Lua Player :-)Nils wrote: Shine > seems interesting :)
" Libart has full support for RGB and RGBA image operations, including rotation, scaling, skewing, and alpha compositing."
screen:clear() or myemptygraphic:clear() doesnt work for me; nobody uses that, not even you in snake but at newgame ?
Puzzle Bobble - The arcade port!
Ok Shine, thanks for that info. I now have the following flow :Shine wrote:For successful debugging imperative programs (if you would like to write it in Prolog, it would be more correct like you've done it) you have to simulate the program flow in your brain or on paper. This is what your program does:F34R wrote:Now this doesnt move the smiley at all.
1. usb active, image loading
2. blit background to offscreen
3. set start position
4. check pad and update position
5. goto 4
6. blit smiley to offscreen and flip visible screen and offscreen
7. exit, if start was pressed
8. goto 2
Perhaps now you can correct your program.
Yes, this is possible. There was a discussion on #pspdev on freenode and ooPo suggested to use libart. It has some nice vector operations, and could be built on top of the current graphics.c. Then you can use the old API, but if you want something more, which may be slower, you can use the libart functions, too.Nils wrote:Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. restart if Start is pressed.
8. end the while do loop.
My problem is getting the new value to update. Just a little hint please. I am soooo trying to figure this out.
First off, thanks Shine for your great tutorial and work on LuaPlay.
I've been testing small code, nothing useful at all, but something's better than nothing...anyways, the problem I'm having is that "Press start to restart" is shown on the screen when I start the code. I added the screenshot feature in and took a sceen to show you what I mean.
Here's the code:
And the screenshot:
Thanks for any help.
I've been testing small code, nothing useful at all, but something's better than nothing...anyways, the problem I'm having is that "Press start to restart" is shown on the screen when I start the code. I added the screenshot feature in and took a sceen to show you what I mean.
Here's the code:
Code: Select all
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
white = Color.new(255, 255, 255)
red = Color.new(255, 0, 0)
orange = Color.new(255, 140, 0)
System.usbDiskModeActivate()
while true do
screen:print(1, 80, "To see the best and worst teams of the NFL:", white)
screen:print(1, 90, "Press Circle: The best NFL teams.", white)
screen:print(1, 100, "Press Square: The worst NFL teams.", white)
screen:print(1, 110, "Press Triangle: Exit USB mode.", white)
screen:print(1, 260, "Created by Nate", green)
pad = Controls.read()
if pad:start() then
break
end
if pad:circle() then
screen:print(1, 140, "Here are the best NFL teams:", orange)
screen:print(1, 150, "Jacksonville Jaguars", blue)
screen:print(1, 160, "Carolina Panthers", blue)
screen:print(1, 170, "Miami Dolphins", blue)
end
if pad:square() then
screen:print(1, 200, "Here are the worst NFL teams:", orange)
screen:print(1, 210, "San Francisco 49ers", red)
screen:print(1, 220, "Cleveland Browns", red)
screen:print(1, 230, "Chicago Bears", red)
end
if pad:triangle() then
System.usbDiskModeDeactivate()
screen:print(1, 250, "USB Mode Deactivated", white)
end
if pad:select() then
Image:save("screen.tga")
end
screen.waitVblankStart()
screen.flip()
end
Thanks for any help.
Try that at beginning... i ran into this bug also.
Code: Select all
-- this to prevent the press start to restart display bug
layout =Image.createEmpty(480, 272)
layout:fillRect(0, 0 , 480, 272, Color.new(0,0,0))
screen:blit(0, 0, layout)
screen.flip()
screen:blit(0, 0, layout)
screen.flip()
Puzzle Bobble - The arcade port!
-
- Posts: 15
- Joined: Tue Feb 08, 2005 6:36 pm
Hi everyone. I'm having trouble creating an options menu for my game and I was wondering what your opinion was on the best way to go about making a menu. I've been trying several different ways over the last few days but nothing seem to work right. Is there a simple way to do it? I've never programmed anything before so, I'm not quite sure how to go about it. Here is what I'm trying to do:
I wanted to make a menu where you would press up or down to change to the selected option and the title would highlight blue, then pressing left or right to select 1, 2, or 3. I got a few ideas in the middle of the night, so I got up and wrote them down, but it didn't work. I don't know what the hell I'm doing! :P
If anyone has some example code of a menu or if you could let me know what I should study up on, I would appreciate that very much. (or you could write the code for me!) :)
Oh by the way I made this little lua player logo screen, if anybody wants to use it.
I wanted to make a menu where you would press up or down to change to the selected option and the title would highlight blue, then pressing left or right to select 1, 2, or 3. I got a few ideas in the middle of the night, so I got up and wrote them down, but it didn't work. I don't know what the hell I'm doing! :P
If anyone has some example code of a menu or if you could let me know what I should study up on, I would appreciate that very much. (or you could write the code for me!) :)
Oh by the way I made this little lua player logo screen, if anybody wants to use it.
Thanks, this is a bug, it will be fixed for the next version. The problem is, that the screen is not deleted for the second start, after the text "Press start to restart" was displayed. Just add one "screen:clear()" before all your text outputs and ignore the confusing tip of Nils :-)MSX wrote:I've been testing small code, nothing useful at all, but something's better than nothing...anyways, the problem I'm having is that "Press start to restart" is shown on the screen when I start the code.
Can you describe in detail what does not work for you? Remember that all drawing operations goes to the offscreen or seperate images, even the clear functions. And it may be confusing, that image:clear() deletes the image with transparent pixels, so blitting this with alpha channel enabled to screen doesn't delete the content, if you doen't specify a color without alpha, for example with the default parameter from Color.new: "opaqueBlack = Color.new(0, 0, 0); image:clear(opaqueBlack)". This is ok for Snake for the multilayer concept for which it is used in this code, but perhaps it should be better commented in the functions.txt and tutorial.Nils wrote:screen:clear() or myemptygraphic:clear() doesnt work for me; nobody uses that, not even you in snake but at newgame ?
Another important thing when programming is to be exact. Point 7 is not very clear. Do you restart your loop, or is the whole scripted exited for the restart message? And if this is really your program flow, it will display the "Press start for restart" message after one drawing immidiatly, because in point 8 you say, that you end your loop instead of jumping back to some other number. It is not that difficult: Just read your script line by line and imagine what Lua Player does. A program flow is not just writing the commands in plain English, but you have to think, which line is executed as next under which circumstances.F34R wrote:Ok Shine, thanks for that info. I now have the following flow :
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. restart if Start is pressed.
8. end the while do loop.
Instead of using a numbered list, you can draw it as a flowchart, or if you like buzz words, an UML state diagram.
"confusing tip"...i cannot get clear() to work and that was the only way to get rid of the "press restart" bug in 0.7.
I tried all possible ways of clear() with nevyn on IRC.
Tried screen:clear(), screen:clear(Color.new(0,0,0)), screen:clear(Color.new(0,0,0,255)) myEmptygraphic:clear() ... nothing happens. No nothing. Also just did add as you suggested screen:clear() at beginning of the script to get rid of the "press start to restart" bug, nothing happens.
Try it Shine.
See my 3dcube demo script there http://lua.ventoline.com/3dcube.lua.txt , locate the theScene:fillRect(0, 0 , 480, 272, color.black) around line 114 (there is only one like that), try to replace it with theScene:clear() or any others that i tried... I even thought that i needed to blit just after to take in account that, but it doesnt work :/
That's 3 times i post for that now .... try it at least :) It doesnt work for me . Show me an example with it working, with an animated thing on screen not leaving trails with clear() :)
I tried all possible ways of clear() with nevyn on IRC.
Tried screen:clear(), screen:clear(Color.new(0,0,0)), screen:clear(Color.new(0,0,0,255)) myEmptygraphic:clear() ... nothing happens. No nothing. Also just did add as you suggested screen:clear() at beginning of the script to get rid of the "press start to restart" bug, nothing happens.
Try it Shine.
See my 3dcube demo script there http://lua.ventoline.com/3dcube.lua.txt , locate the theScene:fillRect(0, 0 , 480, 272, color.black) around line 114 (there is only one like that), try to replace it with theScene:clear() or any others that i tried... I even thought that i needed to blit just after to take in account that, but it doesnt work :/
That's 3 times i post for that now .... try it at least :) It doesnt work for me . Show me an example with it working, with an animated thing on screen not leaving trails with clear() :)
Puzzle Bobble - The arcade port!
Well, lol.
I managed to get clear working, but NOT in the way it should: it behaves strangely:
i had to do a screen:clear() in my main while loop, AND a theScene:clear() in my rotate function that is called just after that, meaning it clears screen, then clears theScene.
It doesnt work with one or the other only, it needs both ! How come ? Bug ?
See it here -> http://lua.ventoline.com/3dcube2.lua.txt
[edit] and FPS has decreased drastically...it's slow now. I'll stick with fillrect until clear() is cleared :)[/edit]
I managed to get clear working, but NOT in the way it should: it behaves strangely:
i had to do a screen:clear() in my main while loop, AND a theScene:clear() in my rotate function that is called just after that, meaning it clears screen, then clears theScene.
It doesnt work with one or the other only, it needs both ! How come ? Bug ?
See it here -> http://lua.ventoline.com/3dcube2.lua.txt
[edit] and FPS has decreased drastically...it's slow now. I'll stick with fillrect until clear() is cleared :)[/edit]
Puzzle Bobble - The arcade port!
First release on the PSP scene! Wouldn't be of much use, but it makes for a good tutorial, and it's fun to play around with :D
Download Here - Looking for mirrors alsoHey guys...
I've been coding and testing all night in Lua, and I've come up with something that's somewhat useful, well, I guess not useful, but this is my first PSP app .
Basically this will output whichever button you press to the PSP screen, except for Home, Vol +/-, Display Brightness, and the Musical Note buttons. It isn't too hard, but if you put too much power into it, you can turn the PSP off instead of turning Hold off (if you press it to show the output on the screen).
You can go into and out of USB mode while still in this program. Read the readme to see the controls for clearing the screen, starting USB mode, and exiting USB mode.
I think that covers it...hopefully I'll release a more advanced game soon .
Enjoy
-
- Site Admin
- Posts: 347
- Joined: Sat Jan 17, 2004 9:49 am
- Location: Melbourne, Australia
- Contact:
Just a reminder that anyone looking for a place to host their projects. The main ps2dev.org can be used. Simply login using your userid/password from forums and then use "add topic" from the right menu in one Demos page. After you've added a topic which describes your project, then do "add file" to add your latest release.
Accounts are copied from the forums for anyone who has posted ~8+ posts. If you've done less, just private message me, and I'll setup the account for you.
David. aka Oobles.
ps2dev.org site admin.
Accounts are copied from the forums for anyone who has posted ~8+ posts. If you've done less, just private message me, and I'll setup the account for you.
David. aka Oobles.
ps2dev.org site admin.
Not knowing what you are doing is always a bad thing when it comes to programming :-)indianajonesilm wrote:I wanted to make a menu where you would press up or down to change to the selected option and the title would highlight blue, then pressing left or right to select 1, 2, or 3. I got a few ideas in the middle of the night, so I got up and wrote them down, but it didn't work. I don't know what the hell I'm doing! :P
A menu could look like this:
Code: Select all
options = { speed = 1, backgroundImage = "stone" }
possibleOptions = {
speed = {
displayName = "Speed",
values = { 1, 2, 3} },
backgroundImage = {
displayName = "Background Image",
values = { "wood", "stone" }
}
}
function menu()
selectedOptionNumber = 0
deactiveColor = Color.new(0, 255, 0)
activeColor = Color.new(255, 255, 255)
oldPad = Controls.read()
while true do
screen:clear()
y = 0
selectedOptionValues = nil
selectedOptionIndex = nil
selectedOptionName = nil
for optionKey, possibleOption in possibleOptions do
color = deactiveColor
if selectedOptionNumber == y then
color = activeColor
selectedOptionValues = possibleOption.values
end
screen:print(0, y * 10, possibleOption.displayName, color)
for i, value in possibleOption.values do
color = deactiveColor
if options[optionKey] == value then
color = activeColor
if selectedOptionNumber == y then
selectedOptionIndex = i
selectedOptionName = optionKey
end
end
screen:print(i * 50 + 150, y * 10, value, color)
end
y = y + 1
end
pad = Controls.read()
if pad ~= oldPad then
if pad:triangle() then break end
if pad:up() then
selectedOptionNumber = selectedOptionNumber - 1
if selectedOptionNumber < 0 then selectedOptionNumber = y - 1 end
end
if pad:down() then
selectedOptionNumber = selectedOptionNumber + 1
if selectedOptionNumber >= y then selectedOptionNumber = 0 end
end
len = table.getn(selectedOptionValues)
if pad:left() then
selectedOptionIndex = selectedOptionIndex - 1
if selectedOptionIndex <= 0 then selectedOptionIndex = len end
options[selectedOptionName] = selectedOptionValues[selectedOptionIndex]
end
if pad:right() then
selectedOptionIndex = selectedOptionIndex + 1
if selectedOptionIndex > len then selectedOptionIndex = 1 end
options[selectedOptionName] = selectedOptionValues[selectedOptionIndex]
end
oldPad = pad
end
screen.waitVblankStart()
screen.flip()
end
end
I think it is the note button, which is used to enable/disable the sound (read your PSP manual), but I don't know, if it is available with the note() function. Perhaps a callback needs to be registered for it.MSX wrote:Anyone know what button controls:note() is?
See the animation example from the tutorial page:Nils wrote: That's 3 times i post for that now .... try it at least :) It doesnt work for me . Show me an example with it working, with an animated thing on screen not leaving trails with clear() :)
Code: Select all
System.usbDiskModeActivate()
green = Color.new(0, 255, 0)
time = 0
pi = math.atan(1) * 4
while true do
screen:clear()
x = math.sin(pi * 2 / 360 * time) * 150 + 192.5
screen:print(x, 100, "Hello World!", green)
time = time + 1
if time >= 360 then
time = 0
end
screen.waitVblankStart()
screen.flip()
pad = Controls.read()
if pad:start() then
break
end
end
I don't see any bug. Your code is redundant. Drop the "theScene" image, call screen:clear() at start of your loop, draw everything on the screen (which is in fact the offscreen) and call screen.waitVblankStart() and screen.flip(). Should be faster, because you save one memory copy, which was even slower with your code, because you used the blit function with alpha enabled.Nils wrote: i had to do a screen:clear() in my main while loop, AND a theScene:clear() in my rotate function that is called just after that, meaning it clears screen, then clears theScene.
It doesnt work with one or the other only, it needs both ! How come ? Bug ?
and FPS has decreased drastically...it's slow now. I'll stick with fillrect until clear() is cleared
Thx Shine... i did indeed drop the theScene and everything on screen. Now the screen:clear() works.
Seems weird though that theScene:clear() didnt work.
I'm off to code more ... :)
Seems weird though that theScene:clear() didnt work.
I'm off to code more ... :)
Puzzle Bobble - The arcade port!
just a heads up to say that MSX released his button logger app for the psp over at PSP News forums http://www.dcemu.co.uk/vbulletin/showthread.php?t=9224
Windows version
You can download a first version of the Lua Player for Windows. It is a very early alpha version, but graphics should work. Sound and directory functions doesn't work and it could be slower than on PSP (depends on your computer) and it flickers. I've tested it with Snake and some demo progams, which are running fine.
Usage: Copy all your game files into the luaplayerwindow directory, open a DOS command prompt, change to the directory and call "luaplayer script.lua". Hit the escape key to close the window (don't close the window with the mouse, there is a bug in OpenGL GLUT, which this program use). The key mappings:
'a' = select
's' = start
'q' = left trigger
'w' = right trigger
'f' = circle
'r' = tirangle
'c' = cross
'd' = square
cursor keys = pad
Usage: Copy all your game files into the luaplayerwindow directory, open a DOS command prompt, change to the directory and call "luaplayer script.lua". Hit the escape key to close the window (don't close the window with the mouse, there is a bug in OpenGL GLUT, which this program use). The key mappings:
'a' = select
's' = start
'q' = left trigger
'w' = right trigger
'f' = circle
'r' = tirangle
'c' = cross
'd' = square
cursor keys = pad
-
- Posts: 15
- Joined: Tue Feb 08, 2005 6:36 pm
OH WOW! Thank you so much Shine!Shine wrote:Not knowing what you are doing is always a bad thing when it comes to programming :-)
A menu could look like this:
Let me just take this opportunity to to thank Shine, nevyn, and all the other people here who take the time to help out newbs like myself. I know what a pain we can be, always asking for help and asking dumb questions sometimes but you guys are always helpful and patient. A big thank you to Shine for Lua Player, I'm having more fun writing lua scripts than I do playing actual PSP games! Also, thanks for the menu example, it's perfect! :)
The Controls:note() is indeed the little note button next to the select button. I added it because I saw that it existed in the C libraries. And no, it doesn't seem to work...
Shine: What the hey, no cross platform thingie? :P Source? I'd really like this thing running on Mac, too... (luaplayer.org seems unreachable...?)
Shine: What the hey, no cross platform thingie? :P Source? I'd really like this thing running on Mac, too... (luaplayer.org seems unreachable...?)
-
- Posts: 116
- Joined: Mon Jul 18, 2005 2:20 am
Re: Windows version
Thanks!Shine wrote:You can download a first version of the Lua Player for Windows. It is a very early alpha version, but graphics should work. Sound and directory functions doesn't work and it could be slower than on PSP (depends on your computer) and it flickers. I've tested it with Snake and some demo progams, which are running fine.
I don't have much experience with compiling for Mac, but when I have some more time, I'll port it to this system, too. It is OpenGL based with GLUT, so should be as easy as copying the windows/windows.c to mac/mac.c, tweaking a bit the CreateThread and nanosleep things and writing a Makefile for using the Mac libraries and headers for OpenGL and GLUT. Perhaps someone with more Mac developing experience can do it.nevyn wrote:Shine: What the hey, no cross platform thingie? :P Source? I'd really like this thing running on Mac, too... (luaplayer.org seems unreachable...?)
Regarding luaplayer.org: I use this as a test, to see if a Lisp webserver can be used for websites, but looks like I have to learn a bit more about how to setup the Lisp webserver the right way, sometimes it hangs, but I have enabled debugging and now I can login into the running Lisp process on the server and examine the environment, so I think I'll find the problem. Currently it works :-)
Shine,
I think I see what you mean.
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. Goto 5 with new x,y position.
Is that correct ? I just dont get how to display the image again with the new x,y coords..
I think I see what you mean.
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. Goto 5 with new x,y position.
Is that correct ? I just dont get how to display the image again with the new x,y coords..
Dude, I am a mac coder :P But I can't very well port it without source, can... Oh! It's at the svn. Of course. I'll try to port it tonight.Shine wrote:I don't have much experience with compiling for Mac, but when I have some more time, I'll port it to this system, too. It is OpenGL based with GLUT, so should be as easy as copying the windows/windows.c to mac/mac.c, tweaking a bit the CreateThread and nanosleep things and writing a Makefile for using the Mac libraries and headers for OpenGL and GLUT. Perhaps someone with more Mac developing experience can do it.
(that luaplayer.org site really is *slow*...)