yeah but im sort of getting the idea
Printable View
yeah but im sort of getting the idea
Good, null is a useful part of programming.
Use nil instead of NULL for Lua.
Hey can someone help me out with making this rpg work. I'm trying to make my sprites do a proper walk so if they press down it looks like it's going down like it is a real rpg.
Code:grass = Image.load("grass.png")
player = Image.load("player.png")
player1 = Image.load("player1.png")
player2 = Image.load("player2.png")
player3 = Image.load("player3.png")
player4 = Image.load("player4.png")
player5 = Image.load("player5.png")
player6 = Image.load("player6.png")
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
Player = { }
Player[1] = { x = 200, y = 50 }
while true do
pad = Controls.read()
screen:clear()
for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end
screen:blit(Player[1].x,Player[1].y,player)
if Player[1].dir=="left" then
screen:blit(Player[1].x,Player[1].y,player1)
end
if Player[1].dir=="right" then
screen:blit(Player[1].x,Player[1].y,player2)
end
if Player[1].dir=="up" then
screen:blit(Player[1].x,Player[1].y,player3)
end
if Player[1].dir=="down" then
screen:blit(Player[1].x,Player[1].y,player4)
end
if pad:left() and Player[1].x > 0 then
Player[1].dir = "left"
Player[1].x = Player[1].x - 4
end
if pad:right() and Player[1].x < screenwidth then
Player[1].dir = "right"
Player[1].x = Player[1].x + 4
end
if pad:up() and Player[1].y > 0 then
Player[1].dir = "up"
Player[1].y = Player[1].y - 4
end
if pad:down() and Player[1].y < screenheight then
Player[1].dir = "down"
Player[1].y = Player[1].y + 4
end
if pad:home() then break
end
screen.waitVblankStart()
screen.flip()
end
hey can someone tell me:
A. what image files are supported with luaplayer
B. what image file can be over 480x272 while still being transparent
C. why a png can't be over 480x270
i need this for a boss in my game Orbz. the boss looks horrible because I used a jpeg for it cause the total strip image is 30XX by 163
also, coding help:
A. is there a function/code that will allow me to do something like:
move_towards(xvar_of_obje ct,yvar_of_object,x,y,spe ed)
or any form of a "move towards a point"? or even like move in a direction
move(xvar_of_object,yvar_ of_object,direction,speed ) ?
A. png and jpg, bmp if you use BMPlib be youresam.Zitat:
Zitat von mako
B. none. if you have anything over 480x272, theres a 90% chance lua wont load it.
C.cause it takes wayyy too much ram. a 200x200 png image takes almost 1MB, and you only have like 10MB to work with.
CODING
A. youll have to do it yourself.
B: I can load a 3000x163 jpg fine, just no transparency. and on the psp, it doesn't show up at all. just a big white blockZitat:
Zitat von Grimfate126
so will splitting the images and loading them separately work? i reeli doubt it, but hey, its worth a shot. there would be about 40 163x163 pngs
well, jpegs have a higher chance of loading, but they just become white blocks.Zitat:
Zitat von mako
so will splitting the images and loading them separately work? i reeli doubt it, but hey, its worth a shot. there would be about 40 163x163 pngs
Zitat:
Zitat von mako
40?!?? i doubt it. but u might as well try. if that dont wrk. convert your code to C. it should work much better.
OK, I know how to access the music folder on the PSP.
blank = Sound.load(ms0:/PSP/MUSIC)
But, how would I make it so it loads the first song, then plays it, when it's over, load the second song, then plays it. etc.?
Im not sure what the play music function is so Im gonna make it up for this purpose :pI believe that would work...Code:blank = Sound.load(ms0:/PSP/MUSIC)
blank1 = Sound.load(ms0:/PSP/MUSIC1)
if blank = nil then
music.play(blank1)
end
Nevermind. I'm thing totally wrong.
-= Double Post =-
How would you detect if a person is holding a button or not? If I put:
if pad:cross() then
player.speed = player.speed + 1
end
It will add 1 only once. But I want to continue adding 1 as long as the x button is held. How would I do this?
And how would I detect if you let go of the X button?
actually, if you put that in your main loop, it will add 1 for every frame you press it. on the contary if you want it so that you have to let go each time before it adds one do this:Zitat:
Zitat von ARza
Code:buttonPressed = false
while true do
pad = Controls.read()
if pad:up() then
if not buttonPressed then
y = y-1
end
buttonPressed = true
else
buttonPressed = false
end
hi guys. okay so i went to this tutorial thing and it told me to make a text file and rename it script.lua then i put the code in it (this is hello world) and its like
blue = Color.new(0, 0, 255)
screen:print(200, 130, "Hello World!", blue)
screen.flip()
while true do
screen.waitVblankStart()
end
but when i start up lua player its not script.lua anymore its script.lua.text and it says there is nothing we can do to this file. what do i do?
-= Double Post =-
okay so im looking at the other lua things and they are all strictly lua files not script.lua in a text file. so do i have to convert my script.lua to a lua file?
Read the thread you already made, it clarifies in there.
ya thanks man.
-= Double Post =-
need some help. how do i make lets say start exit the program. all i can find is how to restart the program.
i think its likeZitat:
Zitat von GuitarGod1134
Code:Controls.read()
if pad:start() and Select == 1 then
break
end
ill try it. cause if its wrong then we both learn something LOL.
-= Double Post =-
nope thats not it. when u instert that code it gives u an error
ok try this
Code:blue = Color.new(0, 0, 255)
while true do
pad=Controls.read()
screen:print(200, 130, "Hello World!", blue)
if pad:start() then
break
end
screen.flip()
screen.waitVblankStart()
end
thats the entire hello world code isnt it?
ok im making a side scrolling game and i got most of the code done but i was at a stopping point and wanted to look at my work , but when i loaded it the screen just stayed black and then shuts off my psp heres my code:
System.usbDiskModeActivat e()
pink = Color.new(255, 0 , 153)
GameStatus = "Loading"
LoadingTimer = Timer.new()
playera = Image.load("playera.png")
sscgb1 = Image.load("sscgb1.png")
sscgb2 = Image.load("sscgb2.png")
sscgb3 = Image.load("sscgb3.png")
slide = {}
slide[1] = { x = 0, y = 0, pic = Image.sscb1(480, 272) }
slide[2] = { x = -480, y = 0, pic = Image.sscbg2(480, 272) }
slide[3] = { x = -960, y = 0, pic = Image.sscgb3(480, 272) }
playera = {}
playera = {x = 200, y = 50}
screenwidth = 480 - player.width()
screenheight = 272 - player.width()
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Playera.x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Playera.y = Player[1].y - 2
end
if pad:down() and Player[1].y < screenheight then
Playera.y = Player[1].y + 2
end
move = true
while true do
pad = Controls.read()
LoadingTimer:start()
if GameStatus == "Loading" and LoadingTimer:time() >= 1 and LoadingTimer:time() < 50 then
screen:clear()
screen:print(194, 136, "Loading: 0%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 50 and LoadingTimer:time() > 100 then
screen:clear()
screen:print(194, 136, "Loading: 20%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 100 and LoadingTimer:time() > 150 then
screen:clear()
screen:print(194, 136, "Loading: 40%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 150 and LoadingTimer:time() > 200 then
screen:clear()
screen:print(194, 136, "Loading: 60%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 200 and LoadingTimer:time() > 250 then
screen:clear()
screen:print(194, 136, "Loading: 80%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 250 and LoadingTimer:time() > 300 then
screen:clear()
screen:print(194, 136, "Loading: 90%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() >= 300 and LoadingTimer:time() > 350 then
screen:clear()
screen:print(194, 136, "Loading: 100%", pink)
screen.flip()
end
if GameStatus == "Loading" and LoadingTimer:time() > 351 then
LoadingTimer:stop()
LoadingTimer:reset()
GameStatus = "Menu"
end
for blit_slides = 1, 3 do
screen:blit(slide[blit_slides].x, slide[blit_slides].y, slide[blit_slides].pic)
end
for move_slides = 1, 3 do
if move == true then
slide[move_slides].x = slide[move_slides].x + 2
end
end
for repeat_slides = 1, 3 do
if slide[repeat_slides].x > 480 then
slide[repeat_slides].x = -960
end
end
if pad:start() and move == true then
move = false
elseif pad:start() and move == false then
move = true
end
screen.waitVblankStart()
screen.flip()
end
i have been trying for months to get it to work ive started over from scratch 2 now andam hoping one you all can get it working
i think you are starting to much thing @ one time and thats not good for the ram
-= Double Post =-
and the timer is not good
i dont kwo exactualy but it shows it to fast so you cant see it
does anyone know how to make it so u exit out of the program by pressing start or something?
yeah thats what i thought but if i take out the timer and add
If background = nill
will that fix it?
Yes, but you have to know how to do button input. Check out ProgramLua, tutorial 3 for that. Then just do something like:Zitat:
Zitat von GuitarGod1134
if pad:start() then
os.exit()
end
I have been told this works, but haven't tested it.
okay guys im working on a simple application here. while in lua player starting this will access the memstick with the usb so u dont have to quit into the xmb. and so far this is what i have
System.usbDiskModeActivat e()
red = Color.new(255, 0, 0)
orange = Color.new(255, 102, 0)
screen:print(90, 60, "usb being accessed! Program by GuitarGod1134", red)
screen.flip()
while true do
screen.waitVblankStart()
end
and what im stuck on is how to make it so like when i press start or something it will stop accessing the memory stick and go back to lua player.
just showing my progress
Code:--kirE v0.1
--Coded by psphacker12.
white = Color.new(255, 255, 255)
black = Color.new(0,0,0)
red = Color.new(255,0,0)
green = Color.new(0,255,0)
blue = Color.new(0,0,255)
tiles = Image.load("data/new.png")
cyan = Color.new(0,255,255)
figure = Image.load("data/playerone.png")
white = Color.new(255, 255, 255)
font = Font.load("data/font/eighttrack.ttf")
font:setPixelSizes(0, 20)
bigfont = Font.load("data/font/eighttrack.ttf")
bigfont:setPixelSizes(0, 48)
gameover = Font.load("data/font/eighttrack.ttf")
gameover:setPixelSizes(0, 64)
range={60,100}
System.usbDiskModeActivate()
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 10%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 20%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 30%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 40%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 50%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 60%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 70%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 80%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 90%", white)
screen.flip()
screen.waitVblankStart(30)
screen:clear(blue)
screen:fontPrint(bigfont,130, 150, "Loading - 100%",white)
screen.flip()
screen.waitVblankStart(60)
screen:clear(blue)
Select = 1
maxSelect = 1
oldpad = Controls.read()
while true do
pad = Controls.read()
screen:clear()
if pad:up() and oldpad:up() ~= pad:up() then
Select = Select - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
Select = Select + 1
end
if Select > maxSelect then
Select = 1
elseif Select <= 0 then
Select = maxSelect
end
screen:clear(blue)
if Select == 1 then
screen:fontPrint(bigfont,150,150," kire v0.1", white)
screen:fontPrint(font,150,180, "coded by psphacker12", white)
end
if pad:cross() and Select == 1 then
break
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
counter = Timer.new()
level = 1
mapSource = {
"ffffffffffffffffffffffffffffff",
"fnnnononononononononononononnf",
"fnnnnononononononononononononf",
"fonnonbaaaaaaaaaaaaaaaaaaaaaaa",
"fnonnobonnnonnnonnnonnnonnbonf",
"fonbbnbnonononononononononbnof",
"fnobnobononnnonnnonnnonnnononf",
"fonbonbnnncccccccccccccccccccc",
"fnobnobnondnononononononononnf",
"fonbonbnnodonononononononononf",
"fnobnobnondnonnondddddnonnnnof",
"cccbnnbonndnnonononondnonnnonf",
"fnobbnbnondnononononodonononnf",
"fnnnnnbnnoddddddddddddononnonf",
"fnnnnnonononononononononononof",
"fonnnnnnnnnnnnnnnnnnoooonnnnnf",
"ffffffffffffffffffffffffffffff"
}
board = Image.createEmpty(480, 272)
function drawTile(tile, x, y)
tile = string.byte(tile, 1) - string.byte("a")
local tileX = math.mod(tile, 4)
local tileY = math.floor(tile / 4)
board:blit(16 * x, 16 * y, tiles, 17 * tileX + 1, 17 * tileY + 1, 16, 16, false)
end
map = {}
for y = 1, 17 do
line = mapSource[y]
map[y] = {}
for x = 1, 30 do
tile = string.sub(line, x, x)
map[y][x] = tile
drawTile(tile, x - 1, y - 1)
end
end
playerX = 6
playerY = 14
animation = 0
animationDirection = 1
animationSlowDown = 0
speedStep = 0
dx = 0
dy = 0
score = 0
while true do
counter:start()
currentTime = counter:time()
if currentTime >= 50000 then
screen:clear(blue)
screen:fontPrint(font,180,150,"Game Over",white)
screen:fontPrint(font,180,180,"press start", white)
if pad:start() and Select == 1 then
break
end
screen.flip()
screen.waitVblankStart(60)
end
pad = Controls.read()
if pad:select() then
screen:save("screenshot.png")
end
if pad:start() and Select == 1 then
break
end
if speedStep == 0 then
oldPlayerX = playerX
oldPlayerY = playerY
playerX = playerX + dx
playerY = playerY + dy
newTile = map[playerY][playerX]
if newTile ~= "n" and newTile ~= "p" and newTile ~= "o" then
playerX = oldPlayerX
playerY = oldPlayerY
end
if newTile == "p" then score = score + 5 end
if newTile == "o" then score = score + 1 end
if newTile == "p" or newTile == "o" then
map[playerY][playerX] = "n"
drawTile("n", playerX - 1, playerY - 1)
end
dx = 0
dy = 0
else
if pad:up() then
dy = -1
elseif pad:down() then
dy = 1
elseif pad:left() then
dx = -1
elseif pad:right() then
dx = 1
end
end
speedStep = speedStep + 1
if speedStep == 5 then
speedStep = -1
end
screen:blit(0, 0, board, 0, 0, board:width(), board:height(), false)
screen:blit((playerX - 1) * 16 - 4, (playerY - 1) * 16 - 4, figure, 1 + 25 * animation, 1, 24, 24)
animationSlowDown = animationSlowDown + 1
if animationSlowDown == 3 then
animationSlowDown = 0
animation = animation + animationDirection
if animation == 4 then
animationDirection = -1
elseif animation == 0 then
animationDirection = 1
end
end
screen:fontPrint(font,15, 20, "Current Score: " .. score, white)
screen.waitVblankStart()
screen:flip()
oldpad = pad
end
i usuallly define all the colors just in case i use them
orZitat:
Zitat von ARza
if pad:start() then
break
end
hey i know how to exit using the start button, but now pause the game how can i do this???
at the start of the code somewhere put
in your main loop putCode:function paused()
resumeok=0
while true do
pad=Controls.read()
resumeok=resumeok+1
screen:clear()
screen:print(180,160,"Game Paused", anycolour)
screen:print(180,150,"Press Start to Continue",anycolour)
if resumeok>100 and pad:start() then
resumeok=0
break
end
screen.waitVblankStart()
screen.flip()
end
end
Now i need some help, I got thisCode:if pad:start() then
paused()
end
i get the message cant compare a number to a string. I completely understand why, but how can i get around this?Code:--Before the main loop
file=io.open("highscore.txt","r")
highscore=file:read()
file:close()
--In the main loop
if score<=highscore then
file=io.open("highscore.txt","w")
file:write(score)
file:close()
end
Use file:read(*n), which returns a number instead of a string.Zitat:
Zitat von JoeDaStudd
Thanks I tried that before, but forgot the speech marks around the *n, lol. Great help thanks
dude. u can optimize that code like 10x better: here is a optimized version if ur code:Zitat:
Zitat von %chrono trigger%
try that. if it gives errors, try to fix them, otherwise tell me.Code:
Spoiler for Optimized Code:
BTW, thx for using my tut!!:tup:
okay,i have a highscore menu like this
BUT you have to HOLD the X button just to view the highscore.Code:if pad:cross() and Select == 2 then
screen:blit(0, 0, background)
screen:fontPrint(bigfont,150,150, "highscore:" .. highscore, white)
screen.waitVblankStart()
if pad:circle() then
return
end
how can i make it like if u press circle then it returns you to the menu???
plz reply
make a variable
there is other ways, but that should doCode:if pad:cross() then
variable = 1
elseif pad:circle() then variable= 2 end
if variable == 1 then
-- view highscore
end
if variable == 2 then
-- menu
end
Posted in error.
ok but now if you are viewing the highscore what function do i use to make it return to the menu?
You just make another variable...
if screen == 1 then....