def update(this, delta_time): # If within 5 tiles of player... if ((this.X - world.player.X) ** 2 + (this.Y - world.player.Y) ** 2) <= this.attributes["aggro_range"]: if not ("mov_del" in this.attributes["effects"]): # Possibly move to player. diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0 and (world.map[this.X + 1][this.Y][3]): # Make sure you don't move onto a wall this.X += 1 if diffX > 0 and (world.map[this.X - 1][this.Y][3]): this.X -= 1 if diffY < 0 and world.map[this.X][this.Y + 1][3]: this.Y += 1 if diffY > 0 and world.map[this.X][this.Y - 1][3]: this.Y -= 1 # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect(this, this.attributes["mov_spd"]) if (this.attributes["attack"] is None) and ("del_atk" not in this.attributes["effects"]): # Must make a new attack this.attributes["effects"]["del_atk"] = effect.effect(this, this.attributes["atk_spd"]) atk = attack.circle_attack(this.attributes["damage"], randrange(this.attributes["range_min"], this.attributes["range_max"] + 1), this) world.objects.append(atk) this.attributes["attack"] = atk super().update(delta_time)
def update(this, delta_time): # Movement code if not ("mov_del" in this.attributes["effects"]): diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0: this.X += 1 else: this.X -= (not not diffX) # Should give either 1 or 0. if diffY < 0: this.Y += 1 else: this.Y -= (not not diffY) # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect(this, this.attributes["mov_spd"]) # Attack code this.attributes["to_atk"] -= delta_time if this.attributes["to_atk"] <= 0: this.attributes["to_atk"] = this.attributes["atk_spd"] - 200 + this.attributes["HP"] # He attacks faster with less HP # Find which direction to shoot diffX = world.player.X - this.X # How much it needs to move left to hit player diffY = world.player.Y - this.Y # How much it needs to move down to hit player if diffX < 0: diffX = -1 else: diffX = int(not not diffX) if diffY < 0: diffY = -1 else: diffY = int(not not diffY) world.objects.append(attack.boss_attack(this.X + diffX, this.Y + diffY, diffX, diffY, this.attributes["damage"], this.attributes["range"], 250, this)) # Update all effects. eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list if this.attributes["HP"] <= 0: this.die() world.load("tutorial.boss-killed") world.objects = [world.player] + world.objects world.player.X = 10 world.player.Y = 10 world.dispworld() return True
def update(this, delta_time): # If within 5 tiles of player... if ((this.X - world.player.X) ** 2 + (this.Y - world.player.Y) ** 2) <= this.attributes["aggro_range"]: if not ("mov_del" in this.attributes["effects"]): # Possibly move to player. diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0 and (world.map[this.X + 1][this.Y][3]): # Make sure you don't move onto a wall this.X += 1 if diffX > 0 and (world.map[this.X - 1][this.Y][3]): this.X -= 1 if diffY < 0 and world.map[this.X][this.Y + 1][3]: this.Y += 1 if diffY > 0 and world.map[this.X][this.Y - 1][3]: this.Y -= 1 # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect(this, this.attributes["mov_spd"]) super().update(delta_time)
def update(this, delta_time): if "mov_del" not in this.attributes["effects"]: # Find nearest player locX = this.X # For quicker checking locY = this.Y closest_plr = None dist = 101 # Only players close enough for plr in world.players: if (locX - plr.X)**2 + (locY - plr.Y)**2 < dist: closest_plr = plr dist = ((locX - plr.X)**2 + (locY - plr.Y)**2)**.5 # Now that we have the closest enemy, damage it. if closest_plr is not None: dist_x = closest_plr.X - locX dist_y = closest_plr.Y - locY move_x = 0 if dist_x == 0 else dist_x // abs(dist_x) move_y = 0 if dist_y == 0 else dist_y // abs(dist_y) this.X += move_x this.Y += move_y this.attributes["effects"]["mov_del"] = effect.effect( this, this.attributes["speed"]) super().update(delta_time)
def update(this, delta_time): for plr in world.players: if world.map[plr.X][plr.Y] == [ display.BLUE, display.BLUE, 'W', True ] and "water_slow" not in plr.attributes["effects"]: plr.attributes["effects"]["water_slow"] = effect.effect( plr, 999, "Slow", {"mov_spd": -100})
def update(this, delta_time): # If within 5 tiles of player... if ((this.X - world.player.X)**2 + (this.Y - world.player.Y)**2) <= this.attributes["aggro_range"]: if not ("mov_del" in this.attributes["effects"]): # Possibly move to player. diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0 and (world.map[this.X + 1][this.Y][3] ): # Make sure you don't move onto a wall this.X += 1 if diffX > 0 and (world.map[this.X - 1][this.Y][3]): this.X -= 1 if diffY < 0 and world.map[this.X][this.Y + 1][3]: this.Y += 1 if diffY > 0 and world.map[this.X][this.Y - 1][3]: this.Y -= 1 # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect( this, this.attributes["mov_spd"]) super().update(delta_time)
def update(this, delta_time): if "mov_del" not in this.attributes["effects"]: # Find nearest player locX = this.X # For quicker checking locY = this.Y closest_plr = None dist = 101 # Only players close enough for plr in world.players: if (locX - plr.X) ** 2 + (locY - plr.Y) ** 2 < dist: closest_plr = plr dist = ((locX - plr.X)**2 + (locY - plr.Y)**2) ** .5 # Now that we have the closest enemy, damage it. if closest_plr is not None: dist_x = closest_plr.X - locX dist_y = closest_plr.Y - locY move_x = 0 if dist_x == 0 else dist_x // abs(dist_x) move_y = 0 if dist_y == 0 else dist_y // abs(dist_y) this.X += move_x this.Y += move_y this.attributes["effects"]["mov_del"] = effect.effect(this, this.attributes["speed"]) super().update(delta_time)
def update(this, delta_time): # Movement code if not ("mov_del" in this.attributes["effects"]): diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0: this.X += 1 else: this.X -= (not not diffX) # Should give either 1 or 0. if diffY < 0: this.Y += 1 else: this.Y -= (not not diffY) # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect(this, this.attributes["mov_spd"]) if not ("atk_del" in this.attributes["effects"]): # Attack! world.objects.append(attack.shoot_attack(this.X + 1, this.Y - 1, 1 , -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X + 1, this.Y , 1 , 0 , this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X + 1, this.Y + 1, 1 , 1 , this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X , this.Y - 1, 0 , -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X , this.Y + 1, 0 , 1 , this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X - 1, this.Y - 1, -1, -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X - 1, this.Y , -1, 0 , this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append(attack.shoot_attack(this.X - 1, this.Y + 1, -1, 1 , this.attributes["damage"], this.attributes["range"], 300, this)) this.attributes["effects"]["atk_del"] = effect.effect(this, this.attributes["atk_spd"]) if this.attributes["HP"] < this.attributes["lastHP"]: diff = this.attributes["lastHP"] - this.attributes["HP"] # Difference in HP between this frame and last frame if diff > 10: # Soft damage cap diff = 10 + ((diff - 10) ** .75) if diff > 50: # Hard damage cap diff = 50 this.attributes["lastHP"] -= diff this.attributes["HP"] = this.attributes["lastHP"] super().update(delta_time)
def collide(this, obj): if (not this.team & obj.team) and ("HP" in obj.attributes) and ( obj.attributes["name"] + "-attack-del" not in this.attributes["effects"]): # If collides with something, damage it. Wait to damage again for 500ms obj.attributes["HP"] -= this.attributes["damage"] this.attributes["effects"][obj.attributes["name"] + "-attack-del"] = effect.effect( this, 500)
def update(this, delta_time): super().update(delta_time) # Attack if "atk_del" not in this.attributes["effects"]: if this.attributes["go_diag"]: world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1 , 1 , 200, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1 , -1, 200, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, 1 , 200, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, -1, 200, False)) else: world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1 , 0 , 100, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, 0 , 100, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 0 , 1 , 100, False)) world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 0 , -1, 100, False)) this.attributes["go_diag"] = not this.attributes["go_diag"] this.attributes["effects"]["atk_del"] = effect.effect(this, 500) # Move if "mov_del" not in this.attributes["effects"]: if (this.X, this.Y) == this.attributes["going_to"]: # If we're where we want to be, choose new location to go. this.attributes["going_to"] = (random.randint(0, world.WORLD_X - 1), random.randint(0, world.WORLD_Y - 1)) if (this.X, this.Y) == this.attributes["going_to"]: # If we randomized to same coord. this.attributes["going_to"] = (25, 10) # Just move to middle if (this.X, this.Y) == this.attributes["going_to"]: # If it already was in the middle and we randomized middle this.attributes["going_to"] = (15, 7) # Go wherever. dist_x = 0 dist_y = 0 if this.X == this.attributes["going_to"][0]: # Move on y dist_y = this.attributes["going_to"][1] - this.Y dist_y = dist_y / abs(dist_y) else: dist_x = this.attributes["going_to"][0] - this.X dist_x = dist_x / abs(dist_x) # Now we actually move world.objects.append(boss_slime.boss_slime(this.X, this.Y, this)) this.X += int(dist_x) this.Y += int(dist_y) this.attributes["effects"]["mov_del"] = effect.effect(this, 300)
def update(this, delta_time): # If within 5 tiles of player... if ((this.X - world.player.X)**2 + (this.Y - world.player.Y)**2) <= this.attributes["aggro_range"]: if not ("mov_del" in this.attributes["effects"]): # Possibly move to player. diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0 and (world.map[this.X + 1][this.Y][3] ): # Make sure you don't move onto a wall this.X += 1 if diffX > 0 and (world.map[this.X - 1][this.Y][3]): this.X -= 1 if diffY < 0 and world.map[this.X][this.Y + 1][3]: this.Y += 1 if diffY > 0 and world.map[this.X][this.Y - 1][3]: this.Y -= 1 # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect( this, this.attributes["mov_spd"]) if (this.attributes["attack"] is None) and ("del_atk" not in this.attributes["effects"] ): # Must make a new attack this.attributes["effects"]["del_atk"] = effect.effect( this, this.attributes["atk_spd"]) atk = attack.circle_attack( this.attributes["damage"], randrange(this.attributes["range_min"], this.attributes["range_max"] + 1), this) world.objects.append(atk) this.attributes["attack"] = atk super().update(delta_time)
def update(this, delta_time): super().update(delta_time) # Move this.attributes["theta"] += (delta_time * .002 / this.attributes["radius"]) this.X = int(this.attributes["radius"] * math.cos(this.attributes["theta"]) + this.attributes["spawner"].X) this.Y = int(this.attributes["radius"] * math.sin(this.attributes["theta"]) + this.attributes["spawner"].Y) if this.X < 0: this.X = 0 if this.X >= world.WORLD_X: this.X = world.WORLD_X - 1 if this.Y < 0: this.Y = 0 if this.Y >= world.WORLD_Y: this.Y = world.WORLD_Y - 1 # Attack if "atk_del" not in this.attributes["effects"]: closest_player = None dist = float("Inf") for plr in world.players: # Find closest player if (this.X - plr.X)**2 + (this.Y - plr.Y)**2 < dist: closest_player = plr dist = (this.X - plr.X)**2 + (this.Y - plr.Y)**2 if closest_player is not None: x_dist = this.X - closest_player.X y_dist = this.Y - closest_player.Y x_mov = 0 y_mov = 0 if abs(x_dist) > abs(y_dist): x_mov = -1 if x_dist > 0 else 1 else: y_mov = -1 if y_dist > 0 else 1 world.objects.append( directed_attack.directed_attack(this.X + x_mov, this.Y + y_mov, this.attributes["damage"], this, x_mov, y_mov, 150, True, 10)) this.attributes["effects"]["atk_del"] = effect.effect(this, 1000)
def update(this, delta_time): super().update(delta_time) if "atk_del" not in this.attributes["effects"]: closest_player = None dist = float("Inf") for plr in world.players: # Find closest player if (this.X - plr.X) ** 2 + (this.Y - plr.Y) ** 2 < dist: closest_player = plr dist = (this.X - plr.X) ** 2 + (this.Y - plr.Y) ** 2 if closest_player is not None: x_dist = this.X - closest_player.X y_dist = this.Y - closest_player.Y x_mov = 0 y_mov = 0 if abs(x_dist) > abs(y_dist): x_mov = -1 if x_dist > 0 else 1 else: y_mov = -1 if y_dist > 0 else 1 world.objects.append(directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, x_mov, y_mov, 150)) this.attributes["effects"]["atk_del"] = effect.effect(this, 1000)
def update(this, delta_time): super().update(delta_time) # Move this.attributes["theta"] += (delta_time * .002 / this.attributes["radius"]) this.X = int(this.attributes["radius"] * math.cos(this.attributes["theta"]) + this.attributes["spawner"].X) this.Y = int(this.attributes["radius"] * math.sin(this.attributes["theta"]) + this.attributes["spawner"].Y) if this.X < 0: this.X = 0 if this.X >= world.WORLD_X: this.X = world.WORLD_X - 1 if this.Y < 0: this.Y = 0 if this.Y >= world.WORLD_Y: this.Y = world.WORLD_Y - 1 # Attack if "atk_del" not in this.attributes["effects"]: closest_player = None dist = float("Inf") for plr in world.players: # Find closest player if (this.X - plr.X) ** 2 + (this.Y - plr.Y) ** 2 < dist: closest_player = plr dist = (this.X - plr.X) ** 2 + (this.Y - plr.Y) ** 2 if closest_player is not None: x_dist = this.X - closest_player.X y_dist = this.Y - closest_player.Y x_mov = 0 y_mov = 0 if abs(x_dist) > abs(y_dist): x_mov = -1 if x_dist > 0 else 1 else: y_mov = -1 if y_dist > 0 else 1 world.objects.append(directed_attack.directed_attack(this.X + x_mov, this.Y + y_mov, this.attributes["damage"], this, x_mov, y_mov, 150, True, 10)) this.attributes["effects"]["atk_del"] = effect.effect(this, 1000)
def update(this, delta_time): super().update(delta_time) if "atk_del" not in this.attributes["effects"]: closest_player = None dist = float("Inf") for plr in world.players: # Find closest player if (this.X - plr.X)**2 + (this.Y - plr.Y)**2 < dist: closest_player = plr dist = (this.X - plr.X)**2 + (this.Y - plr.Y)**2 if closest_player is not None: x_dist = this.X - closest_player.X y_dist = this.Y - closest_player.Y x_mov = 0 y_mov = 0 if abs(x_dist) > abs(y_dist): x_mov = -1 if x_dist > 0 else 1 else: y_mov = -1 if y_dist > 0 else 1 world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, x_mov, y_mov, 150)) this.attributes["effects"]["atk_del"] = effect.effect(this, 1000)
def update(this, delta_time): for plr in world.players: if world.map[plr.X][plr.Y] == [display.BLUE, display.BLUE, 'W', True] and "water_slow" not in plr.attributes["effects"]: plr.attributes["effects"]["water_slow"] = effect.effect(plr, 999, "Slow", {"mov_spd" : -100})
def collide(this, obj): if (not this.team & obj.team) and ("HP" in obj.attributes) and (obj.attributes["name"] + "-attack-del" not in this.attributes["effects"]): # If collides with something, damage it. Wait to damage again for 500ms obj.attributes["HP"] -= this.attributes["damage"] this.attributes["effects"][obj.attributes["name"] + "-attack-del"] = effect.effect(this, 500)
def collide(this, obj): if obj.type == "player" and ("del_atk" not in this.attributes["effects"]): obj.attributes["HP"] -= this.attributes["damage"] this.attributes["effects"]["del_atk"] = effect.effect( this, this.attributes["mov_spd"])
def update(this, delta_time): # Reprint top bar status display.printc( 8, 0, str(int(this.attributes["HP"])) + "/" + str(int(this.attributes["maxHP"])) + " ") display.printc( 8, 1, str(int(this.attributes["MP"])) + "/" + str(int(this.attributes["maxMP"])) + " ") display.printc(10, 2, str(this.attributes["money"]) + " ") display.printc(12, 3, str(this.attributes["level"])) display.printc( 5, 4, str( int(0.5 * this.attributes["level"]**2 + 0.5 * this.attributes["level"] + 4 - this.attributes["EXP"])) + " to level ") # Check HP diff for flash on hit stuff if this.attributes["HP"] < this.attributes["lastHP"]: this.attributes["sincehit"] = 0 else: this.attributes["sincehit"] += delta_time # Check for movement if display.keyDown( ord('W')) and (not "del_up" in this.attributes["effects"]): if (this.Y > 0) and world.map[this.X][this.Y - 1][3]: this.Y -= 1 this.attributes["effects"]["del_up"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if display.keyDown( ord('S')) and (not "del_down" in this.attributes["effects"]): if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y + 1][3]: this.Y += 1 this.attributes["effects"]["del_down"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if display.keyDown( ord('A')) and (not "del_left" in this.attributes["effects"]): if (this.X > 0) and world.map[this.X - 1][this.Y][3]: this.X -= 1 this.attributes["effects"]["del_left"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if display.keyDown( ord('D')) and (not "del_right" in this.attributes["effects"]): if (this.X < world.WORLD_X - 1) and world.map[this.X + 1][this.Y][3]: this.X += 1 this.attributes["effects"]["del_right"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) # Check for spell cast if display.keyDown(ord(' ')) and this.attributes["can_cast"]: this.attributes["spell"].cast(this) this.attributes["can_cast"] = False if not display.keyDown(ord(' ')): this.attributes["can_cast"] = True # Attacks! if (display.keyDown(ord('I'))) and (this.Y != 0) and ( world.map[this.X][this.Y - 1][3]) and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y - 1, 0, -1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if (display.keyDown(ord('J'))) and (this.X != 0) and ( world.map[this.X - 1][this.Y][3]) and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X - 1, this.Y, -1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if (display.keyDown(ord('K'))) and (this.Y != 19) and ( world.map[this.X][this.Y + 1][3]) and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y + 1, 0, 1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if (display.keyDown(ord('L'))) and (this.X != 49) and ( world.map[this.X + 1][this.Y][3]) and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X + 1, this.Y, 1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula. # Check for item use if display.keyDown( display.CONST.VK_LSHIFT) and this.attributes["can_item"] and ( this.attributes["consumable"].name != "Nothing"): this.attributes["consumable"].use(this) this.attributes["can_item"] = False this.attributes["consumable"].amount -= 1 if this.attributes["consumable"].amount == 0: del this.attributes["items"][this.attributes["items"].index( this.attributes["consumable"])] this.attributes["consumable"] = item.item( "Nothing", "consumable", 0, 1, { "icon": [" ", " ", " "], "color": 0 }) this.attributes["consumable"].draw() if not display.keyDown(display.CONST.VK_SHIFT): this.attributes["can_item"] = True # Update all effects. eff_printed = 0 if display.sidebar_line < 10: # Must have room to show some effects display.printc(50, display.sidebar_line, "Effects:") eff_printed = display.sidebar_line display.sidebar_line += 1 eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list if eff_printed == display.sidebar_line - 1: display.printc(50, display.sidebar_line, " No effects") display.sidebar_line += 1 if this.attributes[ "HP"] <= 0: #TODO: Actually have things happen when you die. display.printc(33, 9, "+++++++++++++", display.RED) display.printc(33, 10, "+ You DIED! +", display.RED) display.printc(33, 11, "+++++++++++++", display.RED) display.refresh() time.sleep(1) display.flushinp() while display.getch() != -1: # Wait for key release pass while display.getch() == -1: # Wait for keypress pass display.end() # Finally, update lastHP. Done after effects because we don't want effects to make you constantly red this.attributes["lastHP"] = this.attributes["HP"]
def update(this, delta_time): this.attributes["sidebar"] = "" try: if this.attributes["pipe"].poll(): message = json.loads(this.attributes["pipe"].recv()) if message["type"] == 'keydown': this.attributes["keys"][message["d"]] = True elif message["type"] == 'keyup': this.attributes["keys"][message["d"]] = False elif message["type"] == "inv": if message["data"] == "exit": # Just exit inv without doing anything this.attributes["using_inv"] = False else: # Equip the item! to_equip = this.attributes["items"][message["data"]] print(to_equip) this.attributes[to_equip.type].unequip( this) # Unequip other item this.attributes[ to_equip.type] = to_equip # Put in equipped slot to_equip.equip(this) # Equip this.send_inventory() this.attributes["timeout"] = 0 else: this.attributes["timeout"] += delta_time if this.attributes[ "timeout"] > 1000 * 10: # No ping in last 10s display.log("Timeout: " + this.attributes["name"]) world.to_del_plr.append(this) return except Exception as ex: world.to_del_plr.append(this) return if this.attributes["esc_menu"] is not None: opt = this.attributes["esc_menu"].update() if opt is not None: # They chose an option if this.attributes["esc_menu_type"] == "main": if opt == 0: this.attributes["esc_menu"] = None elif opt == 1: this.attributes["esc_menu"] = None this.attributes["using_inv"] = True this.attributes["keys"] = bytearray(display.NUM_KEYS) this.send_inventory() elif opt == 2: options = [] # All options to go in the menu. spell_list = this.attributes[ "spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu( "Set to what?", this, "Back", *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "spell" elif opt == 3: options = [] # All options to go in the menu. spell_list = this.attributes[ "spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu( "Switch what spell?", this, "Back", *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "sorder1" elif opt == 4: this.attributes["esc_menu"] = None world.to_del_plr.append(this) return elif this.attributes[ "esc_menu_type"] == "set": # Let them set an item if opt != 0: itm = this.attributes["set_list"][ opt - 1] # Find chosen item if itm in this.attributes[ "items"]: # If they have the item this.attributes[ this.attributes["set_name"]].unequip( this) # Unequip other item this.attributes[this.attributes[ "set_name"]] = itm # Put in equipped slot itm.equip(this) # Equip this.attributes["esc_menu"] = display.menu( "Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow\\fw", this, "Back", "Set Consumable", "Set Weapon", "Set Hat", "Set Shirt", "Set Pants", "Set Ring") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "inv" elif this.attributes[ "esc_menu_type"] == "spell": # Let them set a spell if opt != 0: this.attributes["spell"] = opt - 1 this.attributes["esc_menu"] = display.menu( "Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" elif this.attributes["esc_menu_type"] == "sorder1": if opt != 0: this.attributes[ "spell_switch"] = opt - 1 # First switch option. options = [] # All options to go in the menu. spell_list = this.attributes[ "spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu( "Switch with what?", this, *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "sorder2" else: this.attributes["esc_menu"] = display.menu( "Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" elif this.attributes["esc_menu_type"] == "sorder2": # Switch spells this.attributes["spells"][ this.attributes["spell_switch"]], this.attributes[ "spells"][opt] = this.attributes["spells"][ opt], this.attributes["spells"][ this.attributes["spell_switch"]] this.attributes["esc_menu"] = display.menu( "Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" # Open ESC menu if needed. if this.attributes["keys"][ display.KEY_ESC] and this.attributes["esc_menu"] is None: this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" # Inventory screen if this.attributes["keys"][display.KEY_INVENTORY]: this.attributes["using_inv"] = True this.attributes["keys"] = bytearray(display.NUM_KEYS) this.send_inventory() # Check HP diff for flash on hit stuff if this.attributes["HP"] < this.attributes["lastHP"]: this.attributes["sincehit"] = 0 else: this.attributes["sincehit"] += delta_time # Check for movement. TODO: maybe add speed multiplier? if this.attributes["keys"][display.KEY_MOV_UP] and ( not "del_up" in this.attributes["effects"]): if (this.Y > 0) and world.map[this.X][this.Y - 1][3]: this.Y -= 1 this.attributes["effects"]["del_up"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_DOWN] and ( not "del_down" in this.attributes["effects"]): if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y + 1][3]: this.Y += 1 this.attributes["effects"]["del_down"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_LEFT] and ( not "del_left" in this.attributes["effects"]): if (this.X > 0) and world.map[this.X - 1][this.Y][3]: this.X -= 1 this.attributes["effects"]["del_left"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_RIGHT] and ( not "del_right" in this.attributes["effects"]): if (this.X < world.WORLD_X - 1) and world.map[this.X + 1][this.Y][3]: this.X += 1 this.attributes["effects"]["del_right"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"]))) # Check for spell cast if this.attributes["keys"][ display.KEY_SPELL] and this.attributes["can_cast"]: this.attributes["spells"][this.attributes["spell"]].cast(this) this.attributes["can_cast"] = False if not this.attributes["keys"][display.KEY_SPELL]: this.attributes["can_cast"] = True # Check for spell cycle if this.attributes["keys"][ display.KEY_LASTSPELL] and this.attributes["can_spell_cycle"]: if this.attributes[ "spell"] == 0: # Cycle to end of list if at start this.attributes["spell"] = len(this.attributes["spells"]) this.attributes["spell"] -= 1 # Cycle backwards this.attributes["can_spell_cycle"] = False if this.attributes["keys"][ display.KEY_NEXTSPELL] and this.attributes["can_spell_cycle"]: this.attributes["spell"] += 1 if this.attributes["spell"] >= len( this.attributes["spells"] ): # If at end of list, cycle to start this.attributes["spell"] = 0 this.attributes["can_spell_cycle"] = False if not (this.attributes["keys"][display.KEY_LASTSPELL] or this.attributes["keys"][display.KEY_NEXTSPELL]): this.attributes["can_spell_cycle"] = True # Attacks! TODO: maybe add speed multiplier? So you can have really slow weapons. if this.attributes["keys"][display.KEY_ATK_UP] and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y, 0, -1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_LEFT] and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y, -1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_DOWN] and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y, 0, 1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_RIGHT] and ( not "del_atk" in this.attributes["effects"]): world.objects.append( attack.attack( this.X, this.Y, 1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect( this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"]))) # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula. # Check for item use if this.attributes["keys"][ display.KEY_ITEM] and this.attributes["can_item"] and ( this.attributes["consumable"].name != "Nothing"): this.attributes["consumable"].use(this) this.attributes["can_item"] = False this.attributes["consumable"].amount -= 1 if this.attributes["consumable"].amount <= 0: del this.attributes["items"][this.attributes["items"].index( this.attributes["consumable"])] this.attributes["consumable"] = no_item.no_consumable() if not this.attributes["keys"][display.KEY_ITEM]: this.attributes["can_item"] = True # Update all effects. this.attributes["sidebar"] += "Effects:\n" sidebar_len = this.attributes["sidebar"].count('\n') eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list # Reset lastHP, done after effect updating so damaging effects don't force you red. this.attributes["lastHP"] = this.attributes["HP"] if this.attributes["sidebar"].count('\n') == sidebar_len: this.attributes["sidebar"] += " No effects\n" if this.attributes["HP"] <= 0: # Dead # Remove all effects in case they were on fire for 100hrs or something. # Repeatedly dying to that wouldn't be fun. # I guess this also adds a slight death penalty if you had a useful effect up. for eff_name, eff in this.attributes["effects"].items(): eff.uneffect(this) this.attributes["effects"].clear() this.attributes["HP"] = this.attributes["maxHP"] # Recover HP, MP this.attributes["MP"] = this.attributes["maxMP"] this.X = this.attributes["respawnX"] # Return to last saved place this.Y = this.attributes["respawnY"] world.move_requests.append( (this.attributes["respawnMap"], this)) # At last saved map... world.to_del_plr.append(this) # Exit from this map. display.log("Player died" + this.attributes["name"])
def luckboost(player): if "lucky_day" in player.attributes["effects"]: player.attributes["effects"]["lucky_day"].time += 15000 else: player.attributes["effects"]["lucky_day"] = effect.effect( player, 15000, "Extra Lucky", {"luck": 10})
def update(this, delta_time): this.attributes["sidebar"] = "" try: if this.attributes["pipe"].poll(): message = json.loads(this.attributes["pipe"].recv()) if message["type"] == 'keydown': this.attributes["keys"][message["d"]] = True elif message["type"]== 'keyup': this.attributes["keys"][message["d"]] = False elif message["type"] == "inv": if message["data"] == "exit": # Just exit inv without doing anything this.attributes["using_inv"] = False else: # Equip the item! to_equip = this.attributes["items"][message["data"]] print(to_equip) this.attributes[to_equip.type].unequip(this) # Unequip other item this.attributes[to_equip.type] = to_equip # Put in equipped slot to_equip.equip(this) # Equip this.send_inventory() this.attributes["timeout"] = 0 else: this.attributes["timeout"] += delta_time if this.attributes["timeout"] > 1000 * 10: # No ping in last 10s display.log("Timeout: " + this.attributes["name"]) world.to_del_plr.append(this) return except Exception as ex: world.to_del_plr.append(this) return if this.attributes["esc_menu"] is not None: opt = this.attributes["esc_menu"].update() if opt is not None: # They chose an option if this.attributes["esc_menu_type"] == "main": if opt == 0: this.attributes["esc_menu"] = None elif opt == 1: this.attributes["esc_menu"] = None this.attributes["using_inv"] = True this.attributes["keys"] = bytearray(display.NUM_KEYS) this.send_inventory() elif opt == 2: options = [] # All options to go in the menu. spell_list = this.attributes["spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu("Set to what?", this, "Back", *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "spell" elif opt == 3: options = [] # All options to go in the menu. spell_list = this.attributes["spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu("Switch what spell?", this, "Back", *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "sorder1" elif opt == 4: this.attributes["esc_menu"] = None world.to_del_plr.append(this) return elif this.attributes["esc_menu_type"] == "set": # Let them set an item if opt != 0: itm = this.attributes["set_list"][opt - 1] # Find chosen item if itm in this.attributes["items"]: # If they have the item this.attributes[this.attributes["set_name"]].unequip(this) # Unequip other item this.attributes[this.attributes["set_name"]] = itm # Put in equipped slot itm.equip(this) # Equip this.attributes["esc_menu"] = display.menu("Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow\\fw", this, "Back", "Set Consumable", "Set Weapon", "Set Hat", "Set Shirt", "Set Pants", "Set Ring") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "inv" elif this.attributes["esc_menu_type"] == "spell": # Let them set a spell if opt != 0: this.attributes["spell"] = opt - 1 this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" elif this.attributes["esc_menu_type"] == "sorder1": if opt != 0: this.attributes["spell_switch"] = opt - 1 # First switch option. options = [] # All options to go in the menu. spell_list = this.attributes["spells"] # The spell corresponding to the option for spl in spell_list: # Find all items options.append(spl.name + "(" + str(spl.amount) + ")") this.attributes["esc_menu"] = display.menu("Switch with what?", this, *options) this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "sorder2" else: this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" elif this.attributes["esc_menu_type"] == "sorder2": # Switch spells this.attributes["spells"][this.attributes["spell_switch"]], this.attributes["spells"][opt] = this.attributes["spells"][opt], this.attributes["spells"][this.attributes["spell_switch"]] this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" # Open ESC menu if needed. if this.attributes["keys"][display.KEY_ESC] and this.attributes["esc_menu"] is None: this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order","Exit Server") this.attributes["esc_menu"].is_esc_menu = True this.attributes["esc_menu_type"] = "main" # Inventory screen if this.attributes["keys"][display.KEY_INVENTORY]: this.attributes["using_inv"] = True this.attributes["keys"] = bytearray(display.NUM_KEYS) this.send_inventory() # Check HP diff for flash on hit stuff if this.attributes["HP"] < this.attributes["lastHP"]: this.attributes["sincehit"] = 0 else: this.attributes["sincehit"] += delta_time # Check for movement. TODO: maybe add speed multiplier? if this.attributes["keys"][display.KEY_MOV_UP] and (not "del_up" in this.attributes["effects"]): if (this.Y > 0) and world.map[this.X][this.Y - 1][3]: this.Y -= 1 this.attributes["effects"]["del_up"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_DOWN] and (not "del_down" in this.attributes["effects"]): if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y + 1][3]: this.Y += 1 this.attributes["effects"]["del_down"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_LEFT] and (not "del_left" in this.attributes["effects"]): if (this.X > 0) and world.map[this.X - 1][this.Y][3]: this.X -= 1 this.attributes["effects"]["del_left"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if this.attributes["keys"][display.KEY_MOV_RIGHT] and (not "del_right" in this.attributes["effects"]): if (this.X < world.WORLD_X - 1) and world.map[this.X + 1][this.Y][3]: this.X += 1 this.attributes["effects"]["del_right"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) # Check for spell cast if this.attributes["keys"][display.KEY_SPELL] and this.attributes["can_cast"]: this.attributes["spells"][this.attributes["spell"]].cast(this) this.attributes["can_cast"] = False if not this.attributes["keys"][display.KEY_SPELL]: this.attributes["can_cast"] = True # Check for spell cycle if this.attributes["keys"][display.KEY_LASTSPELL] and this.attributes["can_spell_cycle"]: if this.attributes["spell"] == 0: # Cycle to end of list if at start this.attributes["spell"] = len(this.attributes["spells"]) this.attributes["spell"] -= 1 # Cycle backwards this.attributes["can_spell_cycle"] = False if this.attributes["keys"][display.KEY_NEXTSPELL] and this.attributes["can_spell_cycle"]: this.attributes["spell"] += 1 if this.attributes["spell"] >= len(this.attributes["spells"]): # If at end of list, cycle to start this.attributes["spell"] = 0 this.attributes["can_spell_cycle"] = False if not (this.attributes["keys"][display.KEY_LASTSPELL] or this.attributes["keys"][display.KEY_NEXTSPELL]): this.attributes["can_spell_cycle"] = True # Attacks! TODO: maybe add speed multiplier? So you can have really slow weapons. if this.attributes["keys"][display.KEY_ATK_UP] and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y, 0, -1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_LEFT] and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y, -1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_DOWN] and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y, 0, 1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if this.attributes["keys"][display.KEY_ATK_RIGHT] and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y, 1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula. # Check for item use if this.attributes["keys"][display.KEY_ITEM] and this.attributes["can_item"] and (this.attributes["consumable"].name != "Nothing"): this.attributes["consumable"].use(this) this.attributes["can_item"] = False this.attributes["consumable"].amount -= 1 if this.attributes["consumable"].amount <= 0: del this.attributes["items"][this.attributes["items"].index(this.attributes["consumable"])] this.attributes["consumable"] = no_item.no_consumable() if not this.attributes["keys"][display.KEY_ITEM]: this.attributes["can_item"] = True # Update all effects. this.attributes["sidebar"] += "Effects:\n" sidebar_len = this.attributes["sidebar"].count('\n') eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list # Reset lastHP, done after effect updating so damaging effects don't force you red. this.attributes["lastHP"] = this.attributes["HP"] if this.attributes["sidebar"].count('\n') == sidebar_len: this.attributes["sidebar"] += " No effects\n" if this.attributes["HP"] <= 0: # Dead # Remove all effects in case they were on fire for 100hrs or something. # Repeatedly dying to that wouldn't be fun. # I guess this also adds a slight death penalty if you had a useful effect up. for eff_name, eff in this.attributes["effects"].items(): eff.uneffect(this) this.attributes["effects"].clear() this.attributes["HP"] = this.attributes["maxHP"] # Recover HP, MP this.attributes["MP"] = this.attributes["maxMP"] this.X = this.attributes["respawnX"] # Return to last saved place this.Y = this.attributes["respawnY"] world.move_requests.append((this.attributes["respawnMap"], this)) # At last saved map... world.to_del_plr.append(this) # Exit from this map. display.log("Player died" + this.attributes["name"])
def update(this, delta_time): super().update(delta_time) # Attack if "atk_del" not in this.attributes["effects"]: if this.attributes["go_diag"]: world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1, 1, 200, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1, -1, 200, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, 1, 200, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, -1, 200, False)) else: world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 1, 0, 100, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, -1, 0, 100, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 0, 1, 100, False)) world.objects.append( directed_attack.directed_attack(this.X, this.Y, this.attributes["damage"], this, 0, -1, 100, False)) this.attributes["go_diag"] = not this.attributes["go_diag"] this.attributes["effects"]["atk_del"] = effect.effect(this, 500) # Move if "mov_del" not in this.attributes["effects"]: if (this.X, this.Y) == this.attributes[ "going_to"]: # If we're where we want to be, choose new location to go. this.attributes["going_to"] = (random.randint( 0, world.WORLD_X - 1), random.randint(0, world.WORLD_Y - 1)) if (this.X, this.Y) == this.attributes[ "going_to"]: # If we randomized to same coord. this.attributes["going_to"] = (25, 10 ) # Just move to middle if (this.X, this.Y) == this.attributes[ "going_to"]: # If it already was in the middle and we randomized middle this.attributes["going_to"] = (15, 7) # Go wherever. dist_x = 0 dist_y = 0 if this.X == this.attributes["going_to"][0]: # Move on y dist_y = this.attributes["going_to"][1] - this.Y dist_y = dist_y / abs(dist_y) else: dist_x = this.attributes["going_to"][0] - this.X dist_x = dist_x / abs(dist_x) # Now we actually move world.objects.append(boss_slime.boss_slime(this.X, this.Y, this)) this.X += int(dist_x) this.Y += int(dist_y) this.attributes["effects"]["mov_del"] = effect.effect(this, 300)
def update(this, delta_time): # Reprint top bar status display.printc(8, 0, str(int(this.attributes["HP"])) + "/" + str(int(this.attributes["maxHP"])) + " ") display.printc(8, 1, str(int(this.attributes["MP"])) + "/" + str(int(this.attributes["maxMP"])) + " ") display.printc(10, 2, str(this.attributes["money"]) + " ") display.printc(12, 3, str(this.attributes["level"])) display.printc(5, 4, str(int(0.5*this.attributes["level"]**2 + 0.5*this.attributes["level"] + 4 - this.attributes["EXP"])) + " to level ") # Check HP diff for flash on hit stuff if this.attributes["HP"] < this.attributes["lastHP"]: this.attributes["sincehit"] = 0 else: this.attributes["sincehit"] += delta_time # Check for movement if display.keyDown(ord('W')) and (not "del_up" in this.attributes["effects"]): if (this.Y > 0) and world.map[this.X][this.Y - 1][3]: this.Y -= 1 this.attributes["effects"]["del_up"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if display.keyDown(ord('S')) and (not "del_down" in this.attributes["effects"]): if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y + 1][3]: this.Y += 1 this.attributes["effects"]["del_down"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if display.keyDown(ord('A')) and (not "del_left" in this.attributes["effects"]): if (this.X > 0) and world.map[this.X - 1][this.Y][3]: this.X -= 1 this.attributes["effects"]["del_left"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) if display.keyDown(ord('D')) and (not "del_right" in this.attributes["effects"]): if (this.X < world.WORLD_X - 1) and world.map[this.X + 1][this.Y][3]: this.X += 1 this.attributes["effects"]["del_right"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"]))) # Check for spell cast if display.keyDown(ord(' ')) and this.attributes["can_cast"]: this.attributes["spell"].cast(this) this.attributes["can_cast"] = False if not display.keyDown(ord(' ')): this.attributes["can_cast"] = True # Attacks! if (display.keyDown(ord('I'))) and (this.Y != 0) and (world.map[this.X][this.Y - 1][3]) and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y - 1, 0, -1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if (display.keyDown(ord('J'))) and (this.X != 0) and (world.map[this.X - 1][this.Y][3]) and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X - 1, this.Y, -1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if (display.keyDown(ord('K'))) and (this.Y != 19) and (world.map[this.X][this.Y + 1][3]) and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X, this.Y + 1, 0, 1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) if (display.keyDown(ord('L'))) and (this.X != 49) and (world.map[this.X + 1][this.Y][3]) and (not "del_atk" in this.attributes["effects"]): world.objects.append(attack.attack(this.X + 1, this.Y, 1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this)) this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"]))) # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula. # Check for item use if display.keyDown(display.CONST.VK_LSHIFT) and this.attributes["can_item"] and (this.attributes["consumable"].name != "Nothing"): this.attributes["consumable"].use(this) this.attributes["can_item"] = False this.attributes["consumable"].amount -= 1 if this.attributes["consumable"].amount == 0: del this.attributes["items"][this.attributes["items"].index(this.attributes["consumable"])] this.attributes["consumable"] = item.item("Nothing", "consumable", 0, 1, {"icon" : [" ", " ", " "], "color" : 0}) this.attributes["consumable"].draw() if not display.keyDown(display.CONST.VK_SHIFT): this.attributes["can_item"] = True # Update all effects. eff_printed = 0 if display.sidebar_line < 10: # Must have room to show some effects display.printc(50, display.sidebar_line, "Effects:") eff_printed = display.sidebar_line display.sidebar_line += 1 eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list if eff_printed == display.sidebar_line - 1: display.printc(50, display.sidebar_line, " No effects") display.sidebar_line += 1 if this.attributes["HP"] <= 0: #TODO: Actually have things happen when you die. display.printc(33, 9, "+++++++++++++", display.RED) display.printc(33, 10, "+ You DIED! +", display.RED) display.printc(33, 11, "+++++++++++++", display.RED) display.refresh() time.sleep(1) display.flushinp() while display.getch() != -1: # Wait for key release pass while display.getch() == -1: # Wait for keypress pass display.end() # Finally, update lastHP. Done after effects because we don't want effects to make you constantly red this.attributes["lastHP"] = this.attributes["HP"]
def luckboost(player): if "lucky_day" in player.attributes["effects"]: player.attributes["effects"]["lucky_day"].time += 15000 else: player.attributes["effects"]["lucky_day"] = effect.effect(player, 15000, "Extra Lucky", {"luck" : 10})
def use(this, owner): owner.attributes["effects"]["tutbosseff"] = effect.effect(owner, 10000, "Ugh") this.amount += 1
def update(this, delta_time): # Movement code if not ("mov_del" in this.attributes["effects"]): diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0: this.X += 1 else: this.X -= (not not diffX) # Should give either 1 or 0. if diffY < 0: this.Y += 1 else: this.Y -= (not not diffY) # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect( this, this.attributes["mov_spd"]) # Attack code this.attributes["to_atk"] -= delta_time if this.attributes["to_atk"] <= 0: this.attributes[ "to_atk"] = this.attributes["atk_spd"] - 200 + this.attributes[ "HP"] # He attacks faster with less HP # Find which direction to shoot diffX = world.player.X - this.X # How much it needs to move left to hit player diffY = world.player.Y - this.Y # How much it needs to move down to hit player if diffX < 0: diffX = -1 else: diffX = int(not not diffX) if diffY < 0: diffY = -1 else: diffY = int(not not diffY) world.objects.append( attack.boss_attack(this.X + diffX, this.Y + diffY, diffX, diffY, this.attributes["damage"], this.attributes["range"], 250, this)) # Update all effects. eff_del_list = [] for eff_name in this.attributes["effects"]: eff = this.attributes["effects"][eff_name] eff.tick(delta_time) # Tick effect if eff.time <= 0: # Remove effect eff_del_list.append(eff_name) for eff_name in eff_del_list: this.attributes["effects"][eff_name].uneffect(this) del this.attributes["effects"][eff_name] del eff_del_list if this.attributes["HP"] <= 0: this.die() world.load("tutorial.boss-killed") world.objects = [world.player] + world.objects world.player.X = 10 world.player.Y = 10 world.dispworld() return True
def update(this, delta_time): # Movement code if not ("mov_del" in this.attributes["effects"]): diffX = this.X - world.player.X # How much it needs to move left to hit player diffY = this.Y - world.player.Y # How much it needs to move down to hit player if diffX < 0: this.X += 1 else: this.X -= (not not diffX) # Should give either 1 or 0. if diffY < 0: this.Y += 1 else: this.Y -= (not not diffY) # Add boundary checking if this.X == 0: # Left side this.X += 1 if this.X == world.WORLD_X - 1: # Right side this.X -= 1 if this.Y == 0: # Top this.Y += 1 if this.Y == world.WORLD_Y - 1: # Bottom this.Y -= 1 this.attributes["effects"]["mov_del"] = effect.effect( this, this.attributes["mov_spd"]) if not ("atk_del" in this.attributes["effects"]): # Attack! world.objects.append( attack.shoot_attack(this.X + 1, this.Y - 1, 1, -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X + 1, this.Y, 1, 0, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X + 1, this.Y + 1, 1, 1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X, this.Y - 1, 0, -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X, this.Y + 1, 0, 1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X - 1, this.Y - 1, -1, -1, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X - 1, this.Y, -1, 0, this.attributes["damage"], this.attributes["range"], 300, this)) world.objects.append( attack.shoot_attack(this.X - 1, this.Y + 1, -1, 1, this.attributes["damage"], this.attributes["range"], 300, this)) this.attributes["effects"]["atk_del"] = effect.effect( this, this.attributes["atk_spd"]) if this.attributes["HP"] < this.attributes["lastHP"]: diff = this.attributes["lastHP"] - this.attributes[ "HP"] # Difference in HP between this frame and last frame if diff > 10: # Soft damage cap diff = 10 + ((diff - 10)**.75) if diff > 50: # Hard damage cap diff = 50 this.attributes["lastHP"] -= diff this.attributes["HP"] = this.attributes["lastHP"] super().update(delta_time)
def collide(this, obj): if obj.type == "player" and ("del_atk" not in this.attributes["effects"]): obj.attributes["HP"] -= this.attributes["damage"] this.attributes["effects"]["del_atk"] = effect.effect(this, this.attributes["atk_spd"])
def use(this, owner): owner.attributes["effects"]["tutbosseff"] = effect.effect( owner, 10000, "Ugh") this.amount += 1