Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: bikemadness on June 07, 2015

Title: single action button push
Post by: bikemadness on June 07, 2015
moves a simple object around the screen using arrow keys
one action, per button push, at a time

Code: [Select]
open window 640,512
x=320
y=256
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
c=peek("port1")

if and(c,16)<>0 up=1
if up=1 u=u+1
if u>2 u=2
if u=2 up=0
if and(c,16)=0 u=0

if and(c,64)<>0 down=1
if down=1 d=d+1
if d>2 d=2
if d=2 down=0
if and(c,64)=0 d=0

if and(c,128)<>0 left=1
if left=1 l=l+1
if l>2 l=2
if l=2 left=0
if and(c,128)=0 l=0

if and(c,32)<>0 right=1
if right=1 r=r+1
if r>2 r=2
if r=2 right=0
if and(c,32)=0 r=0

if up=1 y=y-50
if down=1 y=y+50
if left=1 x=x-50
if right=1 x=x+50

if x<25 x=25
if x>615 x=615
if y<25 y=25
if y>485 y=485
rectangle x-25,y-25 to x+25,y+25
until (1=0)