 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
alex_dsnews
Joined: 03 Aug 2005 Posts: 13
|
Posted: Fri Aug 12, 2005 11:11 pm Post subject: |
|
|
| Quote: | | Why not just try it? :P |
at work. ;)
looks like (from Shine's eg) that you can quite happily blit well offscreen, though, which is useful. |
|
| Back to top |
|
 |
Laurens
Joined: 28 Jun 2005 Posts: 14
|
Posted: Sat Aug 13, 2005 1:31 am Post subject: Re: PhysicsFS, Lowser and savegame data |
|
|
Since I'm the one currently working on the physfs thing, I'll also comment on it :)
| Shine wrote: |
- System.openArchive(name) is added, which adds all files from the archive for all read functions (I omitted the nasty details here, like rewriting Lua io-lib and Mikmod to make this possible :-)
|
I don't quite see what that function would be good for - in my opinion, on startup, _ALL_ .zipfiles can be added to the path, so there is no need to open archives from within scripts yourself. Not having an extra functions should be easier for users.
| Shine wrote: |
So the proposed changes to Lua Player:
- EBOOT.PBP first searchs for script.lua and starts it, if found
- if not found, it search for game.zip, opens it as a PhysicsFS archive and starts script.lua from within it
|
I'd say: add all found archives to the path. The archives should have a subfolder for the game (so in mygame.zip, there would be mygame/index.lua).
| Shine wrote: |
- System.openArchive(name) is added, which adds all files from the archive for all read functions (I omitted the nasty details here, like rewriting Lua io-lib and Mikmod to make this possible :-)
- System.closeArchive(name) is added, for example for Lowser to find the index.lua from the currently opened archive, only
- Lowser scans the Applications directory for directories and for zip-archives
|
These functions & changes are imo only needed if not all archives are added at bootup.
As for the path, I think /psp/GAME/luaplayer would be better, or is there a reason you guys like /psp/luaplayer better?
The nasty thing is, unfortunately, that a simple compile of physfs is not possible, so I've started working on a psp driver for it.
BTW: I'm working with the 1.0-stable release of physfs. You guys think I should use the developent version 1.1? _________________ If a beautiful girl tells you she's done some modeling work in the past, and you ask her what 3D software she used, you might be a gamedeveloper. |
|
| Back to top |
|
 |
nevyn
Joined: 31 Jul 2005 Posts: 136 Location: Sweden
|
Posted: Sat Aug 13, 2005 1:56 am Post subject: Re: PhysicsFS, Lowser and savegame data |
|
|
| Laurens wrote: | | As for the path, I think /psp/GAME/luaplayer would be better, or is there a reason you guys like /psp/luaplayer better? |
Yeah. /psp/GAME/luaplayer contains the binary, so that if you want to upgrade to a new version of luaplayer, you have to move all your files (Applications, Documents) somewhere else, remove the old version, put the new version in, and put all the files back. Plus, GAME is indeed for the binaries, and user files don't belong there. (That's like saving your Photoshop images to /Program Files/Photoshop/ or whatever.)
(That's why I place all my roms in ms0:/Documents/ROMS/ and not ms0:/PSP/GAME/whateveremulator/ROMS/) |
|
| Back to top |
|
 |
Laurens
Joined: 28 Jun 2005 Posts: 14
|
Posted: Sat Aug 13, 2005 2:47 am Post subject: Re: PhysicsFS, Lowser and savegame data |
|
|
Good point. _________________ If a beautiful girl tells you she's done some modeling work in the past, and you ask her what 3D software she used, you might be a gamedeveloper. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Aug 13, 2005 3:42 am Post subject: Re: PhysicsFS, Lowser and savegame data |
|
|
| Laurens wrote: | | These functions & changes are imo only needed if not all archives are added at bootup. |
You are right, no need for user functions for PhysFS archives, if all files with ".luapp" are opened as archives on startup. This can be recursive: If a script is called with the new script instantiate function call and it is in a normal directory, all archives within this directory are opened, too, which may be useful while developing, because you can place your graphics in one file in the directory, but you can still editing the script file(s). |
|
| Back to top |
|
 |
liquid8d
Joined: 30 Jun 2005 Posts: 66
|
Posted: Sat Aug 13, 2005 4:40 am Post subject: |
|
|
Hey guys,
Great job on this... I just got to check out the player for the first time, and looks like it will be great to work with...
Quick question though, please don't take this as a feature request, but do you intend sometime in the future (i know you probably have your hands full now) to add network functions to this?
I would like to start working on a simple game but would like to include some network support, and wasn't sure if I should wait for this, or use the hackaround available for network send/receive. I currently have an ftp client in testing, but as a newbie to C, i am having some difficulties getting everything working properly. It would be nice for simple lua purposes, to be able to just call upon network functions like (net.connect net.listen, etc)
Thanks,
LiQuiD8d |
|
| Back to top |
|
 |
alexmae
Joined: 12 Mar 2005 Posts: 22
|
Posted: Sat Aug 13, 2005 4:40 am Post subject: |
|
|
| how can i make it work if 2 keys are pressed at the same time? it only gets one |
|
| Back to top |
|
 |
MikeHaggar
Joined: 18 Jul 2005 Posts: 116
|
Posted: Sat Aug 13, 2005 5:16 am Post subject: |
|
|
| alexmae wrote: | | how can i make it work if 2 keys are pressed at the same time? it only gets one |
make sure you got it like this:
| Code: |
pad = Controls.read()
if pad:cross() then
etc
end
if pad:circle() then
etc
end
|
and not:
| Code: | pad = Controls.read()
if pad:cross() then
etc
elseif pad:circle() then
etc
end
|
|
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 5:36 am Post subject: |
|
|
any chance of a lua tutorial being put together. I have used PASCAL and BASIC on a minimal level. I was wondering if anyone could put together a tutorial of sorts that comments on how to common tasks, such as :
displaying images, button input, sound playing with button presses, looping, scrolling images.
I've been following this thread for a while now, and I have an idea on how to do most of this, but its not working out the way I thought it would lol.
If this would be too much trouble, i'll just keep reading, and trying hehe.
Thanks for making Lua on the PSP. It gives me something that I can use to attempt at creating for the PSP. Thank you. |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sat Aug 13, 2005 7:21 am Post subject: |
|
|
Any way to implement a millisecond function in lua ? It really lacks it...
We have os.time(), which returns the time in seconds....
How about a os.timems(), which returns the time in milliseconds ? _________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Aug 13, 2005 7:25 am Post subject: |
|
|
| Nils wrote: | Any way to implement a millisecond function in lua ? It really lacks it...
We have os.time(), which returns the time in seconds....
How about a os.timems(), which returns the time in milliseconds ? |
what about os.clock() ? |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sat Aug 13, 2005 7:59 am Post subject: |
|
|
Excellent .... thx Shine. Lua's doc is really awful and so incomplete.
We lack a math.int or math.round .. somehow founded that one, but would be nice to implement directly in lua:
function math.round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
idp being the number of decimals you want.
I was wondering also about coroutines / threads, any clue where to look at ?
I'm looking for a typical "onEnterFrame() as in Flash" way to have independents objects behave ; doing everything in a linear way seems weird :/ _________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sat Aug 13, 2005 8:27 am Post subject: |
|
|
Ok.. been running a few tests to see what was the fastest loop. Somehow, as usual, it seems that while - is the fastest around.
| Quote: |
System.usbDiskModeActivate()
color = {
red = Color.new(255,0,0);
green = Color.new(0, 255, 0);
blue = Color.new(0,0,255);
}
local q = 0
local j = 0
local time = os.clock()
for i=1,100000 do
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 40, "for loop: " .. tostring(delay) .. " milliseconds", color.red)
screen:print(10, 50, "|_iterations : " .. tostring(q), color.red)
local q = 0
local i = 0
local j = 100000
local time = os.clock()
while i < j do
i = i +1
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 60, "while + loop: " .. tostring(delay) .. " milliseconds", color.green)
screen:print(10, 70, "|_iterations : " .. tostring(q), color.green)
local v = 0
local q = 0
local j = 100000
local time = os.clock()
while j > v do
j = j -1
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 80, "while - loop: " .. tostring(delay) .. " milliseconds", color.blue)
screen:print(10, 90, "|_iterations : " .. tostring(q), color.blue)
while not Controls.read():start() do
screen.waitVblankStart()
screen.flip()
end
System.usbDiskModeDeactivate()
|
Results for me:
For loop, 675.21 ms
While + loop, 639.35 ms
While - loop, 635.05 ms
Not much .. but good to know
[edit]
1 million iterations:
for loop: 7.138 secs
while + loop: 6.790 secs
while - loop: 6.745 secs
[/edit] _________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
alexmae
Joined: 12 Mar 2005 Posts: 22
|
Posted: Sat Aug 13, 2005 8:51 am Post subject: |
|
|
| MikeHaggar wrote: | | alexmae wrote: | | how can i make it work if 2 keys are pressed at the same time? it only gets one |
make sure you got it like this:
| Code: |
pad = Controls.read()
if pad:cross() then
etc
end
if pad:circle() then
etc
end
|
thanks alot ;)
and not:
| Code: | pad = Controls.read()
if pad:cross() then
etc
elseif pad:circle() then
etc
end
|
|
|
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 9:05 am Post subject: |
|
|
I am just learning here, so excuse the noobness of this post lol. I am having trouble just displaying a backgroud behind my text. I've looked at the snake example, still having troubles... can anyone clarify what I am doing wrong here.
| Code: |
-- Define Text Color
green = Color.new(0, 255, 0)
-- Load background Image
backimage = Image.load("background.png")
-- Print out text with pre-defined color
screen:print(240, 136, "Just Testing", green)
-- Display background Image
image:blit(0, 0, backimage, 0, 0, backimage:width(), backimage:height(), false)
screen.flip()
while true do
screen.waitVblankStart()
end
|
|
|
| Back to top |
|
 |
nevyn
Joined: 31 Jul 2005 Posts: 136 Location: Sweden
|
Posted: Sat Aug 13, 2005 9:36 am Post subject: |
|
|
| F34R wrote: | I am just learning here, so excuse the noobness of this post lol. I am having trouble just displaying a backgroud behind my text. I've looked at the snake example, still having troubles... can anyone clarify what I am doing wrong here.
| Code: |
-- Define Text Color
green = Color.new(0, 255, 0)
-- Load background Image
backimage = Image.load("background.png")
-- Print out text with pre-defined color
screen:print(240, 136, "Just Testing", green)
-- Display background Image
image:blit(0, 0, backimage, 0, 0, backimage:width(), backimage:height(), false)
screen.flip()
while true do
screen.waitVblankStart()
end
|
|
Um. Look at your code. First you print text to the screen. Then, you paint an image on top of that. Or actually, you're painting the image into nothing... It should be screen:blit(0,0,backimage, false) (the rest of the parameters are redundant)
Reverse the image blitting and the text printing and you should be fine. |
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 9:51 am Post subject: |
|
|
like i said, I am VERY new to all this, so thank you very much. I'll work on that. Thats why I wondered about a tutorial that showed basic concepts like these.
I'll work on that, and thanks again.
ok... got it all working now... TYVM !!
here is the final code for my first display using Lua ... hehe...
| Code: |
-- Define text colors
green = Color.new(0, 255, 0)
-- Load Images
background = Image.load("background.png")
splash = Image.load("luasplash.png")
-- Display Lua Splash
screen:blit(0, 0, splash, false)
screen.waitVblankStart()
screen.flip()
screen.waitVblankStart(240)
screen.flip()
-- Display Background Image
screen:blit(0, 0, background, false)
screen.waitVblankStart()
screen.flip()
screen.waitVblankStart(250)
screen.flip()
-- Print text on the screen
screen:print(200, 100, " DID IT WORK ? ", green)
screen.flip()
while true do
screen.waitVblankStart()
-- End
end
|
Now I know that many of you could do this sort of thing with your eyes closed and fingers taped up lol... I am excited that it was really that easy after I learned what I had done wrong.
Another thing:
I noticed that sound and music are saved as .xm files... how do you create those ? and is there a size limit on them ?
What does screen.flip() actually do ? |
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 12:23 pm Post subject: |
|
|
Ok, another question. This one is about displaying a graphic, like the snake. I noticed that the background in the snake tileset is white. Does it HAVE to be white.
I downloaded a few samples of a character walking. It included all 8 directions of the character walking. The background for this brown. Its not a tileset either. Its a seperate bitmap file for each part of the animation.
Will I be able to use this ? Or does it have to be a tileset on a white background ?
I am going to attempt to write the code to display him walking on my own, before asking for help on that. This will be using the D-Pad. |
|
| Back to top |
|
 |
gabriel
Joined: 11 Aug 2005 Posts: 5
|
Posted: Sat Aug 13, 2005 3:09 pm Post subject: on_KeyPress / on_KeyRelease ? |
|
|
| MikeHaggar wrote: | | alexmae wrote: | | how can i make it work if 2 keys are pressed at the same time? it only gets one |
make sure you got it like this:
| Code: |
pad = Controls.read()
if pad:cross() then
etc
end
if pad:circle() then
etc
end
|
and not:
| Code: | pad = Controls.read()
if pad:cross() then
etc
elseif pad:circle() then
etc
end
|
|
Is there any way to track key presses and releases?
I tried to write code which kept track of the last pressed key and this worked good while pressing single buttons. But, when I held the left button and tapped another button the button that was being held was still being executed as though it was being pressed at the same rate as the one I was pressing continuously.
Here's a sample of what I tried:
| Code: | pad = Controls.read()
if pad:left() and pad ~= last_k then
--processed key left. prevent execution of code while key remains pressed
end
last_k = pad |
|
|
| Back to top |
|
 |
gabriel
Joined: 11 Aug 2005 Posts: 5
|
Posted: Sat Aug 13, 2005 3:28 pm Post subject: Image Rotate |
|
|
I noticed that the "rotate.lua" script contains a function which allows you to rotate an image 90° clockwise however it does not allow you to rotate the image 90° counter-clockwise (which may come in handy for someone). I originally tried to simulate a counter-clockwise rotation by doing 3 clockwise rotations but it didn't seem right.
Here's my modified version of the function:
| Code: | function rotate(image, dir)
local w = image:width()
local h = image:height()
local result = Image.createEmpty(h, w)
for x=0,w-1 do
for y=0,h-1 do
if dir == 0 then
result:pixel(h-y-1, x, image:pixel(x, y))
else
result:pixel(y, w-x-1, image:pixel(x, y))
end
end
end
return result
end |
| Code: | tank = Image.load("tank.png")
--90° Clockwise:
tank = rotate(tank, 0)
screen:blit(0, 0, tank, 0, 0, tank:width(), tank:height(), false)
--90° Counter-Clockwise:
tank = rotate(tank, 1)
screen:blit(0, 0, tank, 0, 0, tank:width(), tank:height(), false) |
I hope this comes in handy for someone. |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sat Aug 13, 2005 3:39 pm Post subject: |
|
|
Hi ... My first contrib to luaplayer. Shine, you missed that in your apps !
So here is the classic 3d wireframe cube demo made on all systems / languages... lua for psp had to have it :)
Download it here :
- full with lua 0.7 embedded
- lua script version only
Pad or analog pad to move, select for screenshot, start to get out.
Up to more ... Lua is a wonderful toy :) _________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 9:13 pm Post subject: |
|
|
| Shine wrote: | | F34R wrote: | Ok, another question. This one is about displaying a graphic, like the snake. I noticed that the background in the snake tileset is white. Does it HAVE to be white.
|
It is not white, use a better graphics program.
|
LOL. I was just viewing it in windows explorer. I opened it up in PS and I see that is has a transparent background. Ok, I admit, I am just shy of being retarded when it comes to this lol.
Thanks for the Tuts thread Shine. |
|
| Back to top |
|
 |
SnowSurfer
Joined: 08 Jul 2005 Posts: 21
|
Posted: Sat Aug 13, 2005 10:31 pm Post subject: |
|
|
| nice tuts shine, i think one needs to be added about using a timer in a game to determine how much time is left until you get gameover.. :) |
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sat Aug 13, 2005 10:40 pm Post subject: |
|
|
Ok, I have my little smiley going left, right, up, and down. Here is what i cant figure out...
When I press "right", my smiley moves to the right, but it only moves ONCE. When I stop pressing "right" on the dpad, the smiley moves back to its original position. How do I make it stay on the new position ? I tried doing a while loop, and it locked the psp up hehe..
This locked up the psp
| Code: |
while pad:right() do
x = x + 2
end
|
I used that instead of whats below, and like I said, it locked the psp up.
| Code: |
x = 20
y = 100
pad = Controls.read()
if pad:right() then
x = x + 10
end
if pad:left() then
x = x - 10
end
if pad:up() then
y = y - 10
end
if pad:down() then
y = y + 10
end
screen.blit(x, y, smiley)
screen.waitVblankStart()
screen.flip()
pad = Controls.read()
if pad:start() then
break
end
|
This only made the smiley move in the direction pressed, then put the smiley back to the original x/y position.
Last edited by F34R on Sat Aug 13, 2005 10:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Aug 13, 2005 10:43 pm Post subject: |
|
|
| SnowSurfer wrote: | | nice tuts shine, i think one needs to be added about using a timer in a game to determine how much time is left until you get gameover.. :) |
Things like this are the prerequisites for the Lua Player tutorial, I don't want to write a general Lua tutorial, there are better ones for this purpose, like http://lua-users.org/wiki/TutorialDirectory |
|
| Back to top |
|
 |
gabriel
Joined: 11 Aug 2005 Posts: 5
|
Posted: Sun Aug 14, 2005 2:18 am Post subject: |
|
|
| F34R wrote: | Ok, I have my little smiley going left, right, up, and down. Here is what i cant figure out...
When I press "right", my smiley moves to the right, but it only moves ONCE. When I stop pressing "right" on the dpad, the smiley moves back to its original position. How do I make it stay on the new position ? I tried doing a while loop, and it locked the psp up hehe..
This only made the smiley move in the direction pressed, then put the smiley back to the original x/y position. |
Wow, you really need to review the tutorials and focus on basic programming with lua...
Anyway, define your starting x/y positions outside of the main program loop so that your positions will remain.
Example:
--starting positions
| Code: | x = 20
y = 100
while true do
pad = Controls.read()
if pad:right() then
x = x + 10
end
if pad:left() then
...blah blah blah
end |
Just make sure that you don't put that x=20 and y=100 within the main "while" loop. |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sun Aug 14, 2005 5:59 am Post subject: |
|
|
Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
I've been coding a few functions, like reading the pixels 1 by 1 of a given image, storing the x,y,color in a table, then recreating the image with that array dot by dot, and modifying x,y in that array live applying 2d sin and cos rotation, but it's AWFULLY slow, even for small images.... besides, the limitation of displaying a dot somewhere (a dot cannot be displayed on negative coords :( makes this rotation trick a real pain in the a**.
Many games rotate images, and the lack of rotation means one has to precompute rotated still images :(
Something wonderful would be image:rotation(int angle) ...
Also, i've been thinking about my wireframe cube, and it seems impossible to make it textured, as Lua lacks a "fillShape" function... would be great, i'm pretty sure Lua can handle textured 3d with the draw API, but it needs to be enhanced. _________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
F34R
Joined: 28 Jul 2005 Posts: 29
|
Posted: Sun Aug 14, 2005 6:54 am Post subject: |
|
|
Gabriel,
I had tried doing a while loop already, maybe I didnt have the syntax right. Addind the while/do loop for the pad input just made a loop that i can break out of unless I added a break in the while loop.
Here is what I changed the code to. Just FYI, I did go back and read a good bit of the tutorials at http://lua-users.org/wiki/TutorialDirectory. Anywas.. here it is.
| Code: |
System.usbDiskModeActivate()
background = Image.load("background.png")
smiley = Image.load("smiley.png")
while true do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
-- Set start position for the smiley
x = 221
y = 135
-- Set postition when dpad is pressed
while true do
pad = Controls.read()
if pad:right() then
x = x + 5
end
if pad:left() then
x = x - 5
end
if pad:up() then
y = y - 5
end
if pad:down() then
y = y + 5
end
end
screen:blit(x, y, smiley)
screen.waitVblankStart()
screen.flip()
if pad:start() then
break
end
end
|
Now this doesnt move the smiley at all. |
|
| Back to top |
|
 |
Nils
Joined: 03 Aug 2005 Posts: 16
|
Posted: Sun Aug 14, 2005 7:20 am Post subject: |
|
|
F34R,
try that:
| Code: |
System.usbDiskModeActivate()
background = Image.load("background.png")
smiley = Image.load("smiley.png")
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
-- Set start position for the smiley
x = 221
y = 135
-- Set postition when dpad is pressed
function keypad()
local pad = Controls.read()
if pad:right() then
x = x + 5
elseif pad:left() then
x = x - 5
elseif pad:up() then
y = y - 5
elseif pad:down() then
y = y + 5
end
end
while not Controls.read():start() do
keypad()
screen:blit(x, y, smiley)
screen.waitVblankStart()
screen.flip()
end
|
_________________ Puzzle Bobble - The arcade port! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|