my little game and still a bit new to classes and how to access one class from another

alright I have a class for shooting(shots) in my game, also a player, map and game class.

so I have the player creating the shots with
1
2
3
4
5
void Player::shoot()
{
	//not sure how to get the new shot everytime 
 	shot.push_back(Shots(Player::getPosition(),sf::Color::Red, 2.5f, sf::Vector2f(-1.f, -1.f)));// sf::Color::Red, 2.5f, (-1.f, -1.f));
}


I have the main creates game and game creates map and map creates player. so where I draw the player I think I want to draw the shots as well and I have this.....
1
2
3
4
5
window.draw(circle) // this is the player for now
for(int i = 0; i < shot.size(); i++)
	{
		window.draw(shot[i].projectile); // but here it says projectile is inaccessable
	}


I have the shot as a circle as well as "sf::CircleShape projectile;"
im a little lost on how I can get this to draw to the screen.
You should tell each shot to draw itself to the window, rather than stealing its job.
ok, not sure how to go about this, I want to make a new function called render in the shots class but then im not quite sure how to draw up the individual shot this is what I have but does not work
[code]
void Shots::render(sf::RenderWindow& window)
{
for(int i = 0; i < shot.size(); i++)
window.draw(projectile[i]);
}
[code]
A shot should only worry about itself. Why do you have a loop? There is nothing to loop over - just draw the one and only graphic for the shot.
ok but what about all the other shots? do I not need to draw them as well
In your player class, you can loop through the shots and tell them to draw themselves. That means, calling the function you made.
thank u I did get it to start working, now the tough part of getting them to move and collide :)
Topic archived. No new replies allowed.