Hola a todos este es mi primer correo en la lista acabo de
registrarme, soy novato en python la cosa es que estoy jugando con un
programita que contiene modulos de pygame de un tiro parabolico lo que
no se como hacer es para que la variable t que calcula el tiempo el
cual estuvo en el aire el proyectil no imprima el valor en 0 sino el
ultimo valor que tubo antes de tocar tierra...
#!/usr/bin/env psython
#coding: UTF-8
 
def printos(superficie, text, x, y, color, font):
    text_in_lines = text.split('\n')
    for line in text_in_lines:
        new = font.render(line, 1, color)
        superficie.blit(new, (x, y))
        y += new.get_height()
 
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))))
 
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))
    
 
import pygame, math
pygame.init() 
 
size = width, height = 1280, 700 
 
black = (0, 0, 0)
blue = (0, 0, 255)
green = (0, 255, 0)
background = (200, 200, 101)
 
screen = pygame.display.set_mode(size) 
pygame.display.set_caption("Tiro Parabolico") 
 
 
radio = 10
x = 10
y = height - radio
 
pygame.font.init() 
font = pygame.font.Font(None, 30) 
 
clock = pygame.time.Clock()
 
t = 0.0
dt = 0.5
 
v0 = 40.0
a = 1.0
ang = 30.0
 
vx = 40
vy = 0
 
lock = True
lock1 = False
second = False
while 1: 
    screen.fill(background)
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT:
            exit()
    teclado = pygame.key.get_pressed()
    if(tuple(set(teclado)) == (0,1) and lock):
        if (teclado[pygame.K_UP]):
            ang += 1
            if(ang >= 90):
                ang = 90
        if (teclado[pygame.K_DOWN]): 
            ang -= 1
            if(ang < 0):
                ang = 0
        if (teclado[pygame.K_RIGHT] and v0 < 100): 
            v0 += 1
        if (teclado[pygame.K_LEFT] and v0 > 1):
            v0 -= 1
        if (teclado[pygame.K_SPACE]):
            lock = False
            lock1 = True
            vy0 = v0*math.sin(math.radians(ang))
    if (teclado[pygame.K_ESCAPE]): 
        break
    vx0 = v0*math.cos(math.radians(ang))
    vy = a*t - v0*math.sin(math.radians(ang))
    if(lock1):
        y = (height - radio) - vy0*t + .5*a*(t**2)
        x = radio + vx0*t
        t += dt
        if(y > (height - radio)):
            y = height - radio
            t = 0
            lock1 = False
            second = True
    if(second):
        printos(screen, "Continuar? S/N", 0, 60, green, font)
        if(teclado[pygame.K_s]):
            lock = True
            second = False
            x = radio
        elif(teclado[pygame.K_n]):
            break
 
    printos(screen, "x = %d y = %d ang = %d v0 = %d vx = %d vy = %d t = %d "%(x - radio, height - radio - y, ang, v0, vx0, vy, t), 0, 0, green, font)
    pygame.draw.circle(screen, blue, (int(x), int(y)), radio) 
    vector(screen, blue, x, y, ang)
    pygame.display.flip()
    clock.tick(30)
_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Responder a