Jump to content

  • Log In with Google      Sign In   
  • Create Account

Edgar Reynaldo

Member Since 16 Apr 2011
Offline Last Active May 13 2013 11:43 AM

#4894081 Collision hiccups

Posted by on 14 December 2011 - 11:04 PM

If your pixel perfect collision library is working as it should be, then it is a problem with the way you 'undo' the collisions. Check the future positions of your objects, not your current position after you move them but before you detect a collision. Ie.. Check for a collision at the end of the update before you move your object. 'Fix' the collision by reducing the velocity of the object until there would be no collision, and continue to check that object with its now reduced velocity against the rest of your objects.

#4822636 Best Calculus Textbook?

Posted by on 13 June 2011 - 12:52 AM

I used to know calculus rather well, but I'm afraid the years have taken their toll and rusted out the portion of my brain that knew about it.

So, I'm looking for a good calculus text book that fits these criteria :
1) Is hard bound.
2) Has good reference tables of common derivatives and integrals.
3) Provides good proofs for learning the formulas that govern it.
4) Covers derivatives, integrals, and volume calculations at the least.
5) Advanced calculus like partial differentials not necessary, but might be nice to learn anyway (new to these).

So if you've got a good textbook that you can recommend to me to buy, that would be really great. Please make sure to include the ISBN number of the book so I can get an exact copy.


#4814441 2d scrolling and collision

Posted by on 22 May 2011 - 10:06 PM


            	//draw levelCurrent chunk

When you draw the map, why are you adding the players grid position to the map grid position in your checks? Don't you want to draw the entire mini map the whole time?
   for (b = 0 ; b < 20 ; ++b) {
  	for (c = 0 ; c < 20 ; ++c) {
     	if (levelCurrent[c][b].walkable == 1) {
        	al_draw_pixel(c , b , al_map_rgb(0,127,255));

Next, to clean up your map drawing, you need to set up a camera and have it follow your player's position on the map.
int camx = 0;
int camy = 0;

// whenever you set the position of your player, reset your cameras position as well
// center on the player's center
camx = player_x + player_width/2 - view_width/2;
camy = player_y + player_height/2 - view_height/2;
// make sure the camera stays over the map
if (camx < 0) {camx = 0;}
if (camy < 0) {camy = 0;}
if (camx > (map_width - view_width)) {camx = map_width - view_width;}
if (camy > (map_height - view_height)) {camy = map_height - view_height;}

Now you draw your walls based on the camera position :
int start_tile_x = camx/tile_width;
int offset_x = -(camx%tile_width);
int start_tile_y = camy/tile_height;
int offset_y = -(camy%tile_height);
int num_tiles_wide = view_width/tile_width + 1;
int num_tiles_tall = view_height/tile_height + 1;

for (b = start_tile_y ; b < start_tile_y + num_tiles_tall ; ++b) {
   int drawy = (b - start_tile_y)*tile_height + offset_y;
   for (c = start_tile_x ; c < start_tile_x + num_tiles_wide ; ++c) {
  	int drawx = (c - start_tile_x)*tile_width + offset_x;
  	if (levelCurrent[c][b].walkable == 0) {
     	al_draw_bitmap(wall , drawx , drawy , 0);

I don't know why your code caused the map to 'skip' a tile here and there, but this code shouldn't suffer from the same problem.

Now when you draw your player, you will need to subtract the camera position from the player position to get the screen position :
int player_screen_x = player_x - camx;
int player_screen_y = player_y - camy;
al_draw_bitmap(player , player_screen_x , player_screen_y , 0);

To use this code, you'll have to substitute in values for tile width and height and view width and height. A better idea would be to keep them as variables though instead of hard coded constants in case you ever change your mind about how big your tiles or your view should be. It would also be nice to see better variable names instead of things like b and c and x and y. If you have any questions, just ask ,and I'll explain as best I can.