Beginner's guide to Construct 3

1940

Index

Contributors

Stats

1,314,559 visits, 3,815,968 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.

Published on 20 Sep, 2017. Last updated 24 Jun, 2024

More game logic

If each event block is described in as much detail as before, it's going to be quite a long tutorial. Let's make the description a little briefer for the next event blocks. Remember, the steps to add a condition or action are:

  1. Double-click to insert a new event block, or click an Add action link to add an action.
  2. Double-click the object the condition/action is in.
  3. Double-click the condition/action you want.
  4. Enter parameters, if any are needed.

From now on, event blocks will be described as the object, followed by the condition/action, followed by any parameters. For example, the event we have just inserted could be written:

Add condition SystemEvery tick

Add action PlayerSet angle towards position, and for X: Mouse.X, Y: Mouse.Y

Get the player to cast spells

When the player clicks, they should cast a spell. This can be done with the Spawn an object action in Player, which creates a new instance of an object at the same position and angle. The Bullet movement we added earlier will then make it fly out forwards. Make the following event block:

Condition: MouseOn clickLeft clicked (the default)

Action: PlayerSpawn another object, then for Object, choose the Spell object. Leave the other parameters as they are.

Your event block should now look like this:

The event to cast a spell

If you run the game, you can cast spells! However you may notice the spells shoot from the middle of the player, rather than from somewhere that would make more sense like the wizard's hand. Let's fix that by placing an image point at the end of the hand. An image point is just a position on an image that you can spawn objects from, and we can reference it in the Spawn another object action.

Right-click the player in the Project Bar and select Edit animations.

Editing the player's animations

The image editor for the player reappears. Click the origin and image points tool:

The image points tool

...and then the side pane turns in to a list of image points:

The image points pane

Notice the object origin appears in the list. That's the "hotspot" or "pivot point" of the object. If you rotate the object, it spins around the origin. That's also what's used when you spawn an object at image point 0, as our action did. We want to add another image point to represent the wizard's hand, so right-click in the list and select Add a new image point. A new item appears in the list, and an icon appears over the image to indicate where this image point is. Left-click at the end of the wizard's hand to place the image point there:

Placing the image point

Close the image editor. Double-click the Spawn an object action we added earlier, and change the Image point to 1. The event should now look like below - note it says Image point 1 now:

Spawning at an image point

Preview the game again. The spells now come from the player's hand! The spells don't do anything yet, though. Hopefully, however, you'll start to realise that once you get to grips with the event system, you can put together your game's logic very quickly.

Let's make the spells hit goblins. Add the following event:

Condition: SpellOn collision with another objectGoblin.

Action: GoblinDestroy

Action: SpellSpawn another objectSparkFlash

Action: SpellDestroy

Here's what the finished event looks like.

Spell collision event

The spark flash effect

Preview the game, and try casting a spell at a goblin. Oops, the spark flash has that big black border!

Spark flash with black border

You might have predicted it'd look like that from the start, and wondered if our game was really going to end up like that! Don't worry, it won't. Click the SparkFlash object in the Project Bar. Its properties appear in the Properties Bar on the left. In the Effects section, set its Blend mode to Additive. Now try the game again.

Spark flash with additive blend

Why does this work? Without going too much in to the nuts and bolts, ordinary images are pasted on top of the screen. With the additive blend mode, each pixel is instead added (as in, summed) with the background pixel behind it. Black is a zero pixel value, so nothing gets added - you don't see the black background. Brighter colors add more, so appear more strongly. It's great for lighting effects and explosions.

Making goblins a little smarter

Right now the goblins just wander off the layout to the right. Let's make them a bit more interesting. First of all, let's start them at a random angle.

Condition: SystemOn start of Layout

Action: GoblinSet angle to random(360)

They will still wander off forever when they leave the layout, never to be seen again. Let's keep them inside. What we'll do is point them back at the player when they leave the layout. This does two things: they always stay within the layout, and if the player stands still, goblins end up coming right for them!

Condition: GoblinIs outside layout

Action: GoblinSet angle toward position X: Player.X Y: Player.Y

Here are what the two finished events look like.

Goblin events

Preview the project. If you hang around for a while, you'll notice the goblins stay around the layout too, and they're going in all kinds of directions. It's hardly AI, but it'll do!

Now, suppose we want to have hit a goblin with a spell five times before it disappears, rather than instantly disappearing like it is at the moment. How do we do that? If we only store one "Health" counter, then once we've hit a goblin five times, all the goblins will disappear. Instead, we need each goblin to remember its own health. We can do that with instance variables.

Next Tutorial In Course

How to Learn Construct 3? Next Steps for Beginners 51:05

Get started with Construct's built in examples and game templates

Disabled Comments have been disabled by the owner.