Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SCREEN _NEWIMAGE(1280, 720, 256)
- CLS
- _DISPLAY
- A = 0
- R = 10 ' Rotational Speed (ie by how many Degrees per keypress the rotation will change, higher number = faster rotation)
- DIM Player(11) AS _FLOAT 'Creates the Array for the Player (X, Y, X0, Y0, X1, Y1, X2, Y2, X3, Y3, SP)
- Player(0) = 640 ' Actual (X) Position of the Player
- Player(1) = 360 ' Actual (Y) Position of the Player
- 0
- F = 0
- Player(2) = 0
- Player(3) = -30 ' Position of the first point of the Player
- Player(4) = 10
- Player(5) = 20 ' Second point
- Player(6) = 0
- Player(7) = 10 ' Third point
- Player(8) = -10
- Player(9) = 20 ' Forth point
- Player(10) = 0 ' Speed of the Player
- 1
- IN$ = INKEY$
- SELECT CASE IN$ ' Checks the Keyboard Buffer (basically reads the Keyboard)
- CASE "w"
- Player(10) = Player(10) - .05 ' Changes Player Speed (Forwards)
- CASE "s"
- Player(10) = Player(10) + .05 ' Changes Player Speed (Backwards)
- CASE "e" ' Rotates the Player (Clockwise)
- A = R
- A1 = A1 - R
- IF A1 < 0 THEN ' Since A1 (Angle1) is supposed to be and Angle it needs to underflow to 360 and never reach Negative Numbers
- A1 = A1 + 360
- END IF
- CASE "q" ' Rotates the Player (Counter-Clockwise)
- A = -R
- A1 = A1 + R
- IF A1 > 360 THEN ' Same as CASE "e" but this one overflows from 359 to 0 since 360° = 0°
- A1 = A1 - 360
- END IF
- CASE "r" ' Resets the Player's Rotation and Speed, Position stays the same though
- A = 0
- A1 = 0
- F = 1
- CASE ELSE
- PRINT "IDLE"
- A = 0
- END SELECT
- IF F = 1 GOTO 0
- 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
- 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
- PRINT A1 ' Debug Information (Angle for Directional Movement)
- PRINT Player(10) ' Debug Information (Speed of the Player)
- FOR I = 2 TO 8 STEP 2 ' Loop for rotating every Point of the player around the Actual position using the Angle A
- PRINT Player(I); Player(I + 1) ' Debug Information (Coordinates of each point before rotation)
- X1 = Player(I) + Player(0)
- Y1 = Player(I + 1) + Player(1)
- CALL rotate(Player(0), Player(1), X1, Y1, A / 180 * _PI) ' First time using a Subroutine! even though it is not nessesary.
- Player(I) = X1 - Player(0)
- Player(I + 1) = Y1 - Player(1)
- NEXT
- PSET (Player(0), Player(1)), _RGB(255, 0, 0)
- PSET (Player(10) + Player(0), Player(11) + Player(1)), _RGB(0, 255, 0)
- PSET (Player(8) + Player(0), Player(9) + Player(1)), 15
- FOR I = 2 TO 8 STEP 2
- LINE -(Player(I) + Player(0), Player(I + 1) + Player(1)), _RGB(255, 255, 255)
- NEXT
- _DISPLAY ' Afer everything has been drawn the Screen updates and afterwards clears itself (which is not visble anymore, meaning this prevents flickering!)
- CLS
- GOTO 1
- SUB rotate (X0, Y0, X1, Y1, A0) ' Subroutine for rotating point X1, Y1 around X0, Y0, at an Angle of A0
- Xnew = COS(A0) * (X1 - X0) - SIN(A0) * (Y1 - Y0) + X0
- Ynew = SIN(A0) * (X1 - X0) + COS(A0) * (Y1 - Y0) + Y0
- X1 = Xnew
- Y1 = Ynew
- A0 = 0
- PRINT "Rotated!", X1; Y1 ' Debug Information (Shows the Coordinates of each point after the rotation)
- END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement