class Tile(): def __init__(self, image, posx, posy ,map_posx, map_posy): w, h = director.get_window_size() sc = 1920/w self.namenumber = 0 self.name = 'floor' self.map_pos_x = map_posx self.map_pos_y = map_posy self.open_P = 0 self.sprite = Sprite(Images.tile_image[self.name], (posx, posy), scale = 1/sc) self.sprite_smoke = Sprite(Images.tile_image['smoke'], (posx, posy), scale = 1/sc) self.monster = 0 self.smoke = 0 self.buildav = 1 self.wall = 0 def next_turn(self): if self.smoke: self.smoke = self.smoke - 1 def next_turn_DM(self): self.buildav = 1 if (self.open_P) or (self.smoke): self.buildav = 0 def on_click_P(self): self.open_P = 1 def draw(self): self.sprite.image = Images.tile_image[self.name] self.sprite.draw() if self.smoke: self.sprite_smoke.draw()
class ImageMenuItem (BaseMenuItem): """ A menu item that shows a selectable Image """ def __init__(self, image, callback_func, *args, **kwargs): if isinstance(image, string_types): image = pyglet.resource.image(image) self.image = image super(ImageMenuItem, self).__init__(callback_func, *args, **kwargs) def generateWidgets(self, pos_x, pos_y, font_item, font_item_selected): anchors = {'left': 0, 'center': 0.5, 'right': 1, 'top': 1, 'bottom': 0} anchor = (anchors[font_item['anchor_x']] * self.image.width, anchors[font_item['anchor_y']] * self.image.height) self.item = Sprite(self.image, anchor=anchor, opacity=255, color=font_item['color'][:3]) self.item.scale = font_item['font_size'] / float(self.item.height) self.item.position = int(pos_x), int(pos_y) self.selected_item = Sprite(self.image, anchor=anchor, color=font_item_selected['color'][:3]) self.selected_item.scale = (font_item_selected['font_size'] / float(self.selected_item.height)) self.selected_item.position = int(pos_x), int(pos_y) def draw(self): glPushMatrix() self.transform() if self.is_selected: self.selected_item.draw() else: self.item.draw() glPopMatrix()
class BuildingMenu(Layer): def __init__(self): super(BuildingMenu, self).__init__() self.end_of_init() def end_of_init(self): w, h = director.get_window_size() sc = 1920//w self.visible = 0 self.b_types = {} self.b_types[0] = SecondB_menu('trap', 0) self.b_types[1] = SecondB_menu('monster', 1) self.b_types[2] = SecondB_menu('magic', 2) self.b_types[3] = SecondB_menu('wall', 3) self.scroll = Sprite(Images.menu_scroll, (1500//sc, 380//sc), scale = 1/sc) self.active = -1 def draw(self): if self.visible: w, h = director.get_window_size() sc = 1920//w self.scroll.draw() for b_type in self.b_types: self.b_types[b_type].sprite.draw() if self.active == b_type: self.b_types[b_type].draw()
class ImageMenuItem(BaseMenuItem): """ A menu item that shows a selectable Image """ def __init__(self, image, callback_func, *args, **kwargs): if isinstance(image, string_types): image = pyglet.resource.image(image) self.image = image super(ImageMenuItem, self).__init__(callback_func, *args, **kwargs) def generateWidgets(self, pos_x, pos_y, font_item, font_item_selected): anchors = {'left': 0, 'center': 0.5, 'right': 1, 'top': 1, 'bottom': 0} anchor = (anchors[font_item['anchor_x']] * self.image.width, anchors[font_item['anchor_y']] * self.image.height) self.item = Sprite(self.image, anchor=anchor, opacity=255, color=font_item['color'][:3]) self.item.scale = font_item['font_size'] / float(self.item.height) self.item.position = int(pos_x), int(pos_y) self.selected_item = Sprite(self.image, anchor=anchor, color=font_item_selected['color'][:3]) self.selected_item.scale = (font_item_selected['font_size'] / float(self.selected_item.height)) self.selected_item.position = int(pos_x), int(pos_y) def draw(self): glPushMatrix() self.transform() if self.is_selected: self.selected_item.draw() else: self.item.draw() glPopMatrix()
def draw(self): w, h = director.get_window_size() sc = 1920/w if (self.hero.turnav > 0): c = Sprite(Images.hero_icons[self.hero.name], ((1235 + Icon_size*self.number*1.1)//sc, 960//sc), scale = 1/sc) else: c = Sprite(Images.hero_icons_black[self.hero.name], ((1235 + Icon_size*self.number*1.1)//sc, 960//sc), scale = 1/sc) c.draw()
class Coin (Layer): def __init__(self): super(Coin, self).__init__() w, h = director.get_window_size() self.coins = [pyglet.resource.image('coins/coin%s.png' % coin_image) for coin_image in range(Coin_image_number)] self.coin_anim = pyglet.image.Animation.from_image_sequence(self.coins, 0.1, True) self.coin = Sprite(self.coin_anim, (w - 300, h - 50)) def draw(self): self.coin.draw()
class Art_get_layer(ColorLayer): is_event_handler = True def __init__(self, main_layer, artmenu): super(Art_get_layer,self).__init__(0,0,32,64) self.main_layer = main_layer w,h = director.get_window_size() sc = 1920/w self.sprite = Sprite(Images.art_choise, (960//sc, 540//sc), scale = 1/sc) self.art_menu = artmenu def on_click(self, mouse_x, mouse_y): w,h = director.get_window_size() sc = 1920/w get_art = False if (mouse_x*sc >= 265 - 75) and (mouse_x*sc <= 265 + 75): if (mouse_y*sc >= 827 - 75) and (mouse_y*sc <= 827 + 75): get_art = True number = 0 if (mouse_y*sc >= 567 - 75) and (mouse_y*sc <= 567 + 75): get_art = True number = 1 if (mouse_y*sc >= 307 - 75) and (mouse_y*sc <= 307 + 75): get_art = True number = 2 if (mouse_x*sc >= 975 - 75) and (mouse_x*sc <= 975 + 75): if (mouse_y*sc >= 827 - 75) and (mouse_y*sc <= 827 + 75): get_art = True number = 3 if (mouse_y*sc >= 567 - 75) and (mouse_y*sc <= 567 + 75): get_art = True number = 4 if (mouse_y*sc >= 307 - 75) and (mouse_y*sc <= 307 + 75): get_art = True number = 5 if (get_art): hero = self.art_menu.hero art_name = Art_menu[hero.name][hero.art_cell + 1][number] if (hero.av_art.count(art_name)): art = Artefact(art_name, hero.art_cell) hero.staff.update({hero.art_cell : art}) hero.av_art.remove(art_name) for i in range(5): if (hero.staff.get(i) == None): hero.art_cell = i break art.on_get(hero) self.main_layer.status = 'usuall' self.main_layer.remove(self.main_layer.art_get_layer) self.main_layer.art_get_layer = 0 def draw(self): self.sprite.draw() self.art_menu.draw()
class Buttons (Layer): def __init__(self): super(Buttons, self).__init__() self.img = pyglet.resource.image('next_turn.png') w, h = director.get_window_size(); self.nextturn_button = Sprite(self.img, (w - Button_size/2, Button_size/2)) def draw ( self ): self.nextturn_button.draw()
def draw(self): w, h = director.get_window_size() sc = 1920//w c = Sprite(Images.frame_black, (1100//sc, (580 - self.number*B_Menu_size*1.1)//sc), scale = 1/sc) c.draw() for object in range(len(self.objects)): dx, dy = self.get_coordinates(object) c = Sprite(Images.B_images[self.name][object], ((1315 + dx)//sc, (505 + dy)//sc), scale = 1/sc) c.draw()
class Background(Layer): def __init__(self): Layer.__init__(self) image = pyglet.resource.image(resconfig.battle_ground_1) self.backgound = Sprite(image, position=(image.width/2, image.height/2)) def draw(self, *args, **kwargs): self.backgound.draw()
class Buttons(Layer): def __init__(self): super(Buttons, self).__init__() self.img = pyglet.resource.image('next_turn.png') w, h = director.get_window_size() self.nextturn_button = Sprite(self.img, (w - Button_size / 2, Button_size / 2)) def draw(self): self.nextturn_button.draw()
def draw(self): w, h = director.get_window_size() sc = 1920/w c = Sprite(Images.portraits[self.hero.name], (1400//sc, 480//sc), scale = 1/sc) c.draw() c = HeroStats(self.hero) c.draw() for art in self.hero.staff: self.hero.staff[art].draw() for skill in self.hero.skills: skill.draw()
class Coin(Layer): def __init__(self): super(Coin, self).__init__() w, h = director.get_window_size() self.coins = [ pyglet.resource.image('coins/coin%s.png' % coin_image) for coin_image in range(Coin_image_number) ] self.coin_anim = pyglet.image.Animation.from_image_sequence( self.coins, 0.1, True) self.coin = Sprite(self.coin_anim, (w - 300, h - 50)) def draw(self): self.coin.draw()
class Artefact(): def __init__(self, name, number): w, h = director.get_window_size() sc = 1920/w self.name = name self.number = number self.sprite = Sprite(Images.art_image[self.name], ((1562 + 75/2)//sc, (899 - art_pos[self.number])//sc), scale = 1/sc) def on_get(self, hero): if (ArtEffects.get(self.name)): ArtEffects[self.name](hero).effect() def draw(self): self.sprite.draw()
class TestLayer(cocos.layer.Layer): def __init__(self): super(TestLayer, self).__init__() self.x, self.y = director.get_window_size() self.sprite = Sprite('runner1.png') self.sprite.position = self.x // 3, self.y // 3 self.add(self.sprite) self.brick = pyglet.image.load("../assets/brick.png") def draw(self): self.brick.blit(self.x // 2, self.y // 2) self.sprite.draw()
def draw(self): w, h = director.get_window_size() for i in range(self.mapx): for j in range (self.mapy): c = self.parent.model.map.get((i, j)) if (c.open_P == 1): c.draw() elif (c.open_P == 0): greytile = Sprite(Images.greytile, c.position) greytile.draw() wiz = self.parent.model.wizard wiz.draw() for dx, dy in adject_tiles: i = wiz.map_posx + dx j = wiz.map_posy + dy if (i >= 0) and (j >= 0) and (i < self.mapx) and (j < self.mapy): Sprite(Images.frame_blue, ((2*i + 1)*Tile_size/2 + left_space, (2*j + 1)*Tile_size/2 + (h - Quad_side*Tile_size)/2)).draw()
def draw(self): w, h = director.get_window_size() for i in range(self.mapx): for j in range(self.mapy): c = self.parent.model.map.get((i, j)) if (c.open_P == 1): c.draw() elif (c.open_P == 0): greytile = Sprite(Images.greytile, c.position) greytile.draw() wiz = self.parent.model.wizard wiz.draw() for dx, dy in adject_tiles: i = wiz.map_posx + dx j = wiz.map_posy + dy if (i >= 0) and (j >= 0) and (i < self.mapx) and (j < self.mapy): Sprite(Images.frame_blue, ((2 * i + 1) * Tile_size / 2 + left_space, (2 * j + 1) * Tile_size / 2 + (h - Quad_side * Tile_size) / 2)).draw()
class Skill(): def __init__(self, name, number, hero, model): w, h = director.get_window_size() sc = 1920/w self.name = name self.number = number self.sprite = Sprite(Images.skill_image[self.name], ((1208)//sc, (899 - skill_pos[self.number])//sc), scale = 1/sc) self.skill = Skills[self.name](hero , model) def draw(self): w, h = director.get_window_size() sc = 1920/w if (self.skill.learnt): self.sprite.draw() if self.skill.cd_left: self.label = Label('%d' %self.skill.cd_left, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) ) self.label.position = ((1208)//sc, (899 - skill_pos[self.number])//sc) self.label.draw() def use(self): if self.skill.available: self.skill.use()
class Hero_portriat_DM(): def reload(self, model, hero_name): w, h = director.get_window_size() sc = 1920/w self.model = model self.name = hero_name if self.name == 'wizard': self.hero = self.model.heroes[self.name] self.sprite = Sprite(Images.hero_icons[self.name], (1600//sc, 900//sc), scale = 1/sc) self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1600//sc, 900//sc), scale = 1/sc) self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) ) self.label.position = 1600//sc, 870//sc if self.name == 'priest': self.hero = self.model.heroes[self.name] self.sprite = Sprite(Images.hero_icons[self.name], (1720//sc, 900//sc), scale = 1/sc) self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1720//sc, 900//sc), scale = 1/sc) self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) ) self.label.position = 1720//sc, 870//sc if self.name == 'warrior': self.hero = self.model.heroes[self.name] self.sprite = Sprite(Images.hero_icons[self.name], (1600//sc, 780//sc), scale = 1/sc) self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1600//sc, 780//sc), scale = 1/sc) self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) ) self.label.position = 1600//sc, 750//sc if self.name == 'rogue': self.hero = self.model.heroes[self.name] self.sprite = Sprite(Images.hero_icons[self.name], (1720//sc, 780//sc), scale = 1/sc) self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1720//sc, 780//sc), scale = 1/sc) self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) ) self.label.position = 1720//sc, 750//sc def draw(self): if self.hero.alive: self.sprite.draw() self.label.font_name = '%d' %self.hero.stats.health self.label.draw() else: self.sprite_black.draw()
def draw(self): w, h = director.get_window_size() sc = 1920/w #Drawing the map for i in range(self.mapx): for j in range (self.mapy): c = self.parent.model.map.get((i, j)) #Checking that tile have been opened if (c.open_P == 1): c.draw() elif (c.open_P == 0): greytile = Sprite(Images.greytile, c.sprite.position, scale = 1/sc) greytile.draw() if c.smoke: c.sprite_smoke.draw() hero = self.actual_hero if (hero.alive): hero.portrait.draw() #Drawing heroes for hero_name in self.parent.model.heroes: hero = self.parent.model.heroes[hero_name] #print(hero.name) if (hero.alive): hero.draw() hero = self.actual_hero #Drawing blue frames for available turns if (hero.turnav) or (self.cheat): for dx, dy in adject_tiles: i = hero.map_posx + dx j = hero.map_posy + dy if (i >= 0) and (j >= 0) and (i < self.mapx) and (j < self.mapy): Sprite(Images.frame_blue, (((2*i + 1)*Tile_size/2 + left_space)//sc, (2*j + 1)*Tile_size/2//sc + (h - Quad_side*Tile_size//sc)/2), scale = 1/sc).draw()
def draw(self): w, h = director.get_window_size() sc = 1920/w #Actual square drawing if (self.act_tile): c = Sprite(self.act_tile.sprite.image, (1320//sc, 830//sc), scale = 3.5/sc) c.draw() #map drawing for i in range(self.mapx): for j in range (self.mapy): c = self.model.map.get((i, j)) c.draw() #Drawing blue frames for opened tiles if (c.open_P == 1): Sprite(Images.frame_blue, (((2*i + 1)*Tile_size/2 + left_space)//sc, (2*j + 1)*Tile_size/2//sc + (h - Quad_side*Tile_size//sc)/2), scale= 1/sc).draw() #Drawing heroes for hero_name in self.parent.model.heroes: hero = self.parent.model.heroes[hero_name] if (hero.alive): hero.sprite.draw() if (self.act_tile): i, j = self.act_tile.map_pos_x, self.act_tile.map_pos_y Sprite(Images.frame_yellow, (((2*i + 1)*Tile_size/2 + left_space)//sc, (2*j + 1)*Tile_size/2//sc + (h - Quad_side*Tile_size//sc)/2), scale = 1/sc).draw() self.model.interface_DM.draw() if (self.act_tile): if (self.act_tile.buildav): self.building_menu.draw()
class Hero(): def __init__(self, name, number ,model, map_posx, map_posy): w, h = director.get_window_size() sc = 1920/w self.name = name self.number = number self.map_posx = map_posx self.map_posy = map_posy self.sprite = Sprite(Images.heroes[self.name], scale = 1/sc) self.sprite.position = (((2*self.map_posx + 1)*Tile_size/2 + left_space)//sc, ((2*self.map_posy + 1)*Tile_size/2 + (h*sc - Quad_side*Tile_size)/2)//sc) self.portrait = Portraits(self) self.icon = Icons(self) self.alive = 1 self.techstats = Tech_Stats(self.name) self.stats = Stats(self.name) self.staff = [] self.av_art = list(Artefacts) self.model = model self.turnav = self.techstats.speed self.stats.health = self.techstats.max_health self.skills = [] for s in Hero_skills[self.name]: self.skills.append(Skill(s[0], s[1], self, self.model)) def replace_hero(self, map_posx, map_posy): w, h = director.get_window_size() sc = 1920/w self.map_posx = map_posx self.map_posy = map_posy self.sprite.position = (((2*self.map_posx + 1)*Tile_size/2 + left_space)//sc, ((2*self.map_posy + 1)*Tile_size/2 + (h*sc - Quad_side*Tile_size)/2)//sc) def on_turn(self, tile): self.turnav = self.turnav - 1 replace_hero = 1 if (tile.name == 'lava'): self.model.controler.damage_hero(self.name, lava_damage) if (tile.name == 'wall'): replace_hero = 0 if (tile.monster): result = tile.monster.monster.fight(self) if result == 'lose': replace_hero = 0 if (tile.open_P == 0): self.stats.exp = self.stats.exp + self.techstats.exp_per_tile if self.stats.lvl < maxlvl: if (self.stats.exp >= ExpNeed[self.stats.lvl]): self.model.controler.lvlup_hero(self.name) if (tile.name == 'floor'): self.stats.luck = self.stats.luck + self.techstats.luck_per_tile if self.stats.luck >= 100: self.stats.luck = self.stats.luck - 100 if (len(self.staff) < 5): self.stats.luck = 0 self.model.on_artget(self) '''art_name = self.av_art[random.randint(0, len(self.av_art) - 1)] art = Artefact(art_name, len(self.staff)) self.av_art.remove(art_name) self.staff.append(art) art.on_get(self)''' if replace_hero: self.replace_hero(tile.map_pos_x, tile.map_pos_y) if (tile.name == 'treasure'): self.model.on_youwin() def draw(self): self.sprite.draw() self.icon.draw()
class Hero(): def __init__(self, name, number ,model, map_posx, map_posy): w, h = director.get_window_size() sc = 1920/w self.name = name self.number = number self.map_posx = map_posx self.map_posy = map_posy self.sprite = Sprite(Images.heroes[self.name], scale = 1/sc) self.sprite.position = (((2*self.map_posx + 1)*Tile_size/2 + left_space)//sc, ((2*self.map_posy + 1)*Tile_size/2 + (h*sc - Quad_side*Tile_size)/2)//sc) self.portrait = Portraits(self) self.icon = Icons(self) self.alive = 1 self.techstats = Tech_Stats(self.name) self.stats = Stats(self.name) self.staff = {} self.av_art = list(Artefacts) self.art_cell = 0 self.model = model self.turnav = self.techstats.speed self.stats.health = self.techstats.max_health self.skills = [] self.effects = Hero_effects(self, self.model) for s in Hero_skills[self.name]: self.skills.append(Skill(s[0], s[1], self, self.model)) def replace_hero(self, map_posx, map_posy): w, h = director.get_window_size() sc = 1920/w self.map_posx = map_posx self.map_posy = map_posy self.sprite.position = (((2*self.map_posx + 1)*Tile_size/2 + left_space)//sc, ((2*self.map_posy + 1)*Tile_size/2 + (h*sc - Quad_side*Tile_size)/2)//sc) def on_turn(self, tile): self.turnav = self.turnav - 1 replace_hero = 1 if (tile.name == 'lava'): self.model.controler.damage_hero(self.name, lava_damage) if (tile.name == 'ice'): self.turnav = 0 self.effects.miss_turn = 1 if (tile.name == 'poison'): self.effects.trap_poison = trap_poison_duration if (tile.name == 'wall'): replace_hero = 0 if (tile.monster): result = tile.monster.monster.fight(self) if result == 'lose': replace_hero = 0 if result == 'win': self.on_win() if (tile.open_P == 0): self.stats.exp = self.stats.exp + self.techstats.exp_per_tile if self.stats.lvl < maxlvl: if (self.stats.exp >= ExpNeed[self.stats.lvl]): self.model.controler.lvlup_hero(self.name) if (tile.name == 'floor'): self.stats.luck = self.stats.luck + self.techstats.luck_per_tile if self.stats.luck >= 100: if (self.stats.lvl >= self.art_cell + 1): self.stats.luck = self.stats.luck - 100 if (len(self.staff) < 5): self.stats.luck = 0 self.model.on_artget(self) else: self.stats.luck = self.stats.luck - self.techstats.luck_per_tile if replace_hero: self.replace_hero(tile.map_pos_x, tile.map_pos_y) if (tile.name == 'treasure'): self.model.on_youwin() self.effects.on_turn_effects() def on_win(self): if self.effects.drain_life: self.stats.health = self.stats.health + drain_health self.techstats.max_health = self.techstats.max_health + drain_health self.stats.armor = self.stats.armor + drain_armor self.stats.attack = self.stats.attack + drain_attack def draw(self): self.sprite.draw() self.icon.draw() def reload(self): self.turnav = self.techstats.speed self.effects.reload()