Original Post
....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 [Edit: Added [source lang="python"][/source] tags - Oluseyi] [Edited by - Oluseyi on September 27, 2006 2:10:02 PM]
# Baseball game 2
# get pitcher to throw
# kyle cantrell 9/6/06
from livewires import games
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
THE_SCREEN = games.Screen(SCREEN_WIDTH, SCREEN_HEIGHT)
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
VELOCITY_FACTOR = 7
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:
self.destroy()
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")
my_screen.set_background(field_image)
Game.create_pitcher(screen = my_screen, x = SCREEN_WIDTH / 2, y = SCREEN_HEIGHT / 2)
main()