Bonjour
J'ai fais un petit jeu avec pygame
j'ai fais deux class,un cible qui te suis et un petit demon qui va tres vite sur toi mais qui tourne pas tres vite,le probleme est que j'ai voulu faire 3 cibles mais elles ne s'affichent pas alors qu'une,ça marche
apparament c'est juste fenetre.blit(self.img,self.p_cible) qui ne marche pas
mais les cibles sont pourtant là car elles peuvent te toucher
voici mon code
Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import pygame
from pygame.locals import *
from math import*
pygame.init()
r=2*pi
class fleche():
    def __init__(self,x,y):
        self.img=pygame.image.load("c.png").convert_alpha()
        self.p_fleche=self.img.get_rect()
        self.vo=pi
        self.vr=5
        self.px=x
        self.py=y
        self.p_fleche=self.p_fleche.move(x,y)
    def disp_fleche(self):
        fenetre.blit(self.img,self.p_fleche)
    def update_vec(self,point):
        an=atan2(point[0]-self.p_fleche[0],point[1]-self.p_fleche[1])
        if ((self.vo+0.5*pi-an)%r)<pi:
            self.vo-=0.04
        else:
            self.vo+=0.04
        self.px+=self.vr*cos(self.vo)
        self.py-=self.vr*sin(self.vo)
        self.p_fleche[0]=int(self.px)
        self.p_fleche[1]=int(self.py)
    def collision(self,point):
        return (self.p_fleche[0]-point[0])**2+(self.p_fleche[1]-point[1])**2<400
class cible():
    def __init__(self,x,y):
        self.img=pygame.image.load("b.gif").convert_alpha()
        self.p_cible=self.img.get_rect()
        self.vx=0.0
        self.vy=0.0
        self.px=x
        self.py=y
        self.p_cible=self.p_cible.move(x,y)
    def disp_cible(self):
        fenetre.blit(self.img,self.p_cible)
    def update_vec(self,point):
        an=atan2(self.p_cible[0]-point[0],self.p_cible[1]-point[1])
        self.vx=-2*sin(an)
        self.vy=-2*cos(an)
        self.px+=self.vx
        self.py+=self.vy
        self.p_cible[0]=int(self.px)
        self.p_cible[1]=int(self.py)
    def collision(self,point):
        return (self.p_cible[0]-point[0])**2+(self.p_cible[1]-point[1])**2<400
fenetre = pygame.display.set_mode((640, 480))
perso =pygame.image.load("a.png").convert_alpha()
fond =pygame.image.load("d.png").convert_alpha()
lci=[]
for i in range(3):
    lci.append(cible(40+i*20,40))
fleche1=fleche(300,40)
pos_fond=fond.get_rect()
position_perso = perso.get_rect()
fenetre.blit(perso, position_perso)
pygame.display.flip()
pygame.key.set_repeat(10,10)
continuer = True
position_perso = position_perso.move(0,460)
vy=0
key=[False]*323
while continuer:
    pygame.time.Clock().tick(100)
    for event in pygame.event.get():
        if event.type == QUIT:
            continuer = False
        if event.type == KEYDOWN:
            key[event.key]=True
        if event.type == KEYUP:
            key[event.key]=False
    if key[K_UP]:
        vy=-5
    if key[K_RIGHT]:
        position_perso = position_perso.move(3,0)
    if key[K_LEFT]:
        position_perso = position_perso.move(-3,0)
    position_perso = position_perso.move(0,vy)
    if position_perso[0]<=0:
        position_perso[0]=0
    if position_perso[0]>=620:
        position_perso[0]=620
    if position_perso[1]<=0:
        position_perso[1]=1
        vy=0
    if position_perso[1]>460:
        position_perso[1]=460
        vy=0
    vy+=0.3
    for ci in lci:
        ci.update_vec(position_perso)
        ci.disp_cible()
        if ci.collision(position_perso):
            continuer=0
    if fleche1.collision(position_perso):
        continuer=0
    fenetre.blit(fond, pos_fond)
    fleche1.update_vec(position_perso)
    fleche1.disp_fleche()
    fenetre.blit(perso, position_perso)
    pygame.display.flip()
pygame.quit()