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


ADVERTISEMENT

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

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

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 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

Calculate Possible Tiles Clicked Unit Can Be Moved On And Display It To Player

May 15, 2014

Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.

The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.

Example: (unit = o; possible tiles = x) (assuming movement of 2).

[ ][ ][ ][ ][x][ ][ ][ ][ ]
[ ][ ][ ][x][x][x][ ][ ][ ]
[ ][ ][x][x][o][x][x][ ][ ]
[ ][ ][ ][x][x][x][][ ][ ]
[ ][ ][ ][ ][x][ ][ ][ ][ ]

I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.

@Override
public void mouseClicked(MouseEvent e) {
if (Main.cards.size() > 0) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
int startingColumn = 0;

[Code] ......

View Replies View Related

Player One Type A Number And Player Two Suppose To Guess - Infinite Looping

Apr 2, 2014

Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.

import java.io.*;
class GuessingGame
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String firstPlayer, secondPlayer;
int firstInput, secondInput;
int guessCount = 0;

[Code] .....

View Replies View Related

How To Add Tiles To Screen

Mar 24, 2014

this is my first java game im making i tried to add tiles to the screen but i just get a black screen with no errors?

View Replies View Related

Error While Moving The Tiles In Frame

Jan 17, 2014

I was following a tutorial on how to make a game when i suddenly got an error concerning moving tiles. i get this error when i tried to use a and d to move:

Exception in thread "Display" java.lang.ArrayIndexOutOfBoundsException: 48600
at com.cherno.graphics.Screen.render(Screen.java:44)
at com.cherno.Game.render(Game.java:124)
at com.cherno.Game.run(Game.java:87)
at java.lang.Thread.run(Unknown Source)

I do not get the error while using w or s but the tiles are still not moving when pressing them.

I have three classes at work here.

The main, Game.java;

package com.cherno;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

[Code] .....

View Replies View Related

2D Game - How To Create A Library Of Tiles

Apr 8, 2014

So I'd like to make like a library of tiles, and it isn't too big, which I could just call using a method, and I would specificy what information I need to get, and it would return that information.

For example, a small section of the tiles library is grass_tile, I call this library and specify what I need, and in this case let's say I need the width, or can the character enter it from north? or can the character just stand on it? So it's like a library or array, with sections of it being named by tiles, and by mentioning these tiles I can information about them.

gTile("grass","walkon") will return true, first because I specifiy grass, and yes the character can walk on grass, so it returns a boolean value of true.

gTile("stone","width") will return 16, first because I specify stone, and the stone's png image size is 16.

What I'm asking is not for how to work out if the character can walk on the tile, or read the width of a tile, but can I create like a library from which I can obtain information by giving the name of the tile, and then telling it what info I need.

If up key pressed && gTile((yTILE + 1).name(),"walkon") == true then moveChar("up")

View Replies View Related

Scrabble Been Able To Match 7 Random Tiles From ArrayList

Nov 25, 2014

I am trying to do here is to get as many words as we can to match words from the text file giving the 7 random letters from the arraylist ...

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
public class Scrabble {
public static Scanner scan = new Scanner(System.in);

[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

LibGdx / Box2D - How To Group Tiles Into One Larger Polygon

Jan 19, 2015

I am making a tile based top-down 2D RPG and am using Box2D for the physics. Since my game is tile-based, there are many tiles on each map that cannot be moved through. This results in many small individual Box2D bodies. This is obviously very inefficient and makes the game lag. Therefore I figured that combining the individual tiles' bodies into larger complex groups would be better.

The way I thought of doing it is to, first, group together tiles into groups of tiles that all share 2 vertices with at least one other tile in the group. Then, for each group I do the following. First I get all of the uncommon vertices (these should be the ones on the outside of the polygon). Then I connect all of those vertices and then remove all of the overlapping lines. This should result in only lines on the outside of the polygon. Then I sort the lines so that the first line in the sorted array shares its end point with the second line's start point, etc. Then I remove the doubled vertices and using those remaining vertices (I called them the "true vertices") I create the polygon. I know that Box2D only supports convex polygons, but with Box2DSeparator I should be able to do this, but I first want this method to actually work.

/**
* Attempts to combine the given blocks into larger bodies to improve performance.
* @param bs The created wall blocks.
* @param w The world. Used for body creation.
*/
private void makeLargeBodies(Block[][] bs, World w) {
Array<Tile> tiles = new Array<Tile>();
for(int i = 0; i < bs.length; i++) {

[Code] .....

However, this is where the first problem arises. This method is extremely slow for large maps (like 200x200 tiles). I have worked at this for very long and right now my head can't figure out how to make the loop more efficient...

Now for the next part. After that I attempt to create the bodies for the TileGroups:

//create all the groups' bodies
size = groups.size;
System.out.println(size + " groups");
for(int i = 0; i < size; i++) {
TileGroup g = groups.get(i);
System.out.println("Starting group " + i + ".");
long timeCheck = TimeUtils.millis();
g.createBody(w);
System.out.println("Group 0 took " + (TimeUtils.millis() - timeCheck) + " millis");
}

*Note that the printing is for debugging purposes*...

This method is probably not a problem; it is what is inside createBody(World) that is the issue...

public void createBody(World w) {
Array<Vector2> allVertices = new Array<Vector2>();
Array<Vector2> uncommonVertices = new Array<Vector2>();
System.out.print("Starting search for uncommon vertices. ");
long timeCheck = TimeUtils.millis();

[Code] .....

Most of the code is self-explanatory (with comments). My current issue is where I connect the uncommon vertices (see the printed statements). This method does not actually finish (I have let it run for several minutes and it does not complete). This is likely due to a large number of vertices (often around 3000 in a 60x60 map), but I cannot figure out how to make the loop more efficient... Because of this early failure I don't know if the rest of the method works, both physically and in theory.

All relevant classes (Tile, TileGroup, Line) are below:

private class Tile {
private Vector2[] vertices;
private TileGroup group;
public Tile(int x, int y) {
vertices = new Vector2[4];

[Code] ....

View Replies View Related

Two Rectangles Overlap

Oct 27, 2014

the thing with this program is that instead of it having preset variables, I want to prompt the user to enter values of the two rectangles. I don't know how to use the scanner in this case, or even if I should use the scanner.

class MyRectangle2D {
//declare the variables
private double x, y;
private double width, height;

[code]...

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

How To Make 2 Rectangles In Same Window

Oct 2, 2014

My goal is to make 2 rectangles in the same window. so far I have this.

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class BoxComponent extends JComponent

[Code] ....

After running the program I get one rectangle, the red one. If I take the code out for the red rectangle, I only get 1 blue one. What am I missing?

View Replies View Related

Determine If Rectangles Cover Each Other

Oct 22, 2014

[URL] .... This is a link to the credentials that need to be met.

/* Constructors, getters and setters that will determine if the rectangles cover each other.*/

import java.util.Random;
import java.lang.Math.*;
class Rectangle{
   int width = 50;
   int length = 50;
   int x = 90;
   int y = 90;
  
[Code] ....

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

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

Drawing Rectangles From Array List

Nov 13, 2014

The program is where you will click anywhere in the jframe and it will draw a new rectangle. I have altered the code given to us but the problem that I am having is the fact that when I click the rectangle will always be connected to the upper left hand part of the jframe, no matter where I click. The program should create rectangles of the same length and width wherever you click. Here is what I have. I believe I have to change something in the addRectangle method, but nothing that I have tried works.

Java Code:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.util.ArrayList;
public class RectangleComponent2 extends JComponent

[Code] .....

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

Applets :: Drawing Ovals And Rectangles In JApplet With Two Separate Buttons

Apr 15, 2014

I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.

public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");

[Code] .....

View Replies View Related







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