Video Game - Collision Detection Class?

Apr 30, 2014

I use eclipse as my IDE. I have decided to make my own video game and somebody had sent me a class that could be used for collision detection. The problem with the collision detection class was that it made a box around an object and if something else had touched the object, the collision detection would work. My problem with this class is what happens when i want to use circles? I cant have a box drawn around it. Then it wouldn't work as i would want. Is there a pixel perfect collision detection class out there I can use? It'll be useful in my journey to become successful in computer science! By the way this is in the java language.

View Replies


ADVERTISEMENT

Pong Game - Y Axis Collision Detection

Jan 28, 2014

I have made a "Pong" game and how to check if the ball has hit the top or the bottom of a paddle, however I do know how to check if it has hit the left or right side:

Java Code:

if((BALL.getX() >= LEFT_BAT.getX() && BALL.getX() <= LEFT_BAT.getX() + LEFT_BAT.getWidth()
&& BALL.getY() >= LEFT_BAT.getY() && BALL.getY() <= LEFT_BAT.getY() + LEFT_BAT.getHeight())
&& (BALL.getX() >= RIGHT_BAT.getX() && BALL.getX() <= RIGHT_BAT.getX() + RIGHT_BAT.getWidth()
&& BALL.getY() >= RIGHT_BAT.getY() && BALL.getY() <= RIGHT_BAT.getY() + RIGHT_BAT.getHeight())){
BALL.increaseDX();
BALL.setDX(-BALL.getDX());
} mh_sh_highlight_all('java');

It seems as though I would use the same code for checking the top or bottom.

View Replies View Related

Space Invaders Game - Collision Detection

Apr 19, 2014

I'm working on a space invaders game and I'm having problems with collision detection. My main issue is I'm having problems getting what the y value of the "missile" is as it goes up towards the top of the game. I have tried for many hours and tried to look at other people's space invaders game in an attempt to figure out how to figure out my problem. Also I'm not sure if I have the code for my collision detection in the correct spot. Right now I have the code in the keyPressed method. Below is the code for the main and missle classes ...

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;

[Code] ....

View Replies View Related

Object Collision Detection - Character Freezes

Dec 2, 2014

I don't understand why when I collide into my objects my character freezes. Such as if I collide into collision() I can go left and right but, not up and if I collide into collision2() I freeze in all places but, if I collide into the bounds I made I can still go in all directions without problems. The xa and ya are still being set to 0.

package com.questkings.game;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;

[Code] .....

View Replies View Related

Collision Detection Using Rectangles - Player Sometimes Passes Through The Tiles

May 19, 2014

I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.

private void movement(){
left=bindObject.getLeft();
right=bindObject.getRight();
up=bindObject.getUp();
down=bindObject.getDown();
bindObject.setColliding(colliding);

[Code] .....

Where bindObject is a class which contains key bindings of following keys:-

left arrow key (when pressed) , left arrow key (when released),
right arrow key (when pressed), right arrow key (when released),
up arrow key (when pressed), up arrow key (when released),
down arrow key (when pressed), down arrow key (when released)

View Replies View Related

JAVA Platform Game Jumping And Collision

Sep 16, 2014

i have problem in what comes to jumping because in what i have now mario jumps with the key lsitener, key pressed up arrow and it jumps smooth but when im trying to make it fall down he appears immediatly at ground and it doesnt simulate the fall as it should be.

import java.awt.BorderLayout;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.awt.EventQueue;

[code]....

The other problem is that i dont really know how to detect collisions if there is a method that makes easier this proceso and how to make the map to continue and repeat so mario could continue walking,

View Replies View Related

Swing/AWT/SWT :: BorderLayout - Adding Multiple Video Game Oriented Objects Such As Sprites To JFrame?

May 24, 2014

I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that.Before you answer: Also, is using BorderLayout the best option for adding multiple video game oriented objects such a sprites to a JFrame?

So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: URL....

Here is the code:

**main.java** --> The main method class + JFrame/JPanel/JButton constructor
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class main {

[code]....

View Replies View Related

Dead On Collision

Jun 15, 2014

okay so far I have made a game with character that runs with constant velocity it jumps and ducks . I want the player to be dead on collision from a hurdle and then play a specific png, which shows the dying style . I am able to build collision detection but it passes from background I want it to collide and be dead on collision.

View Replies View Related

JavaFX 2.0 :: Point Of Collision Between Shapes

May 25, 2015

I have a problem in with colissions in JavaFX.
 
First, I detect a collision between a line and a circle using the follow code:
 
if(line.getBoundsInParent().intersects(circle.getBoundsInParent())){
System.out.println("Collision!");
}
 
After this, i need catch the coordinate of collision, like the below figure:

How to catch this coordinate?
 
[]'s

View Replies View Related

Object Motion Detection

Mar 25, 2014

Any examples for object detection or motion detection program..

View Replies View Related

Face Detection On Camera?

Sep 3, 2014

I want to do face detection on the camera.

View Replies View Related

Directed Graph Cycle Detection

Jan 4, 2015

I have some problem checking if a directed graph has a cycle or not. So I have a given rooted directed graph, and find if there at least one existing cycle.

For example, I have to input the Root Node, followed by a number of nodes, the nodes in the graph, number of edges, and the adjacency list representing the edges. Each entry in the adjacency list contains a pair of nodes. The ordering of the nodes in the pair represents the direction of the edge. An entry A, B means that there is an edge from A to B. Nodes in each pair is separated by a space. One input per line.

And the output should display whether the directed graph has a cycle or not.

Sample input:

A //Root Node
6 //Number of Nodes
A //Nodes in Graph
B
C
D
E
F
6 //Number of edges
A B //Adjacency list representing the edges
B C
C D
C F
F E
E B

Output:
Cycle!

Graph Representation:

Based on the illustration above, the graph has one cycle. The cycle exists in nodes B, C, F and E.

View Replies View Related

Faulty Mouse Point Detection?

May 26, 2014

So I'm making buttons for a game I'm making. The graphics work, at least to the extent that I don't have to fix them yet. However, click detection is a bit iffy. For example pressing where the black line is in the first picture below, triggers a response. Now obviously that point is not on the button. I have tested the buttons bounding box by drawing a rectangle around it, using it's getBounds() method (which is also used for click detection) and it draws a perfect rectangle around it. So then I tested the mouse click points and it turns out that even though the button is placed at y = 100, at the black line, the mouse point is also equal to 100... Now, why that is happening, especially because, if I place the button in the top left corner, the mouse detection correctly detects the top pixels and there is no offset...

View Replies View Related

Servlets :: Feature Detection - Determine Browser Type

Apr 22, 2014

I need to be able to detect IE 9, IE 10, IE 11 and the latest from Firefox and Chrome. The old method using the user-agent string is unreliable and not recommended. There is a different approach called, "Feature Detection". But I need to know what features to test to determine the browser. I can write it myself, or if there is a handy dandy API using feature detection already written that would be OK too.

View Replies View Related

Unable To Detect Collision Between Moving And Stationary Jbuttons Using Rectangle Intersection

Apr 5, 2014

I am trying to detect the collision between a moving Jbutton and stationary Jbuttons using Rectangle Intersection.

When I run the program I am getting a NullPointerException on line 'msg1.setBounds(new Rectangle(320,50,400,50));'.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class gamePanel01 extends JPanel implements KeyListener {
character ch1 = new character("Hero");
//Global Variables
JButton blocker01;
JButton blocker02;

[Code]...

View Replies View Related

Game Class - Nothing Will Print Into Console

May 7, 2014

I'm new to java, and i'm trying to make a gaming, but for some reason nothing will print into the console. I want it to have the system to print out the frames, and ticks, but nothing will happen.

package ca.trey.game; 
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
 
[Code] .....

View Replies View Related

Text From The Class Game Doesn't Update

May 3, 2014

I have a main class that hold the frame and paints, a class for drawing my game, and an image that is drawn too.
I want to count the amount of times I click on this "android" (right now it counts if i click the screen) but the text from the class Game doesn't update.

androidX = Main.width - android.getWidth();

doesn't work. In my head the image should be inside the borders but it isn't. Have I calculated the pixels wrong or am I missing something?

public class Main extends JPanel{
public static final int width = 600;
public static final int height = 600;
Game game = new Game();
Android android = new Android();
public void paint(Graphics g) {
super.paint(g);
game.render(g);
android.render(g);

[code]....

View Replies View Related

Design Class - How To Organize Classes For UNO Card Game

Mar 20, 2014

I'm currently taking a computer program design class which has done a lot for my understanding of how to organize classes, but isn't giving me challenging enough assignments and I don't believe it's going to be covering interfaces and abstract classes, which is a shame. So I've been digging into these topics myself and decided to work on my own program (an Uno game program) that would utilize everything we've been learning and give me some practice with GUIs.

My current plan:

Have an abstract UnoCard class that determines the basic properties/methods common to all cards. Create a class for each card type extending from UnoCard, which would be - the generic card (number and color), action cards (skip, reverse, draw two), and special cards (wild, wild draw four, and blank).

Two enums, one for color, one for rank (which includes the numbers, as well as the action and special card ranks (reverse, wild, exc.) ).

A deck class would have an ArrayList <UnoCard> property and it's constructor would initialize a fresh deck.

A hand class that also has an ArrayList <UnoCards> where it gets said cards from the deck class.

A discard pile class, which contains the cards discarded and the current card in play.

A "board" class (haven't figured out a better name for it yet) which would determine/keep track of the number of players/hands, the turn order, the locations of the cards, and the winning condition.

Area of confusion and concern I'm having:

From what I've read, I want to avoid circular dependency. So if that's the case, when a card type effects the state of a "hand" or the turn order or really anything else, then in what class do I place the method(s) that effect that? If I place it in the specific card class, wouldn't that create a circular dependency? So would it be better then to have the hand class figure out what can be done with a specific card and what that specific card effects (which wouldn't that hinder the cohesion of the class?)?

I was also thinking a possible solution might be to have the non-generic card types contain methods that return values as apposed to manipulating higher level classes, such as a boolean drawCards which returns true if cards need to be drawn, false otherwise (same for skip, reverse, exc.).Then maybe the board class can determine what to do if those values are true or false (which actually seems more convoluted since only one value would be allowed to be true at any given time).

The other solution I was considering is to have a single UnoCardRules class, which serves the sole function of providing methods to determine the effects of each card, that way each card class can only worry about defining the card's state.

View Replies View Related

Hangman Game Using Class - It Keeps On Bringing Up Exception Error

Apr 23, 2015

I wrote a program that would play a game of Hangman. It plays the game but it keeps on bringing up a exception error. This is my class code

import java.util.ArrayList;
class Assignment2Q4
{
private final ArrayList<Character> guessList = new ArrayList<>();
private final char[] charArray;
private final String secretWord;
private int guesses;

[Code] ....

This is the output that is given:

Enter the secret word:
pizza
Guess a letter:
d
?????
Guess a letter:

[Code] .....

Also when I guess the first letter of the word correctly it stops the program without going further on with the guessing.

Like for ex. P????

View Replies View Related

Second Video Cancels First

Oct 31, 2014

How do I correct this problem… The first video wil cancel out the second one. Can it be stopped?

<script language="Javascript" type="text/javascript">
function reload()
{
setTimeout('reloadImg("refresh")',1000)
};
function reloadImg(id)

[code]....

View Replies View Related

Which Listener To Use On Video Panel

Jun 4, 2014

I have panel = window(new frame) and its used to render a video image on, i need to pickup a touchscreen press change of event but not sure which event listener to use and on which component. Is it a panel, window or frame event? and which listener would detect a focus change or a mouse press

I know mouse listener and focus listener and window listeners are available but not sure they would be able to detect the screen press on the video rendered image...

View Replies View Related

Inserting Video Into Graphics?

Feb 12, 2014

So I'm doing a project for my CS class where we have to create a snowman doing something. My picture is of Vince Young in the 2005 Rose Bowl. I'm trying to make the actual video clip from Youtube (do I need to download it? If so I can do that) appear on the scoreboard, but how.

import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
class snowBackground
{
public static void drawField(Graphics g, Color field)

[code]....

There are 3 other files that make the actual Snowmen.Also, would I need to download the mp3 sound file seperately and play that, or will inserting the video do both?

View Replies View Related

Swing/AWT/SWT :: Inserting A Video Into Graphics?

Feb 12, 2014

So I'm doing a project for my CS class where we have to create a snowman doing something. My picture is of Vince Young in the 2005 Rose Bowl. I'm trying to make the actual video clip from Youtube (do I need to download it? If so I can do that) appear on the scoreboard. As of right now, this is my background file:

import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
class snowBackground {
public static void drawField(Graphics g, Color field) {
Color sky = new Color(95,166,243);

[Code]...

and this is the Driver file (not sure if this is necessary):

import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
public class SnowDriverWSB {
public static void main(String args[]) {
GfxApp gfx = new GfxApp();
gfx.setSize(1000,650);

[Code]...

There are 3 other files that make the actual Snowmen. To do this, I need VERY basic steps, as I'm extremely confused and new to Java. Also, would I need to download the mp3 sound file seperately and play that, or will inserting the video do both?

View Replies View Related

Encrypted Video Chat Program Using JMF

Oct 23, 2014

I am trying to make an encrypted video chat program using JMF. I have successfully written the "video chat" part - which includes getting data from webcam and transmitting it using RTP, but how to get raw data video to encrypt it before it stream between the webcam and the network.

For RTP I am using RTPManager, and for reading from the webcam I am using this code:

DataSource ds;
CaptureDeviceInfo di = null;
StateHelper sh = null;System.out.println("Started Video");
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
String str3 = "vfw:Microsoft WDM Image Capture (Win32):0 : vfw://0";

[Code] .....

I plan on using a stream cipher for encryption, maybe RC4.

View Replies View Related

How To Play Video Into Java Application

Feb 10, 2015

How to insert and play a video or a music background in a java application. Let me explain better... I need to develop a game where sometime I need to show picture, or play videos and also, if is possible, add a music in background... I work with eclipse and I know quite good the main concept of java's language...

View Replies View Related

Video Chat Tool Using Java RMI

Jul 3, 2014

I am stuck in making a C/S video chat program using JAVA RMI technology. I am more familiar with Java RMI.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved