• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
phil67rpg

opengl invaders

11 posts in this topic

I am programming a space invaders clone. I want to use a vector to move the aliens across the screen. I am unsure of how to proceed. I am studying vectors. 

0

Share this post


Link to post
Share on other sites

Are you wanting to use std::vector or a mathematical vector?

 

Edit: Only a mathematical vector would make sense really.

 

A vector has a direction and a magnitude. This Wolfram Alpha entry describes vectors. You can use vectors to specify an object's velocity and acceleration. What are you hung up on or having issues with?

Edited by David.M
0

Share this post


Link to post
Share on other sites

well if you have a velocity vector of some speed at some angle - then you would multiply that speed by the amount of time you want the alien to move for that frame and then you would add that movement to the aliens current position (keeping in mind the angle).. practically it might go something like this..

 

Alien is at x = 0 and y = 0 .. you want the alien to move at 10 pixels per second in the 45 degree angle (from top left of screen to bottom right of screen)

 

ill call your time elapsed for the frame dt

 

lets say your screen is 1920 by 1080

 

so if this frame dt = .014 seconds to keep the speed 10 pixels per second the alien needs to move 10 pixels/sec * .014 sec = 0.14 pixels (assuming you are using float for the calculation) in the 45 degree direction..

 

so moving it in the 45 degree direction is the bit that is a tiny bit more tricky but not really.. since you are looking for the x and y lengths of a right triangle with a hypotenuse = 0.14 pixels and one angle = 45 degrees you know that x must = y and therefore by Pythagorean's theorem :

x^2 + y^2 = 0.14^2       :    since x = y

2(x^2) = 0.14^2    : solving for x

x = sqrt( 0.14^2 / 2)

 

and so you would shift x and y by sqrt( (speed * dt)^2 / 2) if you were at a 45 degree angle

 

 

however for more general angles you know that

 

sin (angle) = y / (speed * dt )      and

cos ( angle )  = x / (speed * dt)   

 

so to find how much x and y positions should change for a frame that took dt time for a given speed and angle (which remember speed at an angle is a velocity vector) you solve for x and y

 

y = speed * dt * sin(angle)

x = speed * dt * cos(angle)

 

in the case of moving across the screen I would add this x and y amount to your aliens position every frame until its position was equal to 1920 by 1080

 

something like that

1

Share this post


Link to post
Share on other sites

Math stuff

 

Although you're right, this is very likely a bit overwhelming considering his response. Also considering that the original space invaders only moved sideways and down, the explanation about how to incorporate angles is a bit to much I think. It's still something you want to know in the end, but perhaps this is not the time for a (what seems) beginner.

 

Anyway, You should get an idea of what a vector is both in it's "container" and mathematical form. Very likely when you're talking about movement you are talking about the mathematical form, but to make it a bit more understandable, you should just consider a point.

 

You should see your window as a graph where X is the horizontal part and Y is the vertical part and both are an X amount in length. (800 x 600 for example) When you position your alien on 400 x 300 it should be in the middle of your screen. When you now increment the X value (which is 400) by 10 for example, the new position would become 410 x 300. The alien is simply a point on this graph. 

 

To make sure your aliens don't go off the screen, check against the boundaries of your screen. you know that your screen is 800 x 600. So if an alien gets over that, you know it's going out of screen and you should do something about it. Move them a row down if it's on the horizontal axis or game over on the vertical axis (whatever you choose).

 

Last thing to keep in mind is the framerate. You probably heard of the term "FPS" already, Frames Per Second. If you increment your aliens position by 10 every frame and your FPS is 60, the alien will move 600 pixels each second. This is why you calculate the time between frames (the deltatime or DT) and use that in your movement code. This is a topic that has been covered multiple times on this forum and a simple search will give you the proper explanation you need.

 

Good luck! :)

0

Share this post


Link to post
Share on other sites

Why are you using OpenGL to write a simple 2d space invaders clone?  Why not use an API made for 2D games, instead of over-complicating things?  Check out SFML for a simple API for graphics, sound, Input, windows, system, and , networking.

 

Space invaders isn't too complicated.  I would use a 2 dimensional array to store the alien's class data (since, in space invaders, the aliens are aligned in a grid).  The only thing a vector might require is for alien bullets sinec there could be any number of bullets on screen at one time, but my recollection of space invaders is it only allows 1 of the player's bullet on screen at a time, so It doesn't need a vector.  Also, I recall the bullets (both the players and the aliens) simply go up or down, so there isn't any need for "a lot of math."

 

Have all the aliens move along the x-axis every so often (but speeding up as time goes on), and when it reaches some X boundary, shift them down vertically some amount and move them the other way.  When a bullet hits one, it disappears (basically, marking some variable in the alien's class, say, IsDead  = false), and don't draw aliens that are dead.  When they're all dead, go to next level.

 

Have some aliens be able to drop some bullets, and if it hits the player, lose a life, and start at that point.

2

Share this post


Link to post
Share on other sites

+1 for what BeerNutts said.

 

Space invaders is also the first game I programmed, but I used a framework that already provided me with drawing sprites to take a lot of stuff I needn't worry about yet out of my hands so I could focus on the fundamentals of game programming itself.

 

Check out SFML or SDL for some nice APIs you can work in.

 

I used the framework provided in this tutorial (http://devmaster.net/posts/2843/introduction-to-c-with-game-development-part-1-intro). I attend this college so we had to work in it at the start. Perhaps it's also a tutorial you can benefit from, but there are plenty of SFML and SDL tutorials out there as well that provided more functionality. 

0

Share this post


Link to post
Share on other sites

well I don't have any books on sfml or sdl. I wrote my breakout game using opengl and I took a class in opengl in college.I have also found a good site that teaches opengl called videotutorialsrock.com

0

Share this post


Link to post
Share on other sites

well I don't have any books on sfml or sdl. I wrote my breakout game using opengl and I took a class in opengl in college.I have also found a good site that teaches opengl called videotutorialsrock.com

Why you need books on SFML? You can find plenty of resources on the net. https://github.com/LaurentGomila/SFML/wiki/Tutorials for example. SFML is very easy to pick up, you can be a pro in just a week.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0