Beispiel #1
0
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)
Beispiel #2
0
    def __init__(self, args):
        self.args = args

        pyglet.resource.path.append(os.path.join(dname,'resources'))
        pyglet.resource.reindex()
        pyglet.font.add_file('resources/DejaVuSans.ttf')
        pyglet.font.add_file('resources/unifont.ttf')

        director.set_show_FPS(False)
        w = director.init(fullscreen=True, caption=self.title, visible=True, resizable=True)

        # width = director.window.width
        # height = director.window.height
        # wnew, hnew = int(width * .75), int(height * .75)
        # director.window.set_fullscreen(False)
        # director.window.set_size(wnew, hnew)
        # w.set_location((width-wnew)/2, (height-hnew)/2)

        director.window.pop_handlers()
        director.window.push_handlers(Handler())

        self.gameScene = Scene()
        self.gameLayer = AgarLayer()
        self.gameScene.add(self.gameLayer)

        director.replace(self.gameScene)

        director.window.set_visible(True)
Beispiel #3
0
    def go(self):
        director.init(640, 480, caption="Fubar")

        splash_image = pyglet.image.load('dung-beetle-title2.png')
        splash_sprite = Sprite(splash_image)
        splash_sprite.position = (640 / 2, 480 / 2)

        intro_menu = IntroMenu(self)

        intro_layer = Layer()
        intro_layer.add(intro_menu, z=1)
        intro_layer.add(splash_sprite, z=0)

        intro_scene = Scene(intro_layer)

        self.server = GameServer()

        director.set_show_FPS(True)
        director.run(intro_scene)
def main():
	# data
	pyglet.resource.path.append('../../challenges/challenge1/pix/')
	pyglet.resource.reindex()
	resolution = 800, 600

	# init
	director.init(width=resolution[0], height=resolution[1])

	# scene
	bg = BgLayer()
	perso = PersoLayer(bg)

	scene = Scene()
	scene.position = (resolution[0] - bg.image.width) / 2, \
			(resolution[1] - bg.image.height) / 2, 
	scene.add(bg)
	scene.add(perso)

	# run
	director.set_show_FPS(True)
	director.run(scene)
Beispiel #5
0
import pyglet
from pyglet import font

from cocos.director import director

import chessmodemenu as menu

pyglet.resource.path.append('images')
pyglet.resource.reindex()
font.add_directory('fonts')

if __name__ == '__main__':

    director.init(width=800, height=600, vsync=False)
    director.set_show_FPS(True)

    ## code to make pygletreactor also work with cocos
    @director.window.event
    def on_close():
        print 'closing reactor'
        reactor.callFromThread(reactor.stop)  #@UndefinedVariable
        # Return true to ensure that no other handlers
        # on the stack receive the on_close event
        return True

    director.replace(menu.get_menu())

    ## Start the reactor

    reactor.run()  #@UndefinedVariable
Beispiel #6
0
defaultconfigfile = "settings.ini"
cfg.configRead(defaultconfigfile)
if cfg.configuration["Debug"]["error"] == "False":
    import error
    sys.excepthook = error.fatalError
import events
import time
import logger
logger.init()

reswidth, resheight = [int(res) for res in cfg.resolution.split("x")]
fullscreen = True if cfg.configuration["Core"]["fullscreen"] == "True" else False
vsync = True if cfg.configuration["Core"]["vsync"] == "True" else False
showfps = True if cfg.configuration["Core"]["showfps"] == "True" else False
director.init(width=reswidth, height=resheight, caption="Game", fullscreen=fullscreen, autoscale=True, resizable=True, vsync=vsync)
director.set_show_FPS(showfps)

logger.addLog("Init resources", logger.loglevel["debug"])
import resources
resources.resourceLoad()


import mainmenu
import gamemenu
import leveleditor
import settings
import controls

import renderer
renderer.init()
Beispiel #7
0
def main():	
	# Initialize Director
	window = dtor.init(width=config.WIDTH,
			  height=config.HEIGHT,
			  caption=config.TITLE,
			  fullscreen=config.FS,
			  resizable=False,
			  do_not_scale=True,
			  )
	window.set_exclusive_mouse(True)
	# Initialize the InputManager
	in_man.init()
		
	in_man.bind(config.PLAYER_1)
			
	print config.WIDTH, config.HEIGHT
	
	"""			
	main_scene = cocos.scene.Scene()
	
	sm = cocos.layer.ScrollingManager()
	sm.scale = config.SCALE

	tile_map = cocos.tiles.load('logic-map-1.tmx')
	structure = tile_map['Structure']
	sm.add(structure, z=0, name='structure')
	el = en.EntityLayer(map=structure)
	sm.add(el, z=1)
	
	player = en.Entity()
	
	robot = en.get_blocky_image('animated-robot.png')
	robot = pyglet.image.ImageGrid(robot, 1, 3)
	seq = robot.texture_sequence
	robo_anim = pyglet.image.Animation.from_image_sequence(seq, 0.1)
	player.add_component(comp.SpriteComponent(robo_anim))
	player.add_component(comp.MapColliderComponent())
	player.add_component(comp.PhysicsComponent())
	player.add_component(comp.Jumper())
	
	player.position = 24, 32
	
	el.add_entity(player)
	el.to_track = player
	
	main_scene.add(sm, name='Scroller')
	
	def track_player(dt, *args, **kwargs):
		sm.set_focus(*player.position)
		
	#main_scene.schedule(track_player)
	
	dtor.interpreter_locals['el'] = el
	
	"""
	img = pyglet.resource.image('contrast-robot.png')
	img = pyglet.image.ImageGrid(img, 1, 3)
	seq = img.texture_sequence
	#walk_anim = seq.get_animation(0.2)
	walk_anim = pyglet.image.Animation.from_image_sequence(seq, 0.1)
	stand_anim = pyglet.image.Animation.from_image_sequence(seq[:1], 0.1)
	anim = jumper.JumperAnimation()
	anim.walk_right = walk_anim
	anim.walk_left  = walk_anim.get_transform(flip_x=True)
	anim.stand_right = stand_anim
	anim.stand_left = stand_anim.get_transform(flip_x=True)
	
	print 'walk_anim: {}'.format(walk_anim)
	
	tile_map = cocos.tiles.load('logic-map-1.tmx')
	
	first_level = level.Level()
	first_level.foreground = tile_map['Structure']
	
	# build out level
	db = first_level.database
	
	e_1 = db.new_entity()
	sc = spritesystem.Sprite()
	sc.sprite = cocos.sprite.Sprite(walk_anim, opacity=250)
	first_level.sprites.add(sc.sprite)
	pos = common.Position()
	pos.x = 100
	pos.y = 100
	db.add_component(e_1, pos)
	db.add_component(e_1, sc)
	
	db.add_component(e_1, common.Velocity())
	db.add_component(e_1, common.PlayerInput(1))
	db.add_component(e_1, common.RectCollider(collide_with_map=True))
	db.add_component(e_1, jumper.Jumper(jump=350))	
	db.add_component(e_1, anim)
	
	first_level.systems.add_system(jumper.JumperSystem(), 0)
	first_level.systems.add_system(jumper.WalkerSystem(), 1)

	first_level.systems.add_system(common.VelocitySystem(), 3)
	first_level.systems.add_system(common.GravitySystem(), 2)	
	
	first_level.systems.add_system(common.RectColliderTrackerSystem(), 4)
	first_level.systems.add_system(common.MapCollisionSystem(), 5)
	
	first_level.systems.add_system(jumper.JumperAnimationSystem(), 6)
	first_level.systems.add_system(spritesystem.SpriteTrackerSystem(), 7)
	
	first_level.systems.add_system(common.PlayerViewTrackerSystem(), 8)
	
	pyglet.gl.glClearColor(*config.BG_COLOR)	
	dtor.set_show_FPS(config.SHOW_FPS)
	dtor.run(first_level)		
Beispiel #8
0
def main():
    director.init(width=settings.SCR_W, height=settings.SCR_H, vsync=False)
    director.set_show_FPS(True)
    director.run(IntroScene() if not settings.SKIP_INTRO else MenuScene())
Beispiel #9
0
#encoding: utf-8

from cocos.director import director
from scenes import StartMenuScene, GameScene, GameOverScene
import config
from events import fj_event_dispatcher
from cocos import scenes


# 游戏开始事件监听
@fj_event_dispatcher.event
def on_game_start():
    director.replace(GameScene())


# 游戏结束事件监听
@fj_event_dispatcher.event
def on_game_over():
    director.replace(GameOverScene())


# 初始化导演类
director.init(width=config.WIN_WIDTH,
              height=config.WIN_HEIGHT,
              fullscreen=False,
              caption='知了飞机')

# 运行第一个场景
director.set_show_FPS(30)
director.run(StartMenuScene())
Beispiel #10
0
        self.rect = cocos.layer.ColorLayer(34, 177, 76, 255, width=8, height=8)
        self.rect.position = rect_x, rect_y
        self.l_x = random.choice(['+', '-', ' '])
        self.l_y = random.choice(['+', '-', ' '])

    # 移动碎片 
    def move(self):
        x, y = self.rect.position
        if self.l_x == ' ' and self.l_y == ' ':
            self.l_y = '+'
        if self.l_x == '+':
            x += self.speed
        elif self.l_x == '-':
            x -= self.speed
        elif self.l_x == ' ':
            pass
        if self.l_y == '+':
            y += self.speed
        elif self.l_y == '-':
            y -= self.speed
        elif self.l_y == ' ':
            pass
        self.rect.position = (x, y)

if __name__ == '__main__':
    director.init(1000, 700)
    main_layer = GameStart()
    scene = scene.Scene(main_layer)
    director.set_show_FPS(main_layer)
    director.run(scene)
Beispiel #11
0
 def run(self):
     director.set_show_FPS(True)
     director.run(self.intro_scene)
Beispiel #12
0
    def go(self):

        self.intro_layer.do(ServerNetworkAction(None))

        director.set_show_FPS(True)
        director.run(self.intro_scene)