예제 #1
0
def get_scene():
    global keyboard, scroller
    keyboard = key.KeyStateHandler()
    director.window.push_handlers(keyboard)

    model = Model()

    world_layer = WorldMap(2000, 2000, model)
    scroller = cocos.layer.ScrollingManager()
    scroller.add(world_layer)

    car_layer = layer.ScrollableLayer()
    car = cocos.sprite.Sprite('car.png')
    car_layer.add(car)
    car.position = (200, 100)
    # car.max_forward_speed = 200
    # car.max_reverse_speed = -100
    car.max_forward_speed = 400
    car.max_reverse_speed = -200
    car.do(DriveCar(model))
    scroller.add(car_layer)

    scene = Scene()
    scene.add(scroller)

    return scene
예제 #2
0
def start():
    director.init(width=CONF.window_width,
                  height=CONF.window_height,
                  caption=CONF.caption)
    scene = Scene()
    scene.add(menu.MainMenu(), z=1)
    director.run(scene)
예제 #3
0
파일: pyfense.py 프로젝트: faide/pyfense
def main():
    director.init(**resources.settings['window'])
    scene = Scene()
    scene.add(MultiplexLayer(
        MainMenu(scene),
        LevelSelectMenu(),
        OptionsMenu(),
        ScoresLayer(),
        HelpLayer(),
        AboutLayer()
    ),
        z=1)
    director.set_show_FPS(resources.settings["general"]["showFps"])
    w, h = director.get_window_size()

    # Music - moved to resources
    # 1st Try - doesnt play anything
    # scene.load_music("assets/music.wav")
    # scene.play_music()

    # 2nd Try - static noise louder than music
    # music = pyglet.resource.media("assets/music.wav", streaming = True)
    # music.play()

    # 3rd Try - music stops after ca. 1 min (even when piece was longer)
    # and doesnt repeat as it should
#    music_player = pyglet.media.Player()
#    music = pyglet.resource.media("assets/music.wav", streaming = False)
#    music_player.queue(music)
#    music_player.eos_action = music_player.EOS_LOOP
    director.run(scene)
예제 #4
0
def reload_solitaire(replay_file):
    gamescene = Scene()
    gamelayer = IncantusLayer()
    gamescene.add(gamelayer, z=0, name="table")
    director.push(gamescene)
    #director.push(ZoomTransition(gamescene, 1.5))
    gamelayer.game_reload(replay_file)
예제 #5
0
def start_solitaire(player_name, players):
    gamescene = Scene()
    gamelayer = IncantusLayer()
    gamescene.add(gamelayer, z=0, name="table")
    director.push(gamescene)
    #director.push(ZoomTransition(gamescene, 1.5))
    gamelayer.game_start(player_name, pyglet.clock.time.time(), players)
예제 #6
0
def setup(test=False, phase_source = None, train_end_calls = []):
    director.director.init(width=1056, height=700, caption='MatchBrain')
    scene = Scene()
    scene.add(MultiplexLayer(
        MainMenu(test, phase_source, train_end_calls),
    ), z = 1)
    return scene
예제 #7
0
def main():
    """
    test split layers
    """
    from cocos.scene import Scene
    from cocos.director import director

    director.init()

    window_size = director.get_window_size()
    window_rect = Rect(0, 0, *window_size)

    distance = window_size[0] * 3 / 4
    main_rect, rest_rect = split_horizontal(window_rect, distance)

    status_height = 80
    status_rect, menu_rect = split_vertical(rest_rect, status_height)

    main_layer = SplitLayer(main_rect)
    menu_layer = SplitLayer(menu_rect, color=(255, 255, 0, 255))
    status_layer = SplitLayer(status_rect, color=(255, 0, 255, 255))

    scene = Scene()
    scene.add(main_layer, z=0)
    scene.add(menu_layer, z=1)
    scene.add(status_layer, z=2)

    director.run(scene)
예제 #8
0
    def test_6_on_pop_calls_on_enter_on_exit(self):
        global rec
        
        scene0 = Scene()
        scene1 = Scene()

        def on_exit():
            global rec
            rec.append('on_exit_called')

        def on_enter():
            global rec
            rec.append('on_enter_called')

        scene0.on_enter = on_enter
        scene1.on_exit = on_exit
            
        rec = []
        director.on_push(scene0)
        # pyglet mockup 1 don't tickle on_draw, we call
        # directly so the push / pop operation completes
        director.on_draw()

        director.on_push(scene1)
        director.on_draw()

        rec = []
        director.on_pop()
        director.on_draw()

        assert rec[0]=='on_exit_called'
        assert rec[1]=='on_enter_called'
예제 #9
0
def new_game():
    director.init(resizable=False, width=1024, height=768)
    scene = Scene()
    scene.add(BackgroundLayer(), z=0)
    scene.add(MultiplexLayer(
        MainMenu(),
    ), z=1)
    director.run(scene)
예제 #10
0
class GameMenu(Menu):
    def __init__(self):
        super(GameMenu, self).__init__()
        self.scene = Scene()
        self.scene.add(MultiplexLayer(MainMenu(), OptionsMenu(), KeyBindingMenu()), z=1)

    def start_game(self):
        director.run(self.scene)
예제 #11
0
def menu_scene():
    scene = Scene()
    scene.add(BackgroundLayer('menu_backgroud.jpg'), z=0)
    scene.add(MultiplexLayer(
        MainMenu(),
        OptionsMenu()
    ), z=1)
    return scene
예제 #12
0
 def start_game(self):
     scene = Scene()
     scene.add(MultiplexLayer(
                      MainMenu(),
                      OptionsMenu(),
                      HiScoresLayer(),
                      ), z=1)
     scene.add(BackgroundLayer(), z=0)
     director.push(ShuffleTransition(scene, 1.5))
예제 #13
0
def main():
    print(description)
    director.init( resizable=True, width=640, height=480 )
    scene_green = Scene()
    layer_green = ColorLayer(32,255,0,255)
    scene_green.add(layer_green)
    scene_green.do(ac.Delay(2.0) + ac.CallFunc(push_sequence_scene))
    # pyglet 1.1.4 needs this to timely pump actions 
    pyglet.clock.schedule(lambda dt: None)
    director.run(scene_green)
예제 #14
0
 def on_win(self):
     Objects.reset_game()
     server = Objects.get_server(self.levelName)
     server.curLevel = self.level+1
     utils.play_sound("Enter.wav")
     game = Scene(server.map, server)
     game.add(ImageLayer(os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z)
     director.push(game)
     menu_player.stop()
     self.game_started = True
    def previous():
        if SlidesManager.current_position == 0 or \
            SlidesManager.current_position-1 > len(SlidesManager.slides_pool):

            return

        SlidesManager.current_position-=1
        scene = Scene(Presentation())
        scene.add(SlidesManager.slides_pool[SlidesManager.current_position], z=1)
        director.push(scene)
예제 #16
0
def get_newgame():
    '''returns the game scene'''
    scene = Scene()

    # model
    model = GameModel()

    # controller
    ctrl = GameCtrl( model )

    # view
    hud = HUD()
    view = GameView( model, hud )

    # set controller in model
    model.set_controller( ctrl )

    # add controller
    scene.add( ctrl, z=1, name="controller" )

    # add view
    scene.add( hud, z=3, name="hud" )
    scene.add( BackgroundLayer(), z=0, name="background" )
    scene.add( view, z=2, name="view" )

    return scene
예제 #17
0
    def on_join_regular(self):
        global game_controller
        game_controller = GameController()
        main_scene = Scene(
            game_controller.map, game_controller)
        director.push(main_scene)

        #adding a background layer that lies below all layers
        background_layer = ImageLayer(
            os.path.join("images", "backgrounds", "notebook-paper.png"))
        main_scene.add(background_layer, z=-1)
    def next():
        if SlidesManager.current_position+1 > len(SlidesManager.slides_pool):
            return

        scene = Scene(Presentation())
        scene.add(SlidesManager.slides_pool[SlidesManager.current_position], z=1)
        SlidesManager.current_position+=1
       
        trans = [ FadeTRTransition, FlipX3DTransition, CornerMoveTransition, FlipY3DTransition ]
        t = choice(trans)
        director.replace( t(scene, duration=1))
예제 #19
0
 def setup_board(client):
     gamelayer = IncantusLayer()
     gamescene = Scene()
     gamescene.add(gamelayer, z=0, name="table")
     #gamescene.add(chatbox, z=1, name="chat")
     director.push(gamescene)
     #director.push(ZoomTransition(gamescene, 1.5))
     gamelayer.msg_controller.prompt("Waiting for other players")
     #gamelayer.game_status.log("Waiting for other players")
     defrd = client.ready_to_start()
     defrd.addCallback(lambda (seed, players): gamelayer.game_start(player_name, seed, players, client))
    def test_1_push(self):
        old_scene = Scene()
        director.run(old_scene)

        new_scene = Scene()
        new_scene.parent = not_None_value
        director.on_push(new_scene)
        # pyglet mockup 1 don't tickle on_draw, we call
        # directly so the push / pop operation completes
        director.on_draw()

        assert new_scene.parent is None
예제 #21
0
def push_sequence_scene():
    scene_blue = Scene()
    layer_blue = ColorLayer(32,32,255,255)
    scene_blue.add( layer_blue, z=0 )
    scene_blue.do(ac.Delay(2) + ac.CallFunc(pop_scene))

    scene_red = Scene()
    layer_red = ColorLayer(255,32,0,255)
    scene_red.add( layer_red, z=0 )
    scene_red.do(ac.Delay(2) + ac.CallFunc(pop_scene))

    director.push( SequenceScene(scene_blue, scene_red) )
예제 #22
0
 def connected(client, avatar):
     client.avatar = avatar
     #client.msg_callback = chatbox.add_text
     #chatbox.set_callback(client.send_message)
     gamelayer = IncantusLayer()
     gamescene = Scene()
     gamescene.add(gamelayer, z=0, name="table")
     #gamescene.add(chatbox, z=1, name="chat")
     director.push(gamescene)
     #director.push(ZoomTransition(gamescene, 1.5))
     #gamelayer.game_status.log("Waiting for other players")
     gamelayer.msg_controller.prompt("Waiting for other players")
     defrd = client.ready_to_start()
     defrd.addCallback(lambda (seed, players): gamelayer.game_start(player_name, seed, players, client))
예제 #23
0
def get_new_game():
    scene = Scene()
    game = Game()
    hud = Hud()
    end_game = EndGame()
    game_ctrl = GameCtrl(game, hud, end_game)
    scene.add(game, z=0, name="game layer")
    scene.add(game_ctrl, z=1, name="game control layer")
    scene.add(hud, z=2, name="hud layer")
    scene.add(end_game, z=3, name="end game layer")
    return scene
예제 #24
0
    def start_game(self):
        constants.MULTIPLAYER = True
        server = Objects.get_controller()
        server.client_start_game()
        if server.serverStarted:
            utils.play_sound("Enter.wav")
            game = Scene(server.map, server)
            menu_player.stop()
            game.add(ImageLayer(
                     os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z)
            director.push(game)
            self.game_started = True

        else:
            print "start server first"
예제 #25
0
파일: Main.py 프로젝트: joaompinto/SamePop
def main():
    script_dir = os.path.dirname(os.path.realpath(__file__))

    pyglet.resource.path = [join(script_dir, '..')]
    pyglet.resource.reindex()

    director.director.init(width=800, height=650, caption="Match 3")

    scene = Scene()
    scene.add(MultiplexLayer(
        MainMenu()
    ),
        z=1)

    director.director.run(scene)
예제 #26
0
def main():
    print(description)
    director.init(resizable=True)
    main_scene = Scene()

    back = BackgroundLayer()
    sprite = SpriteLayer()

    main_scene.add(back, z=0)
    main_scene.add(sprite, z=1)

    # In real code after a sequence of grid actions the StopGrid() action
    # should be called. Omited here to stay in the last grid action render
    sprite.do(Waves3D(duration=4) + Flip(duration=4))
    back.do(ShuffleTiles(duration=3, grid=(16, 12)))
    director.run(main_scene)
def main():
    print description
    director.init( resizable=True )
    main_scene = Scene()

    red = ColorLayer(255,0,0,128)

    sprite = SpriteLayer()

    red.scale = 0.75

    main_scene.add( red, z=0 )
    main_scene.add( sprite, z=1 )

    sprite.do( Waves3D(duration=2) + Flip(duration=2) )
    director.run (main_scene)
예제 #28
0
파일: main.py 프로젝트: ddunwoody/adastra
def main():
    setup.resources()
    physics.space.gravity = (0, -10)
    director.init(caption="Ad Astra", resizable=True, width=1024, height=640)
    x,y = director.get_window_size()

    lander = Lander(position=(x/2, 50))
    control_handler = ControlHandler(lander)
    director.window.push_handlers(control_handler.keyboard)

    scene = Scene(control_handler, WorldLayer(lander), HUDLayer(lander, control_handler.keyboard))
    def update(dt):
        control_handler.update(dt)
        lander.update(dt)
        physics.space.step(dt)
    scene.schedule_interval(update, 1/60.0)
    director.run(scene)
예제 #29
0
def get_menu_scene():
    scene = Scene()
    scene.add(MultiplexLayer(MainMenu(), OptionsMenu(), ScoresLayer()), z=2)
    scene.add(TitleLayer(), z=2)
    scene.add(CapaNivelScrolling(demo=True), z=1)

    return scene
예제 #30
0
def get_newgame():
    from gamelayers import HUD, PygletParallax
    scene = Scene()
    model = Model()
    controller = Controller(model)
    model.set_controller(controller)
    hud = HUD()
    view = View(model, hud)
    pg = PygletParallax()
    model.set_scroller(pg)
    scene.add(controller, z=1, name='controller')
    scene.add(hud, z=3, name='hud')
    scene.add(pg, z=0, name='background')
    scene.add(view, z=2, name='view')
    return scene
예제 #31
0
 def test_init(self):
     self.watch_layer = WatchLayer()
     scene = Scene(self.watch_layer)
        elif transformationType == 1:  # forwards XorYorZ=0 UpOrDown=1
            return (input_point[1], input_point[0])
        else:
            print "unknown transform type"

    #def on_key_release( self, keys, mod ):

    def draw(self):
        super(Display, self).draw()

        if not self.blank_display:
            self.position_bar.render()
            self.tgt_window.render()
            self.pos_fdbk.render()
            #self.pos_fdbk_txt.draw()
            self.score_txt.draw()
            self.reward_txt.draw()

        self.combo_wait_txt.draw()

if __name__ == "__main__":
    director.init(width=700,
                  height=800,
                  caption="FeedbackDisplay",
                  resizable=True,
                  do_not_scale=True)  #, fullscreen=True)

    scene = Scene(Display())

    director.run(scene)
예제 #33
0
        FlipX3DTransition,
        FlipY3DTransition,
        FlipAngular3DTransition,
        ShuffleTransition,
        ShrinkGrowTransition,
        CornerMoveTransition,
        EnvelopeTransition,
        FadeTRTransition,
        FadeBLTransition,
        FadeUpTransition,
        FadeDownTransition,
        TurnOffTilesTransition,
        FadeTransition,
        ZoomTransition,
    ]
    current_transition = 0

    g = GrossiniLayer()
    g2 = GrossiniLayer2()
    c2 = ColorLayer(128, 16, 16, 255)
    c1 = ColorLayer(0, 255, 255, 255)
    control1 = ControlLayer()
    control2 = ControlLayer()
    controlScene1 = Scene(c2, g, control2)
    controlScene2 = Scene(c1, g2, control2)

    control_p = 0
    control_list = [controlScene1, controlScene2]

    director.run(controlScene1)
예제 #34
0
파일: highscore.py 프로젝트: faide/pyfense
 def on_mouse_release(self, x, y, b, m):
     if self.in_highscore:
         director.replace(Scene(SubmitScore(self.wave)))
     else:
         director.pop()
     return True
예제 #35
0
from cocos.sprite import Sprite
from pyglet.window.key import symbol_string
from cocos.actions import *


class EffectLayer(ColorLayer):
    is_event_handler = True

    def __init__(self):
        super(EffectLayer, self).__init__(231, 76, 60, 1000)

        sprite = Sprite("assets/img/grossini.png")
        sprite.position = 320, 240
        self.add(sprite)

    def on_key_press(self, key, modifiers):
        if symbol_string(key) == "T":
            self.do(Twirl(amplitude=5, duration=2))

        elif symbol_string(key) == "W":
            self.do(Reverse(Waves(duration=2)))

        elif symbol_string(key) == "F":
            self.do(
                FlipX3D(duration=1) + FlipY3D(duration=1) +
                Reverse(FlipY3D(duration=1)))


director.init()
director.run(Scene(EffectLayer()))
예제 #36
0
    text = """Usage:
    python %s file_with_paths.py

An example of input file is tools/foo.py

Keybindings

A : animate
S : save
N : add new bezier curve, make it the selected one
<digits> + Enter : selects the n-th bezier curve
D : multiplies duration by 1.1
Shift D : divides duration by 1.1
T : time_warp * 1.1
shift T: time_warp / 1.1
"""
    return text


if __name__ == "__main__":
    import imp, sys
    print(usage() % sys.argv[0])
    if len(sys.argv) < 2:
        sys.exit()

    path = sys.argv[1]
    client = imp.load_source("client", path)
    director.init()
    draw = PathDraw(client, path)
    director.run(Scene(draw))
예제 #37
0
                      (MenuItem("Vol DOWN", self.vol_DOWN)),
                      (MenuItem("Exit", self.on_quit))}

        #self.song = Audio("aud/LatinIndustries.ogg")
        self.create_menu(menu_items)
        self.is_playing = False

    def play_music(self):
        if self.is_playing:
            self.song.stop()
            self.is_playing = False
        elif not self.is_playing:
            self.song.play(-1)
            self.is_playing = True

    def vol_UP(self):
        volume = self.song.get_volume()
        self.song.set_volume(volume + .1)

    def vol_DOWN(self):
        volume = self.song.get_volume()
        self.song.set_volume(volume - .1)

    def on_quit(self):
        exit()


mixer.init()
director.init()
director.run(Scene(audioMenu()))
예제 #38
0
# After that I set the middle bottom of the sprite's bounded rectangle equal to the middle bottom of the start cell
rect.midbottom = start.midbottom

# And lastly I set the position of the sprite to the center of the rectangle
sprite_layer.sprite.position = rect.center

# From here it's pretty easy sailing
# First I add the map, and set the "z" to 0
scroller.add(map_layer, z=0)
# The z is the vertical axis, so the highest z value layer will always show on top of the others

# Then I add the sprite, and set the z to 1 so that it shows on top of the map layer
scroller.add(sprite_layer, z=1)

# Then I make a ColorLayer, just to spice up the background a bit (which for now is just transparent)
bg_color = ColorLayer(52, 152, 219, 1000)

# Then I make a scene
scene = Scene()
# And I add the scroller to it and put it on top of the stack of layers
scene.add(scroller, z=1)

# And I add the background color (I don't need to define a z because by default it's 0)
scene.add(bg_color)

# And then we run it!
director.run(scene)

# Now our games are starting to get a bit more complex, but it's nothing you can't handle!
예제 #39
0
def get_sprite_test(index):
    d = moves[index]
    return Scene(d(index))
예제 #40
0
        self.background_sprite = cocos.sprite.Sprite(
            pyglet.resource.image('main_background.png'))
        self.background_sprite.position = self.width / 2, self.height / 2
        self.add(self.background_sprite, z=0)

        self.name_sprite = cocos.sprite.Sprite(
            pyglet.resource.image('game_name.png'))
        self.name_sprite.position = self.width / 2, self.height * 0.8
        self.add(self.name_sprite, z=20)

        self.floor_layer = FloorLayer(self.width)
        self.floor_layer.position = 0, 50
        self.add(self.floor_layer, z=10)


if __name__ == "__main__":
    pyglet.resource.path.append('res')
    pyglet.resource.reindex()
    font.add_directory('res')

    director.init(resizable=True, width=500, height=800)

    scene = Scene()
    scene.add(MultiplexLayer(MainMenu(), OptionsMenu(), ScoresLayer()), z=1)

    scene.add(BackgroundLayer(), z=0)
    # scene.add(MainLayer())

    director.set_show_FPS(True)
    director.run(scene)
예제 #41
0
def get_new_trainer(test=False, phase_source=None, train_end_callables=[]):
    scene = Scene()
    view = TrainView(scene, test=test, phase_source=phase_source, train_end_callables=train_end_callables)
    scene.add(view.msg, z=2, name='hud')
    scene.add(view, z=1, name='trainview')
    return scene
예제 #42
0
파일: demo_sprites.py 프로젝트: linas/cocos
def get_sprite_test(index):
    d = tests[index]
    return Scene(FontLayer(title=d[0], subtitle=d[1]), d[2](index))
예제 #43
0
 def test_manually(self):
     director.run(scene=Scene(self.switch))
예제 #44
0
def main():
    font.add_directory('.')

    director.init(resizable=True)
    director.run(Scene(MainMenu()))
예제 #45
0
파일: game.py 프로젝트: m-game/pygames
        oneself = oneself_layer.get_children()[0]
        left = oneself_layer.x - oneself.width
        right = oneself_layer.x + oneself.width
        top = oneself_layer.y + oneself.height
        bottom = oneself_layer.y - oneself.height
        for bullet in bullet_layer.get_children():
            if bullet.rotation == 180:
                if left < bullet.x < right and bottom < bullet.y < top:
                    bullet_removed.add(bullet)
                    print('die')
        for bullet in bullet_removed:
            bullet.to_remove = bullet.actions
            bullet_layer.remove(bullet)


director.init(width=WIDTH, height=HEIGHT)
# 定义主场景
main_scene = Scene()
# 定义层次
background_layer = Background()
oneself_layer = Oneself()
enemy_layer = Enemy()
bullet_layer = Bullet()
# 向主场景添加元素
main_scene.add(background_layer, z=Z_Background)
main_scene.add(oneself_layer, z=Z_Plane)
main_scene.add(enemy_layer, z=Z_Plane)
main_scene.add(bullet_layer, z=Z_Bullet)
# 运行主场景
director.run(main_scene)
예제 #46
0
 def backToPrevious(self):
     destScene = Scene(self.previous)
     self.director.replace(SlideInTTransition(destScene, duration=0.5))
예제 #47
0
        self.bullets.append(accBullet)


# And lastly I set the position of the sprite to the center of the rectangle

spriteLayer = SpriteLayer()
spriteLayer.sprite.position = 100, 600

scroller.add(spriteLayer, z=1)
scroller.add(mapLayer, z=0)
scroller.add(bg, z=-1)

# From here it's pretty easy sailing
# First I add the map, and set the "z" to 0
#scroller.add(map_layer, z=0)
# The z is the vertical axis, so the highest z value layer will always show on top of the others

# Then I add the sprite, and set the z to 1 so that it shows on top of the map layer

bg_color = ColorLayer(52, 152, 219, 1000)

# Then I make a scene
scene = Scene()
# And I add the scroller to it and put it on top of the stack of layers

# And I add the background color (I don't need to define a z because by default it's 0)
scene.add(bg_color)
scene.add(scroller)
# And then we run it!
director.run(scene)
    return (
        (Delay(speed), MoveBy((0, -100), speed)),
        (MoveBy((0, -100), speed), Delay(speed)),
    )


class LetsDance(Layer):
    def __init__(self, sequence, bpm):
        super().__init__()
        self.left_foot = Sprite("./images/flat-black-l.png")
        self.right_foot = Sprite("./images/flat-black-r.png")

        self.left_foot.position = 200, 200
        self.right_foot.position = 300, 200
        self.add(self.left_foot)
        self.add(self.right_foot)

        speed = 60 / bpm
        dance = [s(speed) for s in sequence]

        right_leg_sequence = chain(*(step[0] for step in dance))
        left_leg_sequence = chain(*(step[1] for step in dance))

        self.right_foot.do(Repeat(sum(right_leg_sequence, Delay(0))))
        self.left_foot.do(Repeat(sum(left_leg_sequence, Delay(0))))


if __name__ == "__main__":
    director.init()
    director.run(Scene(LetsDance([left, right, front, back], 120)))
예제 #49
0
#         move = MoveBy((250, 0), 3)
#         jump = JumpBy((-250, 0), 100, 4, 3)

#         sprite.do(move + Delay(5) + jump)

# dance_scene = Scene(BackgroundLayer())


def get_sprite_test(index):
    d = moves[index]
    return Scene(d(index))


def gen_moves(order):
    return {i: move for i, move in enumerate(order, start=1)}


def gen_order(n=4, m=4):
    return list(
        itertools.chain(*[[random.choice(all_moves)] * m for _ in range(n)]))


order = gen_order()
moves = gen_moves(order=order)

if __name__ == "__main__":
    director.init(800, 533, do_not_scale=True, caption="Cocos - Sprite demo")
    dancer = DanceMoveLayer()
    dance_scene = Scene(BackgroundLayer(), dancer)
    director.run(dance_scene)
예제 #50
0
파일: main.py 프로젝트: MacSoares/Spacewars
def signal_handler(signal_received, frame):
    """ Handle Ctrl + C signal """
    if signal_received is signal.SIGINT:
        # erase the ^C on Terminal
        print "\r  "
        exit(0)


if __name__ == "__main__":
    # Add pyglet resources directories
    resource.path.append('data')
    resource.reindex()
    font.add_directory('data/fonts')

    signal.signal(signal.SIGINT, signal_handler)

    keyboard = key.KeyStateHandler()
    EventHandle().keyboard = keyboard

    director.init(width=WIDTH, height=HEIGHT, caption='SpaceWars')
    director.window.push_handlers(keyboard)

    # observer to joystick
    clock.schedule_interval(connect_joystick, .1)

    # Create a initial menu scene
    scene = Scene()
    scene.add(BackgroundLayer('backgrounds/space_background.png'), z=0)
    scene.add(MultiplexLayer(MainMenu(), Credits(), OptionsMenu()), z=1)
    director.run(scene)
예제 #51
0
 def on_key_release(self, keys, mod):
     self.do_move(MoveTo((300, 150), 2))
     for i, Move in moves.items():
         print(Move)
         # self.do_move(Move(i))
         Scene(Move(i))
예제 #52
0
def show_ingame_menu():
    from menu import HierarchicalMenu, InGameMenu
    director.push(Scene(HierarchicalMenu(InGameMenu())))
예제 #53
0
 def on_key_press(self, key, modifiers):
     director.replace(Scene(Layer1()))
예제 #54
0
파일: start.py 프로젝트: vvvbeauty/etc_code
    new.x += layer.sprite.dx
    new.y += layer.sprite.dy
    # dont care about velocity, pass 0, 0
    collider.collide_map(tilemap, last, new, 0.0, 0.0)
    layer.sprite.position = new.center
    scroller.set_focus(*new.center)


# Schedule Updates
layer.schedule(update)

# Add map to scroller
scroller.add(tilemap)

#Create Scene
scene = Scene()

# Create and add background
background = Background()
scene.add(background)

#Add main layer to scroller
scroller.add(layer)
scroller.add(ShowCollision())

# Add scroller to scene
scene.add(scroller)

# Game menu configuration
menu = GameMenu(scene)
menuScene = Scene()
예제 #55
0
 def on_key_press(self, key, modifiers):
     # Here is entire purpose of this lesson!
     director.replace(Scene(Layer2()))
예제 #56
0
class cardriver(Driver):
    def step(self, dt):
        self.target.rotation += (keeb[key.RIGHT] - keeb[key.LEFT]) * 100 * dt
        self.target.acceleration = (keeb[key.UP] - keeb[key.DOWN]) * 500
        if keeb[key.SPACE]:
            self.target.speed -= self.target.speed / 10

        super(cardriver, self).step(dt)
        scroller.set_focus(self.target.x, self.target.y)


class carlayer(ScrollableLayer):
    def __init__(self):
        super(carlayer, self).__init__()
        self.sprite = Sprite("assets/img/car.png")
        self.sprite.position = 200, 100
        self.sprite.max_forward_speed = 200
        self.sprite.max_reverse_speed = -100
        self.add(self.sprite)
        self.sprite.do(cardriver())


car_layer = carlayer()
map_layer = load("assets/road_map.tmx")["map0"]
scroller.add(map_layer)
scroller.add(car_layer)
scene = Scene(scroller)
director.window.push_handlers(keeb)
director.run(scene)
예제 #57
0
from cocos.scene import Scene
from cocos.scenes.transitions import FadeTransition
from cocos.text import Label, TextElement, RichLabel
from cocos.utils import SequenceScene
from cocos.actions.interval_actions import MoveBy, Delay
from constants import BACKGROUND_Z, WINDOW_WIDTH, WINDOW_HEIGHT, FULL_SCREEN
from imageLayer import ImageLayer
from game import *
from cocos.actions.interval_actions import FadeIn

from cocos import pygletreactor
pygletreactor.install()

director.init(width=WINDOW_WIDTH, height=WINDOW_HEIGHT, fullscreen=FULL_SCREEN)

s = Scene(MainMenu())
menu_background = ImageLayer(
    os.path.join("images", "backgrounds", "menu-chalkboard.png"))
menu_background.position = (0, 0)
menu_background.anchor = (0.0, 0.0)
menu_background.scale = 1
s.add(menu_background)

# blank_scene = Scene()
# director.run(FadeTransition(s, 1, blank_scene))


def director_run_no_loop(scene):
    # this is the same as director.run, without the eventloop

    director.scene_stack.append(director.scene)
예제 #58
0
def title():
    return Scene(TitleLayer(), TitleControlLayer())
예제 #59
0
def main():
    director.init(caption="Moving Kitty", width=640, height=480)
    scene = Scene(Game())
    director.run(scene)
예제 #60
0
    # Here is the overload for the on_key_press function
    def on_key_press(self, key, modifiers):
        # Here is entire purpose of this lesson!
        director.replace(Scene(Layer2()))
        # That line replaces whatever scene is currently running in the director with the scene indicated
        # In this case, we create a new scene object inline out of the second layer, which I have coded below


# Here is the second Layer I make, for the second scene
class Layer2(ColorLayer):
    # Same as before, we let it handle user input
    is_event_handler = True

    # Initialize it and call the super class, but this time pass in a different colour
    def __init__(self):
        super(Layer2, self).__init__(231, 76, 60, 1000)

        # Same Label code as before but this time with different text
        text = Label("This is the second scene")
        text.position = director._window_virtual_width / 2, director._window_virtual_height / 2
        self.add(text)

    # And once again the same user input code
    def on_key_press(self, key, modifiers):
        director.replace(Scene(Layer1()))


# Here we initialize the director and start running the first scene
director.init()
director.run(Scene(Layer1()))