Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 3.33 KB | None | 0 0
  1. SCREEN _NEWIMAGE(1280, 720, 256)
  2. CLS
  3. _DISPLAY
  4. A = 0
  5. R = 10      ' Rotational Speed (ie by how many Degrees per keypress the rotation will change, higher number = faster rotation)
  6. DIM Player(11) AS _FLOAT 'Creates the Array for the Player (X, Y, X0, Y0, X1, Y1, X2, Y2, X3, Y3, SP)
  7.  
  8. Player(0) = 640     ' Actual (X) Position of the Player
  9. Player(1) = 360     ' Actual (Y) Position of the Player
  10. 0
  11. F = 0
  12. Player(2) = 0
  13. Player(3) = -30     ' Position of the first point of the Player
  14.  
  15. Player(4) = 10
  16. Player(5) = 20      ' Second point
  17.  
  18. Player(6) = 0
  19. Player(7) = 10      ' Third point
  20.  
  21. Player(8) = -10
  22. Player(9) = 20      ' Forth point
  23.  
  24. Player(10) = 0      ' Speed of the Player
  25.  
  26.  
  27. 1
  28. IN$ = INKEY$
  29. SELECT CASE IN$     ' Checks the Keyboard Buffer (basically reads the Keyboard)
  30.     CASE "w"
  31.         Player(10) = Player(10) - .05   ' Changes Player Speed (Forwards)
  32.     CASE "s"
  33.         Player(10) = Player(10) + .05   ' Changes Player Speed (Backwards)
  34.  
  35.  
  36.     CASE "e"    ' Rotates the Player (Clockwise)
  37.         A = R
  38.         A1 = A1 - R
  39.         IF A1 < 0 THEN      ' Since A1 (Angle1) is supposed to be and Angle it needs to underflow to 360 and never reach Negative Numbers
  40.             A1 = A1 + 360
  41.         END IF
  42.  
  43.     CASE "q"    ' Rotates the Player (Counter-Clockwise)
  44.         A = -R
  45.         A1 = A1 + R
  46.         IF A1 > 360 THEN    ' Same as CASE "e" but this one overflows from 359 to 0 since 360° = 0°
  47.             A1 = A1 - 360
  48.         END IF
  49.  
  50.  
  51.     CASE "r"                ' Resets the Player's Rotation and Speed, Position stays the same though
  52.         A = 0
  53.         A1 = 0
  54.         F = 1
  55.     CASE ELSE
  56.         PRINT "IDLE"
  57.         A = 0
  58. END SELECT
  59.  
  60. IF F = 1 GOTO 0
  61. Player(0) = Player(0) + Player(10) * SIN(A1 / 180 * _PI)    ' Moves the Actual (X) Position of the Player in the direction of the Angle A1
  62. Player(1) = Player(1) + Player(10) * COS(A1 / 180 * _PI)    ' Moves the Actual (Y) Position of the Player in the direction of the Angle A1
  63. PRINT A1            ' Debug Information (Angle for Directional Movement)
  64.  
  65.  
  66. PRINT Player(10)    ' Debug Information (Speed of the Player)
  67. FOR I = 2 TO 8 STEP 2   ' Loop for rotating every Point of the player around the Actual position using the Angle A
  68.     PRINT Player(I); Player(I + 1) ' Debug Information (Coordinates of each point before rotation)
  69.     X1 = Player(I) + Player(0)
  70.     Y1 = Player(I + 1) + Player(1)
  71.     CALL rotate(Player(0), Player(1), X1, Y1, A / 180 * _PI)    ' First time using a Subroutine! even though it is not nessesary.
  72.     Player(I) = X1 - Player(0)
  73.     Player(I + 1) = Y1 - Player(1)
  74. NEXT
  75.  
  76.  
  77. PSET (Player(0), Player(1)), _RGB(255, 0, 0)
  78. PSET (Player(10) + Player(0), Player(11) + Player(1)), _RGB(0, 255, 0)
  79. PSET (Player(8) + Player(0), Player(9) + Player(1)), 15
  80.  
  81. FOR I = 2 TO 8 STEP 2
  82.     LINE -(Player(I) + Player(0), Player(I + 1) + Player(1)), _RGB(255, 255, 255)
  83. NEXT
  84.  
  85.  
  86. _DISPLAY        ' Afer everything has been drawn the Screen updates and afterwards clears itself (which is not visble anymore, meaning this prevents flickering!)
  87. CLS
  88.  
  89. GOTO 1
  90.  
  91. SUB rotate (X0, Y0, X1, Y1, A0)         ' Subroutine for rotating point X1, Y1 around X0, Y0, at an Angle of A0
  92.     Xnew = COS(A0) * (X1 - X0) - SIN(A0) * (Y1 - Y0) + X0
  93.     Ynew = SIN(A0) * (X1 - X0) + COS(A0) * (Y1 - Y0) + Y0
  94.     X1 = Xnew
  95.     Y1 = Ynew
  96.     A0 = 0
  97.     PRINT "Rotated!", X1; Y1            ' Debug Information (Shows the Coordinates of each point after the rotation)
  98. END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement