Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


opengl game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
19 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 23 July 2013 - 03:23 PM

well I have decided to work on a space invaders game, any hints on how to start?



Sponsor:

#2 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 23 July 2013 - 09:44 PM

here is a screen shot of my game so far

 

 

Attached Thumbnails

  • spaceinvadersscreen - Copy.png


#3 EarthBanana   Members   -  Reputation: 941

Like
0Likes
Like

Posted 24 July 2013 - 12:29 AM

looks like your getting it done! What help do you need with it?



#4 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 24 July 2013 - 01:33 PM

well I need to move the aliens from left to right



#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 28 July 2013 - 05:22 PM

well I am attempting to render the aliens on the screen, I want to draw the alien to the screen and move to the right and then erase the sprite and draw a new  sprite and moves the sprite to the right again. basically I want to draw a sprite and erase it and redraw a different sprite and then erase it and then draw the previous sprite and have all the sprite to move to the right.



#6 BlueSpud   Members   -  Reputation: 426

Like
1Likes
Like

Posted 30 July 2013 - 08:23 AM

well I am attempting to render the aliens on the screen, I want to draw the alien to the screen and move to the right and then erase the sprite and draw a new  sprite and moves the sprite to the right again. basically I want to draw a sprite and erase it and redraw a different sprite and then erase it and then draw the previous sprite and have all the sprite to move to the right.

Thats not exactly what you want to do. Create an object for each alien:

class Invader
{
public:
float x,y,z;
void update()

};

Then create the invaders in whatever way you want best to handle them.

Make a callback for glutIdleFunc().

Put in that callback:

//call onUpdate() for all the invaders
updateInvaders()
//draw a new frame
glutPostRedDisplay();

In the onUpdate() for the invaders, move them left and right using their positions. The render for them would look something like this:


void invader::render()
{
glTranslatef(-x,-y,-z);
//render sprite
renderSprite();
}

Hope that helps



#7 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 30 July 2013 - 01:39 PM

yep it does, any more input would be appreciated.



#8 lask1   Members   -  Reputation: 776

Like
0Likes
Like

Posted 01 August 2013 - 10:53 PM

If you want to update multiple enemies and have a list of them and run a for loop to do the update for each one. You can do this by either using a linked list or...not sure if any one would get mad at me for saying this but you could use a vector.

These are both basically dynamic lists like an array that can change in size...be careful with deleting objects while a loop is running.

 

http://www.cplusplus.com/reference/vector/vector/

 

http://www.cplusplus.com/articles/Lw6AC542/

 

Hope this helps.



#9 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 02 August 2013 - 02:35 PM

so I should use a vector? I am somewhat familiar with vectors.



#10 FLeBlanc   Crossbones+   -  Reputation: 3109

Like
0Likes
Like

Posted 02 August 2013 - 02:36 PM

Hi, phil. How you been?



#11 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 02 August 2013 - 05:36 PM

ok how are you FLeBlanc, do you have any input for me?



#12 Solid_Spy   Members   -  Reputation: 420

Like
0Likes
Like

Posted 02 August 2013 - 11:01 PM

so I should use a vector? I am somewhat familiar with vectors.

It depends, you could make your own linked list, but only if it is absolutely necessary. The std::vector does have some overhead, but shouldn't be noticable for this game.


Edited by Solid_Spy, 02 August 2013 - 11:02 PM.


#13 BlueSpud   Members   -  Reputation: 426

Like
1Likes
Like

Posted 03 August 2013 - 03:16 PM

 

so I should use a vector? I am somewhat familiar with vectors.

It depends, you could make your own linked list, but only if it is absolutely necessary. The std::vector does have some overhead, but shouldn't be noticable for this game.

 

If he stored the textures outside the object, just not drawing them and still allocating the RAM for each invader wouldn't be a big deal, he could just clear the vector at the end of the level and it wouldn't be a huge performance problem. 



#14 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 03 August 2013 - 04:16 PM

thanks for all  the help, any more opinions?



#15 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 10 August 2013 - 10:28 PM

I am working on collision detection between the bullets and the aliens. I am unsure of how to proceed.



#16 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 11 August 2013 - 04:27 PM

well I got the collision detection to work with the ufo at the top of the screen, but I also want the bullet to collide with the aliens, and then turn off the aliens.



#17 BlueSpud   Members   -  Reputation: 426

Like
0Likes
Like

Posted 16 August 2013 - 01:56 PM

well I got the collision detection to work with the ufo at the top of the screen, but I also want the bullet to collide with the aliens, and then turn off the aliens.

Because your not really shooting in diagonals, as far as I can tell, check into Axis aligned bounding box collisions, they're pretty easy ex:

struct box
{
float maxx,maxy,minx,miny;
};
bool collision(box* one, box* two)
if (one->maxx < two->minx || one->mazy < two->miny || one->minx > two->maxx || one->miny > two->maxy)
// no collision in any of these cases
return false;
//defaults to colliding
else return true

Of course, you would need to constantly update the boxes position, so you might want to add some kind of offset in there somewhere and add them onto the max,min,etc during the test. If you want something for oriented bounding boxes, boxes that aren't axis aligned, in other words, rotated, look into the separating axis theorem. Its a bit slower, but its fairly simple to implement and its almost pixel perfect.



#18 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 August 2013 - 06:32 PM

ok so AABB is the way to go?



#19 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 August 2013 - 07:19 PM

so how do I do multiple collision detection using AABB.



#20 BlueSpud   Members   -  Reputation: 426

Like
0Likes
Like

Posted 17 August 2013 - 07:21 AM

so how do I do multiple collision detection using AABB.

AABB being good is kind of ipso-facto, only if you want axis aligned boxes. If you want to test all the boxes against your bullet, you don't want to test all of them in say a loop, while your game is pretty simple and you probably wouldn't notice the difference, you should do at least 2 steps. There are a lot of approaches to the 2 step thing, for more complicated collision detection, there are even upwards of 3. By no means am I an expert, but this is what I would do:

1. loop through all the bounding boxes and check if the center of the bullet is within a relatively small distance to the center of each box. If it is, add it to the next step to be tested for the AABB collision.
2. loop through all the boxes that were passed down and as soon as you find a collision, stop the loop because there is no need to keep checking for possible collisions.

 

To reiterate, this isn't really necessary, but it is going to save you quite a bit of CPU time if you have 30 or 40 enemies, or you are testing multiple bullets per frame.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS