addded surface switching system, removed all gui objects

This commit is contained in:
Nicholas Dyer 2023-02-19 22:49:49 -05:00
parent d9c4401f43
commit ec3c3b66ed
No known key found for this signature in database
GPG Key ID: E4E6388793FA2105
8 changed files with 61 additions and 101 deletions

View File

@ -1 +1,3 @@
__version__ = '0.0.1' __version__ = '0.0.1'
from . import main

View File

@ -1,6 +1,6 @@
import sys import sys
from thermopi.screen import main as start import thermopi
if __name__ == '__main__': if __name__ == '__main__':
@ -10,4 +10,4 @@ if __name__ == '__main__':
if arg == '--window': if arg == '--window':
windowed_mode = True windowed_mode = True
start(windowed_mode) thermopi.main.main(windowed_mode)

44
thermopi/main.py Normal file
View File

@ -0,0 +1,44 @@
import pygame
import os
import thermopi.surfaces as surfaces
SCREEN_SIZE = (720, 720)
DIAL_SIZE = int(min(SCREEN_SIZE[0], SCREEN_SIZE[1]) * 0.9)
FPS = 60
PI = 3.14159265
VALID_SURFACES = [
'dial'
]
script_dir = os.path.dirname(os.path.abspath(__file__))
def main(windowed_mode):
pygame.init()
clock = pygame.time.Clock()
if windowed_mode:
window = pygame.display.set_mode(SCREEN_SIZE)
else:
window = pygame.display.set_mode(SCREEN_SIZE, pygame.FULLSCREEN)
surface = getattr(globals()['surfaces'], 'dial').Surface(SCREEN_SIZE)
running = True
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
window.blit(surface, surface.get_rect())
if not surface.running:
next_surface = surface.next_surface
if next_surface not in VALID_SURFACES:
raise Exception('Given surface is not a valid surface!')
surface = getattr(globals()['surfaces'], next_surface).Surface(SCREEN_SIZE)
pygame.quit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 752 B

View File

@ -1,98 +0,0 @@
import math
import pygame
import os
DIAL_SIZE = 500
SCREEN_SIZE = 720
FPS = 60
PI = 3.14159265
script_dir = os.path.dirname(os.path.abspath(__file__))
class Dial(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self._base_image = pygame.image.load(script_dir + '/resources/dial-face.png')
self.position = 0
self.rotation = 77 - (2 * 77.5 * self.position)
self.image = pygame.transform.rotate(self._base_image, self.rotation)
self.rect = self._base_image.get_rect()
self.test_cw = True
self.test = True
def update(self):
self.rotation = 77 - (2 * 77.5 * self.position)
self.image = pygame.transform.rotate(self._base_image, self.rotation)
self.rect = self.image.get_rect(center=self.rect.center)
self.rect.center = (math.sin(math.radians(self.rotation)) * -300 + 360,
math.cos(math.radians(self.rotation + 180)) * 300 + 360)
def move_dial(self, movement_ammount):
self.position += movement_ammount
if self.position > 1:
self.position = 1
if self.position < 0:
self.position = 0
def main(windowed_mode):
pygame.init()
clock = pygame.time.Clock()
if windowed_mode:
window = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE))
else:
window = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE), pygame.FULLSCREEN)
bg_image = pygame.image.load(script_dir + '/resources/dial-bg.png')
dial = Dial()
all_sprites = pygame.sprite.Group(dial)
def draw():
# Draws all the sprites on a black background
all_sprites.update()
window.blit(bg_image, (0, 0))
all_sprites.draw(window)
# Update the entire display
pygame.display.flip()
running = True
prev_mouse_pos = (0, 0)
mouse_pos = (0, 0)
get_mouse_speed = False
pygame.mouse.set_visible(False)
while running:
clock.tick(FPS)
prev_mouse_pos = mouse_pos
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
get_mouse_speed = True
mouse_pos = pygame.mouse.get_pos()
prev_mouse_pos = mouse_pos
if event.type == pygame.MOUSEBUTTONUP:
get_mouse_speed = False
draw()
if get_mouse_speed:
mouse_diff = (prev_mouse_pos[0] - mouse_pos[0], prev_mouse_pos[1] - mouse_pos[1])
movement_speed = math.sqrt((mouse_diff[0] ** 2) + (mouse_diff[1] ** 2))
mouse_angle = math.atan2(mouse_pos[0] - 360, mouse_pos[1] - 360)
diff_angle = math.atan2(mouse_diff[0], mouse_diff[1])
speed_coeff = math.cos((mouse_angle - (0.5 * PI)) - diff_angle)
final_speed = movement_speed * speed_coeff
dial.move_dial(final_speed / -3000.0)
pygame.quit()

View File

@ -0,0 +1 @@
from . import dial

11
thermopi/surfaces/dial.py Normal file
View File

@ -0,0 +1,11 @@
import pygame
class Surface(pygame.Surface):
def __init__(self, window_size):
super().__init__(window_size, pygame.SRCALPHA)
self.running = True
self.next_surface = ''
def update(self):
self.fill((0, 0, 0))