3 pièce(s) jointe(s)
[Pygame]probleme avec move
Bonjour
J’essaie de faire un petit jeu avec pygame.
tu dirige un petit monstre qui vole et un cible te suis.
Mais le move de la cible ne fonctionne que d'un pixel seulement quand le monstre arrive a son niveau:?
Code:
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
| import pygame
from pygame.locals import *
from math import*
pygame.init()
class cible():
def __init__(self):
self.img=pygame.image.load("cible.png").convert_alpha()
self.p_cible=self.img.get_rect()
self.vx=0.0
self.vy=0.0
self.p_cible=self.p_cible.move(40,40)
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=cos(an)
self.vy=sin(an)
self.p_cible=self.p_cible.move(self.vx,self.vy)
fenetre = pygame.display.set_mode((640, 480))
perso =pygame.image.load("monstre.png").convert_alpha()
fond =pygame.image.load("fond.png").convert_alpha()
cible1=cible()
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
cible1.update_vec(position_perso)
fenetre.blit(fond, pos_fond)
cible1.disp_cible()
fenetre.blit(perso, position_perso)
pygame.display.flip()
pygame.quit() |
voici les images utilisées:
Pièce jointe 203435
Pièce jointe 203436
Pièce jointe 203437
PS:pourquoi n'y a-t-il pas de sous forum pygame?C'est pourtant assez connu.