I started reading "programming for dummies" yesterday and got through a little over 200 pages. I mostly began because I wanted to make a video game, like 9 months of story writing and drawing previous, I don't have cable so I had alot of time to learn how to draw and paint,and so far the closest example to it looks like this (and it doesn't look like there are any more) in the book.
I understand everything so far and figure the monster could move towards the hero by using his coordinates but how would I be able to make the hero pick up ammo? or move where the player wants them to move in a way that is not directly typing in coordinates? I want to be able to learn more and kind of peek at other codes so I get a better idea. How would I make this code better and playable is what I want to know and learning references that could help are appreciated.
#include <iostream>
class monster
{
public:
int x_coordinate;
int y_coordinate;
void movement (int, int);
};
void monster::initialize (int init_x, int init_y)
{
x_coordinate = init_x;
y_coordinate = init_y;
}
void monster::moveme(int new_x, int new_y)
{
x_coordinate = x_coordinate + new_x;
y_coordinate = y_coordinate + new_y;
}
class person : public monster
{
publicint ammo;
void shoot(int);
};
void person::shoot(int bullets)
{
ammo = ammo - bullets;
}
int main ()
{
monster zombie;
zombie.initialize (12, 15);
cout << "The X-location of the zombie is" <<
zombie.x_coordinate << "\n";
cout << "The Y-location of the zombie is" <<
zombie.y_coordinate << "\n";
zombie.moveme (34,9);
cout << "The new X-location of the zombie is" <<
zombie.x_coordinate << "\n";
cout << "The new Y-Location of the zombie is" <<
zombie.y_coordinate << "\n\;
Person hero;
hero.initialize (97,52);
hero.ammo = 5;
hero.moveme (49,71);
cout << "The new X-Location of the hero is" <<
hero.x_coordinate << "\n";
cout << "The new Y-Location of the hero is" <<
hero.y_coordinate << "\n";
cout << "The number of bullets initially is " <<
hero.amm << "\n";
hero.shoot(3) ;
cout <<'\nPress ENTER to continue..." << end1;
getchar();
return 0;
}
I'm a little confused by the question but if you're looking to make a graphical 2D game then the console is not the place to do it.
You'd be better off using a library, such as SFML or SDL, where you can load in sprites and play sounds, amongst other things.
Movement depends on your game, but I tend to use vectors (direction, acceleration, velocity) to move things in 2D games.
As for item pickups, in the simplest form you could have a boolean flag for the player class denoting whether or not he has picked an item up. A more robust system would be to implement an inventory, whereby the player can store numerous items.
I'd model this by having a hierarchy of classes representing items. So, for example, you could have a base class Item, a derived class Ammo, and maybe another one for Weapon, another for MedicalKit, and so on, for whatever kind of items you want the heroes (or other characters) to use.
Each character and monster would maintain a list of pointers to Item. This list represents the items carried by that entity.
When the hero kills the monster and searches the body, display the list of items that belong to the monster. When the player takes an item, remove it from the list belonging to the monster, and add it to the list belonging to the hero.
Because you're coding in C++ and using polymorphism, then each entity just needs a single list of pointers to Item, rather than a separate list for each type of item.
That's how I'd do it.
Edit: if you also want to have items lying on the ground, that works too. Each location can also have a list it items. Again, when the player takes an item from the ground, remove it from the list belonging to the location, and add it to the list belonging to the player.