-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (40 loc) · 1.21 KB
/
main.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
import pygame
import math
#initialize pygame
pygame.init()
# create the screen
screen = pygame.display.set_mode((800, 600))
# caption and icon
pygame.display.set_caption("ACAS-Xu")
icon = pygame.image.load('spaceship.png')
pygame.display.set_icon(icon)
defenderIcon = pygame.image.load('spaceship.png')
attackerIcon = pygame.image.load('spaceship.png')
defenderX = 370
defenderY = 280
attackerX = 430
attackerY = 310
defenderVX = 0
defenderVY = 0.1
attackerVX = 0.1
attackerVY = 0.1
# bearing angle from north
def defender(bearing, x, y):
icon = pygame.transform.rotate(defenderIcon, -90 + bearing)
screen.blit(icon, (x, y))
def attacker(bearing, x, y):
icon = pygame.transform.rotate(attackerIcon, -90 + bearing)
screen.blit(icon, (x, y))
running = True
while running:
screen.fill((255, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
defenderX += defenderVX
defenderY += defenderVY
defender(math.degrees(math.atan2(-defenderVY, defenderVX)), defenderX, defenderY)
attackerX += attackerVX
attackerY += attackerVY
attacker(math.degrees(math.atan2(-attackerVY, attackerVX)), attackerX, attackerY)
pygame.display.update()