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
|
#!/usr/bin/env python
import pygame
from sys import exit
from pygame.locals import *
from gameobjects.vector2 import Vector2
pygame.init()
marcheDGJG = pygame.image.load('marcheDGJG.png')
marcheDGJD = pygame.image.load('marcheDGJD.png')
marcheDDJG = pygame.image.load('marcheDDJG.png')
marcheDDJD = pygame.image.load('marcheDDJD.png')
marche=[marcheDGJG,marcheDGJD,marcheDDJG,marcheDDJD]
background_image_filename = 'fond.jpg'
screen = pygame.display.set_mode((640, 640), 0, 32)
pygame.display.set_caption("Combat!!")
background=pygame.image.load(background_image_filename).convert()
class combattant(pygame.sprite.Sprite):
def __init__(self,img,posit):
pygame.sprite.Sprite.__init__(self)
self.image=marche[0]
self.image_pos=posit
self.face=0
def move(self,direction):
if direction[K_LEFT]:
self.face=(self.face+1)%2
self.image_pos.x -= 1
self.image=marche[0+self.face]
print "gauche"
if direction[K_RIGHT]:
print "droit"
self.face=(self.face+1)%2
self.image_pos.x += 1
self.image=marche[2+self.face]
compte=0
julien = combattant(marcheDGJG,Vector2(350,350))
while True:
screen.blit(background,(0,0))
screen.blit(julien.image,julien.image_pos)
temps=pygame.time.get_ticks()
for event in pygame.event.get():
if event.type == QUIT:
exit()
tkey=pygame.key.get_pressed()
julien.move(tkey)
pygame.display.update() |
Partager