def init(self,level_data=level0_data,*args,**kwargs): music.Play('rc/snd/background.wav') self._ld = level_data() GAME_CONSOLE.write('Next level: ', self._ld['title'], '!') if level_data == level0_data: spaceship.Spaceship._fuel = 100 game = DynamicGame(level_data=self._ld) game.on('teleport-player', self.onNextLevel) game.loadFromJSON('rc/lvl/level0.json') self.game = game self.game.on("hitBig", self.foo) self.pushLayerFront(DynamicBG(game.getEntityById('player'), self._ld['bg'])) self.game_layer = GameLayer(game=game, camera=Camera()) self.pushLayerFront(self.game_layer) fuel_progress_bar = ProgressBar(grow_origin='top-left', expression=lambda: game.getEntityById('player')._fuel / 100.0, layout={'height': 40, 'width': 300, 'top': 20, 'left': 20}, player=game.getEntityById('player')) self.pushLayerFront(fuel_progress_bar) self.pushLayerFront(GUITextItem(text="Fuel", fontSize=20, layout={'top': 20, 'width': 100, 'height': 20, 'left': 125})) self.pushLayerFront(Button( onclick=self.pause, layout={'width': 256, 'height': 64, 'right': 20, 'top': 20}, img="rc/img/256x64_menu_btn.png"))
def init(self, *args, **kwargs): # self.pushLayerFront(StaticBackgroundLauer('rc/img/256x256bg.png','fill')) game = Game() game.loadFromJSON('rc/lvl/level0.json') self.pushLayerFront(GameLayer(game=game, camera=Camera())) ssound.Preload('rc/snd/1.wav', ['alias0']) musmap = { 0: 'rc/snd/music/Welcome.mp3', 1: 'rc/snd/music/Time.mp3', 2: 'rc/snd/music/0x4.mp3' } for x in xrange(0, 3): layer = GUITextItem(layout={ 'width': 100, 'height': 20, 'left': 50, 'right': 50, 'offset_y': 70 * x, 'padding': [20, 10], 'force-size': False }, text=musmap[x]) layer.on( 'ui:click', (lambda x: lambda *a: music.Play(musmap[x], loop=True))(x)) self.pushLayerFront(layer) tile = _9Tiles(LoadTexture('rc/img/ui-frames.png'), Rect(left=0, bottom=0, width=12, height=12)) self.pushLayerFront( GUI9TileItem(tiles=tile, layout={ 'left': 100, 'right': 100, 'top': 200, 'bottom': 200 })) GAME_CONSOLE.write('Startup screen created.')
def init(self,*args,**kwargs): self.winner = None self.freeze = False gl.glClearColor(0x1d/255.0,0x5b/255.0,0x70/255.0,1) # self.pushLayerFront(StaticBackgroundLauer('rc/img/256x256bg.png','fill')) game = Game() self.camera = Camera() self.game = game self.game.listen('win') self.game.on('win',self.event('win')) game.loadFromJSON('rc/lvl/level0.json') for pid, pcl in PLAYER_CHOICES.items(): p = pcl() game.addEntity(p) # p.animations = 'rc/ani/player-test-'+pid+'.json' p.position = 500 if pid == 'player-right' else -500, 0 p.id = pid p.trigger('configured') self.gameLayer = GameLayer(game=game,camera=self.camera) self.pushLayerFront(self.gameLayer) self.pushLayerFront(HpProgressBar(grow_origin='top-left', expression=lambda: game.getEntityById('player-left').health / 100.0, layout=ProgressBar.LEFT_LAYOUT,player=game.getEntityById('player-left'))) self.pushLayerFront(HpProgressBar(grow_origin='top-right', expression=lambda: game.getEntityById('player-right').health / 100.0, layout=ProgressBar.RIGHT_LAYOUT,player=game.getEntityById('player-right'))) self.timer = Timer(layout={'top':70,'width':100,'height':20,'force-size':True}) self.pushLayerFront(self.timer) self.pushLayerFront(GUITextItem_(layout={'top':20,'width':100,'height':20},text=('ROUND #'+str(GLOBAL_STATE['round'])))) self.counters = {pid : GUITextItem_(layout={'top':40,pid[7:]:40,'width':0,'height':0},text=str(GLOBAL_STATE['player-left'])) for pid in ['player-left','player-right']} for z,x in self.counters.items(): self.pushLayerFront(x) GAME_CONSOLE.write('Startup screen created.')
def on_player_win(self,player): GAME_CONSOLE.write('Player #',player.id if player else 'NONE',' wins.') self.winner = player self.pushLayerFront(GUITextItem_( layout = { 'width': 10, 'height': 10, 'bottom': 100 }, text=((player.FIGHTER_NAME+ {'player-left':' (Player #1)', 'player-right':' (Player #2)'}[player.id]) if player else 'Nobody')+' wins!')) GLOBAL_STATE['round'] += 1 if player: self.game.getEntityById('camera-controller')._pad = [player.width*3,player.height*3 ] GLOBAL_STATE[player.id] += 1 self.freezeGame()
def init(self,*args,**kwargs): # self.pushLayerFront(StaticBackgroundLauer('rc/img/256x256bg.png','fill')) game = Game() game.loadFromJSON('rc/lvl/level0.json') self.pushLayerFront(GameLayer(game=game,camera=Camera())) ssound.Preload('rc/snd/1.wav',['alias0']) musmap = {0:'rc/snd/music/Welcome.mp3',1:'rc/snd/music/Time.mp3',2:'rc/snd/music/0x4.mp3'} for x in xrange(0,3): layer = GUITextItem( layout={ 'width':100, 'height':20, 'left':50, 'right':50, 'offset_y':70*x, 'padding':[20,10], 'force-size':False }, text=musmap[x]); layer.on('ui:click',(lambda x: lambda *a: music.Play(musmap[x],loop=True))(x)) self.pushLayerFront(layer) tile = _9Tiles(LoadTexture('rc/img/ui-frames.png'),Rect(left=0,bottom=0,width=12,height=12)) self.pushLayerFront(GUI9TileItem( tiles=tile, layout = { 'left': 100, 'right': 100, 'top': 200, 'bottom': 200 })) GAME_CONSOLE.write('Startup screen created.')
def on_player_win(self, player): GAME_CONSOLE.write('Player #', player.id if player else 'NONE', ' wins.') self.winner = player self.pushLayerFront( GUITextItem_(layout={ 'width': 10, 'height': 10, 'bottom': 100 }, text=((player.FIGHTER_NAME + { 'player-left': ' (Player #1)', 'player-right': ' (Player #2)' }[player.id]) if player else 'Nobody') + ' wins!')) GLOBAL_STATE['round'] += 1 if player: self.game.getEntityById('camera-controller')._pad = [ player.width * 3, player.height * 3 ] GLOBAL_STATE[player.id] += 1 self.freezeGame()
def win(self): GAME_CONSOLE.write('you are won!') self.next = Screen.new('WIN') self.endOfGame()
def foo(self): GAME_CONSOLE.write('your died!') self.next = Screen.new('DEATHSCREEN') self.endOfGame()
def init(self,*args,**kwargs): print "Inited" self._player = self._game.getEntityById('player') self._camera.setController(self._player) self._camera.scale = 0.35 GAME_CONSOLE.write('INI GL')
def consoleInfo(self,*args): GAME_CONSOLE.write("{} ({}) ".format(self.FIGHTER_NAME,self.id),*args)
def init(self, *args, **kwargs): self.winner = None self.freeze = False gl.glClearColor(0x1d / 255.0, 0x5b / 255.0, 0x70 / 255.0, 1) # self.pushLayerFront(StaticBackgroundLauer('rc/img/256x256bg.png','fill')) game = Game() self.camera = Camera() self.game = game self.game.listen('win') self.game.on('win', self.event('win')) game.loadFromJSON('rc/lvl/level0.json') for pid, pcl in PLAYER_CHOICES.items(): p = pcl() game.addEntity(p) # p.animations = 'rc/ani/player-test-'+pid+'.json' p.position = 500 if pid == 'player-right' else -500, 0 p.id = pid p.trigger('configured') self.gameLayer = GameLayer(game=game, camera=self.camera) self.pushLayerFront(self.gameLayer) self.pushLayerFront( HpProgressBar(grow_origin='top-left', expression=lambda: game.getEntityById('player-left'). health / 100.0, layout=ProgressBar.LEFT_LAYOUT, player=game.getEntityById('player-left'))) self.pushLayerFront( HpProgressBar(grow_origin='top-right', expression=lambda: game.getEntityById('player-right') .health / 100.0, layout=ProgressBar.RIGHT_LAYOUT, player=game.getEntityById('player-right'))) self.timer = Timer(layout={ 'top': 70, 'width': 100, 'height': 20, 'force-size': True }) self.pushLayerFront(self.timer) self.pushLayerFront( GUITextItem_(layout={ 'top': 20, 'width': 100, 'height': 20 }, text=('ROUND #' + str(GLOBAL_STATE['round'])))) self.counters = { pid: GUITextItem_(layout={ 'top': 40, pid[7:]: 40, 'width': 0, 'height': 0 }, text=str(GLOBAL_STATE['player-left'])) for pid in ['player-left', 'player-right'] } for z, x in self.counters.items(): self.pushLayerFront(x) GAME_CONSOLE.write('Startup screen created.')
def consoleInfo(self, *args): GAME_CONSOLE.write("{} ({}) ".format(self.FIGHTER_NAME, self.id), *args)