How do I let the player win after a specific action?

0 favourites
  • 8 posts
From the Asset Store
Check preview, download and add value to your games.
  • Hi!

    The very first version of my game is finished and I would like to include the possibility of winning. There are 3 starboxes in the game (they are copies and all belong to the same sprite object) and as soon as all of them were found, the player wins (text appears "You won!" and redirecting to menu).

    Also, I would like to show the score in the menu, which is another layout. How can I connect the score to the other layout and show the result at the end?

    Thank you for helping me!

    Maschka

    btw, it's called Tom Tiger: Where is the O? and you find the "demo version" in the section "adventure games".

  • Global variable; set it +1 for each instance found. Condition StarVar=3 into your win condition, reset StarVar=0 each level. Use another like TotalStarsVar to keep track of total stars recovered in the game and use a text box object with text "You Collected: "&TotalStarsVar"Stars!"

  • Just played your Captain J. Doe Saves the Universe game Chris. Lots of fun there man!

  • You can win in your game a few different ways.

    Do a check to see if any boxes are left on the layer.

    Every time a box is found/destroyed add 1 to a Global Variable named Win. For each layout you have: compare that Win Global Variable to whatever score you set for the player to reach to win.

    To win = 20

    System compare variable = 20 > Display Win on layout.

    Add a text box to the menu layout, name it Score or Score_txt, so you can tell the different in names later.

    Add a global variable to event sheet named Score, doesn't matter where you add it, but its preferred to add it where it takes place. As in on the event sheet that the score takes place, such as the gameplay layout.

    On Menu Event Sheet:

    System - Every tick > Score _txt - set text to Score

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks and jeffige, I will try it now. Looks a bit complex at fist sight, we'll see . And I totally agree with Wicked Soft!

  • Thanks, CJDSTU was a fun learning game to make.. I should polish it but I may just rewrite it using better "code" structure.

    Maschka, both our examples primarily rely on one basic concept, the use of variables. They are the building blocks to everything you will do in any programming language or game editor. Variables are easy to learn, and a lot of fun to use. They are just places you store values (be they numbers, strings, true/false, etc).

    I can't strongly recommend it enough to do the starter tutorials like ghost shooter, asteroid, and flappy bird clone. You will learn basically everything you need to get a solid grasp from just those three.

  • I actually did manage to apply your advices and it really is logical, you're right. I only did the ghost shooter and platform tutorial, should do asteroid and flappy bird clone, too thanks! What I didn't get til now is this instance variable thing, but I will work myself through the manual first. I kind of struggle with the word instance, I know it exists in German, too, but even there I don't know what it means!

  • I know you are familiar with some of this but it helps to explain it completely to keep it organized and maybe help others less familiar:

    In Construct2 you have 2 basic types of variables, Global and Instance. A global variable is created inside an event sheet by right-clicking and selecting it, or by using toolbar. A value stored in a Global variable is available everywhere in your project. For example you could make a variable called Score=0, increment it each time the player gains a point using action "add to" inside a conditioned event and then grab or modify this value from ANY event sheet or layout.

    However, the second type Instance variable is "local" in scope. It is created inside of an object using its properties panel. Since instance variables are limited in scope you can't expect to access or modify their values simply by calling up a variable available everywhere. You also need to make sure any event sheets containing objects with instance variables are included (right click inside event sheet and choose "include") so they can be accessed outside their event sheet, You would also need to address it specifically inside its containing object:

    ie. Two variables called hitpoints, both store players hitpoints but one is global and one is instanced inside the player object. To subtract hitpoints you would:

    Global: any action simply used subtract from hitpoints

    Instance: any action would have to use player.hitpoints then subtract from

    As you can see, this isn't a lot of work to do.. so many times I will use instance variables because I can keep them all neatly stored inside their own container object and then modify and call them on the fly from anywhere with just slightly more work. I even like using a "brain" object (simply a sprite kept off screen) that is just an instance variable container for game variables (score, level, etc). I am sure others may point out some limitations to instance variables over global but for most simple-medium sized projects I have found none besides the extra work to call them. That said... I am not trying to sell you on instance variables either. Pretty much all Construct2 projects can be made using nothing but global variables without seeing any appreciable slowing.

    All that said: Most of the confusion you are probably having is with "instance variable" and "instance of an object". Such as when you create an enemy object (sprite) and then give it some instance variables like health, speed, etc. AND then clone it into more "instances" of the original. The instance variable will carry across ALL instances of the object. However, you can still modify them individually using " instance picking", this is how you can have enemies with the same instance variable of health but that will take damage at different rates... they are picked by an event condition such as "on collision" with or "is overlapping" another object. In this case a bullet "object" picks the enemy instance when it hits it. "Instance Picking" is covered in the manual and many tutorials/threads and is a core concept of Construct2, learn it and you will have won most of the battle.

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)