Asteroid clone in less than 100 events

7
  • 129 favourites

Index

Stats

32,710 visits, 118,766 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

A - Base mechanisms

+ Behaviors used : Custom movement, Wrap, Pin, Bullet, Destroy outside of layout, Rotate; Plugins used : System, Sprite, Keyboard.

For this tutorial I started using Ashley's "Custom movement (asteroids).capx" in the "examples" folder that sits in the folder where you installed C2.

You can notice, if you haven't already opened it, that the "examples" folder contains quite a lot of projects showing how to set-up projects and do several specific "usual" "game behavior".

With 5 events the ship/"Player" object using a custom movement and wrap behavior acts as expected.

The keyboard arrow keys (the "Keyboard" plugin has been added to the project) moves the ship in the play-field, and the "space" key allows to shoot "Bullet" objects.

This is the basis.

Open the final project's capx (that you can download in the final project's page in the Arcade) you can see that there is far more code and elements in comparison to the original example.

There are three layouts. Each layout has an event sheet attached to it (each event sheet is named with the prefix "es" and then the name of the layout it is attached to; that's a personal convention to know where I'm at while programming and what event sheet is related to what layout).

Splash: is the splash/loader screen/layout

Score: is to display and check the scores after Splash and Game

Game: is the layout in which the game actually happens

1 - Ship setting and controls

You can find the events of the original example in the "PlayerMovement" group in "esGame". (event 2)

In the final project, you can see that there is more to the movements than in the original example.

It's because as I was developing the game, I needed a few more actions/things to happen/be executed on the player's inputs.

For example I wanted some flames to be displayed when the ship is either moving forward/braking.

So I used a little trick.

The flames for the back and the front are two different sprites.

The animation comes from the "FX" folder in Scirra's free bundle.

Once again refer to the Beginner's guide to Construct 2 to learn how to create new sprite and import textures into it.

You can open the layout "Game", and see how they are five distinct elements, placed on the same layer as the ship, beneath it.

Each sprite ("Thrust" and "Brakes") is set to display a looping animation (a serie of frames that repeat themselves).

Each sprite also has a "Pin" behavior and has its property "Initial visibility" set to "Invisible".

Since I placed those sprites appropriately in the layout view, all I need to do "On start of layout" (event 1 in esGame) is to pin those sprites on the ship. I, then, won't have to bother about placing them, they'll stick to the player's ship in correct position/angle.

In this case of "visual fx", it's more than enough.

"Brakes" has four instances of the same sprite, since it is the same animation, and when I set the sprite to be visible or invisible, both instances are picked and get affected.

Back in the "PlayerMovement" group, you notice that when "UP key is down" (event 3) (so as long as it is being held down), the "Thrust" sprite is set to be visible. So its animation naturally plays without even needing any action on it.

Event 5, when the "UP key is released", the sprite is set back to invisible.

There is more to those two events, but the sub events and actions are relevant to the audio, a subject that I will touch on later and leave aside for now. Please bare with me.

The same logic applies to the "DOWN key". Instead of "Thrust" though, we focus on the "Brakes" sprites, and as mentioned earlier, both instances of the sprite gets modified at once.

To finish on the ship controls, pressing (so pushing down and releasing "in a row") the "Space" key spawns a "Bullet".

The "Bullet" has simply a "Bullet" behavior.

It contains also a "Destroy outside of layout" behavior to keep the object count down (it prevents that "Bullets" that went out of screen don't just stay in memory as long as the game executes which could result into resources wasting).

It also does have a "strategic"/game play impact as you can't just shoot in continuity, hoping that bullets will wrap and finally hit an asteroid "by luck".

Once more, the emphasis is put on the fact that the player is to hit asteroids, not just shoot "randomly".

As first step for the score system, notice that a global variable "Score" is set and will hold the score for the current game being played.

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • I have looked over the asteroid handling group, and it seems like all of my events are in the correct spot. The issue I am having is that the smaller asteroids will not be destroyed, but instead will continue to break apart until they're infinitely small. If anyone can help me with this issue that would be highly appreciated, thank you.