Get the latest Education e-news

 Game Career Guide Forums Programming Compilers Information
 Forum Home Register Members List Mark Forums Read

11-24-2009, 09:30 AM   #11
Siberianhusky89
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

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. """
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
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)

# create the ship
the_ship = Ship(image = Ship.image,
x = games.screen.width/2,
y = games.screen.height/2)

games.screen.mainloop()

# kick it off!
main()

This is the program Yauster, it's SUPPOSE to import games from Livewires, but doesn't.

11-24-2009, 09:58 AM   #12
yaustar

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)

11-24-2009, 10:05 AM   #13
Siberianhusky89
Senior Member

Location: Sterling Height, Michigan

Quote:
 Originally Posted by yaustar 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#
I'm pretty sure that he might be using the same tutorial I am (It's a college book), cause that's actually the first step in making the "astrocrash" game. However, when I run it at school, it works perfectly fine

11-24-2009, 10:34 AM   #14
yaustar

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.

Last edited by yaustar : 11-24-2009 at 10:36 AM.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off