Jesse Emond
  • Member for 11 years, 4 months
  • Last seen more than a week ago
  • Quebec, Canada
What are atan and atan2 used for in games?
Accepted answer
95 votes

The tangent formula is this: tan(angle) = opposite/adjacent Refer to this drawing: Where a is the adjacent side, o is the opposite side and theta is the angle. Similarly, sine and cosine are sin(...

View answer
How do I generate projectiles toward the mouse pointer?
Accepted answer
19 votes

If I understood your problem properly, you just want to shoot a bullet towards a mouse position. Here is how I would do: First of all, you must find the movement required for the bullet to get to the ...

View answer
How do I go from a general idea to a specific draft of a design?
Accepted answer
17 votes

My advice would be not to try to delve into too much details yet. Get a general feel of what type of game you want, with a core gameplay feature that you really want. Once you know what the main ...

View answer
Problems making my basketball bounce around horizontally
Accepted answer
12 votes

Since your ball is scaled, it means that using the texture's width (basketball.Width) is not correct, since the real width is the texture's width times the scale. Your code would change like this: ...

View answer
Stuck in Wall after rectangle bounding box collision
Accepted answer
12 votes

This is because once your object gets into the wall and you find the collision, you're simply stopping the object's movement by setting its velocity to zero, but the object is still within that wall. ...

View answer
Moving a sprite in XNA/C#, using vectors
Accepted answer
12 votes

If I understand your problem properly, you should just have a direction Vector2 representing the direction you want to move in inside your sprite class. Like this: public Vector2 Direction { get; set;...

View answer
Mouse location is off due to camera
Accepted answer
11 votes

The positions that you store within cursorX and cursorY hold the position of the cursor relative to top left corner of your screen monitor (since you add the ClientBounds to it). I'd guess that you ...

View answer
I want to get rid of my make-everything-static-and-global design pattern, but how?
Accepted answer
10 votes

What about a component-based engine? You would have a main class named Engine, which would keep a list of GameScreens, which would themselves hold a list of Components. The engine has an Update and ...

View answer
How should I calculate world and projection matrices in this scenario?
Accepted answer
8 votes

Well, if you want to use it for 2D games (assuming from the tags), you only need a Transform matrix to apply to the SpriteBatch, you don't need World and Projection matrices. So, when you're drawing ...

View answer
Why use this equation to get a percentage?
8 votes

The part (float)rand.Next(0, 1000) generates a number between 0.0f and 999.0f inclusively. Then, you divide it by 10 to get a number from 0.0f to 99.9f. Checking if the number is below or equal to 0....

View answer
How do I detect the direction of 2D rectangular object collisions?
Accepted answer
8 votes

Since this is based on your other question I'll give a solution for when the rectangle is axis-aligned. First, you build up you current object's rectangle with the following values: int boxLeft = ...

View answer
Angle of Reflection
Accepted answer
8 votes

I'm not sure if I understood your problem correctly, but I assumed that what you want to do is find the resultant direction of you ball after a collision. Here's a quick drawing on my white board ...

View answer
What was the game project that felt like "YOUR" game?
8 votes

I personally give up easily on projects, so I found out something that keeps me interested throughout the whole development process. I start out really small, like drawing a character to the screen. ...

View answer
Learning Java for game development
7 votes

I think java proved itself as quite a viable programming language for programming games the same way that C# did with libraries such as XNA. It may not be as efficient as a low-level language like C++ ...

View answer
Efficient way of detecting a touched object in a game?
Accepted answer
7 votes

I'd recommend profiling first and check if the touching check really is a bottleneck. Test with the maximal amount of objects that your game will use as a final product and see if you get frame ...

View answer
How to balance a ball on a rotating plane?
Accepted answer
7 votes

I don't know if I understand your problem correctly, but here is how I would go with the constraints that I understood: I guess you could simply apply gravity to the ball, then resolve the collision ...

View answer
For loop optimisation
5 votes

As much as I agree that preincrementing is intuitively faster (because the implementation does not involve a copy), I would expect the compiler to actually optimize both calls to become equivalent in ...

View answer
XNA Platformer Screen Collision
Accepted answer
5 votes

You want to modify the player's position, not its source rectangle. As I understand it, you use playerRect to represent the rectangle inside the image to draw, in order to animate it properly. That ...

View answer
Debugging tips?
Accepted answer
4 votes

Kind of a simple advice here but a little something that I found very useful is displaying debugging strings/rectangles to the screen. You can print the player's current state, the enemy's animation ...

View answer
Ideas for extending tic-tac-toe game?
Accepted answer
4 votes

You could add more visual effects to the game to make it visually appealing (especially when a player wins. I personally don't like the classic "You won!" text, I prefer fireworks and fire all over ...

View answer
What AI for a resource management + combat?
3 votes

For this type of game, I'd like to refer you to a question that I asked before: Basically the idea is that you keep a power score for every unit owned by a player. This score can be based on the ...

View answer
Is it possible to calculate or mathematically prove if a game is balanced / fair?
3 votes

I guess there is no pre-made mathematical formula to evaluate how fair a game is because of how every game is so different and complex. You can't really compare different game parameters and make up ...

View answer
How do I use D3DXVec3Normalize()?
Accepted answer
3 votes

Basically it allows you to have an input vector different from an output vector, like so: D3DXVECTOR3 bulletMovement = /*...*/; // the whole bullet movement D3DXVECTOR3 bulletDirection = /*...*/; // ...

View answer
Questions regarding games architecture with XNA
3 votes

For your first question, I must admit that I don't really know the actual answer. I guess it would be for the same reason as to why singleton is generally a bad design pattern. I'll refer you to a ...

View answer
XNA beginner - can't display cannon in 2D tutorial
Accepted answer
3 votes

The problem comes from your spriteBatch.Begin call. You're passing SpriteSortMode.BackToFront and since both of your layerDepths are equal to 0, I'd guess that the order would get mixed up when the ...

View answer
Calculating and detecting curves
3 votes

For the curve or straight line problem, I think I'd keep a list of the positions of old input. Then, I'd check the slope between every point (delta Y / delta X). If the slope does not change a lot, ...

View answer
Keeping rotation between two objects
2 votes

In addition to @tesselode's answer, I would recommend you keep a list of attached objects for every world object in your game. Something along the lines of List<WorldObject> AttachedObjects. ...

View answer
Storing and Finding Art Assets
2 votes

What's wrong with using directories with broad categories? You can just put more specific categories if you find that you really have too many assets within a directory. You could just organize it ...

View answer
moving 2D camera
Accepted answer
2 votes

This is because you're setting the position of the camera right away. This will make the camera jump from one position to another when you change direction, therefore giving the illusion that your ...

View answer
Splitting a tetris game apart - where to put time-management?
2 votes

I would create a separate class called CollisionDetection or something that would check if the block reached the bottom of the screen or collided with other blocks, and if there was a collision, ...

View answer