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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| pygame.init()
screen=pygame.display.set_mode((640,480))
clock=pygame.time.Clock()
done=1
J1_x=50
J1_y=50
J2_x=500
J2_y=50
J1_e=1
J2_e=1
j=0
d=0
fond=pygame.image.load("bg.png").convert()
screen.blit(fond,(0,0))
J1=pygame.image.load("J1.png").convert_alpha()
position_J1=(J1_x,J1_y)
screen.blit(J1,position_J1)
J2=pygame.image.load("J2.png").convert_alpha()
position_J2=(J2_x,J2_y)
screen.blit(J2,position_J2)
while done :
for event in pygame.event.get():
if event.type == pygame.QUIT:
continuer = 0
if event.type==pygame.KEYDOWN and event.key==pygame.K_RETURN :
j=1
pressed=pygame.key.get_pressed()
if pressed[pygame.K_DOWN] :
if J1_y<420 :
J1_y+=3
position_J1=(J1_x,J1_y)
if pressed[pygame.K_UP] :
if J1_y>0 :
J1_y-=3
position_J1=(J1_x,J1_y)
if pressed[pygame.K_l] :
if J2_y<420 :
J2_y+=3
position_J2=(J2_x,J2_y)
if pressed[pygame.K_o] :
if J2_y>0 :
J2_y-=3
position_J2=(J2_x,J2_y)
screen.blit(fond,(0,0))
if J1_e :
screen.blit(J1,position_J1)
if J2_e :
screen.blit(J2,position_J2)
if j :
TirJ1=pygame.image.load("T1.png").convert_alpha()
TJ1_rect=TirJ1.get_rect()
TJ1_x=J1_x+50
TJ1_y=J1_y+25
position_TJ1=(TJ1_x,TJ1_y)
screen.blit(TirJ1,position_TJ1)
d=1
j=0
if d :
TJ1_x+=15
position_TJ1=(TJ1_x,TJ1_y)
screen.blit(TirJ1,position_TJ1)
J2_position=J2.get_rect()
J2_position=pygame.Rect((J2_x,J2_y),(64,62))
if TJ1_rect.colliderect(J2_position) :
J2_e=0
if TJ1_x>640 :
d=0
clock.tick(60)
pygame.display.flip() |
Partager