Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Collision Detection between two images in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
Collision Detection between two images in Java
2 Answer(s)      11 months ago
Posted in : Java Beginners


Collision Detection between two images in Java


Advertisement
View Answers

December 23, 2013 at 5:27 PM


Here is code to detect collision between two images.

public class Player
{
    int X;
    int Y;
    int Width;
    int Height;

    // Getters and Setters
}

public class Enemy
{
    int X;
    int Y;
    int Width;
    int Height;

    // Getters and Setters
}

foreach (Enemy e in EnemyCollection)
{
    Rectangle r = new Rectangle(e.X,e.Y,e.Width,e.Height);
    Rectangle p = new Rectangle(player.X,player.Y,player.Width,player.Height);

    // Assuming there is an intersect method, otherwise just handcompare the values
    if (r.Intersects(p))
    {
       // A Collision!
       // we know which enemy (e), so we can call e.DoCollision();
       e.DoCollision();
    }
}


Related Tutorials/Questions & Answers:
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
java collision detection between two images
java collision detection between two images  java collision detection between two images
Advertisements
Java Circle to Circle collision detection
Java Circle to Circle collision detection  Java Circle to Circle collision detection
UIImageView Collision Detection
UIImageView Collision Detection  Is there any way to detect UIImageView Collisions in Objective C? Thanks
combining 5 images and text in between to one single image in java
combining 5 images and text in between to one single image in java  Hi I have to combine 5 images and text in between to one single image. I have image followed by description about the image. I have to put them together
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
Images in java
Images in java  how to handle images in java
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two dates from the database table. I am using combo box to get the date. Problem
to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write a function which calculates the difference between 2 different dates 1.The function...) { // Creates two calendars instances Calendar calendar1 = Calendar.getInstance
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two
To get the String between two strings
To get the String between two strings  How to get string between two strings repeatedly using java?   Hi, Please tell me more about what do you want to achive. Thanks
keep spacings between images when adding to scrollpane
keep spacings between images when adding to scrollpane  !alt textI'm adding a list of images from a directory using an arraylist.When images are added,my ScrollPane gets crowded.How can I keep spacings between images ? here's my
keep spacings between images when adding to scrollpane
keep spacings between images when adding to scrollpane  !alt textI'm adding a list of images from a directory using an arraylist.When images are added,my ScrollPane gets crowded.How can I keep spacings between images ? here's my
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
Hash-function: "weakly collision-free" and "strongly collision-free"
it had two defines of H. It was "weakly collision-free" and "strongly collision-free". I think two defines have the same meaning. Explain: A hash function H...Hash-function: "weakly collision-free" and "strongly collision-free"  
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
error detection - Java Beginners
{ public static void main (string[] args) { Queue q=new
how to get string between two characters
how to get string between two characters  hgow to get string from between two characters. ex:hareesh.arava@gmail.com from the above word i want a string between characters . and @ send the required method and give better example
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
java mail sending with images
java mail sending with images  I need to send images through java mail without giving content path(i.e. we don't want hard code the image path)can you tell me the idea?   Please visit the following links: http
How to manage cookie in between two JSP Pages
How to manage cookie in between two JSP Pages  How to manage cookie in between two JSP Pages   you can set cookies in response object e.g.response.addCookie(new Cookie("userName","Password")). Chandraprakash Sarathe
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example: <html> <head> <title>Number of days between two
images - Java Beginners
images  how to do image watermarking in java? or how to identify watermarked images.. tell something related to the watermarking concept implementation in java?  Hi Friend, Try the following code: import java.io.
java program for Denial of Service (DoS) attacks detection - Swing AWT
java program for Denial of Service (DoS) attacks detection  i want a simple program to generate and detect a Denial of Service (DoS) attacks. using java program
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
images - Java Beginners
("Java"); content.add(button1); ImageIcon cup = new ImageIcon("/home...); content.add(button2); JButton button3 = new JButton("Java", cup..., http://www.roseindia.net/java/example/java/swing/ Thanks
Sending images through java mail
Sending images through java mail  Am trying to develop greeting application that having images..... in one jsp page i displayed all images and by clicking one image the control go to mail sending page in that the image should add
 

 

 

DMCA.com