i'll agree with Nielkie, you should be fine with box collision, but a pixel collision would not appear to have "gaps" between a collision, however if box collision is done correcltly only minor "gaps" would ever appear
Printable View
i'll agree with Nielkie, you should be fine with box collision, but a pixel collision would not appear to have "gaps" between a collision, however if box collision is done correcltly only minor "gaps" would ever appear
Ok thanks
-=Double Post Merge =-
Can I do collision based on the color of an object? Like if a platform is red my player cant go through it?
Yes you can.
How would I do it?
I don't need straight code I just want an explanation.
basically you'll need to internally keep track of what tile is what, than simple loop though the tiles, check if you can move though that tile, than move or don't move though it, it's all internal tracking, it's only the graphics side that display's it's a red tile
Thank You
There is also a way to check for colour. So you could use any object of a particular rgb colour value and the player would collide with it. I'll see what I can do for you in terms of an explanation in a minute. I have a friend who knows a lot about this particular subject.
o, i did not know this, however i believe internal tracking would be faster than checking an rgb value, however do toss out the info for Chrome to know, and for me to know for future refrence
I will do once he comes online. And you're right I think your way is faster.
What is your method eldiablov?
My jumping script isn't working. Once the player hits the ground I can't jump again. http://www.sendspace.com/file/azor5n
for future reference:
rafb.net/paste
or use code tags if your just giving use the script anyways
anywho, let me take a look, probably something simple your forgetting to do
edit:
think i got it:
^^obj1 has to meet the following(at least from how i'm reading it):Code:if (obj1.x + obj1.img:width() > obj2.x) and (obj1.x < obj2.x + obj2.img:width()) and
(obj1.y + obj1.img:height() > obj2.y) and (obj1.y < obj2.y + obj2.img:height()) then
1. be smaller than obj2.
2. be completely inside obj2
which, in most cases that won't happen, i suggest revising it for checking only when one point intersects with obj2, or even making it more advanced and giving feedback depending on what side obj1 is hitting obj2, which could defiantly help you in the future(at least with the suspicion of what i believe your trying to do, and it only takes just a few extra if statements to do this)
Sorry the code was long and my only internet resource atm is my PS3 and I really didnt want to type it on its crappy OSK. Thanks ill try checking whether im hitting the top or bottom. Edit: obj1 doesn't have to be smaller or inside obj2 once they touch it works. But I think your right about checking specific areas.
ok, now i got it, and sorry about pointing in wrong direction, was late when i read it, but it's around the same issue:
^^as soon as you begin to jump, it'l start falling again, so to comphisate i did:Code:function checkCollision(obj1,obj2)
if (obj1.x + obj1.img:width() > obj2.x) and (obj1.x < obj2.x + obj2.img:width()) and
(obj1.y + obj1.img:height() > obj2.y) and (obj1.y < obj2.y + obj2.img:height()) then
if obj1 == Player then
Player.jumpstate = "ground"
end
else Player.jumpstate = "falling"
end
end
and secondly, it still won't jump, because it is slightly embeded into the green block at this point, which means that as soon as you begin to jump the collision function says it's hitting, and sets it back to ground, to compensate i did:Code:function checkCollision(obj1,obj2)
if (obj1.x + obj1.img:width() > obj2.x) and (obj1.x < obj2.x + obj2.img:width()) and
(obj1.y + obj1.img:height() > obj2.y) and (obj1.y < obj2.y + obj2.img:height()) then
if obj1 == Player then
Player.jumpstate = "ground"
end
else if Player.jumpstate~="jumping" then Player.jumpstate = "falling" end
end
end
and with those two changes the block was jumping all over the screenCode:function playerjump()
if Player.jumpstate == "ground" then
if pad:cross() then
Player.jumpstate = "jumping"
Player.y = Player.y - 3; // <-- now it'll move itself out of the block slightly so this way the collision function won't happen
end
elseif Player.jumpstate == "jumping" then
Player.y = Player.y - 3
jumptime = jumptime + 1
if jumptime >= 30 then
Player.jumpstate = "falling"
jumptime = 0
end
elseif Player.jumpstate == "falling" then
Player.y = Player.y + 3
end
end
hope this helps
Thanks alot :tup:
Are you sure you want a jumping and falling state? It will cause problems when you start adding other objects. Just have a moving state and it resets when you hit the top or bottom of an object and slows down when you hit the side based on friction (this means every side of the object has to have its own collision though).
^ i agree with MoAShaun, i think it wouldn't cause Huge problems But annoying ones using a boolean rather than a string it would be easier.
Never mind. I fixed my problem.
I need help with a level editor for my arkanoid deluxe game. Im not even sure how to start. Creating levels was a pain and a level editor would help me out and be a good addition to the game.
You should start by telling us how your levels are stored...
I need a maximum of 30 blocks.
The tables are like this
Block = {}
Block[1] = {x = blah, y = blah, img = blah}
Block[2] = {x = blah, y = blah, img = blah}
...
Block[30] = {x = blah, y = blah, img = blah}
Can anyone help? Even just to point me in the right direction.
There's an insert table function in Lua ;)
table.insert(tablename, the thing you want to insert, optionally the place where you want to insert it otherwise defaults to the end)
Thanks I already googled it though lol.
Can I use infinite arguments? Like
table.insert(BLOCK, BLOCK[1] = {x = blah, y = blah}, .... BLOCK[30] = {})
Im just not totally clear how it works.
No
table.insert would work like this:
Code:table.insert(BLOCK, {x = blah, y = blah, img = blah})
OK
How do I keep text on screen after I select something.
Like when I hit something I have to hold that button for the next set of text to stay. Like if I have to hit Cross(x) for text to appear then I have to hold it for that text to stay. How do I make it so the next text stay up even after I release X?
A sample code would be superb :tup:
Use oldpad
Code:oldpad = Controls.read()
--MAIN LOOP
if pad:cross() and oldpad:cross() ~= pad:cross() then
--Display text
end
--End loop
screen.waitVblankStart()
screen.flip()
oldpad = pad --Make sure you have this
end
I'm a little lost. What exactly are you trying to do? You want it to display one message whilst X isn't being held, and another whilst X is being held? Also, if so, why exactl yisn't it working, what's happening instead?
Also, on a different note, I wanted to ask if there is any way I could fade from one image to another in lua? I know how to fade an image out to black, and then the next in, but is there no way I could do it straight from one to another? Thanks in advance.
No, I want it so that all I have to do is press X and it shows a different text.
So say this is my menu.
Menu Items:
1.Say yes (when selected with X prints "Yes")
2.Say no (when selected with X prints "No")
3.Exit (exits the program obviously)
Now, what im having trouble with is, when I select option 1 with X I have to hold X for the message "Yes" to stay on the screen. If i just press X the message "Yes" only stays on the screen for as long as I hold X.
What im trying to accomplish, is when I press X I want the new message of "Yes" to stay on screen till say I press O or something, i dont know yet. But I do know that i dont want to have to hold X for the message to stay on screen.
Get what im saying lol, its kind of hard to explain.
I'll bet your in a loop, and at the top of the loop is a screen clear, so when you hold X, its really clearing + displaying really quickly...
but since you dont post any code we cant be sure...
To your question: Yes, talk to me on msn for various methods
To original question:
Code:displayText = false
while true do
screen:clear(Color.new(255,255,255))
oldpad = pad
pad = Controls.read
if pad:cross() and not oldpad:cross() then
displayText = not displayText
end
if displayText then
screen:print(0,0,"Text is on")
end
screen.waitVblankStart()
screen.flip()
end
Well, that bit of code works but it doesnt work. Ill let you see for yourself whats going on while its being run.
Note:You will see that with what I have in my code I am still experimenting with Lua, as I amstill learning, so bear with me if some of my choices in the menu dont make sense.
Also, if your trying to run this code, put an image named image.jpg in the same folder as this .lua or it wont load properly.
Code:image = Image.load("image.jpg")
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, white, white, white}
color[menustatus]=red
screen:print(50, 50, "Display Text", color[1])
screen:print(50, 60, "Info", color[2])
screen:print(50, 70, "Display Image", color[3])
screen:print(50, 80, "Screen Lock", color[4])
screen:print(50, 90, "Test", color[5])
screen:print(50, 100, "Exit", color[6])
if menustatus == 1 then
if pad:cross() then
screen:clear(black)
screen:print(50, 50, "Hey it worked!", color[1])
end
end
if menustatus == 2 then
if pad:cross() then
screen:clear(black)
screen:print(50, 50, "Created by Nava -C- 2008", red)
end
end
if menustatus == 3 then
if pad:cross() then
screen:blit(0,0,image)
end
end
if menustatus == 4 then
if pad:cross() then
screen:clear(black)
screen:print(50, 50, "Can you figure out the password?", red)
end
end
if menustatus == 5 then
while true do
displayText = false
oldpad = pad
pad = Controls.read()
if pad:cross() and not oldpad:cross() then
displayText = not displayText
end
if displayText then
screen:print(50,50, "Hey it worked!", red)
end
screen:waitVblankStart()
screen:flip()
end
end
if menustatus <= 0 then
menustatus = 6
end
if menustatus >= 7 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
screen:clear() is defaulted to clear black, you don't really need that Or the created color unless you intend to use it.
How hard would it be for me to port an unindented 1,400-line game into PGE lua from Lua v0.16? And for the change in speed, would it be worth doing it?