different movement speeds

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

Moderators: Shine, Insert_witty_name

Post Reply
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

different movement speeds

Post by imhotep »

-- now obsolete code, see above for new---
Last edited by imhotep on Wed Mar 08, 2006 9:52 pm, edited 1 time in total.
ShUr1k3n
Posts: 42
Joined: Sun Oct 16, 2005 9:04 pm

Post by ShUr1k3n »

When u do this:

Code: Select all

welle = {   w1=Image.load("wave0000.jpg"),
      w2=Image.load("wave0001.jpg"),
      w3=Image.load("wave0002.jpg"),
      w4=Image.load("wave0003.jpg"),
      w5=Image.load("wave0004.jpg"),
      w6=Image.load("wave0005.jpg"),
      w7=Image.load("wave0006.jpg"),
      w8=Image.load("wave0007.jpg"),
      w9=Image.load("wave0008.jpg"),
      w10=Image.load("wave0009.jpg"),
      w11=Image.load("wave0010.jpg")  }
U should use:

Code: Select all

welle = {   [1]=Image.load("wave0000.jpg"),
      [2]=Image.load("wave0001.jpg"),
      [3]=Image.load("wave0002.jpg"),
      [4]=Image.load("wave0003.jpg"),
      [5]=Image.load("wave0004.jpg"),
      [6]=Image.load("wave0005.jpg"),
      [7]=Image.load("wave0006.jpg"),
      [8]=Image.load("wave0007.jpg"),
      [9]=Image.load("wave0008.jpg"),
      [10]=Image.load("wave0009.jpg"),
      [11]=Image.load("wave0010.jpg")  }
and...when u use:

Code: Select all

screen:blit(38,20,welle["w" .. wave])
Change to:

Code: Select all

screen:blit(38,20,welle[wave])
Do the same thing with ur "player_straight"...

Regards,

ShUr1k3n
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

thx,not really the answer but helpful anyways, i'm trying an approach with keyframes right now.

how can i check if a division by a certain number leaves a rest, say .034 or so or not? that would be the key...
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

I (AS A TOTAL NOOB!) DID IT!

i made a function that works with a keyframe concept, check it out!

Code: Select all

-- objects

timeline=1000
frames=1

object = {wave,straight}

player_straight = {	 [1]=Image.load("s1.png"),
		 	         [2]=Image.load("s1.png"),
			         [3]=Image.load("s3.png")   }

welle = {   [1]=Image.load("wave0000.jpg"),
		[2]=Image.load("wave0001.jpg"),
		[3]=Image.load("wave0002.jpg"),
		[4]=Image.load("wave0003.jpg"),
		[5]=Image.load("wave0004.jpg"),
		[6]=Image.load("wave0005.jpg"),
		[7]=Image.load("wave0006.jpg"),
		[8]=Image.load("wave0007.jpg"),
		[9]=Image.load("wave0008.jpg"),
		[10]=Image.load("wave0009.jpg"),
		[11]=Image.load("wave0010.jpg")  }

function frameskip(objectnumber,frame,limit)
--is frame nil or zero?
	if frame==0 or frame==nil then 
		frame=1 end

--is object==nil?
if object[objectnumber]==nil then
	object[objectnumber]=1 end

--frames for every timer : 1000-->reset follows 
--how many times is timeline dividable by frame?
	res=math.floor(timeline/frame) 

	for i=1,res do
		if i*frame==frames then 
			
			-- increase object[..] by 1
			-- test if limit of animation steps is reached
		
			object[objectnumber]=object[objectnumber]+1

				if object[objectnumber]>limit then 
					object[objectnumber]=1 
				end
		end
	end


--count++ & reset the timer if >timeline
frames=frames+1
if frames>=timeline then frames=1 end

number=object[objectnumber]

return number

end

function anim_surfer()
	
	pad=Controls.read()
	
	if pad:left() then
		if xpos>=50 then xpos=xpos-10 end
		screen:blit(xpos,ypos,player_left,true)
		
	elseif pad:right() then
		if xpos<380 then xpos=xpos+10 end
		screen&#58;blit&#40;xpos,ypos,player_right,true&#41;
	
	elseif pad&#58;up&#40;&#41; then 
		frameskip&#40;2,60,1&#41;	

	else
	
	-- straight movement, three animation steps
		
		frameskip&#40;2,20,3&#41;
	
		screen&#58;blit&#40;xpos,ypos,player_straight&#91;number&#93;,true&#41;
       end

end


so objectnumber is 1 for wave and 2 for straight (movement of the surfer)
frame is at which frame and x*frame the change in the animation step occurs
limit is the number of animation steps

hope someone likes it :)

any suggestions??
Post Reply