[Tutor] Game
Seon Kang
seon.kang at gmail.com
Sat Feb 9 23:15:53 CET 2008
First off, here is the code I am working with so far.
import random
from livewires import games, color
games.init(screen_width = 640, screen_height = 480, fps = 50)
controls = "Use The Arrow Keys to Move and the Spacebar to Shoot"
game_controls = games.Message(value = controls,
size = 25,
color = color.black,
x = 320,
y = 240,
lifetime = 250)
Motivation_status = "Motivation:"
motivation_text = games.Text(value = Motivation_status,
size = 20,
color = color.black,
x = 30,
y = 30)
motivation = 5
score = games.Text(value = motivation, size = 25, color = color.black,
x = 90, y = 30)
class Evil_stickman(games.Sprite):
missile_wait = 0
def update(self):
self.shoot()
def shoot(self):
if self.missile_wait > 0:
self.missile_wait -= 1
if self.missile_wait == 0:
missile_image = games.load_image("Missile.bmp", transparent =
True)
new_missile = Bad_Missile(image = missile_image, x = self.x -
10, y = self.y - 3, angle = 270)
games.screen.add(new_missile)
self.missile_wait = 20
def Die(self):
self.destroy()
class Rolling(games.Sprite):
def update(self):
if self.x > 0:
self.x -= 1
self.angle += 2
else:
self.destroy()
class Missile(games.Sprite):
def update(self):
if self.x < 640:
self.x += 2
else:
self.destroy()
class Bad_Missile(games.Sprite):
def update(self):
if self.x > 0:
self.x -= 2
else:
self.destroy()
class Stickman(games.Sprite):
missile_wait = 0
level_number = 1
def update(self):
if games.keyboard.is_pressed(games.K_RIGHT):
self.x += 1
if self.missile_wait > 0:
self.missile_wait -= 1
if games.keyboard.is_pressed(games.K_LEFT):
if self.x >= 0:
self.x -= 1
if games.keyboard.is_pressed(games.K_q):
games.screen.quit()
if games.keyboard.is_pressed(games.K_UP):
if self.y >= 280:
self.y -= 1
if games.keyboard.is_pressed(games.K_DOWN):
if self.y <= 460:
self.y += 1
if games.keyboard.is_pressed(games.K_SPACE) and self.missile_wait ==
0:
missile_image = games.load_image("Missile.bmp", transparent =
True)
new_missile = Missile(image = missile_image, x = self.x + 20, y
= self.y - 2, angle = 90)
games.screen.add(new_missile)
self.missile_wait = 25
if self.level_number == 1:
evilstick_image = games.load_image("badguy.bmp", transparent =
True)
new_evilstick01 = Evil_stickman(image = evilstick_image, x =
580, y = 400)
games.screen.add(new_evilstick01)
if motivation == 0:
self.destroy()
class Introduction(games.Sprite):
def update(self):
if games.keyboard.is_pressed(games.K_RETURN):
self.destroy()
games.screen.add(the_stick)
games.screen.add(game_controls)
intro_sprite_image = games.load_image("Introduction.bmp", transparent =
False)
intro_sequence = Introduction(image = intro_sprite_image, x = 340, y = 240)
games.screen.add(intro_sequence)
wall_image = games.load_image("the-map.bmp", transparent = False)
games.screen.background = wall_image
stickman_image = games.load_image("stickman.bmp", transparent = True)
the_stick = Stickman(image = stickman_image, x = 60, y = 380, angle = 90)
games.screen.mainloop()
The Evil_stickman class seems to have a problem with it. I have added the
missile delay in the hope that he would fire missiles about 2 times every
second, but instead, he shoots a constant stream. In addition, he slows my
entire game down. What is the problem with the code? And how might I go
about fixing it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080209/08f1c634/attachment.htm
More information about the Tutor
mailing list