|
|||||||
| Forum Home | Register | Members List | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | ||||||||
|
Senior Member
Location: Sterling Height, Michigan |
# Astrocrash02
# Get asteroids moving on the screen import random from livewires import games games.init(screen_width = 640, screen_height = 480, fps = 50) class Asteroid(games.Sprite): """ An asteroid which floats across the screen. """ SMALL = 1 MEDIUM = 2 LARGE = 3 images = {SMALL : games.load_image("asteroid_small.bmp"), MEDIUM : games.load_image("asteroid_med.bmp"), LARGE : games.load_image("asteroid_big.bmp") } SPEED = 2 def __init__(self, x, y, size): """ Initialize asteroid sprite. """ super(Asteroid, self).__init__( image = Asteroid.images[size], x = x, y = y, dx = random.choice([1, -1]) * Asteroid.SPEED * random.random()/size, dy = random.choice([1, -1]) * Asteroid.SPEED * random.random()/size) self.size = size def update(self): """ Wrap around screen. """ if self.top > games.screen.height: self.bottom = 0 if self.bottom < 0: self.top = games.screen.height if self.left > games.screen.width: self.right = 0 if self.right < 0: self.left = games.screen.width class Ship(games.Sprite): """ The player's ship. """ image = games.load_image("ship.bmp") ROTATION_STEP = 3 def update(self): """ Rotate based on keys pressed. """ if games.keyboard.is_pressed(games.K_LEFT): self.angle -= Ship.ROTATION_STEP if games.keyboard.is_pressed(games.K_RIGHT): self.angle += Ship.ROTATION_STEP def main(): # establish background nebula_image = games.load_image("nebula.jpg") games.screen.background = nebula_image # create 8 asteroids for i in range(8): x = random.randrange(games.screen.width) y = random.randrange(games.screen.height) size = random.choice([Asteroid.SMALL, Asteroid.MEDIUM, Asteroid.LARGE]) new_asteroid = Asteroid(x = x, y = y, size = size) games.screen.add(new_asteroid) # create the ship the_ship = Ship(image = Ship.image, x = games.screen.width/2, y = games.screen.height/2) games.screen.add(the_ship) games.screen.mainloop() # kick it off! main() This is the program Yauster, it's SUPPOSE to import games from Livewires, but doesn't. |
||||||||
|
|
|
|
|
#12 | ||||||||
|
Administrator
Location: UK |
At a rough guess, it looks like the tutorial might be out of date with the library. try:
games.Screen(screen_width = 640, screen_height = 480) instead or some of the solutions here: http://www.daniweb.com/forums/thread235000.html#
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] |
||||||||
|
|
|
|
|
#13 | |||||||||
|
Senior Member
Location: Sterling Height, Michigan |
Quote:
|
|||||||||
|
|
|
|
|
#14 | ||||||||
|
Administrator
Location: UK |
He is using the same tutorial and hitting the same problem. Others in the thread have recommend fixes, have you tried them?
Like I said, you may have different version (read, older/newer) of the library LiveWires and the tutorials only work with one particular version. Failing all that, ditch LiveWires and just use PyGame as LiveWires is just a wrapper around PyGame anyway.
__________________
Steven Yau [Alix Games Blog] [Portfolio] [How I broke into the Games Industry] [Why I left my Games Job] [How to be a Games Tester] [Getting back into the Game] Last edited by yaustar : 11-24-2009 at 10:36 AM. |
||||||||
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 01:52 AM.





















Linear Mode

