def __init__(self): logger.info("Initializing scene: demo/basic.") self.camera.position = Vector(0., 0.) self.seg_node = Node() self.seg_node.shape = Segment(Vector(-2., -2.), Vector(2., 2.,)) self.circle_node = Node() self.circle_node.shape = Circle(2., Vector(2., 2.)) self.box_node = Node() self.box_node.shape = Polygon.from_box(Vector(1.5, 1.5)) logger.info("Node scene before adding to tree: %s", self.seg_node.scene) self.root.add_child(self.seg_node) self.root.add_child(self.circle_node) self.root.add_child(self.box_node) logger.info("Node scene after adding to tree: %s", self.seg_node.scene) self.virtual_resolutions_cycle = itertools.cycle( [Vector(10, 10), Vector(20, 20), Vector(5, 15), Vector(15, 5)] ) self.virtual_resolution_modes_cycle = itertools.cycle( [VirtualResolutionMode.aggresive_stretch, VirtualResolutionMode.no_stretch, VirtualResolutionMode.adaptive_stretch] ) logger.info("Displays info:") for display in self.engine.get_displays(): logger.info("* %r", display)
def __init__(self): self.camera.position = Vector(0., 0.) self.python_img = Sprite(PYTHON_IMAGE_PATH) self.box_img = Sprite(BOX_IMAGE_PATH) self.objects = [] self.random_collisions = False self.collision_spawning = False self.space = self.root.add_child(SpaceNode()) self.box = self.space.add_child(BodyNode( sprite=self.box_img, body_type=BodyNodeType.kinematic, angular_velocity_degrees=30., )) # create bounding collision box with segments self.box_seg1 = self.box.add_child(HitboxNode( shape=Segment(Vector(-143, -143), Vector(-143, 143)), )) self.box_seg2 = self.box.add_child(HitboxNode( shape=Segment(Vector(-143, 143), Vector(143, 143)), )) self.box_seg3 = self.box.add_child(HitboxNode( shape=Segment(Vector(143, 143), Vector(143, -143)), )) self.box_seg4 = self.box.add_child(HitboxNode( shape=Segment(Vector(143, -143), Vector(-143, -143)), )) for i in range(5): self.spawn_object() self.space.set_collision_handler( COLLISION_TRIGGER, COLLISION_TRIGGER, self.on_collision, phases_mask=(CollisionPhase.begin | CollisionPhase.separate), ) self.observed_ball = [ n for n in self.space.children if isinstance(n, FlyingBall) ][0]
def __init__(self, sound_path, music_path): logger.info("Initializing scene: demo/basic.") self.camera.position = Vector(0., 0.) self.seg_node = Node() self.seg_node.shape = Segment(Vector(-2., -2.), Vector( 2., 2., )) self.circle_node = Node() self.circle_node.shape = Circle(2., Vector(2., 2.)) self.box_node = Node() self.box_node.shape = Polygon.from_box(Vector(1.5, 1.5)) print("Node scene before adding to tree: {}".format( self.seg_node.scene)) self.root.add_child(self.seg_node) self.root.add_child(self.circle_node) self.root.add_child(self.box_node) print("Node scene after adding to tree: {}".format( self.seg_node.scene)) if sound_path: self.sound = Sound(sound_path) else: self.sound = None if music_path: self.music = Music(music_path) else: self.music = None self.virtual_resolutions_cycle = itertools.cycle( [Vector(10, 10), Vector(20, 20), Vector(5, 15), Vector(15, 5)]) self.virtual_resolution_modes_cycle = itertools.cycle([ VirtualResolutionMode.aggresive_stretch, VirtualResolutionMode.no_stretch, VirtualResolutionMode.adaptive_stretch ]) print("Displays info:") for display in self.engine.get_displays(): print("* {!r}".format(display))
def __init__(self): self.camera.position = Vector(0., 0.) self.python_img = Sprite(PYTHON_IMAGE_PATH) self.collisions_enabled = True self.space = self.root.add_child(SpaceNode(position=Vector(0, 0), )) self.box = self.space.add_child( BodyNode( body_type=BodyNodeType.kinematic, angular_velocity=0.3, )) # create bounding collision box with segments self.box_seg1 = self.box.add_child( HitboxNode( shape=Segment(Vector(-4, -4), Vector(-4, 4)), mask=HitboxMask.side, collision_mask=HitboxMask.all, color=Color(0.5, 0.5, 0.5), )) self.box_seg2 = self.box.add_child( HitboxNode( shape=Segment(Vector(-4, 4), Vector(4, 4)), mask=HitboxMask.side, collision_mask=HitboxMask.all, color=Color(0.5, 0.5, 0.5), )) self.box_seg3 = self.box.add_child( HitboxNode( shape=Segment(Vector(4, 4), Vector(4, -4)), mask=HitboxMask.side, collision_mask=HitboxMask.all, color=Color(0.5, 0.5, 0.5), )) self.box_seg4 = self.box.add_child( HitboxNode( shape=Segment(Vector(4, -4), Vector(-4, -4)), mask=HitboxMask.side, collision_mask=HitboxMask.all, color=Color(0.5, 0.5, 0.5), )) self.obj1 = self.space.add_child( BodyNode( mass=1e10, position=Vector(0, -2), velocity=Vector(-3.0, 0.5), # * 10, shape=Circle(0.2), sprite=self.python_img, color=Color(1., 0., 0., 1.), )) self.obj1_hitbox = self.obj1.add_child( HitboxNode( shape=Circle(0.2), mask=HitboxMask.snake, collision_mask=HitboxMask.all, trigger_id=CollisionTrigger.obj, visible=False, )) self.obj2 = self.space.add_child( BodyNode( mass=1e10, position=Vector(0, 2), velocity=Vector(4.0, -0.1), # * 10, shape=Circle(0.2), sprite=self.python_img, )) self.obj2_hitbox = self.obj2.add_child( HitboxNode( shape=Circle(0.2), mask=HitboxMask.snake, collision_mask=HitboxMask.all, trigger_id=CollisionTrigger.obj, visible=False, )) self.obj3 = self.space.add_child( BodyNode( mass=1e15, moment=1e20, position=Vector(-1.5, 0.1), velocity=Vector(-1.0, -2.0), angular_velocity_degrees=35., shape=Polygon([ Vector(-1, -1), Vector(1, -1), Vector(1, 1), Vector(-1, 1) ]), )) self.obj3_hitbox = self.obj3.add_child( HitboxNode( mask=HitboxMask.box1, collision_mask=HitboxMask.all, shape=self.obj3.shape, visible=False, elasticity=0.3, )) self.obj4 = self.space.add_child( BodyNode( position=Vector(0, -2), velocity=Vector(1.0, 5.0), angular_velocity_degrees=-5., shape=Polygon.from_box(Vector(0.5, 1.)), )) self.obj4_hitbox = self.obj4.add_child( HitboxNode( mask=HitboxMask.box2, collision_mask=HitboxMask.all, shape=self.obj4.shape, visible=False, elasticity=0.6, )) self.space.set_collision_handler(CollisionTrigger.obj, CollisionTrigger.obj, self.handle_collision)
def __init__(self): self.camera.position = Vector(0, 0) self.game_over = False # physics setup self.space = self.root.add_child(SpaceNode(sprite=SPRITE_HAND, )) self.space_static = self.space.add_child( BodyNode(body_type=BodyNodeType.static, )) self.border = self.space_static.add_child( HitboxNode( position=Vector(0, 350), shape=Segment(Vector(-600, 0), Vector(600, 0)), trigger_id=CollisionTrigger.border, # color=Color(1., 0., 0., 0.5), z_index=100, )) self.space.set_collision_handler( CollisionTrigger.soap, CollisionTrigger.runner_enemy, self.on_collision_soap_enemy, phases_mask=CollisionPhase.begin, ) self.space.set_collision_handler( CollisionTrigger.border, CollisionTrigger.runner_enemy, self.on_collision_border_enemy, phases_mask=CollisionPhase.begin, ) self.space.set_collision_handler( CollisionTrigger.soap, CollisionTrigger.runner_pickup, self.on_collision_soap_pickup, phases_mask=CollisionPhase.begin, ) self.space.set_collision_handler( CollisionTrigger.border, CollisionTrigger.runner_pickup, self.on_collision_border_pickup, phases_mask=CollisionPhase.begin, ) # background parallax effect self.water_back = self.root.add_child( VerticalScrollingNode( repeat_sprite=SPRITE_WATER_BACK, scroll_duration=9000., z_index=-10, )) self.water_front = self.root.add_child( VerticalScrollingNode( repeat_sprite=SPRITE_WATER_FRONT, scroll_duration=3000., z_index=10, )) self.player_state = PlayerState() self.effects_manager = EffectsManager( root_node=self.root, camera=self.camera, ) self.runners_manager = RunnersManager(space_node=self.space, ) self.powerups_manager = PowerupsManager( player_state=self.player_state, runners_manager=self.runners_manager, ) self.player_manager = PlayerManager( player_state=self.player_state, space_node=self.space, effects_manager=self.effects_manager, ) self.ui_manager = UIManager( player_state=self.player_state, root_node=self.root, )