Okay so I have an assignment to hand in next week, so I thought I'd get on it and learn c++ (Baha.)
I'm try to create a list for some bullets, you know.. I press space, it creates a new bullet and shoots depending on whatever way my player is facing.
Well it occurred to me that I have no actual idea how to do that in C++
I'm more of a C# kinda guy.
So what I'd usually do is something like this
List<Bullets> bullets = new List<Bullets>();
// Bullets being the class and bullets being the variable
Is there a way I can do that in c++
So I can go with bullets.Add(new Bullets(blah, blah, blah);?
Thanks for whatever help you may give me :3
c++ list
Page 1 of 110 Replies - 431 Views - Last Post: 29 June 2012 - 02:03 PM
Replies To: c++ list
#2
Re: c++ list
Posted 27 June 2012 - 01:36 PM
What kind of list are you talking about? Are we talking a bullet pointed list like you would have in Microsoft Word? C++ isn't much like C# save the syntax. Creating and outputting a list in C++ would entail creating a vector or array to hold your strings, and using a for loop to provide output.
Are you trying to input via console, an external file, an input field, or something else entirely? Where are you trying to output to? The code could be very simple, or it could be very involved depending on the whole situation.
If you're just trying to use a container to hold a variable number of strings, I would go with
Don't forget to include the proper headers at the top of your program, though:
But, honestly, I would need more information on what you are trying to do, brother.
Are you trying to input via console, an external file, an input field, or something else entirely? Where are you trying to output to? The code could be very simple, or it could be very involved depending on the whole situation.
If you're just trying to use a container to hold a variable number of strings, I would go with
vector<string> listName;
Don't forget to include the proper headers at the top of your program, though:
#include <vector> #include <string>
But, honestly, I would need more information on what you are trying to do, brother.
This post has been edited by axnjxn: 27 June 2012 - 01:38 PM
#3
Re: c++ list
Posted 27 June 2012 - 01:42 PM
axnjxn: C#'s 'List' is like std::vector so yes; std::vector<Bullet> works well here.
you would add bullets like so:
or if you're using C++11 use uniform initialization instead.
edit:
or even better, emplace_back
you would add bullets like so:
bullets.push_back(Bullet(x, y, z));
or if you're using C++11 use uniform initialization instead.
bullets.push_back(Bullet{x, y, z});
edit:
or even better, emplace_back
bullets.emplace_back(x, y, z);
This post has been edited by ishkabible: 27 June 2012 - 02:10 PM
#4
Re: c++ list
Posted 27 June 2012 - 01:51 PM
Well.. The second post didn't work for me. But probably because I wasn't too clear.
I'm using the DirectX sdk (I think that's what I go around calling it, yes?)
I think the object of my assignment is to make a simple world you can roam about (Game Engine).
So I'm trying to make the code reusable and such.
Which means I'm probably not going to be including bullets any more.
But it is still something I'd like to know for future use.
I'm using the DirectX sdk (I think that's what I go around calling it, yes?)
I think the object of my assignment is to make a simple world you can roam about (Game Engine).
So I'm trying to make the code reusable and such.
Which means I'm probably not going to be including bullets any more.
But it is still something I'd like to know for future use.
#5
Re: c++ list
Posted 27 June 2012 - 01:53 PM
Quote
Okay so I have an assignment to hand in next week, so I thought I'd get on it and learn c++
Quote
I think the object of my assignment is to make a simple world you can roam about (Game Engine).
You're SCREWED.
#6
Re: c++ list
Posted 27 June 2012 - 02:04 PM
#7
Re: c++ list
Posted 27 June 2012 - 02:12 PM
Quote
Well.. The second post didn't work for me.
what didn't work?
#8
Re: c++ list
Posted 27 June 2012 - 02:35 PM
#9
Re: c++ list
Posted 27 June 2012 - 02:56 PM
For std::vector you need to include #include <vector>
Now, once you have that the fun part comes up that you need to have a 3D-vector (as in the mathematical vector) to determine which direction that Bullet is facing (this will probably make most sense to store within the bullet itself). You will need to have some way to update its position (probably within Bullet as well), and some way to draw it to the screen (if you are using directX some of this is down for you, except the important things like the mesh, texture, etc.). If you are instead doing this in a 2D world (significantly easier as far as things are concerned because there is just an X and Y you need to worry about).
I expect you already know most/ all the math required for this type of thing, so I am going to stop there and hopefully make for an easy to read and understand post.
Hope that helps.
Now, once you have that the fun part comes up that you need to have a 3D-vector (as in the mathematical vector) to determine which direction that Bullet is facing (this will probably make most sense to store within the bullet itself). You will need to have some way to update its position (probably within Bullet as well), and some way to draw it to the screen (if you are using directX some of this is down for you, except the important things like the mesh, texture, etc.). If you are instead doing this in a 2D world (significantly easier as far as things are concerned because there is just an X and Y you need to worry about).
I expect you already know most/ all the math required for this type of thing, so I am going to stop there and hopefully make for an easy to read and understand post.
Hope that helps.
#10
Re: c++ list
Posted 29 June 2012 - 12:38 PM
I'm pretty sure I had mentioned in my prior post to use
I won't say "you're screwed", but usually a team of programmers puts together a game engine. What kind of class would give you an assignment to build your own game engine for an explorable world? Seems pretty advanced for 1 person to tackle no matter how good they are. But then, I've never tried to program 3d with DirectX before. If you come up with a solution, do post.
#include <vector>.
Quote
I think the object of my assignment is to make a simple world you can roam about (Game Engine).
I won't say "you're screwed", but usually a team of programmers puts together a game engine. What kind of class would give you an assignment to build your own game engine for an explorable world? Seems pretty advanced for 1 person to tackle no matter how good they are. But then, I've never tried to program 3d with DirectX before. If you come up with a solution, do post.
#11
Re: c++ list
Posted 29 June 2012 - 02:03 PM
axnjxn, on 29 June 2012 - 12:38 PM, said:
I won't say "you're screwed", but usually a team of programmers puts together a game engine. What kind of class would give you an assignment to build your own game engine for an explorable world? Seems pretty advanced for 1 person to tackle no matter how good they are. But then, I've never tried to program 3d with DirectX before. If you come up with a solution, do post.
It's my second year studying computer games programming.
It's pretty silly if you ask me.
This is my second assignment, my first was to build a render core, which went well.
My Assignment spec isn't clear, I thought I had to build a game engine but instead I'm supposed to use a game engine created by some fella called Jim Adams and turn it into a game.
So I pretty much have to do nothing other than write a beefy report.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote









|