Hi all, just done a little joypad code adding to the code within the Help bar within BMax. Provides some block movement code with some simple acceleration and deceleration logic involved. Not to function heavy, hope it helps someone.
regards,
Blitzplotter
' testjoy.bmx '----------------------- ' M Gormley - 7 Jul 07 '----------------------- ' added some simple block moving code via analogue sticks on joypad ' rudimentary acceleration and deceleration incorporated '----------------------- Import Pub.FreeJoy Strict If Not JoyCount() RuntimeError "No joystick found!" Global xmax = 640 Global ymax = 480 Global xdot = 300 Global ydot = 300 Global block_size = 10 ' size in pixels of the movable square Global xchanged = 0 Global ychanged = 0 Global zchanged = 0 Global rchanged = 0 Global vchanged = 0 Global uchanged = 0 Global x = 0 Global y = 0 Global xa,ya,ua,va,za,ra Global xspeedy,xslow_accel, yspeedy, yslow_accel, slow_x_decel, slow_y_decel, xneg, yneg Graphics xmax,ymax Function speed(p#, xmove,ymove) If xspeedy <=10 If xslow_accel > 5 xspeedy = xspeedy + 1 xslow_accel = 0 Else xslow_accel = xslow_accel + 1 EndIf EndIf If yspeedy <=10 If yslow_accel > 5 yspeedy = yspeedy + 1 yslow_accel = 0 Else yslow_accel = yslow_accel + 1 EndIf EndIf Print "xspeedy" + xspeedy + "yspeedy" + yspeedy End Function Function drawprop(n$,p#,y) Local w DrawText n$,0,y w=Abs(p)*256 If p<0 DrawRect 320-w,y,w,16 Else DrawRect 320,y,w,16 EndIf End Function Local t=0 While Not KeyHit(KEY_ESCAPE) Cls SetColor 255,255,255 Local n=JoyCount() DrawText "joycount="+n,0,0 DrawText "JoyName(0)="+JoyName(0),0,20 DrawText "JoyButtonCaps(0)="+Bin$(JoyButtonCaps(0)),0,40 DrawText "JoyAxisCaps(0)="+Bin$(JoyAxisCaps(0)),0,60 For Local i=0 To 31 SetColor 255,255,255 If JoyDown(i) SetColor 255,0,0 DrawOval i*16,80,14,14 Next SetColor 255,255,0 xa= JoyX(0) ya= JoyY(0) za= JoyZ(0) ra= JoyR(0) ua= JoyU(0) va= JoyV(0) If xa <> 0 xchanged = 1 speed(xa,1,0) Print "x" If xa < 0 xneg = -1 Else xneg = 1 EndIf EndIf If ya <> 0 ychanged = 1 speed(ya,0,1) Print "y" If ya < 0 yneg = -1 Else yneg = 1 EndIf EndIf If za <> 0 zchanged = 1 speed(za,1,0) Print "z" EndIf If ra <> 0 rchanged = 1 speed(ra,0,1) Print "r" EndIf ' If ua <> 0 ' uchanged = 1 ' speed(ua) ' Print "u" ' EndIf ' If va <> 0 ' vchanged = 1 ' speed(va) ' Print "v" ' EndIf drawprop "JoyX=",xa,100 drawprop "JoyY:",ya,120 drawprop "JoyZ:",za,140 drawprop "JoyR:",ra,160 drawprop "JoyU:",ua,180 drawprop "JoyV:",va,200 drawprop "JoyHat:",JoyHat(0),220 drawprop "JoyWheel:",JoyWheel(0),240 DrawRect 0,280,t,10 t=(t+1)&511 If xchanged xchanged = 0 If xdot + (xa*xspeedy) <= xmax xdot = xdot + (xa*xspeedy) Print"xchanged" + xdot EndIf Else If xspeedy > 0 If slow_x_decel > 5 xspeedy = xspeedy -1 slow_x_decel = 0 Print "slowing" + xspeedy If xdot + xspeedy <= xmax xdot = xdot + (xspeedy * xneg) Print"xchanged" + xdot EndIf Else slow_x_decel = slow_x_decel +1 EndIf EndIf EndIf If ychanged ychanged = 0 If ydot + (ya*yspeedy)<= yMax ydot = ydot + (ya*yspeedy) Print"xchanged" + ydot EndIf Else If yspeedy > 0 If slow_y_decel > 5 yspeedy = yspeedy -1 slow_y_decel = 0 Print "slowing" + yspeedy If ydot + yspeedy<= yMax ydot = ydot + (yspeedy * yneg) Print"xchanged" + ydot EndIf Else slow_y_decel = slow_y_decel +1 EndIf EndIf EndIf 'draw the block For x = 1 To block_size For y = 1 To block_size Plot xdot+x,ydot+y Next Next Flip Wend End
regards,
Blitzplotter