1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import os,sys import time import pygame from whimp import Whimp from fist import Fist from pygame.locals import * from tool import load_sound from config import whiff_sound,punch_sound
def main():
if not pygame.font: print('sorry, this game no font') if not pygame.mixer.Sound: print('sorry,this game no sound')
pygame.init() screen = pygame.display.set_mode((400,80)) bg = pygame.Surface(screen.get_size()) bg = bg.convert() bg.fill((250,250,250)) pygame.mouse.set_visible(0)
if pygame.font: text = pygame.font.Font(None,32).render('Hit The Nut And Win $$$',1,(10,10,10)) bg.blit(text,(screen.get_width() / 2 - text.get_width() /2,30)) screen.blit(bg,(0,0)) pygame.display.flip() print(text.get_rect()) clock = pygame.time.Clock() whimp = Whimp() fist = Fist() punch_s = load_sound(punch_sound) whiff_s = load_sound(whiff_sound)
allsprite = pygame.sprite.RenderPlain((whimp,fist))
while True: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.K_ESCAPE: exit() if event.type == pygame.MOUSEBUTTONDOWN: if fist.punch(whimp): whimp.punched() punch_s.play() else: whiff_s.play() if event.type == pygame.MOUSEBUTTONUP: fist.unpunch() allsprite.update()
screen.blit(bg,(0,0)) allsprite.draw(screen) pygame.display.flip()
if __name__ == "__main__": main()
|