Well i didn't do the entire code, so i don't know if there is any. 333mhz =.= and it is not slow to me.
Printable View
Well i didn't do the entire code, so i don't know if there is any. 333mhz =.= and it is not slow to me.
hey turtles where is the code not indented properly, unless your going to moan about the code inside the while true do loop?
As I said that code probably isn't any good, while I was coding it I came across problems (one being that mp3me.eos() returns a string not a boolean o_O), I was unsure if these were speed issues or with the code that is why there is lots more code than would be needed to accomplish this feature and the reason for the cpu being set to 333mhz.
All in all the code i posted was just a way to do what he wanted that worked, I did not say it was any good, in fact I said the complete opposite.
I disagree, what you have described is premature optimisation. You should get it working, then get it working faster (not rip it out because it is slow) but only if it is seen as a performance bottleneck else leave it.
If you find that a chunk of code is getting unwieldy to work with to make constant changes or you are copying and pasting a similar line/block of code a couple of times, then consider refractoring the code to make it more maintainable and/or reusable.
Spoiler for code:
(The code's a bit big so I wrapped it in spoiler tags)
So heres my code for tile engine I'm porting from QBASIC to Lua
for some reason the map shows up ( the part I want) however it's very choppy and when I come up to a wall it blits all over the screen. Is there anything wrong in the code or is it just my computer?
This isn't the Lua help thread, it's the C/C++ help thread. Post in the appropiate thread. :)
And have you tested it on your PSP?
Last thing, indent your code.
Whoops. :p
Maybe I'm going blind... :(
lol THIS is the C/C++ help thread? Anyway no I havent tried it on my PSP and I did indent my code but the spoiler tags took it out I put them there so the post looked neat not this huge wall of code.
EDIT:
GOD I feel like an idiot I had to add the ShowMap function at the top of the loop now it works perfectly
Spoiler for code:
heres the working code if anyone watns it.
FINE if you don't mind seeing a wall of code here:
Code:red = Color.new(255,0,0)
blue = Color.new(0,0,255)
green = Color.new(0,255,0)
playerImage = Image.createEmpty(16,16)
ground = Image.createEmpty(16,16) -- ground tiles
wall = Image.createEmpty(16,16) -- wall tiels
playerImage:clear(red)
ground:clear(green)
wall:clear(blue)
function CreateWorld() --Create a Table with Data on the world
local buffer1 = {rows,cols,TopRow,TopCol,Action,Direc,PlayerY} -- {total rows,total columns, Top Row the is seen, Top Column that is seen,Check for actions in the loop,Chack for directions,Player's y(not necessary as of now}
return buffer1
end
function MAP()
local buffer1 = {tile}
local buffer2 = {}
setmetatable(buffer2,buffer1)
return buffer2
end
North = 1
South = 2 -- Direction constants
East = 3
West = 4
WorldData = CreateWorld()
Map = MAP()
worldMap = {} -- THE MAP
worldMap[1] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1}
worldMap[2] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[4] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[5] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[6] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[7] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[8] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,1}
worldMap[9] = {2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,2,1}
worldMap[10] ={2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1}
function InitVars() -- Init of the variables on the first map blit
WorldData.TopCol = 1
WorldData.TopRow = 5
end
function MoveDown()
WorldData.Direc = South
WorldData.TopRow = WorldData.TopRow + 1
end
function MoveLeft()
WorldData.Direc = West
WorldData.TopCol = WorldData.TopCol - 1
end
function MoveRight()
WorldData.Direc = East
WorldData.TopCol = WorldData.TopCol + 1
end
function MoveUp()
WorldData.Direc = West
WorldData.TopRow = WorldData.TopRow - 1
end
function DrawTile(x,y,TileNumber) -- draw a specific tile
if TileNumber == 1 then
screen:blit(x,y,ground)
end
if TileNumber == 2 then
screen:blit(x,y,wall)
end
end
function ShowMap() --draw the entire map
for i = 0,1 do
for j = 0,4 do
DrawTile(i*16,j*16,worldMap[i+WorldData.TopCol][j+WorldData.TopRow])
end
end
end
InitVars()
while true do
screen:clear()
pad = Controls.read()
ShowMap()
if pad:down() and oldpad:down() ~= pad:down()then
MoveDown()
WorldData.Action = true
end
if pad:right() and oldpad:right() ~= pad:right() then
MoveRight()
WorldData.Action = true
end
if pad:left() and oldpad:left() ~= pad:left() then
MoveLeft()
WorldData.Action = true
end
if pad:up() and oldpad:up() ~= pad:up() then
MoveUp()
WorldData.Action = true
end
screen:flip()
screen.waitVblankStart()
oldpad = pad
end
You might want to add spacing too, I can't tell what goes together. Also, what is it that you want.
-=Double Post Merge =-
it only draws a corrner....
About the corner:Well yea that's the point, I wanted to only see part of the map because say I made the map bigger I could place myself on one point that could by my start point and move my way through the level this is how 2d scrollers like zelda made their maps (of course their scrolling was way more advanced and looked much better than mine).
This is beggining to annoy me now. I'm trying to get a sound to play properly in a game that I'm currently developing, but it just won't work and I can't figure out why. I'm trying to get a sound to play continously as a laser if firing, without having it playing like 5 times at once, if that makes sense. I want it to loop continuously up until the point the laser stops firing. I'm not good at explaining things, so maybe this will help:
That's something I wrote in another file, just to see if I could get it to work elsewhere first, but it still gives me the same error, just saying 'Loop ingettable'. I don't see what I'm doing wrong. Oh, and if it helps at all, I'm using Luaplayer v0.16.Code:abc = Sound.load("a.wav", false)
while true do
if abc:playing() == false then
abc:play()
end
end
Thanks in advance.
The wav file needs to be mono and at a specific bitrate IIRC.
I had the mono / stereo problem at first, because I created the wav file myself, but that was quickly resolved. Also, thanks for the advice, I hadn't thought of that; I do have other sound effects that have worked in other lua programs, so I'll go find out what bitrate they are. Thanks a lot.
EDIT:
It's still being weird. I've tried quite a lot of bitrates and none of them will work, it will load and play the sound but at the point where I check to see if the siound is already playing, I always get an error. Odd.
use a PCM unsigned 8 bit, mono .wav file, you can change the format of your sound files with goldwave audio player, if that is a bit too much hastle for you then just send me a link to the sound file and ill convert it for you.
A sound object does not have the method "playing"
sound: play() returns a voice object, which you can then manipulate (e.g. stop, playing, etc)
so:
Next time, read the function documentationCode:sound = Sound.load(file)
soundVoice = sound:play()
...
if not soundVoice:playing() then
soundVoice = sound:play()
end
http://wiki.ps2dev.org/psp:lua_playe...ound_and_music
I had I sound problem too I tried to play a wav. file, for the sound of a ball bumping against the wall =, but the problem was that it played a sec. later.
Also, I had it in front of the calculation, would that matter.
Hi, haven't posted here in a while, i was wondering, how could someone code Layers in Lua? For images in Lua. E.g background layer, spirte layer etc.
Probably a few small errors, haven't used Lua for a while.Code:layer = {}
layer[1] = ImageCreateEmpty(480,272)
layer[2] = ImageCreateEmpty(480,272)
while true do
layer[1]:blit(maspritez,0,0)
layer[2]:blit(mabackgrowndz,0,0)
screen.flip()
screen.waitVblankStart()
end
Is this what you meant ? :p
Heres my issue. at the the transition from (Pressing start to play) to (loading "intro) I dont want to use the command
"screen.waitVblankStart() "
because i dont want it to wait. I want it to stay there UNTILL I press start!!
what should I do to display "intro" (its a picture that takes up the whole screen) after I press start also.
So here is my code:
Zitat:
pink = Color.new(255, 0 , 153)
blue = Color.new(0 , 153, 255)
orange = Color.new(255, 102, 0)
gray = Color.new(153, 153, 153)
black = Color.new(0 , 0 , 0)
green = Color.new(0, 255, 0)
white = Color.new(225, 225, 225)
--*****LOADING SCREEN*****
screen:print(194, 136, "Loading: 0%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
intro = Image.load("abaddonsparra ble/introscreen.png")
screen:print(194, 136, "Loading: 20%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
lvlone = Image.load("abaddonsparra ble/levelone intro.png")
screen:print(194, 136, "Loading: 40%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
story = Image.load("abaddonsparra ble/story.png")
screen:print(194, 136, "Loading: 60%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
choiceone = Image.load("abaddonsparra ble/choice1.png")
screen:print(194, 136, "Loading: 80%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
screen:print(194, 136, "Loading: 100%", blue)
screen.flip()
screen.waitVblankStart(60 )
screen:clear()
screen:print(194, 136, "Press START to play", white)
screen.flip()
pad = Controls.read()
if pad:start() then
screen:clear()
screen:blit(0, 0, intro)
screen.flip()
end
You would need to load the images in a separate thread so that the graphics can be updated each frame. I'm not really sure if Lua (on the PSP?) has any threading support, but I would look it up if I were you.
Actually, what? Can you elaborate please?
you can do a while loop if you like for example
note*: it may have some error because i just did it so you can understandCode:inintro = 1
perc = 0
while (inintro == 1) do
screen:clear()
if (perc == 0) then
intro = Image.load("abaddonsparra ble/introscreen.png")
perc = 10
else if (perc == 10) then
lvlone = Image.load("abaddonsparra ble/levelone intro.png")
else if (perc == 100) then
screenrint(194, 140, "Press START to play", white)
pad = Controls.read()
if pad:start() then
inintro = 0
end
end
screen:print(194, 136, "Loading: "..perc.."%", blue)
screen.flip()
end
while (1) do
//start game stuff
end
just keep on using else if for every perc you want to use and modifier the perc so it blit property
well this whole game is just going to be like a scenario game.
for example, here is the first choice you make in the game.
http://i56.photobucket.com/albums/g1.../choice1-1.png
It is just going to be whether you press ^, O, or X and it will load another picture with some story line, and then another choice.
I didnt think the code would be that advanced just to load a picture after pressing a button.
ok let me if i can understand you.
you want to show first a loading animation/screen first to load the images, then you want to blit a serctaine image to the screen depening on the button user press?
if so then it as easy as making 2 while loops one to load all the images and the second to ask the user to press a button and then blit that image to screen
example:
like last time note that commands are not propertly use or missing something, it just meant to give you a idea on how to do it, it simple if you understand what it doing and try it you self :) good luckCode:---Example by Thecobra---
inloading = 1 --say if we are still loading images
perc = 0 --how many images we load in percentage
while(inloading == 1) do ---if we are still laoding then--
screen.clear()
screen:print("loading.."..perc,Color(0,0,255))
screen.flip()
if (perc == 0) then
intro = Image.load("abaddonsparra ble/introscreen.png") --load intro image--
perc = 10
else if (perc ==10) then
image1 = Image.load("abaddonsparra ble/image1.png") --load image 1 if perc = 10--
perc = 20
else if (perc == 20) then
image2 = Image.load("abaddonsparra ble/image2.png") --load image 2 if perc = 20--
perc = 30
---so on and so on for else if--
else if (perc == 100) then
--ok we loaded everything so let exit our loop of loading--
inloading = 0
end
end
--now let start our real program :) ---
imgtodisplay = 1
while true do
pad = Controls.read()
screen.clear()
if imgtodisplay == 1 then
screen:blit(intro)
end
if imgtodisplay == 2 then
screen:blit(image1)
end
if imgtodisplay == 3 then
screen:blit(image2)
end
if imgtodisplay == 4 then
screen:blit(image3)
end
if pad:triangle then
--set current image to something else--
imgetodisplay = 2
end
if pad:square then
--set current image to something else--
imgetodisplay = 3
end
if pad:circle then
--set current image to something else--
imgetodisplay = 4
end
--print out some txt--
screen:print("press triangle to display image 1")
screen:print("press square to display image 2")
screen:print("press circle to display image 3")
screen.flip()
end
Got bored so here is a framework in pure Lua that is easily scalable (virtually data driven). You should be able to understand the code and make it work for PSP and your needs.
Code:-- Constants
DIRECTION_NORTH = 1;
DIRECTION_EAST = 2;
DIRECTION_SOUTH = 3;
DIRECTION_WEST = 4;
roomList = {};
-- Create the rooms
roomList[0] = { imageFilename = "", debugText = "RoomA, exits: West and South", exitRooms = {} };
roomList[1] = { imageFilename = "", debugText = "RoomB, exits: East and South", exitRooms = {} };
roomList[2] = { imageFilename = "", debugText = "RoomC, exits: East and North", exitRooms = {} };
roomList[3] = { imageFilename = "", debugText = "RoomD, exits: West and North", exitRooms = {} };
-- Map the rooms together
roomList[0].exitRooms[DIRECTION_WEST] = roomList[1];
roomList[0].exitRooms[DIRECTION_SOUTH] = roomList[3];
roomList[1].exitRooms[DIRECTION_EAST] = roomList[0];
roomList[1].exitRooms[DIRECTION_SOUTH] = roomList[2];
roomList[2].exitRooms[DIRECTION_EAST] = roomList[3];
roomList[2].exitRooms[DIRECTION_NORTH] = roomList[0];
roomList[3].exitRooms[DIRECTION_WEST] = roomList[2];
roomList[3].exitRooms[DIRECTION_NORTH] = roomList[0];
bGameFinished = false;
currentRoom = roomList[0];
function ChangeRooms( direction )
newRoom = currentRoom.exitRooms[direction];
if newRoom ~= nil then
currentRoom = newRoom;
end
end
while not bGameFinished do
print( currentRoom.debugText );
local sPlayerInput = io.read();
sPlayerInput = string.upper( sPlayerInput );
if "Q" == sPlayerInput then
bGameFinished = true;
elseif "N" == sPlayerInput then
ChangeRooms( DIRECTION_NORTH );
elseif "S" == sPlayerInput then
ChangeRooms( DIRECTION_SOUTH );
elseif "W" == sPlayerInput then
ChangeRooms( DIRECTION_WEST );
elseif "E" == sPlayerInput then
ChangeRooms( DIRECTION_EAST );
end
end
Have you looked at yaustars code ? :/
As said earlier, it is a pure Lua framework. If you want to make it work with LuaPlayer and use button input, you have to do the legwork yourself. If I just give you the exact code, you won't learn or understand anything.
If the code I have given is too complex, then work in baby steps towards it.
You first step should be switching between two images using a button press.
Brief:
- When the program loads up, it displays image A
- When the user presses SQUARE, it displays image B
- When the user presses SQUARE again, it displays image A
- When the user presses SQUARE again, it displays image B
- etc
Post your code here when you have done this.
its probably going to take me a couple days to get it working, and thank you again for the framework.
In the meantime, could you tel me whats wrong with this code?
its for my menu.
when I run it I get the error for line 111: 'then' expected near '='
Zitat:
--********MENU*********
red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4)
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4)
end
color={white, white, white}
screen:print(50, 50, "Start Game", color[1])
screen:print(50,60,"Contr ols", color[2])
screen:print(50,70,"Exit" , color[3])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
end
end
if menustatus == 2 then
if pad:cross() then
screen:print(50,50,"Press Triangle to move North", white)
screen:print(50,60,"Press Circle to move East", white)
screen:print(50,70,"Press Cross To Move South", white)
screen:print(50,80,"Press Square to move West", white)
screen:Print(380,100,"Pre ss Triangle to go back to main menu", blue)
if pad:triangle() then
menustatus = 1
end
end
end
if menustatus == 3 then
if pad:cross() then
break
end
end
if menustatus <= 0 then
menustatus = 3
end
if menustatus => 4 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
The point was for you to take baby steps toward a framework, not for us to continue helping you hardcode it.