Step 5: X-Wing Firing Mechanism

Goal:


We are going to start working on our combat mechanics of the game. The first thing we need to do is to program which button on the keyboard we want to press to fire the laser.

We are going to use the spacebar to tell our game when to create a clone of the lasers. Once the clone is made, then the lasers code will take over and actually move it across the screen.

We also need to add a delay to our firing mechanism or else the X-Wing will just throw out a constant stream of lasers.

Steps:

  1. From the sprite menu, select the one called X_Wing.
  2. From Events, place a when space key pressed block.
  3. From Control, place a create clone of myself block, and change it to Red_laser.
  4. From Control, press a wait block and set it to 0.5.

Code:


Click to replay