Results 1 to 3 of 3
- 01-07-2008, 02:54 PM #1Member
- Join Date
- Jan 2008
- Rep Power
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
Last edited by jaferris; 01-07-2008 at 03:19 PM.
- 01-07-2008, 04:19 PM #2
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. :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-08-2008, 12:19 AM #3
- By markus-sukram in forum New To JavaReplies: 2Last Post: 03-29-2008, 11:25 PM
- By mscwd in forum Sun Java Wireless ToolkitReplies: 0Last Post: 01-28-2008, 09:34 PM
- By cachi in forum Java AppletsReplies: 1Last Post: 08-07-2007, 07:48 AM
- By goldhouse in forum Threads and SynchronizationReplies: 0Last Post: 07-18-2007, 05:18 AM
- By gary in forum AWT / SwingReplies: 0Last Post: 07-11-2007, 04:57 PM