예제 #1
0
def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
#Initialize Everything
    pygame.init()
    screensize = (800, 600)
    screen = pygame.display.set_mode(screensize)

#create the wallpaper, and make it fill the screen
    wallpaper = codeclub.load_image('hall.jpg')
    wallpaper = pygame.transform.scale(wallpaper, (screensize))
    background = pygame.Surface(screensize)
    background.blit(wallpaper, (0, 0))
    
#Prepare Game Objects
    clock = pygame.time.Clock()
    
#Main Loop
    while True:
        clock.tick(60)

    #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return

    #Draw Everything
        screen.blit(background, (0, 0))
        pygame.display.flip()
예제 #2
0
def main():
	pygame.init()
	screensize = (800, 483)
	screen = pygame.display.set_mode(screensize)

	wallpaper = codeclub.load_image('stansted-map.png')
	wallpaper = pygame.transform.scale(wallpaper, (screensize))

	allplanes = pygame.sprite.Group()
	allfixes = pygame.sprite.Group()
	chance_of_new_plane_in_next_tick = 1
	
	clock = pygame.time.Clock()

	draggingplane = None

	while True:
		clock.tick(60)
		if random.random() < chance_of_new_plane_in_next_tick:
			newplane = Plane(screensize)
			allplanes.add(newplane)
			chance_of_new_plane_in_next_tick = -0.003
		else:
			chance_of_new_plane_in_next_tick += 0.0001

		for event in pygame.event.get():
			if event.type == QUIT:
				return
			elif event.type == KEYDOWN and event.key == K_ESCAPE:
				return
			elif event.type == MOUSEBUTTONDOWN:
				for plane in allplanes:
					if plane.rect.collidepoint(pygame.mouse.get_pos()):
						draggingplane = plane
						break
			elif event.type == MOUSEBUTTONUP:
				draggingplane = None

		allplanes.update()
		for planea in allplanes:
			for planeb in allplanes:
				if not planea == planeb:
					if pygame.sprite.collide_mask(planea, planeb):
						return

		if not draggingplane == None:
			fix = Fix(pygame.mouse.get_pos())
			draggingplane.add_destination(fix)
			allfixes.add(fix)

		screen.blit(wallpaper, (0, 0))
		allplanes.draw(screen)
		allfixes.draw(screen)
		pygame.display.flip()
예제 #3
0
def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
#Initialize Everything
    pygame.init()
    screensize = (800, 600)
    screen = pygame.display.set_mode(screensize)
    pygame.mouse.set_visible(0)

#create the wallpaper, and make it fill the screen
    wallpaper = codeclub.load_image('hall.jpg')
    wallpaper = pygame.transform.scale(wallpaper, (screensize))
    background = pygame.Surface(screensize)
    background.blit(wallpaper, (0, 0))
    
#Prepare Game Objects
    clock = pygame.time.Clock()
    felix = codeclub.sprite()
    felix.set_costume('cat1-a.gif', 100)
    herbert = codeclub.sprite()
    herbert.set_costume('mouse1.png', 60)
    allsprites = pygame.sprite.Group((herbert, felix))
    
#Main Loop
    while True:
        clock.tick(60)

    #Handle Input Events
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return

    #Move the sprites
        felix.point_towards(herbert)
        felix.move_unless_frozen(2)
        herbert.move_to(pygame.mouse.get_pos())
        herbert.point_towards(felix)
        
    #See whether Felix has caught Herbert
        if felix.has_caught(herbert):
            felix.freeze(20)
            felix.say("I've got you!", 60)
                
    #Draw Everything
        screen.blit(background, (0, 0))
        allsprites.draw(screen)
        felix.speak(screen)
        pygame.display.flip()