Log In  
Follow
pieceofcrazy

Cart #55452 | 2018-08-21 | Code ▽ | Embed ▽ | No License

I'm trying some animations, but i can't make the sprite rest. Any suggestions?

actor={}
actor.x=40
actor.y=30
actor.sprt=0
actor.spd=0.75

function move_d()
	actor.sprt+=0.125
	if actor.sprt>2.9 then
	 actor.sprt=1
	end
end

function move_u()
	actor.sprt+=0.125
	if actor.sprt>18.9
	or actor.sprt<17 then
	 actor.sprt=17
	end
end

function move_r()
	actor.sprt+=0.125
	if actor.sprt>4.9
	or actor.sprt<3 then
	 actor.sprt=3
	end
end

function move_l()
	actor.sprt+=0.125
	if actor.sprt>20.9
	or actor.sprt<19 then
	 actor.sprt=19
	end
end

function _update()
	if btn(3) then
		move_d()
		actor.y+=actor.spd
	elseif not btn() then
	 actor.sprt=0
	end

	if btn(2) then
		move_u()
		actor.y-=actor.spd
	elseif not btn() then
		actor.sprt=0
	end

	if btn(1) then
		move_r()
		actor.x+=actor.spd
	elseif not btn() then
		actor.sprt=0
	end

	if btn(0) then
		move_l()
		actor.x-=actor.spd
	elseif not btn() then
		actor.sprt=0
	end

end

function _draw()
	cls()
	spr(actor.sprt,actor.x,actor.y)
end
0 comments



Hi everyone! I know something about coding (very basics stuff) and I'm new to PICO-8.
I'm doing some tests, one of this consist in highlighting an object when the user switch between two objects.
I need some kind of switch, like: when you press 4 the first time highlight X, the second time Y, the following times switch to the other.
This is the code, sorry for bad english:

rect1_x1=5 rect1_y1=120
rect1_x2=20 rect1_y2=110

rect2_x1=5 rect2_y1=5
rect2_x2=20 rect2_y2=15

sex1=-1 sey1=-1
sex2=-1 sey2=-1

function _init()
	cls()
end

function _update()
 cls()
 if btn(4) then
 	sex1=rect2_x1-1
 	sey1=rect2_y1-1
 	sex2=rect2_x2+1
 	sey2=rect2_y2+1
 elseif btn(4) then
 	sex1=rect1_x1-1
 	sey1=rect1_y1-1
 	sex2=rect1_x2+1
 	sey2=rect1_y2+1
  else end
end

function _draw()

	--background-----------
	rectfill(0,0,127,127,1)

	--select---------------
	rectfill(sex1,sey1,
										sex2,sey2,10)

 --1--------------------
	rectfill(rect1_x1,rect1_y1,
										rect1_x2,rect1_y2,8)

	--2--------------------
		rectfill(rect2_x1,rect2_y1,
										rect2_x2,rect2_y2,8)
end 
1 comment