Gio
2010-01-30 19:40:32 UTC
# PyFishing
# Version: Alpha
# (c) 2010
# By Gio Di Russo
try:
import os, sys
import pygame
from pygame.locals import *
from File_Loads import load_image
except ImportError, err:
print "couldn't load module. %s" % (err)
sys.exit(2)
salmoncaught = 0
class Rod(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('Rod.bmp', -1)
self.reeling = 0
def update(self):
pos = pygame.mouse.get_pos()
self.rect.midtop = pos
def reel(self, target):
if not self.reeling:
self.reeling = 1
hitbox = self.rect.inflate(0, 0)
return hitbox.colliderect(target.rect)
def unreel(self):
self.reeling = 0
class Salmon(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('Fishshadow.bmp', -1)
self.caught = 0
def update(self):
if self.caught:
salmoncaught + 1
self.contents.clear()
else:
self.swim()
def swim(self):
self.caught = 0
def reeled(self):
if not self.caught:
self.caught = 1
class Finish_Button(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_image('Finish.bmp', -1)
self.area = screen.get_rect()
self.pushed = 0
def update(self):
if self.pushed:
if pygame.font:
font = pygame.font.Font(None, 36)
text = font.render("You caught:", salmoncaught, "salmon", 1, (10, 10, 10))
textpos = text.get_rect(centerx=background.get_width()/2)
background.blit(text, textpos)
def push(self):
self.pushed = 1
pygame.init()
screen = pygame.display.set_mode((500, 500))
pygame.display.set_caption('PyFishing by Gio Di Russo')
pygame.mouse.set_visible(0)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 250))
screen.blit (background, (0, 0))
pygame.display.flip()
rod = Rod()
salmon = Salmon()
finish_button = Finish_Button()
allsprites = pygame.sprite.RenderPlain ((salmon, rod, finish_button))
clock = pygame.time.Clock()
while 1:
clock.tick(60)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
elif event.type == MOUSEBUTTONDOWN:
if rod.reel(salmon):
salmon.reeled()
elif rod.reel(finish_futton):
finish_button.push()
elif event.type == MOUSEBUTTONUP:
rod.unreel()
allsprites.update()
screen.blit(background, (0, 0))
allsprites.draw(screen)
pygame.display.flip()
Now, when i hit F5 to run it, it makes a blue screen, and if I click, it goes nonresponsive. what is wrong?