Question:
Help with making a Pygame game: screen freezes?
Gio
2010-01-30 19:40:32 UTC
OK, heres the code (nvm the indentation):

# 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?
Three answers:
2010-01-30 20:11:17 UTC
Post with indentation (on pastebin.com) and I'll look it over. I can't really debug Python code without indentation. it's too painful.



I tried, but I still don't have everything I need to check your code. File_Loads appears to be a custom module. I don't see why you need it, though, because pygame has a perfectly good image loading mechanism... I also don't have access to your images.



OK. Take a look at this file here:

http://aharris.pastebin.com/m6aab67bb



I did my best to guess at indentation, and I used ordinary image manipulation to build the fishing rod. I just used a simple image for the fishing rod to test, and I got it working just fine. I took out the other sprites, and just tested with one. The basic structure of the game is working fine.



My version is currently running without error until it looks for the salmon object, which I've turned off.



See if this helps...



NOTE: Test your code from the console, not by clicking on it. Any error messages willbe reported back to the console, which will be invisible if you run directly from windows.



Or use a dedicated editor like SPE which returns error messages. (That's what I do...)
2010-02-06 00:53:15 UTC
The most common cause of computer freezes is a corrupt registry.

Most likely your registry is bloated and overstuffed with an assortment of useless pieces of data. The operating system while running your computer has to pick its way through all this excess material. There will be bits of programs which were not completely uninstalled, parts of programs which were never completely installed, fragments of miscellaneous data, useless drivers, and a multitude of other bits and pieces.

The answer is to clean your registry and remove all the material which is not needed.

http://fix-computer-freezing.com/Clean_Up_Center.htm

Get the best one, and completely clean your windows registry with a few clicks of the mouse.



Often there is also spyware which is using your computer for nefarious purposes and slowing its operation.

The answer is to scan your pc with a best anti-spyware to clean spyware/trojan/virus.

http://fix-computer-freezing.com
?
2016-11-08 01:57:54 UTC
I had a undertaking like this slightly in the past, you will be able to desire to purpose the tactic I utilized by skill of beginning your workstation's case then cleansing the interior the workstation with a vacume in case you are trying this determine you eliminate all static in you hands and attempt to no longer touch any factors interior the workstation. attempt your maximum suitable to eliminate all the airborne dirt and dust on your workstation. if this dosent remedy something ask somebody to study the workstation.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...