Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11-24-2009, 09:30 AM   #11
Siberianhusky89
Senior Member

Activity Longevity
0/20 16/20
Today Posts
0/11 ssssss156
Location: Sterling Height, Michigan
Default

# 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.
Siberianhusky89 is offline   Reply With Quote
Old 11-24-2009, 09:58 AM   #12
yaustar
Administrator
 
yaustar's Avatar

Activity Longevity
2/20 19/20
Today Posts
1/11 sssss2254
Location: UK
Default

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#
yaustar is offline   Reply With Quote
Old 11-24-2009, 10:05 AM   #13
Siberianhusky89
Senior Member

Activity Longevity
0/20 16/20
Today Posts
0/11 ssssss156
Location: Sterling Height, Michigan
Default

Quote:
Originally Posted by yaustar View Post
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
Siberianhusky89 is offline   Reply With Quote
Old 11-24-2009, 10:34 AM   #14
yaustar
Administrator
 
yaustar's Avatar

Activity Longevity
2/20 19/20
Today Posts
1/11 sssss2254
Location: UK
Default

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.
yaustar is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 10:06 AM.






UBM Tech