# 1 - Import library import pygame # 2 - Initialize the game pygame.init() screen=pygame.display.set_mode((640, 480)) # 3 - Load images player = pygame.image.load("resources/images/cop.png") floor = pygame.image.load("resources/images/floor.png") bank = pygame.image.load("resources/images/castle.png") # 4 - Game Loop while 1: # 5 - clear the screen before drawing it again screen.fill(0) # 6 - draw the screen elements for x in range(width/grass.get_width()+1): for y in range(height/grass.get_height()+1): screen.blit(grass,(x*100,y*100)) screen.blit(money,(0,30)) screen.blit(money,(0,135)) screen.blit(money,(0,240)) screen.blit(money,(0,345 )) screen.blit(player, (100,100)) # 7 - update the screen pygame.display.flip() # 8 - loop through the events for event in pygame.event.get(): # check if the event is the X button if event.type==pygame.QUIT: # if it is quit the game pygame.quit() exit(0)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question