help. problem with gravity and block.

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Iximon
Posts: 5
Joined: Thu Sep 08, 2005 6:16 am

help. problem with gravity and block.

Post by Iximon »

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: Select all

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&#58;blit&#40;0, 0, background, 0, 0, background&#58;width&#40;&#41;, background&#58;height&#40;&#41;, false&#41;
	-- blitta bakgrunden till skärmen
	
	screen&#58;blit&#40;playerx, playery, player&#41;
	
	array&#91;29&#93;&#91;16&#93; = 1
	array&#91;28&#93;&#91;16&#93; = 1
	array&#91;27&#93;&#91;16&#93; = 1
	array&#91;26&#93;&#91;16&#93; = 1
	array&#91;25&#93;&#91;16&#93; = 1
	array&#91;24&#93;&#91;16&#93; = 1
	array&#91;23&#93;&#91;16&#93; = 1
	array&#91;22&#93;&#91;16&#93; = 1
	array&#91;21&#93;&#91;16&#93; = 1
	array&#91;20&#93;&#91;16&#93; = 1
	array&#91;19&#93;&#91;16&#93; = 1
	array&#91;18&#93;&#91;16&#93; = 1
	array&#91;17&#93;&#91;16&#93; = 1
	array&#91;16&#93;&#91;16&#93; = 1
	array&#91;15&#93;&#91;16&#93; = 1
	array&#91;14&#93;&#91;16&#93; = 1
	array&#91;13&#93;&#91;16&#93; = 1
	array&#91;12&#93;&#91;16&#93; = 1
	array&#91;11&#93;&#91;16&#93; = 1
	array&#91;10&#93;&#91;16&#93; = 1
	array&#91;9&#93;&#91;16&#93; = 1
	array&#91;8&#93;&#91;16&#93; = 1
	array&#91;7&#93;&#91;16&#93; = 1
	array&#91;6&#93;&#91;16&#93; = 1
	array&#91;5&#93;&#91;16&#93; = 1
	array&#91;4&#93;&#91;16&#93; = 1
	array&#91;3&#93;&#91;16&#93; = 1
	array&#91;2&#93;&#91;16&#93; = 1
	array&#91;1&#93;&#91;16&#93; = 1
	array&#91;0&#93;&#91;16&#93; = 1

    for x=0, sizeX do
	  for y=0, sizeY do
	    if array&#91;x&#93;&#91;y&#93; == 1 then
		   screen&#58;blit&#40;x*16, y*16, grass&#41;
		end
		if array&#91;x&#93;&#91;y&#93; == 2 then
		   screen&#58;blit&#40;x*16, y*16, sky&#41;
		end
	  end
    end
	--blitta player till skärmen
	--screen&#58;blit&#40;0, 0, board&#41;
	screen&#58;print&#40;4, 4, "Speed&#58;", green&#41;
	screen&#58;print&#40;50, 4, speed, green&#41;
	screen&#58;print&#40;4, 14, "X pos&#58;", green&#41;
	screen&#58;print&#40;50, 14, playerx, green&#41;
	screen&#58;print&#40;4, 24, "Y pos&#58;", green&#41;
	screen&#58;print&#40;50, 24, playery, green&#41;
	-- skriver ut speed, Y och X  värden i vänstra hörnet på skärmen
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	-- vänd skärmen så att man ser allt.
	
	tilex = playerx / 16
	tiley = playery / 16
	
	if array&#91;tilex&#93;&#91;tiley&#93; == 2 then
		playery = playery
	end
	if array&#91;tilex&#93;&#91;tiley&#93; == 1 then
		playery = playery + 3
	end
end 
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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: Select all

function doControls&#40;&#41;
pad = Controls.read&#40;&#41; -- kontrollerna
   if pad&#58;left&#40;&#41; 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&#58;left&#40;&#41; == 0 then
      bPressOnce1 = false
   end


   if pad&#58;right&#40;&#41; 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&#58;right&#40;&#41; == 0 then
      bPressOnce2 = false
   end
   if pad&#58;up&#40;&#41; then
      playery = playery - 3
   end

   if pad&#58;down&#40;&#41; then
   end
   
   if pad&#58;cross&#40;&#41; then
      break
   end
   
   if pad&#58;triangle&#40;&#41; then
      speed = speed + 0.5
   end
   
   if pad&#58;square&#40;&#41; then
      speed = speed - 0.5
   end 
end

--in while use

while true do
 doControls&#40;&#41;
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 :))
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: Select all

   tilex = playerx / 16
   tiley = playery / 16
tilex and tiley are indexes(integer) --> no float --> rounding?

Code: Select all

   
   if array&#91;tilex&#93;&#91;tiley&#93; == 2 then
      playery = playery
   end 
no need to remind lua which value playery is :)
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
cgruber
Posts: 36
Joined: Tue Sep 06, 2005 6:38 am

Post by cgruber »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
cgruber
Posts: 36
Joined: Tue Sep 06, 2005 6:38 am

Post by cgruber »

I think I'll probably be making a platform psp game in the near future so I'll try to contribute.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
Post Reply