Forums → Programming Forum → HappyBlocks - Collision and Score
- 1 Reply
Were going to start with setting up the text field and creating the variable for the score.
Open your Main.as file and first import the text package
Don't forget to include the variable containing the score.
Now scroll down to the Main function and proceed to creating the dynamic text field.
Here is the new text field, making the selectability of it false eliminates the cursor when the mouse rolls over the text. The final line updates the text to show the score.
There are several ways of score implementation and monitoring. The way we will be doing it here will include event dispatching. Still in the Main function add the listener and the associated function.
From this point we can move into GameClass.as. Scroll down to the AI_Movement function and update it to pass the hero as an argument to the
At a glance there seems to be no noticeable difference. The only difference is this line.
Each block that is in this array will need to be prepped to receive the passed argument. Open all the block classes. Red, Blue, Green, and YellowBlockClass.as files. Scroll to the loop function and add the receiving argument.
public function loop(hero:Sprite):Boolean
The rules of this game will be... The hero touches the block and is the same color as the block, the block will go from being angry to being happy, and the player scores a point. Just for fun we will also make the block move faster as an additional visual confirmation that the collision has occurred to the player.
First add a boolean that indicates whether or not the block is happy.
It starts as false due to the block is initially not happy. Now for the collision between the blocks and the hero. The smaller blocks will first check to see if it is already happy or not. This will save an additional check from the blocks if it is not necessary. You don't need to check the collision to make the block happy if the block is already happy. If the block is not happy, proceed to check if there is a collision with the hero, then if there is a collision make a final check to see if the hero is the correct color.
Once all of these conditions have been met, the block will be happy, smiling, moving faster and the player will have scored a point.
You must be logged in to post a reply!
We strive to deliver the best gaming experiences on the internet and on your mobile phone. Play thousands of free online games, get access to free mmorpg games, online rpg games, fun online flash games, and more.
We offer free flash games in many different genres: online shooting games, online puzzle games, online war games, free online car games, free online hidden object games and dozens more.
This is the best place on the web to play online games for free! No matter what game style you prefer, we've got it here.
Want to advertise on Armor Games? Send us a note!
Gaming websites, passionate bloggers, and quirky streamers are welcome to share or review our games. If you need game keys, art, trailers, screenshots or more check out our press kit website.
Game developer? Visit developers.armorgames.com to request AG developer status, find documentation on our APIs, and get access to our development environment. Let's make sweet, sweet games together.
Looking for a publishing partner that can help your app rocket to success? Contact the mobile team to learn more about how we can help!