55
66
77MAIN_TEMPLATE = dedent (
8+ """\
9+ import spritePro as s
10+
11+ import config
12+ from scenes.main_scene import MainScene
13+
14+
15+ def main():
16+ s.get_screen(config.WINDOW_SIZE, "My SpritePro Game")
17+ s.enable_debug(True)
18+ s.set_debug_camera_input(3)
19+ s.debug_log_info("Game started")
20+ s.set_scene(MainScene())
21+
22+ while True:
23+ s.update(config.FPS, fill_color=(20, 20, 30))
24+
25+
26+ if __name__ == "__main__":
27+ main()
28+ """
29+ )
30+
31+ MAIN_SCENE_TEMPLATE = dedent (
832 """\
933 import pygame
1034 import spritePro as s
@@ -18,25 +42,20 @@ class MainScene(s.Scene):
1842 def on_enter(self, context):
1943 self.player = s.Sprite(f"{IMAGES_DIR}/player.png", (64, 64), (400, 300), speed=5)
2044
45+ def on_exit(self):
46+ pass
47+
2148 def update(self, dt):
2249 self.player.handle_keyboard_input()
2350 if s.input.was_pressed(pygame.K_SPACE):
2451 s.debug_log_info("Space pressed")
52+ """
53+ )
2554
26-
27- def main():
28- s.get_screen((800, 600), "My SpritePro Game")
29- s.enable_debug(True)
30- s.set_debug_camera_input(3)
31- s.debug_log_info("Game started")
32- s.set_scene(MainScene())
33-
34- while True:
35- s.update(fill_color=(20, 20, 30))
36-
37-
38- if __name__ == "__main__":
39- main()
55+ CONFIG_TEMPLATE = dedent (
56+ """\
57+ WINDOW_SIZE = (800, 600)
58+ FPS = 60
4059 """
4160)
4261
@@ -49,16 +68,26 @@ def _project_root_from_target(target: Path) -> tuple[Path, Path]:
4968
5069def create_project (target : Path ) -> Path :
5170 project_root , main_file = _project_root_from_target (target )
71+ config_file = project_root / "config.py"
72+ scenes_root = project_root / "scenes"
73+ scenes_init = scenes_root / "__init__.py"
74+ main_scene_file = scenes_root / "main_scene.py"
5275
5376 project_root .mkdir (parents = True , exist_ok = True )
5477 assets_root = project_root / "assets"
5578 assets_root .mkdir (exist_ok = True )
5679 (assets_root / "audio" ).mkdir (exist_ok = True )
5780 (assets_root / "images" ).mkdir (exist_ok = True )
58- ( project_root / "scenes" ) .mkdir (exist_ok = True )
81+ scenes_root .mkdir (exist_ok = True )
5982
6083 if not main_file .exists ():
6184 main_file .write_text (MAIN_TEMPLATE , encoding = "utf-8" )
85+ if not config_file .exists ():
86+ config_file .write_text (CONFIG_TEMPLATE , encoding = "utf-8" )
87+ if not scenes_init .exists ():
88+ scenes_init .write_text ("" , encoding = "utf-8" )
89+ if not main_scene_file .exists ():
90+ main_scene_file .write_text (MAIN_SCENE_TEMPLATE , encoding = "utf-8" )
6291
6392 return project_root
6493
0 commit comments