Jump to content
  • Advertisement
Sign in to follow this  

main function

This topic is 4310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

....this is pretty raw im new to programming read the absolute beginners guide to programming....third time through i wanted to just be able to get the pitcher to shoot the ball...no animation yet...just tryin to figure out how things work right now but...when i run this program a message says game function not defined...ive tried taking the game function out and mainlooping it instead but it wont fire the ball....can somebody help me out with this....or give me some material to read to improve my coding or anything im so confused on this
# Baseball game 2
# get pitcher to throw
# kyle cantrell 9/6/06

from livewires import games


class Pitcher(games.Sprite):
    """Pitcher who throws the ball on spacebar command"""
    image = games.load_image("pitch2.bmp")

    def __init__(self, screen, x, y):
        self.init_sprite(screen = screen, x = x, y = y, image = Pitcher.image)
        self.pitch_wait = 0

        if self.screen.is_pressed(games.K_SPACE):
            Pitch(self.screen, self.get_xpos(), self.get_ypos(), self.get_angle())

class Pitch(games.Sprite):
    image = games.load_image("ball.bmp")
    BUFFER = 40
    LIFETIME = 40

    def __init__(self, screen, pitcher_x, pitcher_y, pitcher_angle):
        angle = pitcher_angle * math.pi / 180

        buffer_x = Pitch.BUFFER * math.sin(angle)
        buffer_y = -Pitch.BUFFER * math.cos(angle)
        x = pitcher_x + buffer_x
        y = pitcher_y + buffer_y

        dx = Pitch.VELOCITY_FACTOR * math.sin(angle)
        dy = -Pitch.VELOCITY_FACTOR * math.cos(angle)

        self.init_sprite(screen = screen, x = x, y = y,
                         dx = dx, dy = dy, image = Pitch.image)
        self.liftime = Pitch.LIFETIME

    def moved(self):
        self.lifetime -= 1
        if not self.lifetime:

class Game(object):

    def create_pitcher(screen, x, y):
        Game.pitcher = Pitcher(screen = screen, x = x, y = y)

    create_pitcher = staticmethod(create_pitcher)

    def main():
        my_screen = THE_SCREEN
        field_image = games.load_image("field.bmp")

        Game.create_pitcher(screen = my_screen, x = SCREEN_WIDTH / 2, y = SCREEN_HEIGHT / 2)


[Edit: Added [source lang="python"][/source] tags - Oluseyi] [Edited by - Oluseyi on September 27, 2006 2:10:02 PM]

Share this post

Link to post
Share on other sites
Your most immediate problem is that, because it is indented one level, your main function is called inside the body of the Game class. Dedent it.

You have a few other weird bits of code, like whenever you call init_sprite(screen = screen, x = x, y = y, image = ...). What on earth is the portion in bold supposed to do?

Share this post

Link to post
Share on other sites
You may also need to create a Game object at global scope, and call the main() function from that, though it's hard to see whether that function should be part of the Game class or not.

Oluseyi, my guess is that init_sprite can take some keyword arguments, but it does look somewhat redundant.

It's certainly interesting how many people are using this livewires package.

Share this post

Link to post
Share on other sites
thanks for the help however now my pitcher sprite will not show up on the screen...also i am afraid that when he does he will not shoot the ball as intended...any ideas? thanks for the help before

Share this post

Link to post
Share on other sites
Putting that if-check in the __init__ function is not going to work, as the __init__ function only gets called when the Pitcher is created.

Also, you misspell 'lifetime' in one place, which will stop that from working.

I can't comment much further because you haven't shown your changed code, and because it's not clear how livewires works.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!