2020-11-13 07:46:31 -07:00
|
|
|
import pygame
|
2020-11-14 11:12:00 -07:00
|
|
|
from .demos import aabb, vec_proj, sat
|
2020-11-14 10:15:47 -07:00
|
|
|
from . import HEIGHT
|
2020-11-13 07:46:31 -07:00
|
|
|
from .colors import *
|
2020-11-14 10:15:47 -07:00
|
|
|
from .draw import text_screen
|
2020-11-13 07:46:31 -07:00
|
|
|
|
|
|
|
class Screen:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.demos = [
|
|
|
|
vec_proj.VecProj(),
|
|
|
|
aabb.AABBDistance(),
|
|
|
|
aabb.PointAABBDistance(),
|
2020-11-14 11:12:00 -07:00
|
|
|
sat.SeparatingAxisTheorem(),
|
2020-11-13 07:46:31 -07:00
|
|
|
]
|
|
|
|
self.demo = 0
|
|
|
|
|
|
|
|
def handle_input(self):
|
|
|
|
for event in pygame.event.get(pygame.KEYDOWN):
|
2020-11-15 01:48:07 -07:00
|
|
|
self.demos[self.demo].handle_key_down(event.key)
|
|
|
|
|
2020-11-13 07:46:31 -07:00
|
|
|
if event.key == pygame.K_DOWN:
|
|
|
|
self.demo += 1
|
|
|
|
if self.demo >= len(self.demos):
|
|
|
|
self.demo = 0
|
|
|
|
elif event.key == pygame.K_UP:
|
|
|
|
self.demo -= 1
|
|
|
|
if self.demo < 0:
|
|
|
|
self.demo = len(self.demos) - 1
|
|
|
|
|
|
|
|
def draw_demo_list(self, surface):
|
|
|
|
y_offset = 10
|
|
|
|
for i in range(len(self.demos)):
|
2020-11-14 10:15:47 -07:00
|
|
|
text_screen(surface,
|
2020-11-13 07:46:31 -07:00
|
|
|
CYAN if self.demo == i else WHITE,
|
2020-11-14 10:15:47 -07:00
|
|
|
(10, y_offset + i * 20),
|
2020-11-13 07:46:31 -07:00
|
|
|
self.demos[i].title)
|
|
|
|
|
|
|
|
def render(self, surface):
|
|
|
|
self.handle_input()
|
|
|
|
|
|
|
|
self.demos[self.demo].render(surface)
|
|
|
|
|
|
|
|
self.draw_demo_list(surface)
|