Vertical Shmup - Part 3 - Setting up the Player Spaceship
Now that we have the play area set up, let's create the player spaceship and work on the code for controlling it.
MENU: EDITOR > SPRITES (beginners tutorial)
Here's mine, but feel free to get creative with yours!
I'm going to add a second frame for the spaceship, which will display if the player users the THRUST key to move up the screen. It'll just have a little jetflame coming out the rear end of the ship. The quickest way to do this is:
M copy the current frame
I insert a new frame
K paste the original frame
and then edit it:
OK, that will do for the graphics for now, next we'll write some code for controlling the Spaceship, the rules I want are:
1) Left and right keys to move the space ship left and right
2) A Thrust key, which, when pressed, will move the player halfway up the screen, but if released the player will drift back to the bottom. When thrust is pressed we also want to display Frame 001 to show the jetflame
First, let's define our keys, I prefer QAOP Space:
MENU: EDITOR > KEYBOARD CONTROLS (beginners tutorial)
MENU: EVENTS > PLAYER (beginners tutorial)
To start with we'll add some basic MPAGD script that will handle movement:
EVENT PLAYER ; COLOURS ; ======================= SPRITEINK 69 ; Bright Cyan ink IF KEY UP ; Player presses up (thrust) LET FRAME = 1 ; switch to the frame that shows jetflame IF Y > 80 ; If player is below the 80 y pixel line SPRITEUP ; move player up SPRITEUP ; and up again (faster movement) ENDIF ELSE ; if player is not pressing thrust LET FRAME = 0 ; switch to the regular spaceship (no jetflame) SPRITEDOWN ; move player down ENDIF ; PLAYER MOVEMENT ; ==================== IF KEY LEFT ; has player pressed LEFT? IF CANGOLEFT ; can the player move left? SPRITELEFT ; yes, move player left SPRITELEFT ; and again (moves faster) ENDIF ENDIF IF KEY RIGHT ; has the player pressed RIGHT? IF CANGORIGHT ; yes, can the player move right? SPRITERIGHT ; yes, move player right SPRITERIGHT ; and again (moves faster) ENDIF ENDIF ; BOUNDARY CHECK ; ==================== IF Y >= BOTTOMEDGE ; has player gone beyond the bottom edge? LET Y = BOTTOMEDGE ; yes, keep them at the bottom edge ENDIF
Right, that's enough for now, let's build the game and see how it's working...
Success!, the ship can move left and right, thrust up and drift back down again.
Next, we are going to create a basic weapon for the player that they can fire
NEXT: PART 4: THE PLAYER WEAPON