How do I merge objects (fruit merge game)?

0 favourites
  • 3 posts
From the Asset Store
Realisitc Fruits 2D provides you with a variety of realistic fruits.
  • Hi,

    I want to create a simple fruit merge game: Users drop a fruit and when the same fruits touch, a new type of fruit is created.

    I'm stuck at the merge mechanic.

    How do I do it that for example: Blueberry + Blueberry = Cherry?

    So far I have:

    Fruits On Collision with Fruits

    Condition: System - Pick by comparison

    - Object: Fruits

    - Fruits.ObjectTypeName

    - Comparison: Equal to "Blueberry"

    Actions: System create cherry

    Destroy Fruits

    I have the same for cherry (cherry + cherry = grape) but for some reason cherry + blueberry also create a grape.

    Each fruit has the physics behavior and is its own Sprite object. They're also in a Fruits family for random spawning at the top of the layout.

    Thank you

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When you do "Obj on collision with Obj", it picks two instances. And you need to do additional picking if you need to get the type of each of them - use "System pick Nth instance" or "System For Each".

    You can create two families with the same sprites to make things easier. Then you could refer to each instance without having to pick them one by one. For example:

    Fruits1 On Collision with Fruits2
    
     Fruits1.animationName="Blueberry" & Fruits2.animationName="Blueberry"
     -> Create Cherry
    
     Fruits1.animationName="Blueberry" & Fruits2.animationName="Raspberry"
     OR Fruits1.animationName="Raspberry" & Fruits2.animationName="Blueberry"
     -> Create Pineaple
    

    If there are a lot of fruit combinations, this approach is not ideal because you'll have to create a lot of events. If this is the case, I would suggest using an array or JSON to store all these recipes. And perhaps a function which will look up a pair of names in the array and return the name of the merged object.

  • Awesome, this works :). Thank you so much!

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