I can't get my game to work, I've been writing it out fo a couple days, worked at some points, but now isn't. I need to add the happyhouse and plane classes into the game, there are hashmarks letting you know what each is supposed to do. In general, kinda like a space invaders game, shoot present from santas sleigh to hit chimneys, dodge planes. Chimneys are supposed to turn into smiley faces and continue down the screen, also supposed to turn non-collieable.
# Mark Rodriguez
# 11/28/10
# Present Panic!
import random
import math
from livewires import games, color
# Setting up the game window
games.init(screen_width = 400, screen_height = 600, fps = 50)
# This is for when santa runs into a planesprite or chimney sprite
class Crash(games.Animation):
sound = games.load_sound("hohoho.wav")
image = ["crash1.jpg",
"crash2.jpg",
"crash3.jpg",
"crash4.jpg",
"crash5.jpg",
"crash6.jpg"]
# initializes the crash image animation and sound
def __init__(self, x, y):
super(Crash, self).__init__(images = Crash.images,
x = x, y = y,
is_collideable = False)
Crash.sound.play()
#class Happyhouse(self.Sprite):
# sound = games.load_sound("yay.wav")
# image = games.load_image("hap.jpg")
# speed = 2
#
# def __init__(self, x, y):
# super(Happyhouse, self).__init__(image = Happyhouse.image,
# x = x,
# y = y,
# dy = Happyhouse.speed,
# is_collideable = False)
# def update(self):
# if self.bottom > games.screen.height:
# self.destroy()
# This is santa's sleigh, has a sound when he shoots present that delays
class Sleigh(games.Sprite):
image = games.load_image("sleigh.jpg")
sound = games.load_sound("axe_throw.wav")
timer = 0
Delay = 30
def __init__(self, x, y):
super(Sleigh, self).__init__(image = Sleigh.image, x=x, y=y)
self.Present_wait = 0
# Crash sequence that is from the crash class
def crash(self):
new_crash = Crash(x = self.x, y = self.y)
games.screen.add(new_crash)
self.destroy()
# Mouse control and shooting button
def update(self):
self.x = games.mouse.x
self.y = games.mouse.y
if self.overlapping_sprites:
for sprite in self.overlapping_sprites:
sprite.crash()
self.crash()
if self.Present_wait > 0:
self.Present_wait -= 1
if games.keyboard.is_pressed(games.K_SPACE) and self.Present_wait == 0:
Present.sound.play()
new_present = Present(self.x, self.y, self.angle)
games.screen.add(new_present)
self.Present_wait = Present.Delay
self.timer += 1
# timer for when instructions show and rounds begin
if self.timer == 700:
self.intructionsa()
if self.timer == 300:
self.intructionb()
if self.timer == 500:
self.intructionsc()
if self.timer == 850:
self.round_start()
if self.timer == 3300:
self.round_one()
if self.timer == 6100:
self.round_two()
if self.timer == 8900:
self.round_three()
if self.timer == 11700:
self.round_four()
if self.timer == 14500:
self.round_five()
if self.timer == 17300:
self.round_six()
if self.timer == 20100:
self.round_seven()
if self.timer == 24000:
self.round_eight()
# Instructions that display on the screen
def instructiona(self):
round_message = games.Message(value = "Santa got a late start on sending present! Help him by getting present to all the houses before sunrise!",
size = 16,
color = color.green,
x = games.screen.width/2,
y = games.screen.height/.9,
lifetime = 30 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message)
def instructionsb(self):
round_message = games.Message(value = "Shoot presents into the chimneys to deliver presents!",
size = 16,
color = color.green,
x = games.screen.width/2,
y = games.screen.height/.8,
lifetime = 20 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message)
def instructionc(self):
round_message = games.Message(value = "Dodge the late night airplanes, or Santa will crash and not deliver his presents in his 8 hour limit!",
size = 16,
color = color.green,
x = games.screen.width/2,
y = games.screen.height/.9,
lifetime = 30 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message)
def round_start(self):
round_message = games.Message(value = "First hour has started!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message)
def round_one(self):
round_message_one = games.Message(value = "First hour done! Second hour is more busy",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_one)
def round_two(self):
round_message_two = games.Message(value = "Second hour done! Third hour is busier!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_two)
def round_three(self):
round_message_three = games.Message(value = "Third hour done! Fourth hour is even busier, hurry santa!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_three)
def round_four(self):
round_message_four = games.Message(value = "Fourth done, half way there! Here comes the fifth",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_four)
def round_five(self):
round_message_five = games.Message(value = "Fifth hour done santa! Keep it going!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_five)
def round_six(self):
round_message_six = games.Message(value = "Sixth done, good job santa! Only two more until sunrise!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 10 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_six)
def round_seven(self):
round_message_seven = games.Message(value = "Seventh done, WOW! The sky is getting really busy now! Last hour!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 12 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_seven)
def round_eight(self):
round_message_eight = games.Message(value = "All the presents were delivered! Good job santa!",
size = 20,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/1.25,
lifetime = 12 * games.screen.fps,
is_collideable = False)
games.screen.add(round_message_eight)
# Presents are shot at Chimneys to get points, supposed to turn chimneys into smileys faces that turn non collideable and continue down the screen.
class_Present(games.Present):
image = games.load_image("prez.jpg")
Distance = 40
Speed = 15
Present_End = 40
def __init__(self, sleigh_x, sleigh_y, turret_angle):
angle = sleigh_angle * math.pi / 180
distance_x = Present.Distance * math.sin(angle)
distance_y = Present.Disatnce * -math.cos(angle)
x = sleigh_x + distance_x
y = sleigh_y + distance_y
dx = Present.Speed * math.sin(angle)
dy = Present.Speed * -math.cos(angle)
super(Present, self).__init__(image = Present.image,
x = x, y = y,
dx = dx, dy = dy)
self.present_end = Present.Present_End
def update(self):
super(Present, self).update()
self.present_end -= 1
if self.present_end == 0:
self.destroy()
if self.overlapping_sprites:
for sprite in self.overlapping_sprites:
sprite.delievered()
self.delivereded()
#def delivered(self):
# new_happyhouse = Happyhouse(x = self.x, y = self.y)
# games.screen.add(new_happyhouse)
# score.deliveries.value += 1
# Chimenys move as sprites down the screen, supposed to turn into smiley faces when they are hit by a present and add a point to score.
class Chimney(games.Sprite):
image = games.load_image("chim.jpg")
fail = games.load_sound("booo.wave")
speed = 2
#def delivered(self):
#new_happyhouse = Happyhouse(x = self.x, y = self.y)
#games.screen.add(new_happyhouse)
def __init__(self, x, y):
super(Chimney, self).__init__(image = Chimney.image,
x = x,
y = y,
dy = Chimney.speed)
def update(self):
if self.bottom > games.screen.height:
self.end_game()
def end_game(self):
Chimney.sound.play()
lost_message = games.Message(value = "You missed a present delivery! You ruined Christmas!",
size = 35,
color = color.black,
x = games.screen.width/2,
y = games.screen.height/3,
lifetime = 4* games.screen.fps,
after_death = games.screen.quit)
games.screen.add(lost_message)
#class Plane(games.Sprite):
#image = games.load_image("plane.jpg")
#speed = 1
#def __init__(self, x, y):
#super(Plane, self).__init__(image = Plane.image,
#x = x,
#y = y,
#dx = Plane.speed)
#def update(self):
#if self.left > games.screen.right:
#self.destroy()
class Score(object):
deliveries = games.Text(value = 0,
color = color.green,
size = 25,
top = 18
right = games.screen.width/2,
is_collideable = False)
games.screen.add(deliveries)
# starts the plane sprites moving across the screen randomly, santa crashes if he runs into a plane
#def start_planes():
# for i in range(3):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 2600
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(5):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 5400
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(8):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 8200
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(10):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 11000
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(12):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 16600
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(14):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 19400
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#
# for i in range(18):
# x = random.randrange(games.screen.width)
# y = random.randrange(1200) - 22200
# new_Chimney = Chimney(x = x, y = y)
# games.screen.add(new_Plane)
#stars the chimenys moving down the screen, certain times for certain rounds
def start_chimneys():
for i in range(10):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 2600
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(15):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 5400
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(20):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 8200
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(25):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 11000
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(33):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 13800
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(39):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 16600
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(44):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 19400
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
for i in range(61):
x = random.randrange(games.screen.width)
y = random.randrange(1200) - 22200
new_Chimney = Chimney(x = x, y = y)
games.screen.add(new_Chimney)
def main():
background_image = games.load_image("background.jpg")
games.screen.background = background_image
games.music.load("jingle-bells.mid")
games.music.play(-1)
sleigh.image = games.load_image("sleigh.jpg")
santa_sleigh = Sleigh(x = games.screen.width/2,
y = games.screen.height/1.4)
games.screen.add(santa_sleigh)
games.mouse.is_visible = False
start_chimneys()
#start_planes()
games.screen.mainloop()
main()