(no, this is not a banner ad, its the screenshot)![]() Full Source |
import os import pygame, pygame.font, pygame.image, pygame.mixer from pygame.locals import * |
chimpfile = os.path.join('data', 'chimp.bmp')
fistfile = os.path.join('data', 'fist.bmp')
hitfile = os.path.join('data', 'punch.wav')
missfile = os.path.join('data', 'whiff.wav')
|
pygame.init()
screen = pygame.display.set_mode((468, 60), HWSURFACE|DOUBLEBUF)
pygame.display.set_caption('Monkey Fever')
pygame.mouse.set_visible(0)
|
background = pygame.Surface(screen.get_size()).convert() background.fill((250, 250, 250)) |
font = pygame.font.Font(None, 36)
text = font.render("Pummel The Chimp, And Win $$$", 1, (20, 20, 20))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
|
screen.blit(background, (0, 0)) pygame.display.flip() |
chimp = pygame.image.load(chimpfile).convert() chimp.set_colorkey(chimp.get_at((0, 0))) fist = pygame.image.load(fistfile).convert() fist.set_colorkey(chimp.get_at((0, 0))) whiffsound = pygame.mixer.Sound(missfile) hitsound = pygame.mixer.Sound(hitfile) |
chimppos = chimp.get_rect() chimppos.bottom = screen.get_height() chimpmove = 2 reload = 0 |
while 1: |
event = pygame.event.poll()
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
break
|
chimppos.left += chimpmove
if not screen.get_rect().contains(chimppos):
chimpmove = -chimpmove
|
fistpos = pygame.mouse.get_pos()
pressed = pygame.mouse.get_pressed()[0]
if not reload and pressed:
if chimppos.collidepoint(fistpos):
hitsound.play()
else:
whiffsound.play()
reload = pressed
if reload:
fistpos = fistpos[0] - 20, fistpos[1] - 10
|
screen.blit(background, (0, 0)) screen.blit(chimp, chimppos) screen.blit(fist, fistpos) pygame.display.flip() |