forked from JeLLyNinjas/TerminalFighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
targeting_terminal.py
86 lines (69 loc) · 2.44 KB
/
targeting_terminal.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
82
83
84
85
86
import pygame
pygame.font.init()
# CONSTANTS
BLACK = 0, 0, 0
BLUE = 0, 0, 255
RED = 255, 0, 0
WHITE = 255, 255, 255
EVENT_KEY_a = 97
EVENT_KEY_BACKSPACE = 8
EVENT_KEY_ENTER = 13
EVENT_KEY_z = 122
class TargetingTerminal():
def __init__(self, ):
# Initalization Constants
self.current_text_ = ""
self.terminal_rect_ = None
self.error_timer_ = 0
self.error_duration_ = 5
# Terminal Visual Constants
self.terminal_border_width_ = 1
self.terminal_rect_x_ = 10
self.terminal_rect_y_ = 40
self.terminal_size_height_ = 25
self.terminal_size_width_ = 395
self.terminal_color_ = BLUE
self.error_color_ = RED
# Terminal Text Input Constants
self.font_size_ = 20
self.text_alias_ = 1
self.text_input_max_size_ = self.terminal_size_width_ - 20
self.text_input_x_ = 15
self.text_input_y_ = 37
self.ui_font_ = pygame.font.SysFont("monospace", self.font_size_)
self.max_word_size_ = self.text_input_max_size_ / self.ui_font_.size("W")[0]
"""
Access functions
"""
def notify_misfire(self):
self.error_timer_ = self.error_duration_
"""
Update functions
"""
def update(self, current_text):
self.current_text_ = current_text
if self.error_timer_ > 0:
self.error_timer_ -= 1
"""
Draw functions
"""
def draw_terminal(self, screen):
if not self.terminal_rect_:
self.terminal_rect_ = pygame.Rect(self.terminal_rect_x_,
screen.get_height()-self.terminal_rect_y_,
self.terminal_size_width_,
self.terminal_size_height_)
if self.error_timer_ > 0:
pygame.draw.rect(screen, self.error_color_, self.terminal_rect_)
else:
pygame.draw.rect(screen, self.terminal_color_, self.terminal_rect_)
pygame.draw.rect(screen,
WHITE,
self.terminal_rect_,
self.terminal_border_width_)
text_label = self.ui_font_.render(self.current_text_,
self.text_alias_,
WHITE)
screen.blit(text_label,
(self.text_input_x_,
screen.get_height()-(self.text_input_y_)))