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.

58 lines
2.0 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, opacite = 1):
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
def translater (self,axe, sens, vitesse, avance, nbr):
if axe == "x":
if sens == "gauche":
self.pos_x = self.pos_x - vitesse
if self.pos_x <= -self.long:
self.pos_x = self.pos_x + nbr * self.long + avance
else:
self.pos_x = self.pos_x + vitesse
if self.pos_x <= -self.long:
self.pos_x = self.pos_x + self.long + avance
else:
if sens == "haut":
self.pos_y = self.pos_y - vitesse
if self.pos_x <= -self.long:
self.pos_x = self.pos_x + self.long + avance
else:
self.pos_y = self.pos_y + vitesse
if self.pos_x <= -self.long:
self.pos_x = self.pos_x + self.long + avance
self.fenetre.blit(self.image, (self.pos_x,self.pos_y))
def maj (self):
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, avance):
nbr = len(self.lst)
for image in self.lst:
image.translater("x", "gauche", vitesse, avance, nbr)
def affiche(self):
for image in self.lst:
image.maj()