Python - PYGAME movimiento y disparo de figuras

 
Vista:
sin imagen de perfil

PYGAME movimiento y disparo de figuras

Publicado por Ana (1 intervención) el 18/02/2022 17:23:41
lo que quiero es que el cuadrado se mueva y que el circulo pueda disparar hacia el cuadrado pulsando una tecla y usando "w"y "s" se pueda usar un angulo para el disparo, este es mi codigo hasta ahora, hasta aca se murio mi cerebro xd


import sys, os
import pygame
from math import*
import random
def vector(screen, color, x, y, ang):
w, z = x + v0*10*math.cos(math.radians(ang)), y - v0*10*math.sin(math.radians(ang))
x, y, w, z = int(x), int(y), int(w), int(z)
arrow(screen, color, w, z, ang)
pygame.draw.line(screen, blue, (x, y), (w, z))
def arrow(screen, color, x, y, ang):
pygame.draw.line(screen, color, (x, y), (x + 20*math.cos(math.radians(ang + 150.0)), y - 20*math.sin(math.radians(ang + 150.0))))
pygame.draw.line(screen, color, (x, y), (x + 20*math.cos(math.radians(ang + 210.0)), y - 20*math.sin(math.radians(ang + 210.0))))
#MOVIMIENTO DE PELOTA CON FONDO
#constantes
V_ANCHO = 800
V_ALTO = 800
V_TAM = (V_ANCHO,V_ALTO)

FPS = 60
clock = pygame.time.Clock()

###colores
cBlanco = (255,255,255)
cVerde = (0,255,0)
cNegro = (0,0,0)
cRojo = (255,0,0)
cAzul = (0,0,255)
#inicializacion
pygame.init()

pygame.display.set_caption("movimiento vertical")
screen = pygame.display.set_mode(V_TAM,0,32)
screen.fill(cBlanco)

#fuente1 = pygame.font.Font(None,46)
#texto1 = fuente1.render("madara uchija", 0, cRojo)

def main():
#movimiento
cx,cy = 25,580
t = 0
dt = 0.05
px = 0
vx = 10

coordClic = (cx,cy)

while True:

screen.fill(cBlanco)

for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()


if event.type == pygame.MOUSEBUTTONDOWN:
coordClic = event.pos



pygame.draw.line(screen,cVerde,(0,600),(800,600))
pygame.draw.circle(screen,cRojo,(cx+px,cy),20,2)
pygame.draw.rect(screen, cVerde, (600,100,100,40),2)


if (coordClic[1]<600 and coordClic != (cx,cy)):
pygame.draw.line(screen,cAzul,(cx+px,cy ),coordClic)

# screen.blit(texto1, coord)
px = vx*t
t = t+dt


pygame.display.update()
clock.tick(FPS)

if __name__=="__main__":
main()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder