Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is a function way efficient for playing a new game, if lose?  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

newn

  • Guest
Is a function way efficient for playing a new game, if lose?
« on: August 27, 2010, 08:35:52 pm »
Hi everyone. I've been thinking about how to make a new game, after the ball falls off the screen. I thought of a few ways, and it seems, that the best one is write the drawing stuff (with sf:::window) into a function and call it in if statement later. Would that be an efficient way to do it, or is there some better way to do it?
Posted it here, because it seems like the general discussion about how to make the code better, not exatly graphics library, how to do something.

Thanks!

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Is a function way efficient for playing a new game, if lose?
« Reply #1 on: August 27, 2010, 09:36:19 pm »
What?

Did you write your post in a different language and then translated it with google translate?

Quote
I've been thinking about how to make a new game, after the ball falls off the screen


Is there supposed to be a point after "game"? What balls? What does it mean to fall off the screen? You mean, go out of the screen?
 
Okay, so I think what you are asking is this: You have a bunch of sprites (maybe in the shape of balls) and some of them are inside the screen area and some are outside and you want to draw them.

My answer then would be: Don't bother, just send everything to Draw:
Code: [Select]

for(sprite = sprites.begin(); sprite != sprites.end(); ++sprite)
     App.Draw(*sprite);

and let SFML worry about what to draw and where.

TheMagician

  • Newbie
  • *
  • Posts: 7
    • View Profile
Is a function way efficient for playing a new game, if lose?
« Reply #2 on: August 27, 2010, 10:19:06 pm »
You need to elaborate a little more. Do you mean that is it a good practice to put all your game code inside a function (like runGame()) that you can call whenever you want to start a new game?

newn

  • Guest
Is a function way efficient for playing a new game, if lose?
« Reply #3 on: August 27, 2010, 11:30:50 pm »
Okay, i just laughed at myself. Anyway, what i meant was:

I've made a pong game, when the ball falls off the screen (one of the player loses), i should offer to start a new game. Is that an efficient way, how i described, i would do it in, the first post?

Ummm, hope you understood, what i meant now. Lol.

Recruit0

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Is a function way efficient for playing a new game, if lose?
« Reply #4 on: August 28, 2010, 12:50:56 am »
Sounds like you're trying to figure out how to handle multiple (macro) game states. Basically you need to reset everything (ball position, points, etc.). Off the top of my head, you could encapsulate (put) current code inside a loop and have a condition where if the player says "Quit" it exits the loop (this is a loop inside the game loop).

If everything's inside main, you really should at least create a function and move it outside (into another file). You could also use a switch statement to call the correct function depending on what the game state is (running, restart, stop, etc).

Based off of your question it sounds like you're not encapsulating (isolating) code. It's good practice to do because it makes it easier to manage.

Not sure but I hope the above was helpful.