Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 14 Jun 2012
Offline Last Active Nov 19 2012 04:11 PM

Topics I've Started

Best OpenGL books for beginners (C++)

18 November 2012 - 07:35 AM

Hey all,
I am interested as to what your takes are on what books to get for OpenGL programming?

I want to buy a couple books so that I can learn 3D Game Programming with OpenGL in C++ however I am not sure as to what to get. I don't so much want a big reference book as much as I want a book that offers some direction in its text in terms of actual game programming and does not just act as a reference for experienced users. I have been looking at Beginning OpenGL Game Programming, second edition and was thinking that a second book I could buy would be More OpenGL Game Programming?
The one query I have for anyone that has read More OpenGL Game Programming. Its publication date is 2006 whilst Beginning OpenGL Game Programming's publication date is 2009, will its information still be relevant?

What do you all think about what book to get?


Limiting Bullets and stopping spamming - DirectX

30 June 2012 - 12:14 PM

Hey all, I am making a simple sidescroller space shooter and have encountered a problem. I do not know how to limit the amount of bullets adequately or control the difference between input times.

Here is the relevant code that I know is the problem.

I create space in memory for my bullet sprites and I set their default properties (according to my own class):

[source lang="cpp"]//bullet spritesconst int MAX_BULLETS = 20;SPRITE bullets [MAX_BULLETS];//set default propertiesfor (int j = 0; j < MAX_BULLETS;j++) { bullets[j].alive = false; bullets[j].startframe = 0; bullets[j].endframe = 1; bullets[j].delay = 10; bullets[j].x = 0; bullets[j].y = 0; bullets[j].height = 55; bullets[j].width = 16; bullets[j].columns = 1; bullets[j].vely = 6.0f; } imgBullet = LoadTexture("purplefire.tga"); if (!imgBullet) return false; player_shoot_timer = 0;[/source]

I then go onto set bullets to alive when I click space bar like so:

[source lang="cpp"]if (Key_Down(DIK_SPACE)) { //limit firing rate if ((int)timeGetTime() < player_shoot_timer + 100) return; player_shoot_timer = timeGetTime(); if (CurrentBullet >= MAX_BULLETS) CurrentBullet = 0; CurrentBullet++; bullets[CurrentBullet].alive = true; bullets[CurrentBullet].x = player.x + (player.width/2); bullets[CurrentBullet].y = player.y; }[/source]
But the above code is not adequately stopping me from shooting if I hold down for example space bar, any ideas on that?

Finally in my actual game loop, I render the bullets that are deemed "alive" or have been shot already:

[source lang="cpp"]for (int k = 0;k < MAX_BULLETS;k++) { if (bullets[k].isAlive() == true) { bullets[k].y -= bullets[k].vely; // Sprite_Animate(bullets[k].frame,bullets[k].startframe,bullets[k].endframe,1,bullets[k].starttime,bullets[k].delay); Sprite_Draw_Frame(imgBullet,bullets[k].x,bullets[k].y,bullets[k].frame,bullets[k].width,bullets[k].height,bullets[k].columns); } }[/source]

However the problem is that I can hold down spacebar and it will just keep rendering the bullets to that spot and once I finish the program/close it, I get the following error:

Unhandled exception at 0x61a659da (msvcr100d.dll) in Tile_Dynamic_Scroll.exe: 0xC0000005: Access violation reading location 0x4424aac2.

I am guessing this is because I am not resetting the bullets adequately but I can't figure out:

a) how to create a time between each fired bullet so that the user cannot spam spacebar, my current implementation does not work
b) Limit the amount of bullets fired and reset them accordingly.

(if any more code is needed, I will supply upon request as the entire project is largeish)

I do not want the complete answer but merely a nudge in the right direction, any help is appreciated.

Thanks, v0rtex