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 |
P#55242 2018-08-16 13:07 ( Edited 2018-08-16 19:03)
You need to separate drawing and updating game state (and a game state to start with!)
Something like:
— game state local switch_state=true function _update() — note: using btnp to avoid auto-repeat if btnp(4) then switch_state=not switch_state end end function _draw() if switch_state then — draw for X else — draw rect for Y end end |
P#55252 2018-08-16 15:03 ( Edited 2018-08-17 07:51)
[Please log in to post a comment]