October 28, 2020, 05:32:20 AM

Author Topic: [bmx] TMouseStick by ralphy [ 1+ years ago ]  (Read 1050 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] TMouseStick by ralphy [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : TMouseStick
Author : ralphy
Posted : 1+ years ago

Description : Class: TMouseStick
Methods: Init(smoothmove), Refresh
Properties: Up, Down, Lft, Rght (all readonly)
(increasing the smoothmove parameter delays the change of a direction from 1 To 0 when no movement is detected)


Code :
Code: BlitzMax
  1. 'BlitzMax - MouseStick Class Module - Parablax 2006
  2. 'Emulates the mouse as a digital joystick
  3. 'Class: TMouseStick
  4. 'Methods: Init(smoothmove), Refresh
  5. 'Properties: Up, Down, Lft, Rght (all readonly)
  6. '(increasing the smoothmove parameter delays the change of a direction from 1 To 0 when no movement is detected)
  7.  
  8. Strict
  9.  
  10. Local MouseStick:TMouseStick
  11. MouseStick = New TMouseStick
  12. MouseStick.Init(20)
  13. Graphics 320,240,0
  14. HideMouse()
  15. While Not MouseHit(1)
  16.         Cls
  17.         SetColor 200,200,0
  18.         DrawText "Wiggle the mouse - Click to exit",0,0
  19.         SetColor 200,200,200
  20.         If mousestick.up Then DrawText "up",140,60
  21.         If mousestick.Down Then DrawText "down",140,180
  22.         If mousestick.Lft Then DrawText "left",80,120
  23.         If mousestick.Rght Then DrawText "right",200,120
  24.         MouseStick.Refresh     
  25.         Flip
  26. Wend
  27. End
  28.  
  29. 'Types
  30. Type TMouseStick
  31.         Field Up,Down, Lft, Rght
  32.         Field xspeed[], yspeed[]
  33.        
  34.         Method Init(smoothmove)
  35.                 xspeed = New Int[smoothmove]
  36.                 yspeed = New Int[smoothmove]
  37.         End Method
  38.        
  39.         Method Refresh()
  40.                 Local i, j, xspeed_chk, yspeed_chk
  41.                
  42.                 For i = xspeed.length-1 To 1 Step -1
  43.                         xspeed[i] = xspeed[i-1]
  44.                         yspeed[i] = yspeed[i-1]
  45.                 Next
  46.        
  47.                 xspeed[0] =MouseX() -100
  48.                 yspeed[0] =MouseY() -100
  49.                 MoveMouse(100,100)
  50.        
  51.                 For j = 0 To xspeed.length-1
  52.                         xspeed_chk :+ xspeed[j]
  53.                         yspeed_chk :+ yspeed[j]
  54.                 Next
  55.  
  56.                 If xspeed_chk = 0 Then Rght = 0; Lft = 0
  57.                 If yspeed_chk = 0 Then Up = 0; Down = 0
  58.  
  59.                 If xspeed[0]<0 Then     Lft = 1; Rght = 0;
  60.                 If xspeed[0]>0 Then     Lft = 0; Rght = 1;
  61.                 If yspeed[0]<0 Then     Up = 1; Down = 0
  62.                 If yspeed[0]>0 Then     Up = 0; Down = 1
  63.         End Method
  64.        
  65. EndType


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal