Yes, but sometimes LUA isn't very logical.Zitat:
Zitat von head_54us
Printable View
Yes, but sometimes LUA isn't very logical.Zitat:
Zitat von head_54us
altair: u told me how to find current fps, can u link tell me again?? i cant find the post tat u told me in. thx
I think altair is gone. He's coming back, but I think he's on vacation or something.
wheres the first "if"?Zitat:
Zitat von Branin
Whats the best text editor to do lua code in? Im using notepad at the moment but whats the best program that checks your syntax as you type?
this doesnt do luaZitat:
Zitat von jsharrad
RAWR -edited-
oops, wrong link :)
notepad2 again. :P
how do i make an image move using the arrow keys? my image is called "smiley" so some code would be nice :)
Zitat:
Zitat von JaSo PsP
Code:smiley = Image.load("smiley.png")
x = 0
y = 0
while true do
screen:clear()
screen:blit(x, y, smiley)
if pad:right() then
x = x + 1
end
if pad:left() then
x = x - 1
end
if pad:down() then
y = y + 1
end
if pad:right() then
y = y - 1
end
screen.waitVblankStart()
screen:flip()
end
thanxZitat:
Zitat von Grimfate126
ps: u forgot:
plus u got the directions all wrong, up doesnt work and right make it go diagonallyCode:pad = Controls.read()
I'm still having trouble with those two problem.. can someone send me a PM and take a look at my full script please? I dont want to give out everything in this thread. These are the last two problems i need to fix before i release and id like to get it out soon.
what am i doing wrong here?:
Code:if x = 272 then
x = x + 0
end
if y = 480 then
y = y + 0
end
if x == 272 then
x = x + 0
end
if y == 480 then
y = y + 0
end
You forgot the second equals sign.
do u want it so that if the x hits 480 that it wont go any further?? if so: do this:Zitat:
Zitat von JaSo PsP
Code:if x > 480 then
x = 480
end
if y > 272 then
y = 242
end
if x < 0 then
x = 0
end
if y < 0 then
y = 0
end
This is simpler then adding more if's
Code:smiley = Image.load("smiley.png")
x = 0
y = 0
while true do
screen:clear()
screen:blit(x, y, smiley)
if pad:right() and x<272 then
x = x + 1
end
if pad:left() and x>0then
x = x - 1
end
if pad:down() and x<272 then
y = y + 1
end
if pad:right() and x>0 then
y = y - 1
end
screen.waitVblankStart()
screen:flip()
end
k thanxZitat:
Zitat von Grimfate126
theres a problem, i go thru the wall on the right and at the bottom. i found out the answer, i gotta add the dimensions of the smiley face.
-= Double Post =-
Yes! i now have boundries in my first game, now how can i make it detect a collision?
http://evilmana.com/tutorials/lua_tutorial_12.phpZitat:
Zitat von JaSo PsP
I also wrote a simple collision detection program, bounding boxes.
Search QJ's dev forum for collision.
I dont understand, I want my jump sprites to show when I jump, but they wont show! There was no error, but my jump sprites dont show!
Zitat:
Background = Image.load("sunshine_bg.p ng")
green=Color.new(255,0,0)
rgreen=Color.new(0,255,0)
white = Color.new(255,255,255)
MarioScore = 0
LuigiScore = 0
Music.playFile("mus1.it")
player1 = Image.load("mario_left.pn g")
player2 = Image.load("mario_right.p ng")
playerjumpleft = Image.load("mario_jump_le ft.png")
playerjumpright = Image.load("mario_jump_ri ght.png")
luigijumpleft = Image.load("luigi_jump_le ft.png")
luigijumpright = Image.load("luigi_jump_ri ght.png")
luigi1 = Image.load("luigi_left.pn g")
luigi2 = Image.load("luigi_right.p ng")
playerimage = player2
luigiimage = luigi1
math.randomseed(os.time() )
keyimage = Image.load("key.png")
displayTime = math.random(20,500)
counter = 0
screen:blit(0,0,Backgroun d)
screen:blit(0,0,playerima ge)
screen:blit(0,0,luigiimag e)
ground = Image.createEmpty(480,14)
ground:clear(green)
player = {}
player.gravity = 230
player.y = 230
player.x = 50
player.jumpspeed = 10
player.jumpstate = "ground"
luigi = {}
luigi.gravity = 230
luigi.y = 230
luigi.x = 50
luigi.jumpspeed = 10
luigi.jumpstate = "ground"
key = {}
key.x = math.random(1,3)
key.y = math.random (1,3)
while true do
pad = Controls.read()
counter = counter + 1
if counter >= displayTime then
key.x = math.random(1,3)
key.y = math.random (1,3)
if key.x == 1 then
key.x = 224
end
if key.x == 1 then
key.y = 182
end
if key.x == 2 then
key.x = 60
end
if key.x == 2 then
key.y = 132
end
if key.x == 3 then
key.x = 404
end
if key.y == 3 then
key.y = 154
end
displayTime = math.random(500,2000)
counter = 0
end
if player.x > 480 then
Mario.x = 480
end
if player.x < 0 then
Mario.x = 0
end
if luigi.x > 480 then
luigi.x = 480
end
if luigi.x < 0 then
luigi.x = 0
end
if pad:left() then
playerimage = player1
player.x = player.x - 2
end
if pad:right() then
playerimage = player2
player.x = player.x + 2
end
if pad:up() and player.jumpstate == "ground" then player.jumpstate = "jumping" end
if player.jumpstate == "jumping" then
player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed
end
if player.gravity < 0 then
player.jumpstate = "falling"
end
if player.gravity < 230 and player.jumpstate == "falling" then
player.gravity = player.gravity + (player.jumpspeed + 3)
end
if player.gravity == 230 then
player.jumpspeed = 10
player.jumpstate = "ground"
end
if player.gravity > 230 then player.gravity = 230 end
player.y = player.gravity
if pad:square() then
luigiimage = luigi1
luigi.x = luigi.x - 2
end
if pad:circle() then
luigiimage = luigi2
luigi.x = luigi.x + 2
end
if pad:triangle() and luigi.jumpstate == "ground" then luigi.jumpstate = "jumping" end
if luigi.jumpstate == "jumping" then
luigi.jumpspeed = luigi.jumpspeed - 0.5
luigi.gravity = luigi.gravity - luigi.jumpspeed
end
if luigi.gravity < 0 then
luigi.jumpstate = "falling"
end
if luigi.gravity < 230 and luigi.jumpstate == "falling" then
luigi.gravity = luigi.gravity + (luigi.jumpspeed + 3)
end
if luigi.gravity == 230 then
luigi.jumpspeed = 10
luigi.jumpstate = "ground"
end
if luigi.gravity > 230 then luigi.gravity = 230 end
luigi.y = luigi.gravity
if pad:up() and player.jumpstate == "ground" and playerimage == player1 then
playerimage = playerjumpleft
end
if pad:up() and player.jumpstate == "ground" and playerimage == player2 then
playerimage = playerjumpright
end
if playerimage == playerjumpleft and player.jumpstate == "jumping" then
playerimage = player1
end
if playerimage == playerjumpright and player.jumpstate == "jumping" then
playerimage = player2
end
if pad:triangle() and luigi.jumpstate == "ground" and luigiimage == luigi1 then
luigiimage = luigijumpleft
end
if pad:triangle() and luigi.jumpstate == "ground" and luigiimage == luigi2 then
luigiimage = luigijumpright
end
if luigiimage == luigijumpleft and luigi.jumpstate == "jumping" then
luigiimage = luigi1
end
if luigiimage == luigijumpright and luigi.jumpstate == "jumping" then
luigiimage = luigi2
end
screen:blit(0,0,Backgroun d)
screen:blit(key.x, key.y, keyimage)
screen:blit(player.x,play er.y,playerimage)
screen:blit(luigi.x,luigi .y,luigiimage)
screen:blit(0,262,ground)
screen:print(30,20,"Mario 's Score: "..MarioScore,green)
screen:print(30,50,"Luigi 's Score: "..LuigiScore,rgreen)
screen.waitVblankStart()
screen.flip()
end
Right, here you say if the pad has triangle pressed and the jumpstate is "ground" then change jumpstate to "jumping".Code:if pad:triangle() and luigi.jumpstate == "ground" then luigi.jumpstate = "jumping" end
At this point in code, triangle has been pressed and the jumpstate is "jumping". A couple of lines down...
The image will never change to "luigijumpleft" since the jumpstate is now "jumping" rather then "ground". But.....Code:if pad:triangle() and luigi.jumpstate == "ground" and luigiimage == luigi1 then
luigiimage = luigijumpleft
end
Even then it still won't show since at this point of code in the loop, the luigiimage is now "luigijumpleft" and the jumpstate is still "jumping", the luigiimage is chnaged BACK to "luigi1" before it is blitted to the screen.Code:if luigiimage == luigijumpleft and luigi.jumpstate == "jumping" then
luigiimage = luigi1
end
I would get rid of the last 2 bits of code. I would also prefer to have a variable that holds the players current direction rather then check the current image but using your current system, change the first bit of code to:
I let you deal with changing the sprite when the player lands as an exercise to see if you understand the fixes that I have done.Code:if pad:triangle() and luigi.jumpstate == "ground" then
luigi.jumpstate = "jumping"
if lugiimage == luigi1 then
luigiimage = luigijumpleft
else
luigiimage = luigijumpright
end
end
I need to make the object that i collided with dissappear, make the score go up by one and make the object reappear in a random position on the PSP screen. The variables for random x and random y are 'rx and 'ry'. The player is called 'smiley' the object is called 'sad' the dimensions for both of these are 38 x 38. so please can you help me! some code would be nice
Are you serious? Unless you have had a decent go at the code yourself, I don't think anyone is going to just give you the code like that. By doing so, you are not learning anything.
These should help you:
http://evilmana.com/tutorials/lua_tutorial_12.php - box collision detection
http://lua-users.org/wiki/MathLibraryTutorial - random numbers
i will learn, im am currently a learner, if someone writes i will look throught it and understand. I just dunno where to put it all. Is it gonna be something like "if smiley.x + smileyWidth > sad.x then' rite?? i could make it all a function, but i dunno where to put the function. I dunno how to make an object delete then reappear somewhere else with the random variables, it appears first in the game when you start it as:
Code:screen:blit(rx,ry,sad)
and the variables are:
rx = math.random(0,442)
ry = math.random(0,234)
I just posted two links in my previous post to help you with your problem. You are never going to learn unless you have a decent shot at it yorself. Learning how to program is about solving problems. I will not give any advice unless you have a decent shot at this yourself and post some code.
Hint: You are not deleting the object and making it reappear, you are moving it (aka changing the X and Y variable positions)
look at all the stuff ive done so far, btw, ive tried the collision thing, i still dont know how to make the object delete:
Code:--Smiley
--JaSo PsP
red = Color.new(255,0,0)
background = Image.load("cloud.png")
smiley = Image.load("smile.png")
sad = Image.load("sad.png")
math.randomseed(os.time())
rx = math.random(0,442)
ry = math.random(0,234)
boost = 1000
x = 0
y = 5
function booster()
boost = boost - 1
end
while true do
screen:clear()
screen:blit(0,0,background)
screen:print(0,263,"Press X for SPEED BOOST",red)
screen:print(0,0,"Boost Left: "..boost ,red)
screen:blit(x, y, smiley)
screen:blit(rx, ry, sad)
pad = Controls.read()
if pad:right() then
x = x + 1
end
if pad:left() then
x = x - 1
end
if pad:down() then
y = y + 1
end
if pad:up() then
y = y - 1
end
if pad:right() and pad:cross() then
x = x + 3
booster()
end
if pad:left() and pad:cross() then
x = x - 3
booster()
end
if pad:down() and pad:cross() then
y = y + 3
booster()
end
if pad:up() and pad:cross() then
y = y - 3
booster()
end
if pad:start() then
return
end
if x > 442 then
x = 442
end
if y > 234 then
y = 234
end
if x < -2 then
x = -2
end
if y < -2 then
y = -2
end
screen.waitVblankStart()
screen:flip()
end
Sorry, but I don't see any where in that code where you have tried to do any collision. I would at least like to see your attempt at it.
ill see what i can do..
Spoiler for To save me posting it up later:
Ive just been working alot on the boost and now i got it to stop the boost count at 0 when when you run out and stop moving fast when you run out:
-= Double Post =-Code:if pad:right() and pad:cross() then
if boost < 1 then
x = x + 0
else
x = x + 3
booster()
end
end
if pad:left() and pad:cross() then
if boost < 1 then
x = x - 0
else
x = x - 3
booster()
end
end
if pad:down() and pad:cross() then
if boost < 1 then
y = y + 0
else
y = y + 3
booster()
end
end
if pad:up() and pad:cross() then
if boost < 1 then
y = y - 0
else
y = y - 3
booster()
end
end
thanxZitat:
Zitat von head_54us
-= Double Post =-
now i need to know where to find help to make a timer, then when the timer reaches 0 it saves the score as high score, then if the high score is bigger than the current one, it overwrites it. I sort of know how to do this but i just need some help on the time and will the hi score be saved in an external document?
Just search these forums for a thread called 'collision'.
Itll come up with my tutorial on using collision testing via bounding boxes. All you do is copy and paste my function into your code, Then call it supplying the 8 parameters needed.
Timers for LuaPlayer: http://wiki.ps2dev.org/psp:lua_playe...lisecond_timer
To write and read from an external file you have to use the Lua IO library.
edit:
Spoiler for Proper Box Collision function:
i just made a timer out of my own head:Zitat:
Zitat von head_54us
but this slows down everything so 1 thing happends every second.. how do i make the vblankStart only relevant to the timer?Code:function timer()
screen.waitVblankStart(60)
displayTime = displayTime - 1
end
screen.waitVblankStart(X) is an API call to say, wait for the screen to finish refreshing the screen X number of times before proceeding. To answer your question, you can't.
You cant. The vblank basically delays the current thread until a vertical sync, AKA the screen refreshing 'line' his the same spot twice, puesdo code of course.
so is there any way of just making the timer count down every second?Zitat:
Zitat von SG57
SG57, do you know if the string.gmatch function is implemented in the latest PSP version of Luaplyer. I currently only have access to the Windows version and it doesn't seem to have it.
Use the millisecond timer and every time you get the number of ms from the timer, divide by 1000 to get the number of seconds.Zitat:
Zitat von JaSo PsP
BTW, thats why the maximum fps you get see on a screen is 60 correct?Zitat:
You cant. The vblank basically delays the current thread until a vertical sync, AKA the screen refreshing 'line' his the same spot twice, puesdo code of course.
the other collision worked and that site doesn't help, i want a time to count down and i didnt know what the variable was called for the actual number.Zitat:
Zitat von head_54us