elif pressed_key == Keycode.num_1: self.obj.transitions_manager.set( 'color', self._randomize_color_transition() ) elif pressed_key == Keycode.num_2: self.obj.transitions_manager.set( 'pseudo_timer', NodeTransitionsSequence([ NodeTransitionDelay(1.), NodeTransitionCallback( lambda node: node.transitions_manager.set( 'color', self._randomize_color_transition(), ) ) ]) ) elif pressed_key == Keycode.num_0: self.obj.transitions_manager.set( 'color', None ) self.obj.transitions_manager.set( 'pseudo_timer', None ) if __name__ == '__main__': with Engine(virtual_resolution=Vector(300, 300)) as engine: engine.window.size = Vector(800, 600) engine.window.center() engine.run(DemoTransitionsScene())
class SecondScene(Scene): def __init__(self): self.camera.position = Vector(0., 0.) box_image = Sprite(BOX_IMAGE_PATH) self.root.add_child( Node(sprite=box_image, shape=Polygon.from_box(Vector(10, 10)))) def on_enter(self): print(f'{self.__class__.__name__} on_enter') self.engine.renderer.clear_color = Color(0.5, 0.25, 0.75, 1) def update(self, dt): for event in self.input.events(): if event.is_quit(): self.engine.quit() elif event.is_pressing(Keycode.q): self.engine.quit() elif event.is_pressing(Keycode.c): self.engine.change_scene(SCENES['main']) def on_exit(self): print(f'{self.__class__.__name__} on_exit') if __name__ == '__main__': with Engine(virtual_resolution=Vector(10, 10)) as engine: main_scene = MainScene() SCENES = {'main': main_scene, 'second': SecondScene()} engine.run(main_scene)
elif event.is_pressing(Keycode.kp_3): self.text_node.origin_alignment = Alignment.bottom_right elif event.is_pressing(Keycode.w): self.camera.position += Vector(0., -0.3) elif event.is_pressing(Keycode.s): self.camera.position += Vector(0., 0.3) elif event.is_pressing(Keycode.a): self.camera.position += Vector(-0.3, 0.) elif event.is_pressing(Keycode.d): self.camera.position += Vector(0.3, 0.) elif event.is_pressing(Keycode.i): self.camera.scale += Vector(0.05, 0.05) elif event.is_pressing(Keycode.o): self.camera.scale += Vector(-0.05, -0.05) elif event.is_pressing(Keycode.r): self.camera.rotation_degrees += 5. elif event.is_pressing(Keycode.f): self.camera.position = self.text_node.position print("Mouse position: {}".format(self.input.get_mouse_position())) if __name__ == '__main__': engine = Engine(virtual_resolution=Vector(10, 10)) engine.window.show() engine.run(FontDemoScene()) print(" * Deleting engine") del engine print(" * Ending script")
print("Master sound volume: {}".format( self.engine.audio.master_sound_volume)) elif event.keyboard_key.key == Keycode.x: self.music.play() print("Playing music") elif event.keyboard_key.key == Keycode.c: ret = self.music.pause() print("Pausing music, success: {}".format(ret)) elif event.keyboard_key.key == Keycode.v: ret = self.music.resume() print("Resuming music, success: {}".format(ret)) elif event.keyboard_key.key == Keycode.b: ret = self.music.stop() print("Stopping music, success: {}".format(ret)) elif event.music_finished: print("Music finished!") if __name__ == '__main__': with Engine(virtual_resolution=Vector(5, 5)) as engine: set_core_logging_level("engine", CoreLogLevel.debug) scene = DemoScene( sound_path=len(sys.argv) >= 2 and sys.argv[1], music_path=len(sys.argv) >= 3 and sys.argv[2], ) engine.window.size = Vector(800, 600) engine.window.center() engine.run(scene) print(" * Ending script")
class MainScene(Scene): def __init__(self): self.camera.position = Vector(0., 0.) self.space = self.root.add_child( SpaceNode(position=Vector(0, 0), gravity=Vector(0, 20), damping=0.9)) image = Sprite(PYTHON_IMAGE_PATH) random_angle = random.randrange(225, 315) self.node = self.space.add_child( BodyNode(mass=100, sprite=image, angular_velocity=10, shape=Polygon.from_box(Vector(20, 20)), velocity=Vector.from_angle_degrees(random_angle) * 100)) self.node.set_position_update_callback(update_position) self.node.set_velocity_update_callback(update_velocity) def update(self, dt): for event in self.input.events(): if event.keyboard_key: if event.keyboard_key.key_down == Keycode.q: self.engine.quit() if __name__ == '__main__': with Engine(virtual_resolution=Vector(1024, 768)) as engine: engine.run(MainScene())
def test_engine(): with Engine(Vector.xy(1)) as engine: yield engine
if not self.collisions_enabled: self.obj1_hitbox.collision_mask = HitboxMask.side self.obj2_hitbox.collision_mask = HitboxMask.side print("Objects will NOT collide") else: self.obj1_hitbox.collision_mask = HitboxMask.all self.obj2_hitbox.collision_mask = HitboxMask.all print("Objects will collide") if event.keyboard_key.key == Keycode.f: self.engine.window.fullscreen = not self.engine.window.fullscreen if event.keyboard_key.key == Keycode.l: self.engine.window.size = self.engine.window.size + Vector( 20, 20) if event.keyboard_key.key == Keycode.v: self.engine.window.center() if self.input.keyboard.is_pressed(Keycode.q): print("q Pressed - Exiting") self.engine.quit() elif self.input.keyboard.is_pressed(Keycode.x) and self.space: self.space.delete() self.space = None if __name__ == '__main__': engine = Engine(virtual_resolution=Vector(10, 10)) engine.window.title = engine.window.title + "Test 123" engine.window.size = Vector(800, 600) engine.window.center() engine.run(MyScene())
import sys from kaa.engine import Engine from kaa.geometry import Vector sys.path.append('') from hope_in_soap.scenes import GameplayScene if __name__ == '__main__': with Engine(virtual_resolution=Vector(1280, 720)) as engine: engine.run(GameplayScene())
self.material.set_uniform_value('u_blur', (self.blur_quality, 0, 0, 0)) self.node = self.root.add_child( Node(sprite=Sprite(PYTHON_IMAGE_PATH), position=Vector(400, 300), scale=Vector.xy(2), material=self.material)) def update(self, dt): for event in self.input.events(): if event.keyboard_key: if event.keyboard_key.key_down == Keycode.q: self.engine.quit() elif event.keyboard_key.key_down == Keycode.c: if self.node.material: self.node.material = None else: self.node.material = self.material elif event.keyboard_key.key_down == Keycode.a: self.blur_quality = min(self.blur_quality + 1., 100.) self.material.set_uniform_value( 'u_blur', (self.blur_quality, 0, 0, 0)) elif event.keyboard_key.key_down == Keycode.z: self.blur_quality = max(self.blur_quality - 1., 0) self.material.set_uniform_value( 'u_blur', (self.blur_quality, 0, 0, 0)) if __name__ == '__main__': with Engine(Vector(800, 600)) as engine: engine.run(MainScene())
controller_event) def update(self, dt): for event in self.input.events(): if event.keyboard_key: if event.keyboard_key.is_key_down and event.keyboard_key.key == Keycode.q: self.engine.quit() if event.controller_device: if event.controller_device.is_added: self.on_controller_connected(event.controller_device) elif event.controller_device.is_removed: self.on_controller_disconnected(event.controller_device) else: self.log_controller_event(event.controller_device) if event.system and event.system.quit: self.engine.quit() # update the labels for all four controllers for i in range(0, 4): self.slot_nodes[i].update() with Engine(virtual_resolution=Vector(1800, 900)) as engine: scene = MyScene() engine.window.size = Vector(1800, 900) engine.window.center() engine.run(scene)
self._update_ui_nodes() def main(args): print("""Usage: Provide WAV/OGG files as command-line parameters. Keys: * Up/Down arrows - navigation * 0/9 volume up/down * X - play * C - pause * V - resume * B - stop""") samples_paths = [] for path in args: if not os.path.exists(path): raise Exception("Invalid sample path provided: {}" .format(path)) samples_paths.append(path) if not samples_paths: raise Exception("No samples provided") scene = SamplePlayerDemoScene(samples_paths) get_engine().run(scene) if __name__ == '__main__': with Engine(virtual_resolution=Vector(150, 200)) as engine: main(sys.argv[1:])
from kaa.engine import Engine from kaa.geometry import Vector import settings from scenes.gameplay import GameplayScene from scenes.pause import PauseScene from scenes.title_screen import TitleScreenScene import registry from controllers.assets_controller import AssetsController if __name__ == "__main__": with Engine(virtual_resolution=Vector(settings.VIEWPORT_WIDTH, settings.VIEWPORT_HEIGHT)) as engine: # initialize global controllers and keep them in the registry registry.global_controllers.assets_controller = AssetsController() # play music registry.global_controllers.assets_controller.music_track_1.play() # set window to fullscreen mode engine.window.fullscreen = True # initialize and run the scene registry.scenes.gameplay_scene = GameplayScene() registry.scenes.title_screen_scene = TitleScreenScene() registry.scenes.pause_scene = PauseScene() engine.run(registry.scenes.title_screen_scene)