<s> from __future__ import division <EOL> from cocos . actions import AccelDeccel <EOL> from cocos . actions import Delay <EOL> from cocos . actions import FadeTo <EOL> from cocos . actions import JumpBy <EOL> from cocos . actions import Move <EOL> from cocos . actions import MoveBy <EOL> from cocos . actions import Repeat <EOL> from cocos . actions import Reverse <EOL> from cocos . actions import RotateBy <EOL> from cocos . scenes . transitions import FlipAngular3DTransition <EOL> from pyglet . window import key <EOL> import cocos <EOL> import cocos . collision_model as cm <EOL> import pyglet <EOL> import resources <EOL> class Game ( cocos . layer . ColorLayer ) : <EOL> is_event_handler = True <EOL> def __init__ ( self ) : <EOL> super ( Game , self ) . __init__ ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> ) <EOL> self . collision_manager = cm . CollisionManagerBruteForce ( ) <EOL> self . player = cocos . sprite . Sprite ( resources . player ) <EOL> self . player . position = <NUM_LIT> , <NUM_LIT> <EOL> self . player . velocity = <NUM_LIT:0> , <NUM_LIT:0> <EOL> self . player . speed = <NUM_LIT> <EOL> self . add ( self . player , z = <NUM_LIT:2> ) <EOL> self . player . cshape = cm . AARectShape ( <EOL> self . player . position , <EOL> self . player . width // <NUM_LIT:2> , <EOL> self . player . height // <NUM_LIT:2> <EOL> ) <EOL> self . collision_manager . add ( self . player ) <EOL> self . boss = cocos . sprite . Sprite ( resources . boss ) <EOL> self . boss . position = <NUM_LIT> , <NUM_LIT> <EOL> self . boss . scale = <NUM_LIT> <EOL> self . add ( self . boss , z = <NUM_LIT:1> ) <EOL> self . boss . cshape = cm . AARectShape ( <EOL> self . boss . position , <EOL> self . boss . width // <NUM_LIT:2> , <EOL> self . boss . height // <NUM_LIT:2> <EOL> ) <EOL> self . collision_manager . add ( self . boss ) <EOL> self . batch = cocos . batch . BatchNode ( ) <EOL> self . enemies = [ cocos . sprite . Sprite ( resources . enemy ) <EOL> for i in range ( <NUM_LIT:6> ) ] <EOL> positions = ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> for num , enem in enumerate ( self . enemies ) : <EOL> enem . position = positions [ num ] <EOL> enem . cshape = cm . AARectShape ( <EOL> enem . position , <EOL> enem . width // <NUM_LIT:2> , <EOL> enem . height // <NUM_LIT:2> <EOL> ) <EOL> self . collision_manager . add ( enem ) <EOL> self . batch . add ( enem ) <EOL> self . add ( self . batch , z = <NUM_LIT:1> ) <EOL> self . player . do ( Move ( ) ) <EOL> move_basic = MoveBy ( ( <NUM_LIT> , <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> self . enemies [ <NUM_LIT:0> ] . do ( Repeat ( move_basic + Reverse ( move_basic ) ) ) <EOL> self . enemies [ <NUM_LIT:1> ] . do ( Repeat ( Reverse ( move_basic ) + move_basic ) ) <EOL> move_complex = ( MoveBy ( ( - <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1> ) + <EOL> Delay ( <NUM_LIT:0.5> ) + <EOL> MoveBy ( ( - <NUM_LIT> , - <NUM_LIT> ) , <NUM_LIT:1> ) + <EOL> Delay ( <NUM_LIT:0.5> ) + <EOL> MoveBy ( ( <NUM_LIT> , - <NUM_LIT> ) , <NUM_LIT:1> ) + <EOL> Delay ( <NUM_LIT:0.5> ) + <EOL> MoveBy ( ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1> ) + <EOL> Delay ( <NUM_LIT:0.5> ) ) <EOL> self . enemies [ <NUM_LIT:2> ] . do ( Repeat ( move_complex ) ) <EOL> self . enemies [ <NUM_LIT:3> ] . do ( Repeat ( Reverse ( move_complex ) ) ) <EOL> move_jump = AccelDeccel ( JumpBy ( ( <NUM_LIT:200> , <NUM_LIT:0> ) , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> move_jump_rot = AccelDeccel ( RotateBy ( <NUM_LIT> , <NUM_LIT:3> ) ) <EOL> self . enemies [ <NUM_LIT:4> ] . do ( Repeat ( move_jump + Reverse ( move_jump ) ) ) <EOL> self . enemies [ <NUM_LIT:4> ] . do ( Repeat ( move_jump_rot + Reverse ( move_jump_rot ) ) ) <EOL> self . enemies [ <NUM_LIT:5> ] . do ( Repeat ( Reverse ( move_jump ) + move_jump ) ) <EOL> self . enemies [ <NUM_LIT:5> ] . do ( Repeat ( Reverse ( move_jump_rot ) + move_jump_rot ) ) <EOL> self . schedule ( self . update ) <EOL> def on_enter ( self ) : <EOL> super ( Game , self ) . on_enter ( ) <EOL> try : <EOL> music_player . queue ( resources . game_music ) <EOL> except : <EOL> pass <EOL> music_player . play ( ) <EOL> music_player . eos_action = '<STR_LIT>' <EOL> def on_exit ( self ) : <EOL> super ( Game , self ) . on_exit ( ) <EOL> music_player . seek ( <NUM_LIT:1> ) <EOL> music_player . pause ( ) <EOL> def on_key_press ( self , symbol , modifiers ) : <EOL> if symbol == key . LEFT : <EOL> self . player . velocity = - self . player . speed , <NUM_LIT:0> <EOL> elif symbol == key . RIGHT : <EOL> self . player . velocity = self . player . speed , <NUM_LIT:0> <EOL> elif symbol == key . UP : <EOL> self . player . velocity = <NUM_LIT:0> , self . player . speed <EOL> elif symbol == key . DOWN : <EOL> self . player . velocity = <NUM_LIT:0> , - self . player . speed <EOL> elif symbol == key . SPACE : <EOL> self . player . velocity = <NUM_LIT:0> , <NUM_LIT:0> <EOL> def update ( self , dt ) : <EOL> self . player . cshape . center = self . player . position <EOL> for enem in self . enemies : <EOL> enem . cshape . center = enem . position <EOL> collisions = self . collision_manager . objs_colliding ( self . player ) <EOL> if collisions : <EOL> if self . boss in collisions : <EOL> print ( "<STR_LIT>" ) <EOL> cocos . director . director . pop ( ) <EOL> class MainMenu ( cocos . menu . Menu ) : <EOL> def __init__ ( self ) : <EOL> super ( MainMenu , self ) . __init__ ( '<STR_LIT>' ) <EOL> self . font_title [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . font_title [ '<STR_LIT>' ] = <NUM_LIT> <EOL> self . font_title [ '<STR_LIT>' ] = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:255> ) <EOL> self . font_item [ '<STR_LIT>' ] = ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) <EOL> self . font_item_selected [ '<STR_LIT>' ] = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:255> ) <EOL> items = [ ] <EOL> items . append ( cocos . menu . MenuItem ( '<STR_LIT>' , self . on_new_game ) ) <EOL> items . append ( cocos . menu . MenuItem ( '<STR_LIT>' , self . on_options ) ) <EOL> items . append ( cocos . menu . MenuItem ( '<STR_LIT>' , self . on_quit ) ) <EOL> self . create_menu ( items , cocos . menu . shake ( ) , cocos . menu . shake_back ( ) ) <EOL> def on_new_game ( self ) : <EOL> game_layer = Game ( ) <EOL> game_scene = cocos . scene . Scene ( game_layer ) <EOL> cocos . director . director . push ( <EOL> FlipAngular3DTransition ( game_scene , <NUM_LIT:1> ) ) <EOL> def on_options ( self ) : <EOL> self . parent . switch_to ( <NUM_LIT:1> ) <EOL> def on_quit ( self ) : <EOL> pyglet . app . exit ( ) <EOL> class OptionsMenu ( cocos . menu . Menu ) : <EOL> def __init__ ( self ) : <EOL> super ( OptionsMenu , self ) . __init__ ( '<STR_LIT>' ) <EOL> self . font_title [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . font_title [ '<STR_LIT>' ] = <NUM_LIT> <EOL> self . font_title [ '<STR_LIT>' ] = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:255> ) <EOL> self . font_item [ '<STR_LIT>' ] = ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) <EOL> self . font_item_selected [ '<STR_LIT>' ] = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:255> ) <EOL> items = [ ] <EOL> items . append ( cocos . menu . ToggleMenuItem ( <EOL> '<STR_LIT>' , <EOL> self . on_show_fps , <EOL> cocos . director . director . show_FPS ) <EOL> ) <EOL> items . append ( cocos . menu . MenuItem ( '<STR_LIT>' , self . on_fullscreen ) ) <EOL> items . append ( cocos . menu . MenuItem ( '<STR_LIT>' , self . on_quit ) ) <EOL> self . create_menu ( items , cocos . menu . shake ( ) , cocos . menu . shake_back ( ) ) <EOL> def on_fullscreen ( self ) : <EOL> cocos . director . director . window . set_fullscreen ( <EOL> not cocos . director . director . window . fullscreen ) <EOL> def on_quit ( self ) : <EOL> self . parent . switch_to ( <NUM_LIT:0> ) <EOL> def on_show_fps ( self , value ) : <EOL> cocos . director . director . show_FPS = value <EOL> class BackgroundLayer ( cocos . layer . Layer ) : <EOL> def __init__ ( self ) : <EOL> super ( BackgroundLayer , self ) . __init__ ( ) <EOL> self . image = cocos . sprite . Sprite ( resources . background ) <EOL> self . image . position = <NUM_LIT> , <NUM_LIT> <EOL> self . add ( self . image , z = <NUM_LIT:0> ) <EOL> self . player = cocos . sprite . Sprite ( resources . player ) <EOL> self . player . position = <NUM_LIT:200> , <NUM_LIT> <EOL> self . add ( self . player , z = <NUM_LIT:1> ) <EOL> self . enemy = cocos . sprite . Sprite ( resources . enemy ) <EOL> self . enemy . position = <NUM_LIT> , <NUM_LIT> <EOL> self . add ( self . enemy , z = <NUM_LIT:1> ) <EOL> self . boss = cocos . sprite . Sprite ( resources . boss ) <EOL> self . boss . scale = <NUM_LIT> <EOL> rect = self . boss . get_rect ( ) <EOL> rect . midbottom = <NUM_LIT> , <NUM_LIT:50> <EOL> self . boss . position = rect . center <EOL> self . add ( self . boss , z = <NUM_LIT:1> ) <EOL> self . player . do ( Repeat ( JumpBy ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT:100> , <NUM_LIT:1> , <NUM_LIT:1> ) ) ) <EOL> self . enemy . do ( Repeat ( <EOL> MoveBy ( ( - <NUM_LIT> , <NUM_LIT:0> ) , <NUM_LIT> ) + <EOL> MoveBy ( ( <NUM_LIT:50> , <NUM_LIT:0> ) , <NUM_LIT:0.5> ) + <EOL> MoveBy ( ( - <NUM_LIT> , <NUM_LIT:0> ) , <NUM_LIT> ) ) ) <EOL> self . boss . do ( Repeat ( FadeTo ( <NUM_LIT> , <NUM_LIT:0.5> ) + FadeTo ( <NUM_LIT:255> , <NUM_LIT:0.5> ) ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> cocos . director . director . init ( <EOL> width = <NUM_LIT> , <EOL> height = <NUM_LIT> , <EOL> caption = "<STR_LIT>" <EOL> ) <EOL> music_player = pyglet . media . Player ( ) <EOL> music_player . volume = <NUM_LIT:1> <EOL> scene = cocos . scene . Scene ( ) <EOL> scene . add ( cocos . layer . MultiplexLayer ( MainMenu ( ) , OptionsMenu ( ) ) , z = <NUM_LIT:1> ) <EOL> scene . add ( BackgroundLayer ( ) , z = <NUM_LIT:0> ) <EOL> cocos . director . director . run ( scene ) </s>
