rendered paste body#!/usr/bin/python
# -*- coding: utf-8 -*-
import pygame
import sys
pygame.init()
class Mario:
def __init__(self):
self.x = 20
self.y = 20
self.image = pygame.image.load('images/mario.gif').convert_alpha()
def move(self, direction):
if direction == 'gauche' and self.x > 0 : self.x-=1
if direction == 'droite' and (self.x + self.image.get_width()) < Moteur.screenX : self.x+=1
def jump(self):
print "proot"
class Moteur:
def __init__(self):
self.screenX = 640
self.screenY = 480
self.screen = pygame.display.set_mode((self.screenX, self.screenY))
pygame.display.set_caption('Mario 512')
pygame.key.set_repeat(1, 1)
self.mario = Mario()
self.boucle()
def updateScreen(self):
self.screen.fill((255, 255, 255))
self.screen.blit(self.mario.image, (self.mario.x, self.mario.y))
pygame.display.update()
def bordureVerif(self):
if self.mario.x < 0: self.mario.x
if (self.mario.x + self.mario.image.get_width()) > self.screenX: self.mario.x = (self.screenX - self.mario.image.get_width()) - 1
if self.mario.y < 0: self.mario.y = 1
if (self.mario.y + self.mario.image.get_height()) > self.screenY: self.mario.y = (self.screenY - self.mario.image.get_height()) -1
def exit(self):
pygame.quit()
sys.exit()
def getEvents(self):
for event in pygame.event.get():
if event.type == pygame.QUIT: self.exit()
elif event.type == pygame.KEYDOWN:
if event.key == 27: self.exit()
if event.key == 275: self.mario.move('droite')
if event.key == 276: self.mario.move('gauche')
if event.key == 32: self.mario.jump()
def boucle(self):
while 1:
self.getEvents()
# self.bordureVerif()
self.updateScreen()
m = Moteur()