Construct Game Development: Platformer Revisited, a 2D Shooter

Exclusive offer: get 50% off this eBook here
Construct Game Development Beginners Guide

Construct Game Development Beginners Guide — Save 50%

A guide to escalate beginners to intermediate game creators through teaching practical game creation using Scirra construct with this book and ebook.

$26.99    $13.50
by Daven Bigelow | June 2012 | Open Source

Construct Classic is a free, DirectX 9 game creator for Windows, designed for 2D games. Construct Classic uses an event-based system for defining how the game behaves, in a visual, human-readable way - you don't need to program or script anything at all. It's intuitive for beginners, but powerful enough for advanced users to work without hindrance. You never know when you’ll need a helping hand exploring its inner workings, or harnessing its raw power to do your bidding.

In this aticle by Daven Bigelow author of Construct Game Development Beginner's Guide, we shall:

  • Learn how to make a two-player platformer
  • Learn how to make objects shoot projectiles and create muzzle flashes

(For more resources on Game Development, see here.)

Before we start

As there is a large amount of ground to cover in this chapter, we'll be moving quickly through steps similar to those we've done before. If it's been a while since you've used Construct, then you may find it useful to read through a chapter or two again before continuing, because certain steps assume that you are able to complete acO ons we have performed in the past.

Multiplayer: getting your friends involved

We're ready to start our next game, a multiplayer side-scrolling shooter, but before we add any shooO ng, we'll need to have the multiplayer side-scroller part finished first. So let's get to it!

Time for action – creating the game assets and title screen

The first thing we will need to do is to create our game content and create the first layout of the game, the title screen.

  1. First, draw up our player graphics and guns. We'll want the torso to be a separate object from the legs for easier animation. Use red dots where the legs will be attached to as markers for image point placement later on. Also include drawings for three weapons: a pistol, an uzi, and a shotgun:
  2. Construct Game Development

  3. Next, we can draw up our enemies for the game. In this case, we'll use an enemy robot with a turret arm that shoots balls of plasma:
  4. Construct Game Development

  5. We'll also need some scenery and ground objects for the levels:
  6. Construct Game Development

  7. Finally, we'll need a graphic to tell the player to go onto the next screen when no enemies are present:
  8. Construct Game Development

  9. Now we can move on to starting our game. Create a new project and set its Name to SideShooter, and enter your Creator name. Then set the window size to 800 by 600.
  10. Create the global variables CanGoNext, CurrentScreen, NumPlayers, P1Lives, P2Lives, GameWonLost, and RespawnY with values 0, 0, 1, 3, 3, 0, and 100 respectively.
  11. Following that, rename the first layout to Title and its event sheet to Title events .
  12. On this layout, create the layers Text, Buttons, and Background in top-to-bottom order.
  13. Selecting the Background layer, create a Panel object and name it Background before setting its top corner filters to Green and bottom corner filters to DarkGreen. Stretch this object to cover the whole of the layout and lock the layer.
  14. Now, on the Buttons layer, create a sprite and draw a box with the word Play in it.
  15. PosiO on this object in the center of the layout. This will be the start button for our game and should have the name btnPlay.
  16. Next, add the Mouse & Keyboard and XAudio2 objects into the layout and give them the global property.
  17. In order to finish the layout design, create a Text object on the Text layer and set its name to Title and its text to SideShooter, and position it above the btnPlay object:
  18. Construct Game Development

  19. Switch over to the event sheet editor to add in a Start of layout event and use it to play a music file, Title.mp3, and loop it. This can be any title music you'd like, and it will also be played at the game's end screen.
  20. Next, create an event for the MouseKeyboard object with the condition Mouse is over object to check if the mouse overlaps btnPlay.
  21. Give this event the action Set colour filter for the btnPlay object to set the filter to Grey – 40.
  22. Now create an Else event to set the filter color back to White.
  23. In order to finish the event sheet, create an event with the condition On object clicked and select the object btnPlay.
  24. Add actions to this event to set the value of NumPlayers to 1 and the value of CurrentScreen to 0 before adding the final System action Next Layout:
  25. Construct Game Development

Time for action – designing the level

Now that we have our graphics created, we can put them into our second layout and make the first playable level.

  1. Now we're ready to create a level layout. Create a layout and name it Level1 and its event sheet Level1 events . Then create our main game event sheet Game.
  2. For the layout, set its width to a multiple of the screen width (800), and check the box for Unbounded scrolling. In the event sheet of this layout, include our main event sheet Game.
  3. Next, give this layout the layers HUD, Foreground, FrontScenery, Objects, LevelLights, ShadowCasters, BackScenery, and Walls in top-to-bottom order. After that, set the ScrollX and ScrollY rates of the HUD and Walls layers to 0%
  4. On the objects layer, create a Tiled Background object named Ground and give it the smaller light gray tile image. Ensure it has the Solid attribute and stretch and place some of them to form a level design.
  5. Now create a Sprite object with the light green tile image and name it CrateBox . Give it the Solid attribute as well and place some around the level too. Have its collisions mode set to Bounding box.
  6. Next, create a Sprite named ExitLevel and fill it with a solid color. Give it a width of 32 and stretch it so that it's taller than the display height (600). Then finish the object by checking the box for Invisible on start and placing it at the end of the level:
  7. Construct Game Development

  8. With the base layout complete, we can now add in three more invisible objects to handle scrolling. These are going to be Box objects with the names BackStopper, FrontStopper, and GoNextScreen.
  9. Have the BackStopper and FrontStopper objects colored red and marked Solid with a width of 120.
  10. Set the Hotspot property of the BackStopper object to Bottom-right, and the FrontStopper to Bottom-Left, before positioning them at 0,600 and 800,600 respectively.
  11. Next, have the GoNextScreen box colored green and a width of 32 as well as a Hotspot of Bottom-right. Position this object at 800,600:
  12. Construct Game Development

Time for action – creating player characters and conveyor belt objects

Now we can create our player character objects and also add moving and staO c conveyor belts into our level.

  1. We are now ready to create our player objects. Start by inserting a Sprite and paste the standing image of the player character legs into it. Have an image point named 1 at the red spot that we drew earlier, and then place the hotspot at the bottom-middle point of the image ( num-pad 2) as shown in the following image:
  2. Construct Game Development

  3. Name this sprite P1Legs, and for its Default animation, set the animation Tag to Stopped before checking the Auto Mirror checkbox in the main Appearance settings of the object.
  4. Next, give it the platform behavior with the settings shown as follows:
  5. Construct Game Development

  6. Next, scroll down to the Angle properties box and check the Auto mirror checkbox.
  7. Now we are ready to add the object to a family. Scroll up to the Groups sub-group Families and click on Add to bring up the Construct: New Family screen. Note that Construct Classic comes with some default families, but will also display any family that have been used previously:
  8. Construct Game Development

  9. Click on Edit Families to bring up the Construct: Families editor screen. On this screen, enter the name Legs and click on the + button:
  10. Construct Game Development

  11. We can now draw the family image using the image editor that appears, shown as follows:
  12. Construct Game Development

  13. After finishing the image, save it by exiting out of the image editor and check that the family is now in the list. Once finished, click on Done to return to the family selection page.
  14. Now select the Legs family and click on Ok:
  15. Construct Game Development

  16. Now we can add the animation Walk in for our object. In this animation, set the Tag to Walking, and add the other leg sprites so they match the following image:
  17. Construct Game Development

  18. Now change the settings of the animation to have an Animation speed of 5 and check the Loop checkbox.
  19. Next, copy the object and right-click on the layout to use the Paste Clone option, and name this clone as P2Legs. In the Platform behavior for this object, change the Control setting to Player 2 .
  20. Now go into the project properties and scroll to the bottom section, Controls. Click on the Add / Edit option for the Manage Controls setting at the bottom to bring up the controls box:
  21. Construct Game Development

  22. Use the red X button to remove all of the controls below Jump. Then click on the Green plus button to add a new control. Select this control and click on the Pencil and paper button to change its name to Move Left.
  23. Click on the Key name for this control to bring up a drop-down box and set it to A.
  24. Now, in the Player drop-down box, select Player 2 for this control. It should match the following screenshot:
  25. Construct Game Development

  26. Now continue to add controls until it matches the settings in the following screenshot before clicking on Done:
  27. Construct Game Development

  28. Next, we'll create the bodies of our player objects. Create a Sprite called P1Torso and paste the normal body image of our character into it. Then position the Hotspot in the bottom-middle of the body. Give this sprite an image point 1 in the centre of its hand:
  29. Construct Game Development

  30. Rename the Default animation to Normal and set its speed to 0, and check the Auto Mirror checkbox for this object as well.
  31. Create two more animations, Up and Down respectively. Set their frames to match the following screenshot:
  32. Construct Game Development

  33. Now give the object a new family and name it Body. Then create Private Variables of names Weapon, Ammo, and GunAngle . Set the starting values to 0, 99, and 0 respectively.
  34. Clone this object as well to create P2Torso, and replace the sprites with the second player graphics.
  35. Now select P1Legs and scroll down to the Groups | Container properties to click on Add object and select P1Torso. The properties box and sprites should match the following screenshot:
  36. Construct Game Development

  37. Next, put the P2Torso object into the container P2Legs using the same method.
  38. Now, on the Walls layer, create a Tiled Background object named FactoryWall and paste the dark wall graphic into it. Then resize it to 800 in Width by 600 in Height and set its position to 0,0 . The layout should look similar to the following screenshot:
  39. Construct Game Development

  40. Switch to the FrontScenery layer and create a Tiled Background object called ConveyorMiddle, and give it the center piece of the conveyor belt images:
  41. Construct Game Development

  42. Give this object the Private Variables of Direction and Speed with starting values of 0.
  43. Place these around the map to act as scenery, as well as using them as an object to move players with at certain points. Set the Direction variable to 1 to have the conveyor belt move right, and 2 to move left. Speed is the attribute used to determine how fast a player character is moved by the conveyor belt; a speed of 25 works well in this instance. The following screenshot shows a moving conveyor belt in the layout:
  44. Construct Game Development

  45. On the same layer, create a Sprite with the name ConveyorStart and Collisions set to None. Use the starting conveyor belt image for this object and set the Hotspot to the middle-right (num-pad 6). Give this sprite the Attribute of Destroy on Startup.
  46. Create a second Sprite with the same setttigs called ConveyorEnd and a Hotspot in the middle-left (num-pad 4). Both sprites are shown in the following screenshot:
  47. Construct Game Development

Time for action – creating the HUD objects

Now, we will move on to creating the Heads Up Display (HUD) objects for our game.

  1. We are now ready to create the HUD objects for our game. Switch to the HUD layer and create a Sprite called P1Face, and give it an image of the P1Torso head and set its Collisions mode to Bounding Box:
  2. Construct Game Development

  3. Next, create a Text object called P1Info and set it up to match the following screenshot:
  4. Construct Game Development

  5. Create similar objects replacing P1 with P2 for the second player. In this case, have the objects match the following layout screenshot:
  6. Construct Game Development

  7. Now create a Text object for when the second player is not playing, and call it P2Join. Set its text to Press left control to join and have it matched to the following screenshot:
  8. Construct Game Development

  9. Give it a Sine behavior to make it fade in and out by matching its settings to those in the following screenshot:
  10. Construct Game Development

  11. Now create the final HUD item, a Sprite called NextSign, and place the next arrow image into it. Set the Collisions of this object to None:
  12. Construct Game Development

Construct Game Development Beginners Guide A guide to escalate beginners to intermediate game creators through teaching practical game creation using Scirra construct with this book and ebook.
Published: May 2012
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

(For more resources on Game Development, see here.)

Time for action – creating the main game events

Now that our objects are set up, we can go on to make their events in the Game event sheet.

  1. We are now ready to switch to the Event Sheet Editor to make the basics of our game. Start by adding an event sheet name Game to our project and include this from the event sheet of our level.
  2. Open the Game event sheet and create the empty event groups Startup, HUD, Scrolling, Enemies, Guns, Join-In, Players, Death, Sound, and LevelTransitions. These can be given descriptions relative to their group name in their group creation dialog box:
  3. Construct Game Development

  4. In the Startup group, add the System condition Start of layout. Add actions for the BackStopper, FrontStopper, and GoNextScreen objects to match those as shown in the following screenshot:
  5. Construct Game Development

  6. Now add actions to set the Global Variable values of GameWonLost and CurrentScreen to 0.
  7. Next, add actions to destroy P2Legs and make P2Face and P2Info invisible, before finally adding actions to set the Global Variable values of P1Lives and P2Lives to 3. These actions should match those shown in the following screenshot:
  8. Construct Game Development

  9. Now add a sub-event with the For Each Object condition of the System object and select the ConveyorMiddle object.
  10. Create a System object action Create object relative to object to spawn the ConveyorStart object on layer FrontScenery at 0, ConveyorMiddle.Height / 2 from the ConveyorMiddle object.
  11. Do the same for the ConveyorEnd object, this time positioning it at ConveyorMiddle.Width, ConveyorMiddle.Height / 2 from the ConveyorMiddle object. The entire sub-event should now match the following screenshot:
  12. Construct Game Development

  13. Now move to the HUD group and start here by creating an Always event to set the Text of P1Info to "Lives: " & global('P1Lives') & newline & "Ammo: " & P1Torso.Value('Ammo').
  14. Add another event to this group to check if NumPlayers is 2. If so, then set the Text of P2Info to "Lives: " & global('P2Lives') & newline & "Ammo: " & P2Torso.Value('Ammo') and add an action to make P2Join set to Invisible.
  15. Add an Else event just below the previous one to set the P2Join object to Visible. The three events should now look similar to the following screenshot:
  16. Construct Game Development

  17. Now add an event to check if the variable CanGoNext is equal to 0 and give it an action to set the NextSign object to Invisible.
  18. Add an Else event just below this and give it the additional condition Every X Milliseconds from the System object, and set its value to 250 .
  19. Give this event a sub-event to check if NextSign is Visible, and give it an action to make it Invisible. Then add an Else event for this and have it make NextSign set to Visible, and play the sound AppPath & "GoNext.wav":
  20. Construct Game Development

  21. Now move to the Scrolling event group, and add an Always event with actions to set positions of the Body family objects to the Legs family objects at image point 1. Then add another action to set the Body object Angle to Legs.Angle.
  22. Now add the System object action Scroll to X to scroll to X position BackStopper.X + (DisplayWidth / 2).
  23. Now add an event to check when Legs is outside of the layout and Invert it. Give this event a further two sub-events, checking when NumPlayers is either equal to 1 or 2.
  24. When NumPlayers is equal to 1, have an action to Scroll to Y of P1Torso.Y, but when it is equal to 2, have the game scroll to ((P1Torso.Y + P2Torso.Y)/ 2). The two main event branches are shown in the following screenshot:
  25. Construct Game Development

  26. Add an event to check when the X of Legs is Less or equal to BackStopper.X . Give this event an action to set the X of Legs back to BackStopper.X + (Legs.Width / 2).
  27. Create an event for when the variable CanGoNext is equal to 1, and give it a sub-event that compares if NumPlayers is equal to 1 and a Legs object is overlapping the GoNextScreen object.
  28. Add a second sub-event for the main event branch and have this compare when NumPlayers is equal to 2 and both P1Legs and P2Legs overlap the GoNextScreen object.
  29. For both events, add actions to add 1 to CurrentScreen, and set the X positions of BackStopper, FrontStopper, and GoNextScreen to global('CurrentScreen') * DisplayWidth, (global('CurrentScreen') + 1) * DisplayWidth, and (global('CurrentScreen') + 1) * DisplayWidth respectively. The events should now look similar to the following screenshot:
  30. Construct Game Development

  31. Now scroll down to the group Join-In and add an event with conditions to check when NumPlayers is equal to 1 and the control "Shoot" for player 2 is pressed for the MouseKeyboard object.
  32. Give this event actions to set NumPlayers to 2 and create P2Legs on the "Objects" layer at X position (global('CurrentScreen') * DisplayWidth) + 50 and Y position global('RespawnY') .
  33. Finish the event by adding events to make P2Face and P2Info set to Visible:
  34. Construct Game Development

  35. Move to the Players group and start with an Always event to send families Legs and Body to the front of their layout with the action Send to front .
  36. Next, create an event for when the Legs family overlaps the ConveyorMiddle object.
  37. Give this event sub-events to check when the Private Variable for Direction of the conveyor object is equal to 1 and when it is equal to 2.
  38. Using the action Set X component of motion for the Platform behavior of the Legs object, have the first sub-event set the value to Legs[Platform]. VectorX + ConveyorMiddle.Value('Speed'), and for the second sub-event, set the value to Legs[Platform].VectorX - ConveyorMiddle. Value('Speed'):
  39. Construct Game Development

  40. Now create an event for when the Legs object is overlapping the Ground object at an off set of 0, 20. Have an action for this event to set the value of RespawnY to Ground.Y - 250.
  41. Add events for both P1Torso and P2Torso with the condition Control is down? for the MouseKeyboard object to check when the control "Move Up" is down, or else "Move Down", or an Else event for when neither is down. Give these events acO ons to set the animation of the torso object to "Up", "Down", and "Normal" respectively. The events should match the following screenshot:
  42. Construct Game Development

  43. Scroll to the event group Death and create an event for when P1Legs is outside of the layout, and give it the additional condition Trigger once while true .
  44. Add an action to this event to destroy P1Legs and another to play the sound AppPath & "PlayerDie.wav".
  45. Duplicate this event for P2Legs, but add an additional condition above the Trigger once condition to compare if NumPlayers is 2:
  46. Now create an event to compare when P2Legs.Count is equal to 0, and give it the Trigger once condition.
  47. Add a sub-event to check if P1Lives is greater than 0. Have an acrion to spawn the P1Legs object on the "Objects" layer at (global('CurrentScreen') * DisplayWidth) + 50, global('RespawnY') and a second to subtract 1 from P1Lives.
  48. Next, create an Else event to set GameWonLost to 1.
  49. Do the same for the P2Legs object and P2Lives variable. Above the Trigger once condition, add another condition to compare if NumPlayers is equal to 2. The two main events should match those shown in the following screenshot:
  50. Construct Game Development

  51. Scroll down further to the group Sound and add a Start of layout event to play the music file AppPath & "Game.mp3" and another to set it to Loop.
  52. Add another event to check when ConveyorMiddle is on the screen and its Direction value is different than 0. Have a third condition to run the event every 500 milliseconds.
  53. Create an action to play the sound AppPath & "Conveyor.wav" for this event.
  54. Insert another event for when Player 1 presses the control "Jump" and give it an action to play the sound AppPath & "PlayerJump.wav". Have another event like this for Player 2, but also check that NumPlayers is equal to 2. All events in this group should now match the following screenshot:
  55. Construct Game Development

  56. Now, in the final event group LevelTransitions, add an event for when Legs overlaps the ExitLevel object and CanGoNext is equal to 1. Have this event's action GameWonLost set to 2.
  57. Next, add an event to destroy the GoNextScreen object when the ExitLevel object overlaps it.
  58. Add a new event for when GameWonLost is equal to 1 and have it transition to the layout name "GameOver". Then create an event when GameWonLost is equal to 2 to transition to the next layout.
  59. Construct Game Development

Time for action – creating the Game Over layout

Our players also need a screen for when they lose or win the game, so let's make this layout now.

  1. Now create the layout GameOver with layers Text and Background and its event sheet GameOver Events. Set this layout size to 800, 600 .
  2. On the Background layer, create a Panel object stretched across the entire layout called BackgroundRed and set its color Filter to WebRed.
  3. Next, on the Text layer, create three Text objects: GameOver, GameSummary, and AnyKeyText with the default text of Game Over, You ran out of lives., and Press any key to return to the title screen... respectively:
  4. Construct Game Development

  5. Switch to the Event Sheet Editor and add a Start of layout event to play the music file AppPath & "Title.mp3", and set it to Loop.
  6. Add sub-events to compare when GameWonLost is equal to 1 and another for when it is equal to 2.
  7. In the first sub-event, add actions to set the text of GameSummary to "You ran out of lives." and the i>Filter of BackgroundRed to WebRed. For the second sub-event, set the text to "Congratulations, you've completed the game!" and set the Filter of BackgroundRed to BrightGreen.
  8. In order to finish the event sheet, add an event for when any key is pressed and have it transition back to the layout "Title".
  9. Construct Game Development

What just happened?

We've covered a large amount of ground in order to create the foundation of our third game, SideShooter. In between setting our game environment up, we managed to make a two-player game where the second player can join in at anytime and players scroll by one screen at a time. Players can also get a "Game Over" from falling off the map, or be moved by conveyor belts.

Let us take a closer look at some of the things we've done.

Families

In this game, we used Families to consolidate Torso and Legs objects of each player. This enabled us to create events for both of them by referencing their family rather than each object individually.

Containers

We used the Legs objects for containers of their respective Torso objects in order to have them spawn and be destroyed together. This also allows each Torso to know which pair of Legs to join to and allows us to spawn the second player character by only creating P2Legs.

Containers can be used in layout design to save the amount of objects being moved around. At startup, any objects in the layout that are part of a container will spawn their own counterparts automatically.

Multiplayer

Using the built-in controls system, we were able to add our own controls for the second player to use. Construct Classic behaviors will automatically use the controls generated by default and any controls with the same name for other players. Non-default controls such as Shoot must be checked from events, as we did for spawning the object P2Legs.

Static scrolling

We only allow the Y scrolling to be dynamically linked to the Y position of the players, but stop scrolling down when they fall off the screen.

For scrolling in the X axis, we used a mathematical formulae and the value of CurrentScreen to move by increments of the game screen width. Each time the players are able to continue and reach the end of a screen, we set the BackStopper object to the left edge of the new screen, and then the FrontStopper and GoNextScreen objects to the right edge.

Shooting bullets

Our players hold their hands out and aim up and down now, but they don't look right doing that without a gun in their hands.

We'll change this now by adding in guns, muzzle flashes, and bullets.

Time for action – adding some guns

Our players will need some tools to fight off any enemies we add later. Let us do this by adding in guns and bullets for them to use.

  1. In the Layout Editor, select the Objects layer and create a sprite named PistolShot and paste the pistol bullet into it. Give this sprite the Attribute of Destroy on startup and a Private Variable named Damage with value 22.
  2. Now set the Collisions mode to Bounding Box and add the object to a new family called Bullets.
  3. Add the Bullet behavior and give it settings to match the following screenshot:
  4. Construct Game Development

  5. Clone this object and call it UziShot. Paste the uzi bullet image into it, set the Damage of this object to 20 instead, and have its Bullet settings match those shown in the following screenshot:
  6. Construct Game Development

  7. Do the same again for the ShotgunShot object, this time having a Damage of 18 and Bullet settings to match the following screenshot:
  8. Construct Game Development

  9. Now create a Sprite named Pistol and paste the pistol graphic into it. Have this object destroyed on startup and make it part of a new family Guns. Place image point 1 at the barrel of the gun.
  10. Set the Collisions mode to Bounding Box and check the Auto Mirror checkbox before going on to add the Private Variables of Player, WeaponNo, and CoolDown with values 0, 0, and 500 respectively. Scale the gun to fit in the hand of the player torso objects, but also scale the PistolShot object to fit in its barrel.
  11. Duplicate this object to make the Uzi and paste the uzi image into it. Set the WeaponNo to 1 and CoolDown to 250. Scale this in the same way the Pistol object was scaled. Remember to readjust image point 1 to the new barrel.
  12. Creating another duplicate, make an object called Shotgun and paste its respective image into it. Set the WeaponNo to 2 and the CoolDown to 1000 before scaling it to fit in a hand and scale the bullets it fires to the barrel. This object will also need the image point positioned at the barrel again.
  13. Next, add another Sprite named MuzzleFlash and paste a white circle that fades to transparent into it. Set the size of it to 128, 128, the Opacity to 50%, and Filter to a light shade of yellow. Check the Attribute checkbox of Destroy on startup and set the Collisions mode to None. Finish the object by adding the Timer behavior to it. All of the objects together should now match the following screenshot:
  14. Construct Game Development

  15. Switch to the Event Sheet Editor for the Game event sheet and scroll to the Guns event group.
  16. Create a For Each Object event and select the Bullets object. Create two sub-events for when the Bullets family collides with the CreateBox object and the Ground object . Destroy the Bullets family object in each instance.
  17. Construct Game Development

  18. Now create a For Each Object event for the Guns object and give it the Send to front action for the Guns family of objects.
  19. Next, add a sub-event for when the Player value of the Guns object is equal to 0. Give the sub-event three further sub-events for when the value WeaponNo is equal to 0, the P1Torso object collides with the Guns object, and the P2Torso object collides with the Guns object.
  20. In the first sub-event, Destroy the Guns object. Then in the second, set P1Torso value Weapon to Guns.Value('WeaponNo'), the P1Torso value Ammo to 99, and destroy the Guns object.
  21. In the third sub-event, replicate the events from the second for the P2Torso object:
  22. Construct Game Development

  23. Next, add a sub-event to the For Each Object event again for when Guns value Player is equal to 1. Have an action to set the position of the Guns object to P1Torso at image point 1.
  24. Give this event sub-events for when P1Torso animations "Up", "Down", and "Normal" are playing. Use these to set the P1Torso value of GunAngle to -40, 25, and 0 respectively.
  25. Add another sub-event when the Angle of P1Torso is equal to 0 and have the Guns object set its Angle to P1Torso.Angle + P1Torso.Value('GunAngle').
  26. Insert the next sub-event for when the Angle of P1Torso is equal to 180, and have an acrion to set the Guns object Angle to P1Torso.Angle - P1Torso. Value('GunAngle'). These events should all match the following screenshot:
  27. Construct Game Development

  28. Create another sub-event, this time for when player 1 holds down the control "Shoot", and give it an additional condition to run every Guns. Value('CoolDown') milliseconds.
  29. Add actions to spawn the object MuzzleFlash on the Objects layer at image point 1 of the Guns object and then start timer "Flash" with a length of 50 and set to Destroy when finished. Have a third action to subtract 1 from P1Torso value Ammo.
  30. Insert further sub-events to compare when WeaponNo of the Guns object is equal to 0, 1, or 2 and have a Repeat 5 times condition on the final sub-event as well.
  31. For each of these sub-events, have the Guns object spawn the PistolShot, UziShot, or ShotgunShot objects respectively on the "Objects" layer at image point 1 and play the sounds AppPath & "ShootPistol.wav", AppPath & "ShootUzi.wav", and AppPath & "ShootShotgun.wav" respectively. The events will match the following screenshot:
  32. Construct Game Development

  33. Duplicate the entire event structure for when Guns value Player is equal to 1 and replace each mention of 1 with 2. Add an additional condition to check NumPlayers is equal to 2 to the main branch of this, as shown in the following screenshot:
  34. Construct Game Development

  35. Now scroll to the Players event group below the event to compare Body value Ammo to being less than 0 and add an event to compare if P1Torso is equal to 99 and give it an additional Trigger once condition. Add a first sub-event to compare if the Guns value Player is equal to 1 and, if so, Destroy it.
  36. Add another sub-event for when P1Torso value Weapon is equal to 0 and have it create a Pistol at image point 1 of P1Torso and set its value Player to 1. Give an additional acO on to set the Ammo of P1Torso to 0.
  37. Create a similar sub-event, this time checking Weapon is equal to 1 and spawning an Uzi instead. Have the P1Torso value Ammo set to 30.
  38. Add a final sub-event for when Weapon is equal to 2, and create the Shotgun object and set the P1Torso value Ammo to 15:
  39. Construct Game Development

  40. Finish this section of the chapter by repeating steps 1 through 30 for the second player object and having it also include a condition to check if NumPlayers is equal to 2 in the main event:
  41. Construct Game Development

    What just happened?

    We now have guns that our players can pick up and shoot with muzzle flashes. By using the Spawn another object action for the Guns objects, we were able to create bullet projectiles for each type of Gun. The main bullets settings were controlled from the Bullet behavior of each, and once spawned, the bullets were able to keep moving on their own.

    When changing weapons, we set the player Ammo value to 99 so the game knew that the player needed a new weapon.

    Summary

    In this article, we created the beginnings of our side-scrolling shooter game complete with multiplayer and enemies.

    We took steps for making the game multiplayer using Construct Classic's built-in control system to allow a second player to play alongside the main character. Next, we learned how to add guns and bullets into our games. We added a Pistol, Uzi, and Shotgun into our game with different behaviors between them.



Construct Game Development Beginners Guide A guide to escalate beginners to intermediate game creators through teaching practical game creation using Scirra construct with this book and ebook.
Published: May 2012
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Daven Bigelow

Jayjay is a hobby game developer and software programmer. He has been creating 2D games for over eight years, across different game creation tools and programming languages. However, most of his experience lies in Construct Classic, which has been his tool of choice over the last three years.

He can often be found on the Scirra forums, where he provides advice and examples for new users seeking help.

Books From Packt


Cocos2d for iPhone 1 Game Development Cookbook
Cocos2d for iPhone 1 Game Development Cookbook

Cocos2d for iPhone 0.99 Beginner's Guide
Cocos2d for iPhone 0.99 Beginner's Guide

Unity iOS Game Development Beginners Guide
Unity iOS Game Development Beginners Guide

Unity 3.x Game Development Essentials
Unity 3.x Game Development Essentials

3D Graphics with XNA Game Studio 4.0
3D Graphics with XNA Game Studio 4.0

XNA 4.0 Game Development by Example: Beginner's Guide – Visual Basic Edition
XNA 4.0 Game Development by Example: Beginner's Guide – Visual Basic Edition

HTML5 Games Development by Example: Beginner’s Guide
HTML5 Games Development by Example: Beginner’s Guide

Corona SDK Mobile Game Development: Beginner's Guide
Corona SDK Mobile Game Development: Beginner's Guide


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
x
9
5
H
n
h
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software