 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Iximon
Joined: 08 Sep 2005 Posts: 5
|
Posted: Wed Sep 21, 2005 10:51 pm Post subject: help. problem with gravity and block. |
|
|
i have made a array, and then i print the "grass" object, in the x and y and all working but, my gravity and block dosent work, i had to write a new when the array come. it's the last part of the code. help me please.
| Code: | background = Image.load("myimages/background.png")
-- ladda bakgrundsbild
player = Image.load("myimages/marioright2.png")
-- ladda spelarbild
board = Image.load("myimages/board.png")
-- ladda animation
moveright1 = Image.load("myimages/marioright1.png")
moveright2 = Image.load("myimages/marioright2.png")
moveright3 = Image.load("myimages/marioright3.png")
moveleft1 = Image.load("myimages/marioleft1.png")
moveleft2 = Image.load("myimages/marioleft2.png")
moveleft3 = Image.load("myimages/marioleft3.png")
grass = Image.load("myimages/grass.png")
sky = Image.load("myimages/sky.png")
-- marios startbild
player = moveright1
-- ladda board
playerx = 100
playery = 100
-- animeringen börja på 0
move = 0
-- var x och y kordinaterna ska vara ifrån start
speed = 1
-- bestämmer hastigheten på player
green = Color.new(0, 255, 0)
-- delkarera green till färgen grön
-- detta är för animeringen av mario
bPressOnce1 = 0
bPressOnce2 = 0
-- storleken på värden.
sizeX = 30
sizeY = 17
array = {}
for x=0,sizeX do
array[x] = {}
for y=0,sizeY do
array[x][y] = 0
end
end
while true do
pad = Controls.read() -- kontrollerna
if pad:left() then
if bPressOnce1 == 0 then
move= 0
end
bPressOnce1 = true;
playerx = playerx - speed
move = move + 1
if move == 1 then
player = moveleft1
end
if move == 6 then
player = moveleft2
end
if move == 11 then
player = moveleft3
end
if move == 16 then
move = 0
end
end
if pad:left() == 0 then
bPressOnce1 = false
end
if pad:right() then
if bPressOnce2 == 0 then
move = 0
end
bPressOnce2 = true;
playerx = playerx + speed
move = move + 1
if move == 1 then
player = moveright1
end
if move == 6 then
player = moveright2
end
if move == 11 then
player = moveright3
end
if move == 16 then
move = 0
end
end
if pad:right() == 0 then
bPressOnce2 = false
end
if pad:up() then
playery = playery - 3
end
if pad:down() then
end
if pad:cross() then
break
end
if pad:triangle() then
speed = speed + 0.5
end
if pad:square() then
speed = speed - 0.5
end
if playerx > 464 then -- blockera så att den inte kan åka utanför skärmen :)
playerx = 464
end
if playerx < 0 then
playerx = 0
end
if playery > 256 then
playery = 256
end
if playery < 0 then
playery = 0
end --här sluta blockeringen
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
-- blitta bakgrunden till skärmen
screen:blit(playerx, playery, player)
array[29][16] = 1
array[28][16] = 1
array[27][16] = 1
array[26][16] = 1
array[25][16] = 1
array[24][16] = 1
array[23][16] = 1
array[22][16] = 1
array[21][16] = 1
array[20][16] = 1
array[19][16] = 1
array[18][16] = 1
array[17][16] = 1
array[16][16] = 1
array[15][16] = 1
array[14][16] = 1
array[13][16] = 1
array[12][16] = 1
array[11][16] = 1
array[10][16] = 1
array[9][16] = 1
array[8][16] = 1
array[7][16] = 1
array[6][16] = 1
array[5][16] = 1
array[4][16] = 1
array[3][16] = 1
array[2][16] = 1
array[1][16] = 1
array[0][16] = 1
for x=0, sizeX do
for y=0, sizeY do
if array[x][y] == 1 then
screen:blit(x*16, y*16, grass)
end
if array[x][y] == 2 then
screen:blit(x*16, y*16, sky)
end
end
end
--blitta player till skärmen
--screen:blit(0, 0, board)
screen:print(4, 4, "Speed:", green)
screen:print(50, 4, speed, green)
screen:print(4, 14, "X pos:", green)
screen:print(50, 14, playerx, green)
screen:print(4, 24, "Y pos:", green)
screen:print(50, 24, playery, green)
-- skriver ut speed, Y och X värden i vänstra hörnet på skärmen
screen.waitVblankStart()
screen.flip()
-- vänd skärmen så att man ser allt.
tilex = playerx / 16
tiley = playery / 16
if array[tilex][tiley] == 2 then
playery = playery
end
if array[tilex][tiley] == 1 then
playery = playery + 3
end
end |
|
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Thu Sep 22, 2005 4:06 am Post subject: |
|
|
huh
o could you upload a ZIP-package? so its possible to test the code without much work?
o should split up the main while loop and put code to functions (eg controls)
to:
| Code: |
function doControls()
pad = Controls.read() -- kontrollerna
if pad:left() then
if bPressOnce1 == 0 then
move= 0
end
bPressOnce1 = true;
playerx = playerx - speed
move = move + 1
if move == 1 then
player = moveleft1
end
if move == 6 then
player = moveleft2
end
if move == 11 then
player = moveleft3
end
if move == 16 then
move = 0
end
end
if pad:left() == 0 then
bPressOnce1 = false
end
if pad:right() then
if bPressOnce2 == 0 then
move = 0
end
bPressOnce2 = true;
playerx = playerx + speed
move = move + 1
if move == 1 then
player = moveright1
end
if move == 6 then
player = moveright2
end
if move == 11 then
player = moveright3
end
if move == 16 then
move = 0
end
end
if pad:right() == 0 then
bPressOnce2 = false
end
if pad:up() then
playery = playery - 3
end
if pad:down() then
end
if pad:cross() then
break
end
if pad:triangle() then
speed = speed + 0.5
end
if pad:square() then
speed = speed - 0.5
end
end
--in while use
while true do
doControls()
end
|
this does pretty the same thing as yours, but you can exchange controls easily and its easier to see whats going on
note: english comments would help more :))
| Quote: | | my gravity and block dosent work, i had to write a new when the array come. it's the last part of the code. |
what do you mean, did not get the point, sorry | Code: | tilex = playerx / 16
tiley = playery / 16
|
tilex and tiley are indexes(integer) --> no float --> rounding?
| Code: |
if array[tilex][tiley] == 2 then
playery = playery
end |
no need to remind lua which value playery is :) _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
cgruber
Joined: 06 Sep 2005 Posts: 36
|
Posted: Thu Sep 22, 2005 7:17 am Post subject: |
|
|
General gravity concept that I use with my platform games is that you are always falling regardless.
When you jump your still falling but your acceleration upwards is greater than the downward acceleration.
When your standing on a platform your still fallling it's just that the object is holding you in place.
Worked pretty well for me in the past. |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Thu Sep 22, 2005 7:22 am Post subject: |
|
|
| cgruber wrote: | General gravity concept that I use with my platform games is that you are always falling regardless.
When you jump your still falling but your acceleration upwards is greater than the downward acceleration.
When your standing on a platform your still fallling it's just that the object is holding you in place.
Worked pretty well for me in the past. |
it works as it does in reality :D
may you support us wie a sample (or more?)
greets
lumo, who is interested how cgruber solves it _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
cgruber
Joined: 06 Sep 2005 Posts: 36
|
Posted: Thu Sep 22, 2005 7:48 am Post subject: |
|
|
| I think I'll probably be making a platform psp game in the near future so I'll try to contribute. |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Thu Sep 22, 2005 7:53 am Post subject: |
|
|
i will also add some more src files to my page soon (distance vector collsion maybe :) ) _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| 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
|