cars and run 2d
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

import pygame
from pygame.locals import *
from random import randint
class Image():
def __init__ (self, fenetre, chm_acces, pos_x, pos_y, long, larg):
self.fenetre = fenetre
self.chm_acces = chm_acces
self.pos_x = pos_x
self.pos_y = pos_y
self.image = pygame.image.load(self.chm_acces).convert_alpha()
self.long = long
self.larg = larg
self.maj(3)
def translater (self,axe, sens, vitesse):
if axe == "x":
if sens == "gauche":
self.pos_x = self.pos_x - vitesse
else:
self.pos_x = self.pos_x + vitesse
else:
if sens == "haut":
self.pos_y = self.pos_y - vitesse
else:
self.pos_y = self.pos_y + vitesse
self.maj(3)
def maj(self, nbr):
if self.pos_x <= -self.long :
self.pos_x = self.pos_x + self.long * nbr
self.fenetre.blit(self.image, (self.pos_x,self.pos_y))
class GroupeImage():
def __init__ (self, fenetre):
self.fenetre = fenetre
self.lst = []
def creer_Image(self, chm_acces, pos_x, pos_y, long, larg):
self.lst.append(Image(self.fenetre, chm_acces, pos_x, pos_y, long, larg))
def avancer(self, vitesse):
for image in self.lst:
image.translater("x", "gauche", vitesse)
def affiche(self):
for image in self.lst:
image.maj(len(self.lst))