def show_corpse(self): """the event CORPSE, where the player can pay some money to loot the corpse """ _no_corpse = True with open(const.SAVE_FILE) as _file: try: save_data = json.load(_file) except: raise IOError( 'failed to read save file when checking whether there is corpses in the zone') # check whether there is corpses in the zone for _, _data in save_data.items(): if _data['zone']== self.player.zone and (not(_data['alive'])): _no_corpse = False # e.g self.corpse = 'slot1' self.corpse = _ break if _no_corpse: self.show_battle() return 1 #print('game changes into CORPSE status') #print('the COPRSE slot is ', self.corpse) self.game_status = 'CORPSE' materials.main_scr.sprites['enemy_sprite'].image = ( const.image_from_file( const.CORPSE_EVENT_IMG_FILE, const.GUI_ZIP_FILE)) materials.main_scr.sprites['enemy_sprite'].visible = True
def dice_equal(player, _enemy): if player.cri_dice == 2: show_message(const.BATTLE_MESSAGE['DiceDueceThirdTime']) player.cri_dice = 0 player.hp = player.hp / 2 _enemy.hp = _enemy.hp / 2 if player.hp < 1: player.hp = 1 if _enemy.hp < 1: _enemy.hp = 1 materials.sprites['strike'].visible = True materials.sprites['strike'].position = 400, 234 materials.sprites['strike'].image = (const.image_from_file( const.EXPLODE_IMG_FILE, const.GUI_ZIP_FILE)) materials.sprites['strike'].do( actions.MoveBy((0, 100), 1.3) + actions.MoveBy((0, -100), 1.3) + actions.FadeOut(0.5)) battle.show_hp_change(player, _enemy, 2, 0 - int(player.hp / 2), 0 - int(_enemy.hp / 2)) enemy.show_enemy(_enemy) elif player.cri_dice == 1: show_message(const.BATTLE_MESSAGE['DiceDueceTwice']) elif player.cri_dice == 0: show_message(const.BATTLE_MESSAGE['DiceDuece']) player.cri_dice += 1
def show_under_attack(self, cri_dice): '''show the action and the sprites when the player is attacked ''' _action = actions.RotateBy(15, 0.1) + actions.RotateBy(-15, 0.1) self.sprite.do(_action) _sprite = materials.sprites['strike'] _sprite.visible = True _sprite.position = 200, 340 if cri_dice == 1: _sprite.image = const.image_from_file( const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1.5)) elif cri_dice == 0: _sprite.image = const.image_from_file(const.STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1)) elif cri_dice == 2: _sprite.image = const.image_from_file(const.SUPER_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(2.5))
def show_under_attack(self, cri_dice=False): '''Show the action of enemy when attacked (shake) and the corresponding strike-sprite ''' _action = actions.RotateBy(-15, 0.1) + actions.RotateBy(15, 0.1) self.sprite.do(_action) _sprite = materials.sprites['strike'] _sprite.visible = True _sprite.position = 650,340 if cri_dice==1: _sprite.image = const.image_from_file( const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1.5)) elif cri_dice==0: _sprite.image = const.image_from_file( const.STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1)) elif cri_dice==2: _sprite.image = const.image_from_file( const.SUPER_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(2.5))
def set_stage(self, no): '''set the current stage ''' self.player.zone = no self.zone = no materials.front_layer.labels['zone_label'].element.text = ( const.ZONE_NAME[no]) my_main.image = const.image_from_file( const.ZONE_BACK_IMG_FILES[no], const.GUI_ZIP_FILE) # display the stage numbers of the zones where the player can access materials.front_layer.show_map_selector(self.max_stage, no)
def show_camp(self): """ the event CAMP, when the player can pay some money to recover the HP and Enchant the item(not implemented) """ # if the HP is full, generating a enemy insteadly if self.player.hp >= self.player.max_hp: self.show_battle() return 1 self.game_status = 'CAMP' materials.main_scr.sprites['enemy_sprite'].image = ( const.image_from_file(const.CAMP_EVENT_IMG_FILES[self.player.zone], const.GUI_ZIP_FILE)) materials.main_scr.sprites['enemy_sprite'].visible = True
# _ = '{:>2}:{:>2}'.format(str(int(t // 60)), str(int(t % 60))) # return _ def gen_anime_sprite(img, grid_x, grid_y, delay, loop, pos_x, pos_y): _image = pyglet.image.load(img) _anime = pyglet.image.ImageGrid(_image, grid_x, grid_y) _seq = pyglet.image.Animation.from_image_sequence(_anime, delay, loop) return cocos.sprite.Sprite(_seq, position=(pos_x, pos_y)) mixer.init() cocos.director.director.init(width=800, height=600, caption=const.GAME_TITLE) bg_img = const.image_from_file(const.BACKGROUND_IMG_FILE, const.GUI_ZIP_FILE) item_image = pyglet.image.ImageGrid(pyglet.image.load(const.ITEM_IMG_FILE), 60, 5) dice_image = pyglet.image.ImageGrid(pyglet.image.load(const.DICE_IMG_FILE), 5, 2) front_image = const.image_from_file(const.FRONT_IMG_FILE, const.GUI_ZIP_FILE) info_layer_image = const.image_from_file(const.INFO_LAYER_IMG_FILE, const.GUI_ZIP_FILE) images = { 'bg_img': bg_img, 'item_image': item_image, 'dice_image': dice_image, 'front_img': front_image, 'info_layer_img': info_layer_image
def gen_enemy(no=None, rank=None, zone=None, level=None): '''Generate a specific enemy ''' # check the rank of the enemy if rank is None: _r = random.randrange(100) if _r <= const.ENEMY_RATE['CHIEF_BOSS']: rank = 3 elif (const.ENEMY_RATE['CHIEF_BOSS']< _r <= const.ENEMY_RATE['CHIEF_BOSS'] + const.ENEMY_RATE['BOSS']): rank = 2 elif (const.ENEMY_RATE['CHIEF_BOSS'] + const.ENEMY_RATE['BOSS'] < _r <= const.ENEMY_RATE['CHIEF_BOSS'] + const.ENEMY_RATE['BOSS'] + const.ENEMY_RATE['ELITE']): rank = 1 else: rank = 0 if zone is None: zone = random.randrange(0,6) if level is None: level = random.randrange(1,61) #start to generate a enemy _enemy = Enemy() _enemy.rank = rank _enemy.level = level _enemy.zone = zone _enemy.value['Min_Dice'] = 1 # get a list of enemy skills _enemy_skill_no_list = [] for _ in range(len(const.SKILL_DATA)): if const.SKILL_DATA[_]['owner'] == 2: _enemy_skill_no_list.append(_) # shuffle the list random.shuffle(_enemy_skill_no_list) _list = [] _para = const.ENEMY_PARAMETER[str(rank)] _enemy.value['Atk'] = int(level ** 2.5 / 27885 * _para['ATK']) + _para['ATK0'] _enemy.value['max_hp'] = int(level ** 2.5 / 27885 * _para['MHP']) + _para['MHP0'] _enemy.value['CriDmg'] = _para['CRIDMG'] _enemy.value['Max_Dice'] = _para['MAX_DICE'] _list = _enemy_skill_no_list[0:_para['SKILL_COUNT_BY_ZONE'][zone]] # generate a chief-boss enemy! if rank == 3: no = 0 # here come bosses ! elif rank == 2: no = random.randrange(1,3) # here come elites ! elif rank == 1: no = random.randrange(3,31) # now comes the normal enemy elif rank == 0: no = random.randrange(3,31) else: raise ValueError('enemy rank error:', rank) # set no for test #no = 29 # now set the enemy type and confirm the Atk, CriDmg and Maxhp finally # firstly we set the atk _ = random.randrange(5) _enemy.type[0] = _ _enemy.value['Atk'] *= const.ENEMY_ATK_AFFIX[_] / 100 _enemy.value['Atk'] *= const.ENEMY_DATA[no]['Atk'] / 100 # then we set the critical damage _ = random.randrange(5) _enemy.type[1] = _ _enemy.value['CriDmg'] *= const.ENEMY_CRIDMG_AFFIX[_] / 100 _enemy.value['CriDmg'] *= const.ENEMY_DATA[no]['CriDmg'] / 100 # lastly we set the max hp _ = random.randrange(5) _enemy.type[2] = _ _enemy.value['max_hp'] *= const.ENEMY_MAXHP_AFFIX[_] / 100 _enemy.value['max_hp'] *= const.ENEMY_DATA[no]['max_hp'] / 100 _enemy.value['max_hp'] = int(_enemy.value['max_hp']) # check the enemy's passive(type 1) skills # other skills can be see in the battle.py for _ in _list: _enemy.skill.append(skill.Skill(_)) # add the enemy's passive skills # the skill 22: strong life if _ == 22: _enemy.value['max_hp'] *= 1.5 # the skill 23: stubborn, always have the same dice if _ == 23: _enemy.value['Max_Dice'] = int((_enemy.value['Max_Dice'] + 1) / 2) _enemy.value['Min_Dice'] = _enemy.value['Max_Dice'] _enemy.no = no _enemy.hp = _enemy.value['max_hp'] materials.main_scr.sprites['enemy_sprite'].visible = True _enemy.sprite = materials.main_scr.sprites['enemy_sprite'] # Now, get the sprite image of the enemy from the zip file _enemy_img_file = 'monster-' + str(_enemy.no) + '-' + str(_enemy.zone) #print('the enemy is', _enemy_img_file) # if the monster's image file is included in the zip file if _enemy_img_file in const.FILE_TYPE.keys(): _enemy.sprite.image = const.image_from_file(_enemy_img_file) # if there is no corresponding sprite image file else: _enemy.sprite.image = const.image_from_file( const.DEFAULT_MONSTER_IMG_FILE) _enemy.sprite.anchor=_enemy.sprite.width / 2, 0 return _enemy
def __init__(self, game): super(Main_Screen, self).__init__() self.game = game self.keys_pressed = set() self.image = image_from_file(const.ZONE_BACK_IMG_FILES[0], const.GUI_ZIP_FILE) if hasattr(materials.main_scr, 'sprites'): for _, _sprite in materials.main_scr.sprites.items(): self.add(_sprite) _sprite.visible = False if hasattr(materials, 'sprites'): for _, _sprite in materials.sprites.items(): self.add(_sprite) _sprite.visible = False if hasattr(materials, 'labels'): for _, _label in materials.labels.items(): self.add(_label) _label.visible = False if hasattr(materials.main_scr, 'labels'): for _, _label in materials.main_scr.labels.items(): self.add(_label) _label.visible = False materials.sprites['strike'].visible = False materials.sprites['explode'].visible = False materials.main_scr.sprites['icon_select'].visible = False materials.main_scr.sprites['icon_select'].scale = 0.25 for _ in range(8): materials.main_scr.sprites['loot' + str(_)].visible = False materials.main_scr.sprites['loot' + str(_)].scale = 0.4 if hasattr(materials, 'labels'): for _, _label in materials.labels.items(): self.add(_label) _label.visible = False # control sprite is always visible materials.main_scr.sprites['control'].visible = True # use the time interval event to calculate the time used self.schedule_interval(self.refresh_time, 0.1) _sprites = materials.main_scr.sprites for _ in range(3): _sprites['player_dice_' + str(_)].scale = 0.5 _sprites['player_dice_' + str(_)].visible = False _sprites['enemy_dice_' + str(_)].scale = 0.5 _sprites['enemy_dice_' + str(_)].visible = False # map the keys to methods of every status # the keys in GLOBAL status take effects always self.key_events = { "GLOBAL": { ("I", ): self.open_info, ("F2", ): self.return_menu }, "STARTED": { ("UP", "LEFT", "RIGHT"): self.choose_style }, "LOOT": { ("LEFT", "RIGHT"): self.move_loot_cursor, ("DOWN", "UP", "ENTER"): self.handle_loot }, "END": { ("LEFT", "RIGHT", "DOWN"): self.game.move_on, ("_1", "_2", "_3", "_4", "_5", "_6"): self.set_stage }, "GAME_OVER": { ("SPACE", ): self.return_menu }, "CORPSE": { ("LEFT", "DOWN"): self.game.move_on, ("UP", ): self.buy_corpse }, "CAMP": { ("LEFT", "DOWN"): self.game.move_on, ("UP", ): self.go_camp } }
#codetime: 2019/5/28 17:03:36 """THE MAIN SCREEN DEFINITION FILE """ import json import copy import pyglet import cocos from cocos.layer import Layer, ScrollableLayer import materials import random from data import const, player, enemy, battle, item from data.const import image_from_file images = {} player_image = image_from_file(const.PLAYER_IMG_FILE) enemy_image = image_from_file(const.ENEMY_IMG_FILE) icon_select_image = image_from_file(const.ICON_SELECT_IMG_FILE, const.GUI_ZIP_FILE) item_box_image = image_from_file(const.ITEM_BOX_IMG_FILE, const.GUI_ZIP_FILE) attack_style_image = pyglet.image.ImageGrid( pyglet.image.load(const.ATTACK_STYLE_IMG_FILE), 5, 2) attack_image = image_from_file(const.ATTACK_IMG_FILE, const.GUI_ZIP_FILE) defend_image = image_from_file(const.DEFEND_IMG_FILE, const.GUI_ZIP_FILE) luck_image = image_from_file(const.LUCK_IMG_FILE, const.GUI_ZIP_FILE) main_control_image = image_from_file(const.MAIN_CONTROL_IMG_FILE, const.GUI_ZIP_FILE) battle_control_image = image_from_file(const.BATTLE_CONTROL_IMG_FILE,
#Code by Crix @ [email protected] #https://github.com/crixthegreat/ #codetime: 2019/5/28 17:03:36 """The save & load layer definition file """ import os import json from data import const, player import pyglet import cocos from cocos.layer import Layer import materials images = {} save_load_bg_image = const.image_from_file(const.SAVE_LOAD_BG_IMG_FILE, const.GUI_ZIP_FILE) select_bar_image = const.image_from_file(const.SELECT_BAR_IMG_FILE, const.GUI_ZIP_FILE) empty_image = const.image_from_file(const.EMPTY_IMG_FILE, const.GUI_ZIP_FILE) message_box_image = const.image_from_file(const.MESSAGE_BOX_IMG_FILE, const.GUI_ZIP_FILE) """ time_label & best_time_label : as the name says """ labels = {} sprites = {} sprites['select_bar'] = cocos.sprite.Sprite(select_bar_image, position=(150, 425))
#Code by Crix @ [email protected] #https://github.com/crixthegreat/ #codetime: 2019/5/28 17:03:36 """The info layer definition file """ import copy from data import const, skill, item import pyglet import cocos from cocos.layer import Layer import materials images = {} single_item_box_image = const.image_from_file( const.SINGLE_ITEM_BOX_IMG_FILE, const.GUI_ZIP_FILE) single_equiped_item_box_image = const.image_from_file( const.SINGLE_EQUIPED_ITEM_BOX_IMG_FILE, const.GUI_ZIP_FILE) labels = {} labels['skill_description_label'] = cocos.text.Label('', font_size=10,font_name='Gadugi', bold=False,color=const.DEFAULT_COLOR, x=35, y=435, width = 10, multiline=True) labels['player_value_label'] = cocos.text.Label('', font_size=12.5,font_name='Gadugi', bold=False,color=const.DEFAULT_COLOR, x=295, y=562, width = 10, multiline=True) labels['item_box_page'] = cocos.text.Label('NA/NA', font_size=12,font_name='Gadugi',
bold=True, color=const.GREEN_COLOR, x=100, y=380) labels['player_hp_absorb_label'] = cocos.text.Label('', font_size=25, font_name='Gadugi', bold=True, color=const.GREEN_COLOR, x=200, y=380) sprites = {} _file_name = 'number-' for _ in range(6): _number_file_image = const.image_from_file(_file_name + str(_ + 1), const.GUI_ZIP_FILE) sprites['number' + str(_ + 1)] = cocos.sprite.Sprite(_number_file_image, position=(10, 10)) sprites['number' + str(_ + 1)].scale = 0.35 sprites['number' + str(_ + 1)].visible = False sprites['number1'].position = 160, 100 sprites['number2'].position = 50, 150 sprites['number3'].position = 25, 75 sprites['number4'].position = 100, 60 sprites['number5'].position = 140, 160 sprites['number6'].position = 200, 160 _anime = const.image_from_file(const.MAP_SELECT_IMG_FILE, const.GUI_ZIP_FILE) sprites['map_select'] = cocos.sprite.Sprite(_anime, position=(30, 30)) sprites['map_select'].scale = 0.35