Skip to main content
Share Your Experience: Take the 2024 Developer Survey
16 votes
Accepted

2D Collision Detection

Collision detection You can calculate the collision much easier with the Rectangle structure. Use the Contains method if you ...
t3chb0t's user avatar
  • 44.3k
16 votes

2D Collision Detection in C++

const bool Game::isColliding(... This indicates that the returned type is const, and should not be modified by any part of your ...
JohnFilleau's user avatar
12 votes
Accepted

2D Collision Detection in C++

SFML implements functionalities that allow you to determine if two rectangles intersect. You can significantly shorten your current code: ...
Dessus's user avatar
  • 300
10 votes

2D Collision Detection in C++

John's answer is correct on programming matters. I want to comment on the logic of your code. I found the collision detection calculation difficult to interpret. Which point on the square is ...
Mark H's user avatar
  • 2,295
7 votes

2D Collision Detection

Just a quick answer. You are calculating s.Width / 2 for each Picturebox two times. Just calculate it once, store the result in ...
Heslacher's user avatar
  • 50.4k
7 votes
Accepted

Collision Detection in a 2D shooter game

You are creating a new Player and Tile every time this code executes. That is likely your performance hit. Try moving the existing player rather than creating a new ...
Summer's user avatar
  • 2,334
6 votes
Accepted

Kattis "Hitting the Targets" utilizing a polymorphic relashionship

Virtual destructor As a simple rule of thumb, if a base class contains any virtual functions, its destructor should also be ...
Jerry Coffin's user avatar
  • 33.6k
5 votes
Accepted

Flood Fill using unordered_map which has user-defined type as key

I'll ignore questions 1 and 5 regarding hashing, because you don't need a hash function at all. Storing image data A std::vector<std::vector<int>> is, ...
Cris Luengo's user avatar
  • 5,688
5 votes
Accepted

Intersecting rectangles on a torus

bool IntersectsOnTorus(int x1, int w1, int y1, int h1, int x2, int w2, int y2, int h2, int domain) Choosing to phrase it as (x, w, y, h) instead of (x, y, w, h) ...
J_H's user avatar
  • 28.1k
4 votes

Bounding volume hierarchy

Since you say this method is slower than the (also not shown) O(n^2) brute force mechanism, I can only assume that you mean for any n. This implies that your new algorithm is also an O(n^2) algorithm....
RidiculousRichard's user avatar
4 votes
Accepted

Octree Implementation

There are two programming principles that might aid you in your future programming, they are the Don't Repeat Yourself Principle and the Single Responsibility Principle. Following these principles ...
pacmaninbw's user avatar
  • 23.9k
4 votes

Handling collision on a turn-based 2D game

I'm not sure if you're looking to exactly reimplement the Puzzle Pirates collision mechanics described on the wiki page you linked to, or if you're simply looking to develop some reasonable collision ...
Ilmari Karonen's user avatar
4 votes
Accepted

Circle - Line segment collision

Memory costs CPU cycles. That is a lot for code for a simple operation. First some points about vectors, memory and performance. Vectors are small, short lived, most called, basic building blocks of ...
Blindman67's user avatar
  • 22.1k
4 votes

OBBs intersection improvement for AABBs-OBBs

Broad Phase collision detection It looks like you are using this for what is called broad phase collision detection. This is the step in collision detection that is used to determine candidate pairs ...
Harald Scheirich's user avatar
4 votes

Collision Detection in a 2D shooter game

You seem to have a player that changes coordinates when keys are pressed and tiles that are stationary. On each "tick" (~60/second), for each of the tiles (~1000) that is 0 (...
Tibos's user avatar
  • 667
3 votes

OBBs intersection improvement for AABBs-OBBs

Brain dump: The lines are a bit long. I have to consistently scroll to see a full line. While this is exacerbated by the narrow space alotted here on site, some of these lines are just really long :/ ...
Vogel612's user avatar
  • 25.2k
3 votes
Accepted

Simple class game hierarchy with collision detection

There is a somewhat-advanced technique called double dispatch that is useful for resolving situations where you have more than one unknown (virtual) type. In this case, you are using ...
aghast's user avatar
  • 12.4k
3 votes

Find the intersect area of two overlapping rectangles

...
Przemek's user avatar
  • 1,212
3 votes

Maximize the number of PyGame sprites, with collision detection

A quick suggestion. If you look at the implementation of spritecollide, you'll see that it iterates over all the sprites in the group to see if the rectangles ...
Gareth Rees's user avatar
  • 49.6k
3 votes
Accepted

Rectangle-segment collision detection

I am going to comment on code only. const I recommend using const whenever appropriate. It looks like you are not modifying ...
Jan Korous's user avatar
3 votes

Rectangle-segment collision detection

Checking for sign difference The current code is hard to read: //check for sign difference if (!((maindelta >= 0) ^ (checkdelta < 0))) I think the ...
JS1's user avatar
  • 28.5k
3 votes

Calculate next position and velocity after "bounce"

Review You have redundant code. Store position + velocity in a variable. Use well-known variable names when the code is of a mathematical nature. Distance ...
dfhwze's user avatar
  • 13.9k
3 votes
Accepted

Platformer Game: Arrow Key Player Movement and Collision Detection

Right off the bat, using multiple calls to setInterval is a bad idea. setInterval is already kind of unreliable and not very ...
Máté Safranka's user avatar
3 votes

Python Turtle based Pong game

First - You have numeric constants scattered all over the code. Try to change the board width to 500 and you will immediately understand. Numeric constants like board width shall appear exactly once ...
stefan's user avatar
  • 2,980
3 votes

Simplify JavaScript collision detection with offset

Bug #1 Your code does not follow pattern (x - a < y + b) && (x + b + a > y) but ...
dfhwze's user avatar
  • 13.9k
3 votes
Accepted

Making a grid for collision detection in a game that wraps

Some style points first. Always wrap statement and loop blocks in {} eg you wrote ...
Blindman67's user avatar
  • 22.1k
3 votes

Creating a maze game where the game resets if you hit traps/walls and finishes when you hit a different color

From a lengthy review; Clean up tags that are not used (doubles like body or unused like nav) Use a beautifier like https://...
konijn's user avatar
  • 33.2k
3 votes

Generate unique random strings considering collisions

Your code broadly follows the Java conventions. Your objective is unclear, why do you need random strings? If they are for hashkeys there are plenty of strong methods for generating these. If you need ...
Martin Spamer's user avatar
3 votes

Movement and collision function

First understand that your collision algorithm isn't correct. This is evident by either making the player travel speed higher or making the object coordinates closer; you can quite easily end up with ...
Reinderien's user avatar
  • 62.2k
2 votes
Accepted

2D colliding disks in JavaScript (ideal billiard balls)

Some issues and solutions: Using arrays for key-value data What does each element of one of the init_data mean? What is accessed by ...
Anko's user avatar
  • 136

Only top scored, non community-wiki answers of a minimum length are eligible