My Pygame Game Engine
1from src.scripts.modules.renderer import Screen
2from src.scripts.modules.gui import *
3import os
4
5class engine_main_screen(Screen):
6 def __init__(self, game):
7 self.game = game
8
9 self.right_panel = gui_rect(game)
10 self.right_panel.set_pos(percentage_constraint(0.78), pixel_constraint(25), 1)
11 self.right_panel.set_size(percentage_constraint(0.22), percentage_constraint(1), 1)
12 self.right_panel.set_color(self.game.color_handler.get_rgb('engine.background'), 2)
13
14 self.left_panel = gui_rect(game)
15 self.left_panel.set_pos(percentage_constraint(0), pixel_constraint(25), 1)
16 self.left_panel.set_size(percentage_constraint(0.22), percentage_constraint(1), 1)
17 self.left_panel.set_color(self.game.color_handler.get_rgb('engine.background'), 2)
18
19 self.top_panel = gui_rect(game)
20 self.top_panel.set_pos(pixel_constraint(0), pixel_constraint(0), 1)
21 self.top_panel.set_size(percentage_constraint(1), pixel_constraint(25), 1)
22 self.top_panel.set_color(self.game.color_handler.get_rgb('engine.background_alt'), 2)
23
24 self.bottom_panel = gui_rect(game)
25 self.bottom_panel.set_pos(percentage_constraint(0.22), percentage_constraint(0.595), 1)
26 self.bottom_panel.set_size(percentage_constraint(0.56), percentage_constraint(0.4375), 1)
27 self.bottom_panel.set_color(self.game.color_handler.get_rgb('engine.background_alt'), 2)
28
29 self.screen_panel = gui_rect(game)
30 self.screen_panel.set_pos(percentage_constraint(0.22), pixel_constraint(26), 2)
31 self.screen_panel.set_size(aspect_constraint(1.7777), percentage_constraint(0.56), 2)
32 self.screen_panel.set_color((255, 0, 0), 2)
33
34 self.add_asset_button = gui_toggle_button(game)
35 self.add_asset_button.rect.parent = self.bottom_panel
36 self.add_asset_button.rect.set_pos(pixel_constraint(5), pixel_constraint(5), 2)
37 self.add_asset_button.rect.set_size(pixel_constraint(30), pixel_constraint(30), 5)
38 self.add_asset_button.rect.visible = False
39 self.add_asset_button.input_state = "general"
40
41 self.add_asset_button_1 = gui_rect(game)
42 self.add_asset_button_1.parent = self.add_asset_button.rect
43 self.add_asset_button_1.set_pos(center_constraint(), center_constraint(), 2)
44 self.add_asset_button_1.set_size(percentage_constraint(1), percentage_constraint(0.2), 2)
45 self.add_asset_button_1.set_border_radius(10)
46 self.add_asset_button_1.set_color((200, 200, 200), 1)
47
48 self.add_asset_button_2 = gui_rect(game)
49 self.add_asset_button_2.parent = self.add_asset_button.rect
50 self.add_asset_button_2.set_pos(center_constraint(), center_constraint(), 2)
51 self.add_asset_button_2.set_size(percentage_constraint(0.2), percentage_constraint(1), 2)
52 self.add_asset_button_2.set_border_radius(10)
53 self.add_asset_button_2.set_color((200, 200, 200), 1)
54
55 self.add_asset = gui_rect(game)
56 self.add_asset.set_pos(percentage_constraint(0.3), percentage_constraint(1), 1)
57 self.add_asset.set_size(percentage_constraint(0.2), percentage_constraint(0.6), 1)
58 self.add_asset.set_color(self.game.color_handler.get_rgb('engine.background'), 1)
59 self.add_asset.set_border_radius(10)
60
61 def update(self):
62 self.add_asset.set_pos(percentage_constraint(0.3), (percentage_constraint(1)), 6)
63 self.add_asset_button_1.set_color((200, 200, 200), 12)
64 self.add_asset_button_2.set_color((200, 200, 200), 12)
65 if self.add_asset_button.hover:
66 self.add_asset_button_1.set_color((100, 100, 100), 6)
67 self.add_asset_button_2.set_color((100, 100, 100), 6)
68
69 if self.add_asset_button.toggled:
70 self.add_asset_button_1.set_color((100, 100, 100), 6)
71 self.add_asset_button_2.set_color((100, 100, 100), 6)
72 self.add_asset.set_pos(percentage_constraint(0.3), (percentage_constraint(0.5)), 6)
73 self.game.input.set_input_state("asset_pack_change")
74 if not self.add_asset.is_touching_mouse() and self.game.input.is_mouse_button_just_pressed():
75 self.add_asset_button.toggled = False
76 self.game.input.set_input_state("general")
77
78 self.right_panel.update()
79 self.left_panel.update()
80 self.top_panel.update()
81 self.bottom_panel.update()
82 self.screen_panel.update()
83 self.add_asset_button.update()
84 self.add_asset_button_1.update()
85 self.add_asset_button_2.update()
86 self.add_asset.update()
87
88 def render(self):
89 self.game.renderer.main_surface.fill((0, 0, 0))
90 self.right_panel.render()
91 self.left_panel.render()
92 self.top_panel.render()
93 self.bottom_panel.render()
94 self.screen_panel.render()
95 self.add_asset_button.render()
96 self.add_asset_button_1.render()
97 self.add_asset_button_2.render()
98 self.add_asset.render()