For my Game Programming Class we had to my a tamagotchi game. I have been having loads of problems with the window not responding... I've tried multiple things but nothing is working. Any help or suggestions would be awesome.
[source lang="python"]
from TamagochiGame import *
import pygame
from pygame.locals import *
global background
#background = pygame.image.load("background.jpg")
screen = pygame.display.set_mode((600,400), DOUBLEBUF)
#size = (width, height) = background.get_size()
stillPlaying = True
############################ METHODS TO DEFINE #################################
def initializeTamagochi():
"""
Set the initial state of the Tamagochi, and give it some food.
"""
global tamagochiState # Do not delete this part
global nutrition # or this part
tamagochiState = "Bored" #tamagochi is happy at initial start
nutrition = 100
##### SET UP #####
global boredimage
global bored1image
global hungryimage
global hungry1image
global playingimage
global playing1image
global eatingimage
global eating1image
background = pygame.image.load("background.jpg")
boredimage = pygame.image.load("Bored.jpg")
bored1image = pygame.image.load("Bored1.jpg")
hungryimage = pygame.image.load("Hungry.jpg")
hungry1image = pygame.image.load("Hungry1.jpg")
playingimage = pygame.image.load("Playing.jpg")
playing1image = pygame.image.load("Playing1.jpg")
eatingimage = pygame.image.load("Eating.jpg")
eating1image = pygame.image.load("Eating1.jpg")
def updateTamagochiState():
"""
Based on whether there is food or a toy present, change the state of the
Tamagochit
"""
global tamagochiState # Do not delete this part
global nutrition # or this part
if tamagochiState == "Bored":
nutrition = nutrition - 5
if tamagochiState == "Playing":
nutrition = nutrition - 5
if nutrition < 0:
nutrition = 0
if tamagochiState == "Bored":
if nutrition < 20:
tamagochiState = "Hungry"
elif game.seeToy():
tamagochiState = "Playing"
elif tamagochiState == "Eating":
if not game.seeFood(): # No food to eat...
if game.seeToy():
tamagochiState = "Playing"
else:
tamagochiState = "Bored"
elif tamagochiState == "Playing":
if nutrition < 20:
tamagochiState = "Hungry"
elif not game.seeToy():
tamagochiState = "Bored"
elif tamagochiState == "Hungry":
if game.seeFood():
tamagochiState = "Eating"
nutrition = nutrition + 5
if tamagochiState != "Eating":
nutrtion = nutrition - 5
def tamagochiAct():
"""
Based on the state the tamagochi is in, do something (and print it to the
screen)
"""
global tamagochiState # Do not delete this part
global nutrition
global stillPlaying # or this part
stillPlaying = True
frame = 0
frame = frame + 1
frame = 0 + 1
if tamagochiState == "Bored":
print ("Your tamagochi is bored... Do something to cheer him up!")
if frame < 15:
screen.blit(boredimage, (125, 150))
pygame.display.flip()
else:
screen.blit(bored1image, (125, 150))
pygame.display.flip()
elif tamagochiState == "Playing":
print ("Your tamagochi is playing!")
if frame < 15:
screen.blit(playingimage, (125, 150))
pygame.display.flip()
else:
screen.blit(playing1image, (125, 150))
pygame.display.flip()
elif tamagochiState == "Eating":
print ("Your tamagochi is eating!")
if frame < 15:
screen.blit(eatingimage, (125, 150))
pygame.display.flip()
else:
screen.blit(eating1image, (125, 150))
pygame.display.flip()
elif tamagochiState == "Hungry":
print ("Your tamagochi is hungry! Better feed him!")
if frame < 15:
screen.blit(hungryimage, (125, 150))
pygame.display.flip()
else:
screen.blit(hungry1image, (125, 150))
pygame.display.flip()
print ("nutrition = ", nutrition) #Tells what the nurtition level is
#backgroundRect = background.get_rect()
#screen.blit(background, backgroundRect)
#pygame.display.flip()
pygame.display.flip()
if __name__ == "__main__":
initializeTamagochi()
game = TamagochiGame(updateTamagochiState, tamagochiAct)
# And loop until complete
while True:
event = pygame.event.get()
for event in event:
if event.type == QUIT:
stillPlaying = False
game.gameLoop()
[/source]
This is what I have so far
Pygame Window Not-Responding
Hi, marissa13600.
Did you assure all files are in place, all necessities are on-key, and all the syntax is correct?
Remember that Python is a very easy programming language, but also a very limited one.
- Mikey
Did you assure all files are in place, all necessities are on-key, and all the syntax is correct?
Remember that Python is a very easy programming language, but also a very limited one.
- Mikey
Hard to tell without knowing what gameLoop looks like. But I'd assume it's not actually a loop but only a single update? Otherwise there would never be any event handling after the first. Calling it something like "update" instead of "loop" would make that clearer.
Question that must be asked: Are you handling/calling a handler for windows messages somewhere?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement