
3.1 Developing in Construct 2
Installation:
Download and install Construct 2 from its official site.
Open the program and select “New Project” to get started.
User Interface:
Layout: This is where you will design the levels of your game.
Event Sheet: Use event sheets to define game logic without writing code.
Properties Bar: Adjusts the properties of the selected objects.
Creating a Basic Game:
Add Objects: Drag and drop sprites and other objects into the layout.
Define Behaviours: Assign predefined behaviours such as “Platform” or “Solid” to
objects.
Events: Use the event system to define game logic. For example, “If the player presses
the right key, move the character to the right.”
Testing & Export:
Test your game directly in the editor.
Export your game to multiple platforms like HTML5, Windows, Android, etc.
In this case we will use HTML5
3.2 Templates in Construct 2
Construct 2’s templates are designed to be flexible and user-friendly, making it easier for
both beginners and experienced developers to create high-quality games.
3.2.1 Types of Templates in Construct 2
Construct 2 offers several templates that make it easy to start new projects. These templates
provide a solid foundation on which you can build and customize your own game. Here are
some examples:
Platform: Ideal for platform games like Mario. These templates include basic
mechanics such as jumping, running, and collision detection, allowing you to focus on
level design and character development.
● Shooter: For top-down shooter games. These templates often come with
pre-configured controls for movement and shooting, as well as enemy AI and health
systems, making it easier to create action-packed gameplay.
● Puzzle: Templates for puzzle games. These can include mechanics for matching,
sliding, or logic-based puzzles. They provide a framework for creating engaging and
challenging puzzles that test the player’s problem-solving skills.
● RPG: Basic templates for role-playing games. These templates typically include
character stats, inventory systems, and dialogue trees, giving you a head start on
creating immersive RPG experiences.
● Multiplayer: Templates for games with multiplayer functionality. These templates
help you set up networked gameplay, allowing players to connect and compete or
cooperate in real-time.
3.2.2 Additional Templates and Features
● Endless Runner: Templates for creating games where the player character runs
continuously, avoiding obstacles and collecting items. These are great for mobile
games and casual play.
● Tower Defense: Templates for tower defense games, where players must strategically
place towers to defend against waves of enemies. These templates often include
basic enemy paths and tower mechanics.
● Physics-Based Games: Templates that utilize Construct 2’s physics engine to create
games with realistic movement and interactions. These are perfect for creating games
that involve throwing, bouncing, or other physical interactions.
● Customization and Flexibility
Each template in Construct 2 is highly customizable. You can:
● Modify Assets: Replace the default graphics and sounds with your own to give your
game a unique look and feel.
● Adjust Mechanics: Tweak the game mechanics to better fit your vision. For example,
you can change the speed of the player character, the difficulty of enemies, or the
rules of the puzzle.
● Expand Functionality: Add new features and elements to the templates. For instance,
you can introduce new power-ups, levels, or game modes to enhance the gameplay
experience.
3.2.3 Getting Started with Templates
1. Choose a Template: Start by selecting a template that closely matches the type of
game you want to create.
2. Explore the Template: Familiarize yourself with the layout, events, and objects
included in the template.
3. Customize: Begin customizing the template to suit your game’s theme and
mechanics. Replace assets, adjust settings, and add new features as needed.
4. Test and Iterate: Regularly test your game to ensure everything works as expected.
Make adjustments based on feedback and your own observations.
3.3 How to Play
Objective: Defend your garden by destroying waves of trash invaders. Avoid letting them
reach the bottom of the screen.
It is simple, in this game, like the original, you need to collect some kind of “suns” wich will
give you 25 poins for you to use it to plant between 3 plants:
– Peashooter (100 point): This plant is the only plant of the three who can attack the
enemies. This one is essential.
–
– Wall-Nut (50 points): This is a defensive plant. Use it to block the way of the enemies.
– Sunflower (50 points): Probably the most important plant. With this plant you can
generate “suns” every 10 secons more or less.
You will have 5 rows with 9 spaces to plant. The enemies will appear from the right side
of the screen in a random row.
1. Controls:
o Use the left arrow key to move the spaceship left.
o Use the right arrow key to move the spaceship right.
o Press the spacebar to shoot bullets at the aliens.
o Use mouse to Drag and Drop elements to garden spaceships.
2. Scoring:
o Destroy a trash to earn 10 points.
o Your score is displayed at the top of the screen.
3. Game Over:
o The game ends if a trash element reaches the spaceship or the bottom of the
screen.
3.4 The code of the game (construct 2)
3.4.1 Step 1: Setting Up the Project
Create a New Project:
Open Construct 2 and start a new blank project.
Set the layout size to 1280×720 (or your preferred resolution).
Prepare the Game Layout:
Create a “play area” grid by drawing lines or using placeholders. This grid will
define where plants (trash defenders) and zombies will be placed.
Import a suitable background image (e.g., a park, landfill, or recycling center).
Save the Project:
Save your project as “TrashVsPlants.capx.”
3.4.2 Step 2: Adding Game Assets
You will need the following assets:
Trash defenders (plants also including sustainable elements): E.g., solar panel, recycling
cannon, compost bombs.
Zombies: E.g., plastic bags, trash containers.
Projectiles: E.g., recycled cans or energy beams.
Sunlight/Energy items: Representing resources to deploy defenders.
User Interface elements: E.g., score counter, energy counter, start button.
Insert Sprites:
Right-click the layout and select Insert New Object.
Choose “Sprite” and import the trash defender images. Repeat for zombies,
projectiles, and UI elements.
Add Animations:
Use the Animation Editor to add movement or attack animations for zombies and
defenders.
For example, a solar panel defender could have a glowing effect to represent
energy generation.
3.4.3 Step 3: Programming the Mechanics
Step 3.1. Placing Defenders
Drag and Drop:
Add a “Mouse” object to the project.
Create an event for placing defenders:
Event: On mouse click on a defender button
Action: Spawn the defender at the mouse position.
Restrict placement to grid positions using the “Snap to Grid” functionality or
manual position adjustment.
Check Resource Availability:
Add a global variable called Energy.
Before placing a defender, check if the player has enough energy:
Event: On mouse click on defender button
Condition: Compare variable Energy >= DefenderCost
Action: Deduct the defender’s cost from Energy.
Step 3.2. Generating Energy
Sunlight or Energy Drops:
Add a “Sunlight” sprite that falls periodically onto the grid.
Use an event to make sunlight collectible:
Event: On collision between sunlight and mouse click
Action: Add 25 to Energy.
Solar Panel Defender:
Add an event for periodic energy generation:
Event: Every 5 seconds
Condition: If solar panel is on the layout
Action: Add 10 to Energy.
Step 3.3. Zombie Movement
Move Zombies Left:
Add the “Bullet” behaviour to the zombie sprites.
Set their angle of motion to 180 degrees (left) and adjust the speed.
Collision with Defenders:
Event: On zombie collision with a defender
Action: Stop the zombie’s movement.
Action: Deduct health from the defender.
Destroy the defender if health reaches 0.
Reaching the End:
Event: On zombie collision with the left edge of the layout
Action: End the game (e.g., navigate to a “Game Over” layout).
Step 3.4. Defender Attacks
Shooting Projectiles:
Add a “Bullet” behaviour to projectiles.
Event: Every X seconds (depending on defender type)
Condition: Defender is on the layout
Action: Spawn a projectile from the defender’s position.
Zombie Collision with Projectiles:
Event: On projectile collision with zombie
Action: Deduct health from the zombie.
Action: Destroy the projectile.
Destroy the zombie if health reaches 0 and increase the player’s score.
Step 3.5. Waves of Zombies
Spawning Zombies:
Add a “Timer” behaviour to the layout.
Event: Every X seconds
Action: Spawn a random zombie type at the right edge of the layout.
Increase Difficulty:
Gradually reduce the spawn time for zombies.
Introduce stronger zombie types as the game progresses.
3.4.4 Step 4: User Interface
Energy Counter:
Add a “Text” object to display the Energy variable.
Update the text whenever energy changes:
Event: On Energy variable change
Action: Set text to “Energy: ” & Energy.
Score Counter:
Add another “Text” object for the player’s score.
Update the text whenever a zombie is destroyed.
Start Screen:
Create a new layout for the start screen.
Add a “Play” button to navigate to the main game layout.
3.4.5 Step 5: Testing and Polishing
Test Each Mechanic:
Ensure defenders can be placed and interact correctly with zombies.
Verify that energy and scoring work as expected.
Test zombie movement and attacks.
Balance the Gameplay:
Adjust defender costs, energy generation rates, and zombie health to create a
balanced experience.
Add Sounds and Music:
Import sound effects (e.g., for attacks, energy collection, and zombie deaths).
Add background music that loops during gameplay.
Optimize Performance:
Limit the number of objects on the screen to avoid performance issues.
Use “Destroy Outside Layout” behavior to remove unused projectiles or zombies.
3.5 Adding Sounds
1. Importing Sounds:
o Open your Construct 2 project.
o In the Project Panel, right-click on the Sounds folder and select Import
Sounds.
Choose the desired sound files from your list (e.g., SFX plant.ogg, SFX
points.ogg, etc.).
o Click OK to add the selected sounds to the project.
2. Assigning Sounds to Events:
o Go to the Event Sheet for your game.
o Select the event where you want a sound to play. For example:
▪ On shooting a projectile: Add an action to play SFX throw.ogg.
▪ On zombie death: Play SFX splat.ogg.
▪ On plant placement: Play SFX plant.ogg.
o To add a sound action:
▪ Click Add Action -> Choose the Audio object -> Select Play.
▪ In the properties window, choose the imported sound file.
3. Adding Background Music:
o Right-click on the Music folder in the Project Panel and select Import Music.
o Choose background music files (e.g., GrasswalkRS.ogg or Main-Music-10.ogg).
o Add an action in the Event Sheet to start the music:
▪ System -> On Start of Layout: Add an action to play the background
music in a loop.
▪ Example: Use Audio -> Play and set the playback to loop.
3.6 Replacing existing Sprites
There are different kinds of enemies:
Trashy
This enemie is slow. It will apear very commonly.
Thrasy with cone
This enemie is exactly like the normal “Basurilla” but is more resistent
Trash can
This enemie is quiker than the previous two enemies.
It has the same HP (Health points) like a normal Trasy but it is faster
To replace the plants and enemies (zombies) shown in your project, follow these steps:
3.6.1 Replacing Plants
1. Identify the Plant to Replace:
o Based on your list, plants like girasol, Lanzaguisantes, Nuez, and Repetidora
are likely functional sprites.
o Other unnamed sprites (e.g., Sprite10, Sprite11, Sprite8) might be
placeholders or secondary assets.
2. Replace the Plant’s Visual Asset:
o Right-click the plant sprite you want to replace (e.g., girasol).
o Select Edit Image to open the sprite editor.
o Click Open and choose a new image file (e.g., a thematic replacement like a
solar panel for girasol or a trash cannon for Lanzaguisantes).
o Save the changes.
3. Adjust Animations:
o If the new plant has animations (e.g., glowing effects or movement), go to the
Animations Editor tab.
o Add the animation frames for the new design.
o Test the animation in the layout to ensure smooth transitions.
4. Verify Plant Behavior:
o Check the events in the Event Sheet linked to the plant:
▪ For example, girasol might generate energy over time. Ensure this
behaviour is still tied to the new sprite.
Replace projectiles of Lanzaguisantes with a different sprite, such as a
recycled can or energy blast.
3.6.2 Replacing Trash
1. Identify the Trash to Replace:
o Zombies like coneHead, ZombiKarateka, and unnamed sprites (Sprite15,
Sprite17, etc.) are likely enemy characters.
2. Replace the Trash’s Visual Asset:
o Right-click the zombie sprite (e.g., coneHead) and select Edit Image.
o Click Open to load a new image file. For example:
▪ Replace coneHead with a trash heap zombie.
▪ Replace ZombiKarateka with a zombie carrying e-waste or scrap metal.
o Save the changes.
3. Adjust Animations:
o If the trash element has animations (e.g., walking, attacking, or dying), update
each animation frame in the Animations Editor.
o Ensure the frame order and playback speed remain consistent.
4. Verify Trash Behaviour:
o Check the Event Sheet for actions linked to the trash:
▪ For instance, coneHead may have a higher health value due to its
cone. Adjust this value if the new design should behave differently.
▪ Confirm that ZombiKarateka retains its special attack mechanics.