#!/usr/bin/python # -*- coding: utf-8 -*- import pygame import time import sys, os pygame.init() try: import psyco; psyco.full() except: print'not psyco' class Mario: def __init__(self): self.x = 100 self.y = 100 self.power = 100 self.dixieme = 0 self.image = self.image = pygame.image.load('mario.png').convert_alpha() return def bouge(self, direction): if direction == 'gauche': self.x -= 5 if direction == 'droite': self.x += 5 def saute(self): if self.power >5: self.power-=5 self.y-=5 def turn(self): if self.dixieme == 10: self.power+=5 self.dixieme = 0 self.y+=1 self.dixieme+=1 class Moteur : def __init__(self): self.screenx = 1024 self.screeny = 768 self.size = width, height = self.screenx, self.screeny #taille de l'écran self.ecran = pygame.display.set_mode(self.size) #création de la fenêtre graphique pygame.display.set_caption('pyario')#titre pour la fenêtre pygame.key.set_repeat(1, 5)#on active le "set repeat" self.mario = Mario() self.boucle() return def affiche(self): black = 100, 100, 100 self.ecran.fill(black) self.ecran.blit(self.mario.image,(self.mario.x,self.mario.y)) pygame.display.update() return def boucle(self): while 1: self.mario.turn() self.affiche() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == 273:#'HAUT': pass if event.key == 274:#'BAS': pass if event.key == 276:#'GAUCHE': self.mario.bouge('gauche') if event.key == 275:#'DROITE': self.mario.bouge('droite') if event.key == 32:#'ESPACE' self.mario.saute() m = Moteur()