def mark_valid_rails(self, combat_train, py, maxdist): cell = self.map.cells for tx in range(1, len(cell) - 1, 1): if (("trn_" + str(tx - 1) + "_" + str(py) in self.combatants) and (self.combatants["trn_" + str(tx - 1) + "_" + str(py)].combatant == "Locomotive")) and ( ("trn_" + str(tx) + "_" + str(py) in self.combatants) and (self.combatants["trn_" + str(tx) + "_" + str(py)].combatant != "Locomotive")): for addx in range(0, maxdist, 1): if combat_train.right_tx + addx < len(cell): self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)] = {} self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)]["dist"] = addx + 1 cell[tx + addx][py].properties["dist"] = str(addx + 1) self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)]["type"] = "move" square = Sprite( self.gallery.content["trn"] ["valid_square_" + self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)]["type"]], position=(((tx + addx + 0.5) * self.map.tw, (py + 0.5) * self.map.tw))) self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)]["sprite"] = square self.valid_squares["trn_" + str(tx + addx) + "_" + str(py)]["pos"] = (tx + addx, py) self.map.add(square) for tx in range(len(cell) - 2, 1, -1): if (("trn_" + str(tx + 1) + "_" + str(py) in self.combatants) and (self.combatants["trn_" + str(tx + 1) + "_" + str(py)].combatant == "Locomotive")) and ( ("trn_" + str(tx) + "_" + str(py) in self.combatants) and (self.combatants["trn_" + str(tx) + "_" + str(py)].combatant != "Locomotive")): for addx in range(0, maxdist, 1): if combat_train.left_tx - addx > 0: self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)] = {} self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)]["dist"] = -addx - 1 cell[tx - addx][py].properties["dist"] = str(-addx - 1) self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)]["type"] = "move" square = Sprite( self.gallery.content["trn"] ["valid_square_" + self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)]["type"]], position=(((tx - addx + 0.5) * self.map.tw, (py + 0.5) * self.map.tw))) self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)]["sprite"] = square self.valid_squares["trn_" + str(tx - addx) + "_" + str(py)]["pos"] = (tx - addx, py) self.map.add(square)
def say_hello(self): print "HELLO BABY" sprite2 = Sprite(self.image_sister1) self.add(sprite2) sprite2.position = 270, 110
def check_LOS(self, target): self.LOS.end = target tw = self.map.tw cell = self.map.cells if abs(self.LOS.start[0] - self.LOS.end[0]) > abs(self.LOS.start[1] - self.LOS.end[1]): axis = 0 else: axis = 1 if self.LOS.start[axis] > self.LOS.end[axis]: step = -4 else: step = 4 cc = (-1, -1) for pa in range(self.LOS.start[axis], self.LOS.end[axis], step): if axis == 0: px = pa py = ( ((self.LOS.end[1] - self.LOS.start[1]) * (px - self.LOS.start[0])) // (self.LOS.end[0] - self.LOS.start[0])) + self.LOS.start[1] else: py = pa px = ( ((self.LOS.end[0] - self.LOS.start[0]) * (py - self.LOS.start[1])) // (self.LOS.end[1] - self.LOS.start[1])) + self.LOS.start[0] cx, cy = director.get_virtual_coordinates(px, py) ctx = int((cx + self.map.view_x) / tw) cty = int((cy + self.map.view_y - self.viewport_height) / tw) if cc != (ctx, cty): cc = (ctx, cty) if (ctx < 0) or (ctx >= len(cell)) or (cty < 0) or ( cty >= len(cell[ctx]) ) or cell[ctx][cty].properties["terrain"] == "h": break else: if ("trn_" + str(ctx) + "_" + str(cty) not in self.valid_squares): if ("trn_" + str(ctx) + "_" + str(cty) in self.combatants) and ( self.combatants["trn_" + str(ctx) + "_" + str(cty)].side == "_vu"): self.valid_squares["trn_" + str(ctx) + "_" + str(cty)] = {} self.valid_squares["trn_" + str(ctx) + "_" + str(cty)]["dist"] = 99 cell[ctx][cty].properties["dist"] = 99 self.valid_squares["trn_" + str(ctx) + "_" + str(cty)]["type"] = "ranged" square = Sprite( self.gallery.content["trn"] ["valid_square_" + self.valid_squares["trn_" + str(ctx) + "_" + str(cty)]["type"]], position=(((ctx + 0.5) * self.map.tw, (cty + 0.5) * self.map.tw))) self.valid_squares["trn_" + str(ctx) + "_" + str(cty)]["sprite"] = square self.valid_squares["trn_" + str(ctx) + "_" + str(cty)]["pos"] = (ctx, cty) self.map.add(square)
def __init__(self): super().__init__() self.add( Sprite('background.png', position=(size[0] // 2, size[1] // 2)))
def __init__(self, model): super().__init__() self.model = model self.sprites = [Sprite(IMAGES[None]) for _ in range(16)]
def register_events(self): """puts switches and cities on the map""" self.update_properties() for tx, x in enumerate(self.get("rails").cells): for ty, y in enumerate(x): cell = self.get("rails").cells[tx][ty] if y.tile and "switch" in y.properties: if len(self.config.loaded_objects) > 0: for id in self.POI: if self.POI[id]["px"] == tx and self.POI[id][ "py"] == ty and self.POI[id][ "type"] == "switch" and self.POI[id][ "status"] == "on": self.switch_switch(tx, ty) else: self.POI[len(self.POI)] = { "px": tx, "py": ty, "type": "switch", "status": "off" } if y.tile and "bridge" in y.properties: if len(self.config.loaded_objects) > 0: for id in self.POI: if self.POI[id]["px"] == tx and self.POI[id][ "py"] == ty and self.POI[id][ "type"] == "bridge": y.properties["damaged"] = self.POI[id][ "status"] if self.POI[id]["status"] == "N": bridge = Sprite( self.gallery.content["bridge"][ y.tile.properties["directions"]], position=((tx + 0.5) * self.get("rails").tw, (ty + 0.5) * self.get("rails").tw)) self.get("rails").add(bridge, name="bridge_" + str(tx) + "_" + str(ty)) else: if y.properties["damaged"] == "N": bridge = Sprite( self.gallery.content["bridge"][ y.tile.properties["directions"]], position=((tx + 0.5) * self.get("rails").tw, (ty + 0.5) * self.get("rails").tw)) self.get("rails").add(bridge, name="bridge_" + str(tx) + "_" + str(ty)) self.POI[len(self.POI)] = { "px": tx, "py": ty, "type": "bridge", "status": y.properties["damaged"] } # process cities if "event" in y.properties: if y.properties["event"] == "city": neighbours = [{ "X": tx, "Y": ty + 1 }, { "X": tx + 1, "Y": ty }, { "X": tx, "Y": ty - 1 }, { "X": tx - 1, "Y": ty }] # the following long if is split to statements for only better readability # city property is added only if all passed for neighbour in neighbours: if neighbour["X"] < 0 or neighbour["Y"] < 0: continue if len(self.get("rails").cells ) > neighbour["X"]: # check if column exist if len( self.get("rails").cells[neighbour["X"]] ) > neighbour["Y"]: # check if row exist if self.get( "rails" ).cells[neighbour["X"]][neighbour[ "Y"]].properties: # check if has properties if "directions" in self.get( "rails" ).cells[neighbour["X"]][neighbour[ "Y"]].properties: # check if has directions if len( self.get("rails").cells[ neighbour["X"]][ neighbour["Y"]]. properties["directions"] ) == 1: # check if bumper tile self.get("rails").cells[ neighbour["X"]][neighbour[ "Y"]].properties[ "city"] = (tx, ty)
def __init__(self): super().__init__() #Hearts--------------------------------------------------------------- self.is_dead = False self.heart1 = Hearts() self.heart2 = Hearts() self.heart3 = Hearts() self.heart1.scale = 0.5 self.heart2.scale = 0.5 self.heart3.scale = 0.5 self.heart1.visible = False self.heart2.visible = False self.heart3.visible = False #----------------------------------------------------------------------- # second level monsters ------------------------------------------------- #Nightmare self.nightmare_1 = Nightmare() self.nightmare_2 = Nightmare() #HellHound self.red_hound_1 = HellHound() self.red_hound_2 = HellHound() self.green_hound_1 = HellHound() self.green_hound_2 = HellHound() #HellBeast self.hell_beast = HellBeast() self.hell_fire_beast = HellFireBeast() self.ball = self.hell_beast.fire_ball self.ball_f = self.hell_fire_beast.fire_ball #------------------------------------------------------------------------ #Skeleton self.skeleton = GreenSkeleton() #FirstStack--------------------------------------------------------------- self.green_hound_1.sprite.position = (550,400) self.green_hound_1.sprite.color = (0,255,0) self.green_hound_1.sprite.scale_x = -1 self.green_hound_1.lifes = 3 self.green_hound_2.sprite.position = (650,400) self.green_hound_2.sprite.color = (0,255,0) self.green_hound_2.lifes = 3 self.hell_beast.sprite.position = (1000,420) self.hell_beast.sprite.color = (0,255,0) self.hell_beast.fire_ball.color = (0,255,0) #SecondStack self.red_hound_1.sprite.position = (1350,400) self.red_hound_1.sprite.color = (255,0,0) self.red_hound_1.sprite.scale_x = -1 self.red_hound_1.lifes = 3 self.red_hound_2.sprite.position = (1450,400) self.red_hound_2.sprite.color = (255,0,0) self.red_hound_2.lifes = 3 #third self.nightmare_1.sprite.position = (1700,420) self.nightmare_1.sprite.color = (255,0,0) self.hell_fire_beast.sprite.position = (1900,430) self.hell_fire_beast.sprite.color = (255,0,0) self.hell_fire_beast.fire_ball.color = (255,0,0) #fourth self.nightmare_2.sprite.position = (2150,420) self.nightmare_2.sprite.color = (0,255,0) self.skeleton.sprite.position = (2500, 420) self.skeleton.sprite.scale = 2 self.skeleton.sprite.scale_x = -1 self.skeleton.sprite.color = (255,0,0) #-------------------------------------------------------------------------- self.skeleton_is_alive = True self.run_r = False self.run_l = False self.attacks = False self.run_r = False self.run_l = False self.life = 3 self.sprite = Sprite(animations.anim_i) self.can_attack = True self.sprite.position = (100, 410) self.sprite.scale = 2 self.sprite.scale_x = 1 self.sprite.velocity = (0,0) self.attack = False self.flag = False self.x_y = 0 self.mirror_sprite = Sprite(animations.anim_i) self.mirror_sprite.position = (100, 320) self.mirror_sprite.scale = -2 self.mirror_sprite.scale_x = -1 self.mirror_sprite.velocity = (0,0) self.mirror_sprite.color = (0, 0, 0) #FirstStack self.add(self.green_hound_1) self.add(self.green_hound_2) self.add(self.hell_beast) self.add(self.ball) self.ball.visible = False #SecondStack self.add(self.red_hound_1) self.add(self.red_hound_2) #ThirdStack self.add(self.nightmare_1) self.add(self.hell_fire_beast) self.add(self.ball_f) self.ball_f.visible = False #FourthStack self.add(self.nightmare_2) self.add(self.skeleton) #Hearts self.add(self.heart1) self.add(self.heart2) self.add(self.heart3) #------------------------------------- self.add(self.sprite) self.add(self.mirror_sprite) self.pressed = defaultdict(int) self.schedule(self.update)
def __init__(self): super(SpriteLayer, self).__init__() self.sprite = Sprite("assets/img/grossini.png") self.add(self.sprite) self.sprite.do(GameAction())
def __init__(self): super(Game, self).__init__(0, 80, 125, 255) # self.player = Sprite(resources.horngirl) self.player = Sprite("assets/horngirl.png") self.player.position = 160, 120 self.add(self.player)
def __init__(self): super().__init__() self.px_width = 9194 self.px_height = 650 bg = Sprite("bg4.png",position = (self.px_width/2,self.px_height/2)) super().add(bg,z=-3)