Checkers game, getting the piece i've jumped overs location

  • Thread starter Thread starter Dave2041
  • Start date Start date
  • Tags Tags
    Game
Click For Summary
SUMMARY

The discussion focuses on calculating the position of a jumped-over piece in a checkers game implemented in C++ using SDL. The user attempts to derive the coordinates of the jumped piece using the start and end positions of a jump. The formula provided, which calculates the jumped piece's coordinates as (sx + (ex - sx) / 2, sy + (ey - sy) / 2), is confirmed to be correct, although the user encounters issues with negative values when jumping upwards. The conversation emphasizes the importance of correctly defining the coordinate system for accurate calculations.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with SDL (Simple DirectMedia Layer) for game development
  • Basic knowledge of coordinate systems in 2D games
  • Experience with mathematical calculations for game mechanics
NEXT STEPS
  • Review C++ data structures for managing game state
  • Explore SDL documentation for handling graphics and input
  • Learn about implementing game logic for turn-based games
  • Investigate debugging techniques for coordinate calculations in game development
USEFUL FOR

Game developers, particularly those working on 2D games using C++ and SDL, and anyone interested in implementing game mechanics related to movement and collision detection.

Dave2041
Messages
2
Reaction score
0

Homework Statement


in checkers you jump over the enemys piece and land on a square after that.
i'm making this game in c++ using sdl~

i just want to know how to get the square i have jumped over using the end square and start square locations


Homework Equations





The Attempt at a Solution


where sx, sy = start x,y and ex, ey and the end position x,y

disty = ey - sy;
distx = ex - sx;

sx+distx/2 - should be the x val of the square i jumped over

sy+disty/2 - should be the y val of the square i jumped over


is this correct? i tryed it on paper and it seems to work one way but not another, jumping upwards for example gives me a negative number for example, any ideas appreciated :(

should be simple, perhaps i have been looking at this for too long lol.
thanks in advance
 
Physics news on Phys.org
I don't get what you mean by "upwards". Your formula should work regardless. Maybe you failed to give your positions values that mean enough to you, i.e. one corner's square is (0,0) and the opposite corner is (8,8).
 
Last edited:
wow... i just spent a million years thinking that was wrong :'(

thanks anyway!
 
Last edited:

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
Replies
1
Views
6K
  • · Replies 2 ·
Replies
2
Views
17K
  • · Replies 83 ·
3
Replies
83
Views
22K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 19 ·
Replies
19
Views
15K