-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAula2_5.py
65 lines (56 loc) · 1.67 KB
/
Aula2_5.py
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
import pygame, sys
import numpy as np
from pygame.locals import *
###############################
#VETORES
#NORMALIZACAO
#DIRECAO E MOVIMENTO
###############################
pygame.init()
screen = pygame.display.set_mode((400,300))
fpsClock=pygame.time.Clock()
FPS = 15 #num segundos
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
v_pos=[0,100]
v_direcao=[1,0]
while True: #Main loop--
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
# print(event.key)
# print(chr(event.key))
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
#5-COM TECLAS
if event.key == pygame.K_RIGHT:
v_direcao=[1,0]
if event.key == pygame.K_LEFT:
v_direcao=[-1,0]
if event.key == pygame.K_UP:
v_direcao=[0,-1]
if event.key == pygame.K_DOWN:
v_direcao=[0,1]
screen.fill(BLACK)
#1- SO DIRECAO LINEAR
v_pos=np.add(v_pos,v_direcao)
#2- COM SPEED
speed=4
# norm = magnitude
#Vector unitario
v_normalized = v_direcao/np.linalg.norm(v_direcao)
v_velocity=np.multiply(speed, v_normalized)
v_pos=np.add(v_pos,v_velocity)
#3-COM GRAVIDADE
v_forca_gravitacional=[0,0.5]
v_pos=np.add(v_pos, v_forca_gravitacional)
#4-COM VENTO
forca=-0.75
v_direcao_oposta=np.multiply(forca,v_direcao)
v_pos=np.add(v_pos, v_direcao_oposta)
pygame.draw.circle( screen, WHITE, v_pos, 4)
pygame.display.update()
fpsClock.tick(FPS)