- Click Actors->Search and type in treasure.
- It should find a closed treasure chest, select it and add it to your actors list.
- Rename that actor to ChestClosed, since the hyphenated name is just annoying.
- Click Scene->Main->ChestClosed in the actors left sidebar so we can add the treasure to our scene.
- I know what you are thinking, wow that's a big chest. And you're right! It too big, so grab a corner and resize it. 48x48 looked good to.
- Place the chest at location 91,305 and test it out. Try touching the chest!
So what happened? It moved right and your score didn't increase. You still have the goose egg. Good that's what supposed to happen. Why did it move? That's right, mass! We didn't set the mass. Also if we want our score to increase, lets add a collision behavior as well.
- Click Actors->ChestClosed->Properties->Mass. Set the mass value to 10.
- Click Behaviors->Property->Event->Collision. Set the first actor to myself and the second actor to "any instance of this actor:" player. Click Close.
- Click Property in the Chest Closed Behaviour submenu.
- Make sure "Change the value of the" Game is set to Score.
- Click Add then 100. Now close it.
- Rename the Behavior name to "OnTouch"
- Try it now, click Play.
Wow it worked...and worked...and worked. From this one treasure chest we can get infinite points. Woot! Ok now that's not supposed to happen. Our score should only go up once. We need to add a filter behavior to fix this so let's set it up and fix it.
- Click Actors->Properties->Add a property. Then add a property that is m_IsOpenned and set its default value to 0. We'll use this property to tell if the chest is alreadly opened. Click Close.
- Click Behaviors->TouchChest-Filter. Set the filter variable to m_IsOpened and set the value to 0. This way we only get points when it's zero.
- One last thing, we need to set it to one once we touch it as well. So we need to add one more collision behavior for that.
- Click Behaviors->Property. Rename the new behavior to TouchChestOpened.
- Click Event->Collision and set the actors to myself and Player.
- Click the Property submenu of ChestUnlocked Behaviors and Change value of the MYSELF to m_IsOpened and Set it to: 1. To indicate that the treasure is open.
Perfect. It's all working as expected. Too bad the chest doesn't open so we can easily tell if it's got treasure or not. Wait we can fix that as well. But let's do that in the next post since I'm getting tired.