Hi Guys, Im currantly having a problem with simulating balls bouncing of each other in a 2d space, everything is working and all, but it just doesant seem natural for me... If we had any math wizzes here now is your time please:) my circles are painted inside of rectangles..... This is what is the code im using to find the new x and y coordinates of the circles. specifically this piece here... //Pythagerum theorem, a^2 + b^2 = c^2, to figure out the distance between the two circles' centers. int distance = (int) Math.sqrt(((currantXa - currantXb) * (currantXa - …

Member Avatar
Member Avatar
+0 forum 14

Hello! I am looking for some help, and have provided the code. I'm just trying to do some simple stuff. I'm trying to create a simple game without using classes (but using lists). What I'm trying to do is create collision detection among list objects ("bullets" and "baddies"), as you'll be able to see in the code. I'm also trying to fire 10 bullets at once from an "ammoCrate". My problem is that I have to stay on the "ammoCrate" in order for the bullets to do their thing, otherwise they stop in place and disappear, but continue if the …

Member Avatar
Member Avatar
+0 forum 2

This tutorial is the first time I write about coding techniques for improving the performance of software. This is going to be a step-by-step journey through a real example, with real benchmark results at every step so that you can see the effect of the different optimization techniques. And as my first tutorial on performance optimization, I have to talk about the most important principle in performance optimization: keeping things hot. If you expect this tutorial to be about showing bits of code and the assembly listings generated by the compiler and then, showing how to reduce the number of …

Member Avatar
Member Avatar
+7 forum 3

Hey, all! I'm trying to figure out how to add collision detection to the following code but I'm having trouble trying to figure out how to pull in the x and y coordinates of the different eggs that are falling randomly. Would you be able to tell me what I'm doing wrong? Thank you! <html> <style> #playingArea { position: absolute; top: 1; left: 1; width: 750; height: 720; z-index: 2; } #basket { position: absolute; top: 650; left: 228; width: 100; height: 145; } </style> <script type="text/javascript" language="Javascript"> var basket; var basketLeft = 228; function keyListener(e) { document.getElementById("si"+i).style.top=eggsTop; document.getElementById("si"+i).style.left=eggsLeft; if …

Member Avatar
Member Avatar
+0 forum 4

Heya guys, i have been trying to make this very famous ball game using java swing. although the primary code ihave used is from this link [[Click Here](http://www.edu4java.com/en/game/game6.html)](null)but been trying to modify it to make it look less complex..But everytime i run it it gives me following error: Exception in thread "main" java.lang.NullPointerException Exception in thread "main" java.lang.NullPointerException at ballGame.Ball.collision(mainGame.java:209) at ballGame.Ball.move(mainGame.java:196) at ballGame.mainGame.main(mainGame.java:65) so, plz can anybody help me with this?? package ballGame; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JButton; …

Member Avatar
Member Avatar
+0 forum 9

I am trying to determine collision in a 2D Side Scroller environment using Rectangles. However, the way most people do it is to get the bounds of the Tile. I do not use Tile's in this case, I am just drawing Simple Full Colored Rectangles using Graphics2D. `g.drawRect(int x, int y, int width, int height)` I would obviously need a GameObject Class, which I have below, and I do check for an intersect, but I don't think that would actually check for collision because I dont know where it should be called. Also, how would you know which parameters to …

Member Avatar
Member Avatar
+0 forum 4

So im making an RPG. For collision detection, I thought I would do it like this: 1. Read text file containing collision data. 2. Iterate through the list using nested for loops. 3. When a value of 1 occurs (denoting an inpassable tile) add a rectangle to list 'badTiles', where the x and y pos of the rectangle is the x and y value from the nested for loop times the tile width and height. 4. Now that all bad tiles are stored in a list of rectangles, we can check for collision. 5. In player class, perform a foreach …

Member Avatar
Member Avatar
+0 forum 9

So im making a simple RPG using c# and xna. For collision, i am using a text file that contains data about whether a tile is passable or not. I iterate through them and create rectangles based on the position of the 'bad' tile in the text file. I then used these rectangles for collision detectiong. Now, I can easily check whether or not the player is collision with these 'bad' tiles by using the 'Intersection()' method of the Rectangle type. What I am struggling with however, is what do I do once the collision is detected. So far, I …

Member Avatar
Member Avatar
+0 forum 1

So im posting this here and not under game development because this is more of a problem solving question, not directly game related. Im making a simple RPG using xna. Im currently working on collision detection, however running into difficulty. I can successfully check for a collision between the player and a 'bad' tile, however I am stumped as to what the engine should do to prevent the player from passing throguth it! Currently, I am getting the players based on an enum 'Direction', which is set whenever one of the 4 arrow keys are pressed. I am then creating …

Member Avatar
Member Avatar
+0 forum 1

I am doing a school project which is an airplane collision detection system. Can anyone show me a few examples or pseudocode of implementation of closest pair algorithm O(n^2), O(n log^2 n), O(n log n)?

Member Avatar
Member Avatar
+0 forum 10

hey hey folks. I am making a tetris clone for my class project in college. langauge is XNA and I have run into a minor issue. When my bricks get to the bottom, rather than stack, they simply reset back up to the top. I have tried everything I can think of...to no avail. I have been working on this bad boy since about 2pm, its now 1:46 at the time of posting. I *THINK* the issue is somwhere inside my collision detection code way down at the bottom, but im not sure. any halp would surely be appreciated. variables …

Member Avatar
Member Avatar
+0 forum 11

Im making a 2D platformer-ish shooter its really simple and not much effort put in it, it is my first game Im making in python and its for a school project and needs to be finnised really soon. Everything is working just fine but Im having problem with some collision detection with my shoots, I don't know how to make it. So would really appreciate any help I could get. Feel free to tell me if anything is wrong or could be better and use this code for your own learnings. And I know its a bit messy but I …

Member Avatar
Member Avatar
+0 forum 11

Hi! I've been making this game for fun and have run into a few problems, a friend recommended me to ask you guys for help. I have three problems: 1. The player doesn't recongnize when it's not on a platform and because of this it won't fall down. I've narrowed it down to the game not checking for vertical collision all the time but I don't know how I would solve this. 2. If the player is colliding with a wall and you try to use thrusters it'll fall out of the level. I have no idea why this happens, …

Member Avatar
Member Avatar
+0 forum 9

I am trying to create a simple scoring function using sprite collision. I have my sprite ids defined under a seperate header and my class is in order. LEFT_SCORE is animated using a sprite sheet (obviously). int Ball::leftGoal( ) { int leftScore = 1; if (dbSpriteCollision (BALL, 12)) {++leftScore;} dbSetSpriteFrame (LEFT_SCORE, leftScore); return 0; } The output I am getting is that leftScore increases as expected and the LEFT_SCORE sprite acts appropriately... But, the score never tallies. It works only while the two sprites (BALL and 12) are actually touching. After that the value of leftScore returns to 1. I …

Member Avatar
Member Avatar
+0 forum 4

Hello, I've been having a lot of trouble with collision detection recently. I'm attempting to make a 2D platformer. All I need is rectangle-on-rectangle collision detection, and then to respond on collision by moving the two rectangles involved in opposite directions. Thanks in advance.

Member Avatar
Member Avatar
+0 forum 10

I am trying to add collision detection to this simple game, but I am a little lost on where to begin. I know I need to use rects to do this but I am struggling to find out what I need to code to make this work. Any pseudocode or any hints pointing me in the right direction would be greatly appreciated. Here is my code: #Image Variables bg = 'bg.jpg' bunk = 'bunker.png' enemytank = 'enemy-tank.png' #Import Pygame Modules import pygame, sys from pygame.locals import * #Initializing the Screen pygame.init() screen = pygame.display.set_mode((640,360), 0, 32) #Loading Images and More …

Member Avatar
Member Avatar
+0 forum 4

IM A COMPLETE TOOL PLEASE IGNORE / DELETE THIS POST Hello everybody, im currently trying to learn 3d game development (ive developed 2d games in the past, nothing this complex, i am a third year programming student). Ive been working on this project in my spare time for the past few weeks, and im really stumped. Im using axis aligned prisms for my collision detection, and I cant seem to get it to work correctly. Im using java lwjgl to program openGL. I would really appreciate any assistance you guys can offer (even if its just pointing me in the …

Member Avatar
+0 forum 0

I have two bounding boxes defined by the following values: m1.min.x;//the min x value of model 1 m1.min.y;// " " y " " " " m1.min.z;// " " z " " " " m1.max.x;// " max x " " " " m1.max.y;// " " y " " " " m1.max.z;// " " z " " " " m2.min.x;// " min x " " " 2 m2.min.y;// " " y " " " " m2.min.z;// " " z " " " " m2.max.x;// " max x " " " " m2.max.y;// " " y " " " " m2.max.z;// " " …

Member Avatar
Member Avatar
+0 forum 5

I originally asked this question at cplusplus.com but got no responses. In my program I have the main player and enemy tanks. When using the shotgun weapon it works fine for the main player but it kills the bad guy when they use the weapon. I don't understand how this is happening. I'll show (what I believe to be) the relevant code snippet, the cplusplus.com link and also attached is the code in its entirety. unsigned long* collisionhandler::checkpellethit(int good, int *n) { int z=0; unsigned long *dead = new unsigned long[weapons.size()]; int q = weapons.size(); for (int i=0;i<q;i++) { //printf("in …

Member Avatar
+0 forum 0

Hye all, I had a difficulty in codes a ball collision in java. Is there anyone could help me to code it. Here the requirement: 1) There will be two balls in the same size. 2) They move randomly at constant speed until they meet each other. 3) Once collided, they move in a different direction. 4) And the balls will move slower (less velocity) before they collided. I could appreciate more if anyone could help me in this. and I need an immediate response. Thanks :)

Member Avatar
Member Avatar
+0 forum 3

Hello, I'm using SFML to make a game, and, as it has no built-in collision detection function, I made up my own algorithm. Here it is: [CODE] // Collision.cpp #include "Collision.h" Side CollisionBoxTest(sf::Sprite Hitter, sf::Sprite Hittee) { sf::Rect<int> HitterBox; sf::Rect<int> HitteeBox; // Initialize parameters for Hitterbox int BoxHeight = Hitter.GetHeight(); int BoxWidth = Hitter.GetWidth(); sf::Vector2f BoxPos = Hitter.GetPosition(); // Pass parameters to HitterBox HitterBox.Left = BoxPos.x; HitterBox.Right = BoxPos.x + BoxWidth; HitterBox.Top = BoxPos.y; HitterBox.Bottom = BoxPos.y + BoxHeight; // Change the parameters to HitteeBox BoxHeight = Hittee.GetHeight(); BoxWidth = Hittee.GetWidth(); BoxPos = Hittee.GetPosition(); // Pass parameters to HitteeBox HitteeBox.Left …

Member Avatar
Member Avatar
+0 forum 2

I've created a game , somewhat like space invaders, and it looks pretty cool , very proud of what ive done. But I'm stuck on finding a way of unit testing the collision of 2 sprites and the collision between the borders and a sprite. If anyone could point me in the right direction or has any sample code of this happening that would be great!

Member Avatar
Member Avatar
+0 forum 1

Hey y'all, so I've created a 2D billiard program that basically just collides 2 balls together and determines their new direction and velocity however I now want to be able to change the colors of the balls after collision by using [CODE]Color.FromArgb(int r, int g, int b)[/CODE]. I would use something like [CODE]Red component = max( velocity * 25, 255 )[/CODE] ... etc for blue and green to create the colours of the balls afterwards (velocity would just be the sum of the square horizontal and vertical velocities). I was wondering if anyone had any tips other than what I …

Member Avatar
Member Avatar
+0 forum 3

I have this problem: [CODE]struct Position { float x; float y; float z; }; bool CheckCollision(Position *vertices, int numvertices, Position start, Position end) { //return true if there was NOT a collision with the polygon defined by the vertices and the vector defined by the two positions. }[/CODE] I dont even know where to begin, I thought of stepping through the vector from start to end in small increments, but that would be slow and might pass right through the polygon sans interference. Any hints?

Member Avatar
Member Avatar
+0 forum 7

Hey I am making a game and i can make the character jump, but i am trying to make the character land on an object. I am trying to do this with object collision but im not sure how. My code for jumping for an image with a certain height is below. I was trying to do it when the character jumps to a certain height and collides with an object, its new location on the screen will be on top of the object but i am not sure how to add that in. any suggestions would be great. [CODE]//METHOD …

Member Avatar
Member Avatar
+0 forum 1

Hi, I am writing a game in C++ and OpenGL. My whole environment is based on cubes so I guessed bounding box collisions were best. I can currently move around and my program is detecting collisions (I used this tutorial: [url]http://www.3dcodingtutorial.com/Collision-Detection/Collision-Boxes.html[/url]). Now I want to make it so that when the camera hits a bounding box it slides along it (like in any FPS game). My update camera procedure looks like this: [CODE] void updateCamera() { glRotatef(xrot,1.0,0.0,0.0); //rotate the camera on the x-axis (left and right) glRotatef(yrot,0.0,1.0,0.0); //rotate the camera on the y-axis (up and down) glTranslated(-xpos,-ypos,-zpos); //translate the screen …

Member Avatar
Member Avatar
+0 forum 4

EDIT: My problem was solved. :) But I have a doubt, what is the most effective way to wait for something to happen in java? for example, if I want to wait for a boolean b to be true, does this below work? [CODE=java]while(!b) {} //stuff to do after wait here[/CODE] or is it more effective to use a Thread and sleep some time before checking again? Or is there another way? OLD SOLVED STUFF: Hey, I'm developing a game in which you control a ball with your mouse and you must avoid hitting some rectangles that keep rising in …

Member Avatar
Member Avatar
+0 forum 4

Greetings, I've been given a challenge to build a simple game for my daughter. The idea is that you smash the spacebar, and a ball drops into the game, goes down some ramps, and lands at the bottom. Being a newbie programmer, this is becoming a challenge. I decided to use ray-tracing to determine if my ball has collided with the ramps, and I have a Polygon class that defines the vertices of the bounding boxes for collisions with the ramps. I know that I need to determine how many times the rays cross the edges of the polygon, and …

Member Avatar
Member Avatar
+0 forum 1

ok so i need my code to be able to have the balls on the screen detect collision and remove a ball when they collide but for some reason every time i hit the add a ball button they disappear on me. and they dont detect collision in the first place any help would be wonderful :-) o P.S. the way we are tackling it is by putting a rectangle around each circle and using the intersects method that comes with rectangles here's my BallPanel class [CODE]package lab5; import java.awt.*; import javax.swing.*; import java.util.*; /** * A panel containing two …

Member Avatar
Member Avatar
+0 forum 5

The End.