-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
81 lines (65 loc) · 2.3 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 25 15:03:15 2021
Press F1 to start animation
Press F2 to stop animation
Press ENTER to open
Supports the following commands:
/folder x read in folder for animation frames
/fps x set speed of animation
/position x x set animation position
/alpha x x x set the specified colour to transparent
/repeat [on|off] set animation repeat on or off
@author: richa
"""
# pylint: disable=no-member
import init
import pygame
FPS = 12
def set_fps(value):
"""Sets the global fps value. Event callback for SET_FPS"""
global FPS # pylint: disable=global-statement
FPS = value
def render(screen, entities):
"""Renders the entities on the screen"""
screen.fill((255, 255, 255))
for entity in entities:
entity.render(screen)
pygame.display.flip()
def main():
"""Main function"""
pygame.init()
screen = pygame.display.set_mode((600, 400))
clock = pygame.time.Clock()
animation, event_queue, console = init.init()
event_queue.subscribe("SET_FPS", set_fps)
terminated = False
while not terminated:
for event in pygame.event.get():
if event.type == pygame.QUIT:
terminated = True
elif event.type == pygame.KEYUP and event.key == pygame.K_RETURN:
console.toggle_activate()
if not console.active:
console.execute()
elif event.type == pygame.TEXTINPUT and console.active:
console.add_text(event.text)
elif (
event.type == pygame.KEYUP
and event.key == pygame.K_BACKSPACE
and console.active
):
console.remove_last_char()
elif event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
console.errored = False
elif event.type == pygame.KEYUP and event.key == pygame.K_F1:
animation.active = True
animation.counter = 0
elif event.type == pygame.KEYUP and event.key == pygame.K_F2:
animation.active = False
event_queue.update()
render(screen, entities=[animation, console])
clock.tick(FPS)
pygame.display.quit()
if __name__ == "__main__":
main()