diff --git a/surface_switching_test/__init__.py b/surface_switching_test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/surface_switching_test/__main__.py b/surface_switching_test/__main__.py new file mode 100644 index 0000000..1d10f9b --- /dev/null +++ b/surface_switching_test/__main__.py @@ -0,0 +1,5 @@ +from surface_switching_test import main + +if __name__ == '__main__': + main.main() + exit() \ No newline at end of file diff --git a/surface_switching_test/main.py b/surface_switching_test/main.py new file mode 100644 index 0000000..ecf89a0 --- /dev/null +++ b/surface_switching_test/main.py @@ -0,0 +1,35 @@ +import pygame +from surface_switching_test.surfaces import sf_1, sf_2, sf_3 + +WINDOW_SIZE = (800, 600) + +VALID_SURFACES = [ + 'sf_1', + 'sf_2', + 'sf_3' +] + + +def main(): + pygame.init() + + window = pygame.display.set_mode(WINDOW_SIZE) + + clock = pygame.time.Clock() + + running = True + surface = globals()['sf_1'].Surface(WINDOW_SIZE) + while running: + clock.tick(15) + surface.update() + 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 listed in valid surfaces!') + surface = globals()[next_surface].Surface(WINDOW_SIZE) + + pygame.display.flip() + + pygame.quit() diff --git a/surface_switching_test/surfaces/__init__.py b/surface_switching_test/surfaces/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/surface_switching_test/surfaces/objects/__init__.py b/surface_switching_test/surfaces/objects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/surface_switching_test/surfaces/objects/text.py b/surface_switching_test/surfaces/objects/text.py new file mode 100644 index 0000000..51a45aa --- /dev/null +++ b/surface_switching_test/surfaces/objects/text.py @@ -0,0 +1,12 @@ +import pygame.font +import os + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class RegularText: + def __init__(self, text): + font = pygame.font.Font(SCRIPT_DIR + '/../resources/Tuffy_Bold.ttf', 32) + self.surface = font.render(text, True, (0, 0, 0)) + self.rect = self.surface.get_rect() + diff --git a/surface_switching_test/surfaces/resources/Tuffy_Bold.ttf b/surface_switching_test/surfaces/resources/Tuffy_Bold.ttf new file mode 100644 index 0000000..33fcc8a Binary files /dev/null and b/surface_switching_test/surfaces/resources/Tuffy_Bold.ttf differ diff --git a/surface_switching_test/surfaces/sf_1.py b/surface_switching_test/surfaces/sf_1.py new file mode 100644 index 0000000..07a4382 --- /dev/null +++ b/surface_switching_test/surfaces/sf_1.py @@ -0,0 +1,21 @@ +import pygame +from surface_switching_test.surfaces.objects import text as surface_text + +class Surface(pygame.Surface): + def __init__(self, window_size): + super().__init__(window_size, pygame.SRCALPHA) + self.test = 0 + self.running = True + self.next_surface = 'sf_2' + self.countdown = 100 + + def update(self): + self.fill((255, 0, 0)) + + text = surface_text.RegularText('Surface stopping and swtiching to {0} in: {1}'.format(self.next_surface, + str(self.countdown))) + self.blit(text.surface, text.rect) + + self.countdown -= 1 + if self.countdown < 0: + self.running = False \ No newline at end of file diff --git a/surface_switching_test/surfaces/sf_2.py b/surface_switching_test/surfaces/sf_2.py new file mode 100644 index 0000000..0e9f27c --- /dev/null +++ b/surface_switching_test/surfaces/sf_2.py @@ -0,0 +1,21 @@ +import pygame +from surface_switching_test.surfaces.objects import text as surface_text + +class Surface(pygame.Surface): + def __init__(self, window_size): + super().__init__(window_size, pygame.SRCALPHA) + self.test = 0 + self.running = True + self.next_surface = 'sf_3' + self.countdown = 100 + + def update(self): + self.fill((0, 255, 0)) + + text = surface_text.RegularText('Surface stopping and swtiching to {0} in: {1}'.format(self.next_surface, + str(self.countdown))) + self.blit(text.surface, text.rect) + + self.countdown -= 1 + if self.countdown < 0: + self.running = False \ No newline at end of file diff --git a/surface_switching_test/surfaces/sf_3.py b/surface_switching_test/surfaces/sf_3.py new file mode 100644 index 0000000..aba7cc9 --- /dev/null +++ b/surface_switching_test/surfaces/sf_3.py @@ -0,0 +1,21 @@ +import pygame +from surface_switching_test.surfaces.objects import text as surface_text + +class Surface(pygame.Surface): + def __init__(self, window_size): + super().__init__(window_size, pygame.SRCALPHA) + self.test = 0 + self.running = True + self.next_surface = 'sf_1' + self.countdown = 100 + + def update(self): + self.fill((0, 0, 255)) + + text = surface_text.RegularText('Surface stopping and swtiching to {0} in: {1}'.format(self.next_surface, + str(self.countdown))) + self.blit(text.surface, text.rect) + + self.countdown -= 1 + if self.countdown < 0: + self.running = False \ No newline at end of file