Results 1 to 3 of 3
  1. #1
    jaferris is offline Member
    Join Date
    Jan 2008
    Rep Power

    Default 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

    switch (monsterDirection)
    case Input.DOWN:
    // 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; // 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

    switch (monsterDirection)
    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 02:19 PM.

  2. #2
    tim's Avatar
    tim is offline Senior Member
    Join Date
    Dec 2007
    Rep Power

    Default Using collision detection.

    Hello jaferris.

    Collision detection can get tricky. First you must ask yourself:
    1. Are my objects moving fast?
    2. 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
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    how something dissappears when you touch it
    Don't draw it anymore.

Similar Threads

  1. HashMap: Obtaining all values in a collision?
    By markus-sukram in forum New To Java
    Replies: 2
    Last Post: 03-29-2008, 10:25 PM
  2. Collision Detection (Game)
    By mscwd in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-28-2008, 08:34 PM
  3. Listener collision on game
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 07:48 AM
  4. Deadlock detection tools documentation
    By goldhouse in forum Threads and Synchronization
    Replies: 0
    Last Post: 07-18-2007, 05:18 AM
  5. a few problems
    By gary in forum AWT / Swing
    Replies: 0
    Last Post: 07-11-2007, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts