Jump to content

  • Log In with Google      Sign In   
  • Create Account

Pygame Window Not-Responding


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 marissa13600   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2012 - 04:55 PM

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 pygamefrom 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 - 5def 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 completewhile 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

Edited by jbadams, 01 April 2012 - 07:54 PM.
Added [source] tags to post.


Sponsor:

#2 MLillowitz   Banned   -  Reputation: 23

Like
-2Likes
Like

Posted 02 April 2012 - 11:23 PM

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

#3 Trienco   Crossbones+   -  Reputation: 2172

Like
0Likes
Like

Posted 02 April 2012 - 11:58 PM

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.
f@dzhttp://festini.device-zero.de

#4 Narf the Mouse   Members   -  Reputation: 318

Like
0Likes
Like

Posted 03 April 2012 - 12:23 AM

Question that must be asked: Are you handling/calling a handler for windows messages somewhere?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS