Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-07-2008, 02:54 PM
Member
 
Join Date: Jan 2008
Posts: 1
jaferris is on a distinguished road
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
monsterBumpWallSound.play(); // play an appropriate sound
}
break;

// to do - fill in appropriate code for other directions
}
// increment the monster animation counter
monsterAnimationCount++;
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
munchieAnimationCount[i]++;
if (munchieAnimationCount[i] >= 10) // when the counter gets to 10, set it back to 0
munchieAnimationCount[i] = 0;
}

edit

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;
break;
// 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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-07-2008, 04:19 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 296
tim is on a distinguished road
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.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-08-2008, 12:19 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
how something dissappears when you touch it
Don't draw it anymore.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 04:03 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org