Two Problems Rotating and collision detection help
hey i am creating a similar pacman game and i can move the monster UP, Down, Left and Right
What i am trying to do is when moving down how do i make it soo the mouth will face down too same as going left and up.
Other problem is how do i make the object i hit dissapear the collision detection
Sorry if posting in wrong area but any code will be helpfull
here is a sample of the direction code
// monster is moving right, increase its X-coordinate
monsterYPos = monsterYPos + monsterSpeed;
if (monsterYPos > (boardWidth - monsterSize)) // has the monster hit the right wall?
monsterYPos = boardWidth - monsterSize; // move it back to just touching right wall
monsterBumpWallSound.play(); // play an appropriate sound
// to do - fill in appropriate code for other directions
// increment the monster animation counter
if (monsterAnimationCount >= 10) // when the counter gets to 10, set it back to 0
monsterAnimationCount = 0;
// update each munchie animation
for (int i = 0; i < NUM_MUNCHIES; i++)
// increment the animation counter
if (munchieAnimationCount[i] >= 10) // when the counter gets to 10, set it back to 0
munchieAnimationCount[i] = 0;
it now rotates the way i am facing via this code
case Input.LEFT: case Input.NONE:
// this is the angle of the roof of his mouth
// when his mouth is fully open
startAngle = 205;
// to do: fill in animation code for other directions
i just need to know how something dissappears when you touch it
Using collision detection.
Collision detection can get tricky. First you must ask yourself:
- Are my objects moving fast?
- Are my objects complicated in shape?
If your answer is "no" to both these questions then you can simply create a box around your objects and test on a regular basis if the are intersecting. If this is false then collision detection can involve line intersection, distances and creating a "cage" around the object to handle the velocity of the object.
I have collision detection code if you need it, but it is complicated and it can slow down your game if used improperly. The best advise that I can give you is to draw pictures of your objects and solve this problem logically and mathematically. :D