def create_initial_overworld(self, game: Game, rows: int, cols: int): if rows > game.max_map_size.x: print("Map.create_initial. rows is > game.max_map_size.x", "\nrows:", rows, "\nmax_map_size.x", game.max_map_size.x) exit(1) if cols > game.max_map_size.y: print("Map.create_initial. cols is > game.max_map_size.y", "\ncols:", cols, "\nmax_map_size.y", game.max_map_size.y) exit(1) self.is_town_map = False tile = Tile() warp_point = WarpPoint() self.rows = rows self.cols = cols self.move_grid_rows = rows * game.move_grid_ratio self.move_grid_cols = cols * game.move_grid_ratio for i in range(rows): for j in range(cols): tile_point = create_point(i, j) dst = tile_point_to_world_point(tile_point, game.tile_size) src = create_rect(0, 0, 20, 20) shared_srcs = game.sprite_db.find( game, ImageName.Tiles, src) tile.sprite.shared_srcs = shared_srcs tile.sprite.render_dst.dst.x = dst.x tile.sprite.render_dst.dst.y = dst.y tile.sprite.anim_speed = 100 tile.sprite.render_dst.is_camera_rendered = True self.tiles.push(tile) # create warp points tile_point = create_point(10, 15) warp_to_tile_point = create_point(rows - 2, 15) warp_point.set(game, WarpPointName.Forest, tile_point, warp_to_tile_point, 1) self.warp_points.push(warp_point) tile_point = create_point(22, 8) warp_to_tile_point = create_point(0, 20) warp_point.set(game, WarpPointName.Town, tile_point, warp_to_tile_point, 2) self.warp_points.push(warp_point) tile_point = create_point(32, 18) warp_to_tile_point = create_point(rows - 2, 15) warp_point.set(game, WarpPointName.Forest, tile_point, warp_to_tile_point, 3) self.warp_points.push(warp_point)
def set(self, game: Game, warp_point_name: WarpPointName, tile_point: SDL_Point, warp_to_tile_point: SDL_Point, warp_to_map_handle: int): self.warp_point_name = warp_point_name self.tile_point = deref(tile_point) self.tile_point_move_grid.x = self.tile_point.x * game.move_grid_ratio self.tile_point_move_grid.y = self.tile_point.y * game.move_grid_ratio self.warp_to_tile_point = deref(warp_to_tile_point) self.warp_to_tile_point_move_grid.x = self.warp_to_tile_point.x self.warp_to_tile_point_move_grid.y = self.warp_to_tile_point.y self.warp_to_tile_point_move_grid.x *= game.move_grid_ratio self.warp_to_tile_point_move_grid.y *= game.move_grid_ratio self.warp_to_map_handle = warp_to_map_handle world_point = tile_point_to_world_point(self.tile_point_move_grid, game.move_grid_tile_size) self.sprite.render_dst.dst.x = world_point.x self.sprite.render_dst.dst.y = world_point.y if warp_point_name == WarpPointName.Standard: src = create_rect(0, 20, 40, 40) self.sprite.shared_srcs = game.sprite_db.find( game, ImageName.Tiles, src) self.sprite.anim_speed = 100 self.sprite.render_dst.is_camera_rendered = True elif warp_point_name == WarpPointName.Town: src = create_rect(20, 0, 20, 20) self.sprite.shared_srcs = game.sprite_db.find( game, ImageName.Tiles, src) self.sprite.anim_speed = 100 self.sprite.render_dst.is_camera_rendered = True elif warp_point_name == WarpPointName.Forest: src = create_rect(40, 0, 20, 20) self.sprite.shared_srcs = game.sprite_db.find( game, ImageName.Tiles, src) self.sprite.anim_speed = 100 self.sprite.render_dst.is_camera_rendered = True
def set_to(self, game: Game, item_name: ItemName): # clear previous data self.sprite.srcs.clear() # set new data self.item_name = item_name self.sprite.spawn_time = game.engine.current_time self.sprite.render_dst.is_camera_rendered = True self.item_type = ItemType.Misc if item_name == ItemName.NA: print("Item.set_to - attempted to call with ItemName.NA.") exit(1) elif item_name == ItemName.Jelly: self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(20, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 17 elif item_name == ItemName.FurPelt: self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(40, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 32 elif item_name == ItemName.Branch: self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(60, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 44 elif item_name == ItemName.Mushroom: self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(80, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 38 elif item_name == ItemName.BatWing: self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(100, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 27 elif item_name == ItemName.Apple: self.item_type = ItemType.Useable self.sprite.image = game.engine.get_image(ImageName.Items) self.sprite.anim_speed = 100 src0 = create_rect(120, 0, 20, 20) self.sprite.srcs.push(src0) self.cost = 50 else: item_name_as_int = cast(item_name, "int") print("Item.set_to. Item name not handled. ItemName:", item_name_as_int) exit(1)
def set_to(self, game: Game, ability_name: AbilityName): # clear previous ability data self.sprite.srcs.clear() self.portrait.srcs.clear() # set new data self.ability_name = ability_name self.sprite.spawn_time = game.engine.current_time self.sprite.render_dst.is_camera_rendered = True self.sprite.image = game.engine.get_image(ImageName.Abilities) self.portrait.image = game.engine.get_image(ImageName.Items) if ability_name == AbilityName.NA: print("Ability.set_to - attempted to call with AbilityName.NA.") exit(1) elif ability_name == AbilityName.MeleeAttack: self.sprite.anim_speed = 60 self.is_projectile = False self.stats.damage = 20 self.stats.range = 30 self.stats.max_skill_points = 10 portrait_src = create_rect(20, 20, 20, 20) self.portrait.srcs.push(portrait_src) x = 0 w = 30 for i in range(8): src = create_rect(x, 32, w, 30) self.sprite.srcs.push(src) x += w elif ability_name == AbilityName.Fire: self.sprite.anim_speed = 100 self.is_projectile = True self.projectile_speed = 2.0 self.start_offset = create_point(0, -30) self.delay = 500 self.stats.damage = 20 self.stats.range = 100 self.stats.max_skill_points = 10 portrait_src = create_rect(0, 20, 20, 20) self.portrait.srcs.push(portrait_src) src0 = create_rect(64, 0, 16, 21) src1 = create_rect(80, 0, 16, 21) src2 = create_rect(96, 0, 16, 21) self.sprite.srcs.push(src0) self.sprite.srcs.push(src1) self.sprite.srcs.push(src2) else: ability_name_as_int = cast(ability_name, "int") print("Ability.set_to. Ability name not handled. AbilityName:", ability_name_as_int) exit(1)
def text_set_without_str(self, game: Game, dst: SDL_Point, font_style: FontStyle, _text_alignment: TextAlignment, _text_word_wrap: TextWordWrap, _width: int, font_size: int, color: SDL_Color, outline: int, outline_color: SDL_Color, use_drop_shadow: bool): # if the str was set before calling this function (such as in the case of damage text in world) self.render_dst.dst = create_rect(dst.x, dst.y, 0, 0) self.render_dst.scaled_dst = self.render_dst.dst self.font_style = font_style self.text_alignment = _text_alignment self.text_word_wrap = _text_word_wrap self.width = _width self.font_size = font_size * game.engine.scale self.color = deref(color) self.outline = outline self.outline_color = deref(outline_color) self.use_drop_shadow = use_drop_shadow self.font = engine_get_font(game.engine, self.font_style, self.font_size, self.color, self.outline, self.outline_color, self.use_drop_shadow) self.render_dst.is_camera_rendered = False
def text_set(self, game: Game, text_str, dst: SDL_Point, font_style: FontStyle, _text_alignment: TextAlignment, _text_word_wrap: TextWordWrap, _width: int, font_size: int, color: SDL_Color, outline: int, outline_color: SDL_Color, use_drop_shadow: bool): self.render_dst.dst = create_rect(dst.x, dst.y, 0, 0) self.render_dst.scaled_dst = self.render_dst.dst self.font_style = font_style self.text_alignment = _text_alignment self.text_word_wrap = _text_word_wrap self.width = _width self.font_size = font_size * game.engine.scale self.color = deref(color) self.outline = outline self.outline_color = deref(outline_color) self.use_drop_shadow = use_drop_shadow self.str.string_set_literal(text_str) self.font = engine_get_font(game.engine, self.font_style, self.font_size, self.color, self.outline, self.outline_color, self.use_drop_shadow) self.render_dst.is_camera_rendered = False
def create_initial(self, game: Game, rows: int, cols: int, is_town_map): if rows > game.max_map_size.x: print("Map.create_initial. rows is > game.max_map_size.x", "\nrows:", rows, "\nmax_map_size.x", game.max_map_size.x) exit(1) if cols > game.max_map_size.y: print("Map.create_initial. cols is > game.max_map_size.y", "\ncols:", cols, "\nmax_map_size.y", game.max_map_size.y) exit(1) self.is_town_map = is_town_map tile = Tile() warp_point = WarpPoint() self.rows = rows self.cols = cols self.move_grid_rows = rows * game.move_grid_ratio self.move_grid_cols = cols * game.move_grid_ratio for i in range(rows): for j in range(cols): tile_point = create_point(i, j) dst = tile_point_to_world_point(tile_point, game.tile_size) src = create_rect(0, 0, 20, 20) shared_srcs = game.sprite_db.find( game, ImageName.Tiles, src) tile.sprite.shared_srcs = shared_srcs tile.sprite.render_dst.dst.x = dst.x tile.sprite.render_dst.dst.y = dst.y tile.sprite.anim_speed = 100 tile.sprite.render_dst.is_camera_rendered = True self.tiles.push(tile) # create some warp points if self.handle == 1: tile_point = create_point(rows - 2, 15) warp_to_tile_point = create_point(10 + 1, 15) warp_point.set(game, WarpPointName.Standard, tile_point, warp_to_tile_point, 0) self.warp_points.push(warp_point) elif self.handle == 2: tile_point = create_point(0, 20) warp_to_tile_point = create_point(22 - 1, 8) warp_point.set(game, WarpPointName.Standard, tile_point, warp_to_tile_point, 0) self.warp_points.push(warp_point) elif self.handle == 3: tile_point = create_point(rows - 2, 15) warp_to_tile_point = create_point(32 - 1, 18) warp_point.set(game, WarpPointName.Standard, tile_point, warp_to_tile_point, 0) self.warp_points.push(warp_point) # create some initial units if not(self.is_town_map): num_enemies = game.engine.get_rand_int(20, 40) for i in range(num_enemies): unit_handle = game.world.get_handle(HandleType.Unit) unit = game.world.units.at(unit_handle) rand_unit_enum_int = game.engine.get_rand_int(7, 11) rand_unit_name = cast(rand_unit_enum_int, "UnitName") unit.set_to(game, rand_unit_name, Faction.Enemy) unit.join_map(game, self) unit.set_random_spawn_point(game)
def set_to(self, game: Game, unit_name: UnitName): self.anim_state = UnitAnimState.Idle self.idle_down.clear() self.cast_down.clear() self.sit_down.clear() self.overworld_idle_down.clear() self.render_dst.is_camera_rendered = True # should this be set this here, should be fine I think. self.spawn_time = game.engine.current_time self.idle_anim_speed = 1 self.cast_anim_speed = 1 self.sit_anim_speed = 1 self.overworld_idle_anim_speed = 1 # hit_boxes need to be multiples of game.move_tile_grid_size if unit_name == UnitName.RandomTownsPerson0: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 130 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(260, 0, 20, 40) self.idle_down.push(idle_down_src0) elif unit_name == UnitName.Merchant: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 130 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(220, 0, 20, 40) self.idle_down.push(idle_down_src0) cast_down_src0 = create_rect(80, 0, 20, 40) self.cast_down.push(cast_down_src0) sit_down_src0 = create_rect(240, 0, 20, 40) self.sit_down.push(sit_down_src0) overworld_idle_down_src0 = create_rect(20, 40, 20, 20) overworld_idle_down_src1 = create_rect(40, 40, 20, 20) overworld_idle_down_src2 = create_rect(60, 40, 20, 20) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src1) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src2) elif unit_name == UnitName.Explorer: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 130 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(0, 0, 20, 40) idle_down_src1 = create_rect(40, 0, 20, 40) idle_down_src2 = create_rect(0, 0, 20, 40) idle_down_src3 = create_rect(60, 0, 20, 40) self.idle_down.push(idle_down_src0) self.idle_down.push(idle_down_src1) self.idle_down.push(idle_down_src2) self.idle_down.push(idle_down_src3) cast_down_src0 = create_rect(80, 0, 20, 40) self.cast_down.push(cast_down_src0) sit_down_src0 = create_rect(200, 0, 20, 40) self.sit_down.push(sit_down_src0) overworld_idle_down_src0 = create_rect(20, 40, 20, 20) overworld_idle_down_src1 = create_rect(40, 40, 20, 20) overworld_idle_down_src2 = create_rect(60, 40, 20, 20) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src1) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src2) elif unit_name == UnitName.Mage: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(20, 0, 20, 40) self.idle_down.push(idle_down_src0) cast_down_src0 = create_rect(100, 0, 20, 40) self.cast_down.push(cast_down_src0) sit_down_src0 = create_rect(200, 0, 20, 40) self.sit_down.push(sit_down_src0) overworld_idle_down_src0 = create_rect(80, 40, 20, 20) overworld_idle_down_src1 = create_rect(100, 40, 20, 20) overworld_idle_down_src2 = create_rect(120, 40, 20, 20) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src1) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src2) elif unit_name == UnitName.Wizard: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(120, 0, 20, 40) self.idle_down.push(idle_down_src0) cast_down_src0 = create_rect(160, 0, 20, 40) self.cast_down.push(cast_down_src0) sit_down_src0 = create_rect(200, 0, 20, 40) self.sit_down.push(sit_down_src0) overworld_idle_down_src0 = create_rect(20, 40, 20, 20) overworld_idle_down_src1 = create_rect(40, 40, 20, 20) overworld_idle_down_src2 = create_rect(60, 40, 20, 20) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src1) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src2) elif unit_name == UnitName.Scholar: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 240 self.sit_anim_speed = 100 self.overworld_idle_anim_speed = 130 self.hit_box_size = create_point(20, 40) idle_down_src0 = create_rect(140, 0, 20, 40) self.idle_down.push(idle_down_src0) cast_down_src0 = create_rect(180, 0, 20, 40) self.cast_down.push(cast_down_src0) sit_down_src0 = create_rect(200, 0, 20, 40) self.sit_down.push(sit_down_src0) overworld_idle_down_src0 = create_rect(20, 40, 20, 20) overworld_idle_down_src1 = create_rect(40, 40, 20, 20) overworld_idle_down_src2 = create_rect(60, 40, 20, 20) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src1) self.overworld_idle_down.push(overworld_idle_down_src0) self.overworld_idle_down.push(overworld_idle_down_src2) elif unit_name == UnitName.Slime: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 300 self.sit_anim_speed = 100 self.hit_box_size = create_point(20, 18) idle_down_src0 = create_rect(0, 40, 20, 18) self.idle_down.push(idle_down_src0) self.cast_down.push(idle_down_src0) elif unit_name == UnitName.Bunny: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 300 self.sit_anim_speed = 100 self.hit_box_size = create_point(20, 28) idle_down_src0 = create_rect(0, 64, 20, 28) self.idle_down.push(idle_down_src0) self.cast_down.push(idle_down_src0) elif unit_name == UnitName.Bat: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 300 self.sit_anim_speed = 100 self.hit_box_size = create_point(20, 26) idle_down_src0 = create_rect(0, 96, 20, 26) self.idle_down.push(idle_down_src0) self.cast_down.push(idle_down_src0) elif unit_name == UnitName.Stump: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 300 self.sit_anim_speed = 100 self.hit_box_size = create_point(28, 38) idle_down_src0 = create_rect(0, 128, 28, 37) self.idle_down.push(idle_down_src0) self.cast_down.push(idle_down_src0) elif unit_name == UnitName.Shroomed: self.image = game.engine.get_image(ImageName.Units) self.idle_anim_speed = 100 self.cast_anim_speed = 300 self.sit_anim_speed = 100 self.hit_box_size = create_point(26, 34) idle_down_src0 = create_rect(0, 165, 26, 33) self.idle_down.push(idle_down_src0) self.cast_down.push(idle_down_src0) else: unit_name_as_int = cast(unit_name, "int") print("UnitSprite.set_to. Unit name not handled. UnitName:", unit_name_as_int) exit(1)
def set_to(self, game: Game, building_name: BuildingName, move_grid_tile_point: SDL_Point): self.tile_point_hit_box.x = move_grid_tile_point.x self.tile_point_hit_box.y = move_grid_tile_point.y world_point = tile_point_to_world_point(move_grid_tile_point, game.move_grid_tile_size) self.sprite.render_dst.dst.x = world_point.x self.sprite.render_dst.dst.y = world_point.y # clear previous ability data self.sprite.srcs.clear() # set new data self.building_name = building_name self.sprite.spawn_time = game.engine.current_time self.sprite.render_dst.is_camera_rendered = True self.is_shop = False self.building_type = BuildingType.NA self.door_tile_point = deref(move_grid_tile_point) if building_name == BuildingName.NA: print("Building.set_to - attempted to call with AbilityName.NA.") exit(1) elif building_name == BuildingName.PlayerLeague: self.building_type = BuildingType.League self.sprite.image = game.engine.get_image(ImageName.Buildings) self.sprite.anim_speed = 100 src_w = 140 src_h = 200 move_grid_hit_box_size_dims = get_move_grid_size_dims( src_w, src_h, game.move_grid_tile_size) self.tile_point_hit_box.w = move_grid_hit_box_size_dims.x self.tile_point_hit_box.h = move_grid_hit_box_size_dims.y src0 = create_rect(0, 0, src_w, src_h) self.sprite.srcs.push(src0) self.door_tile_point.x = move_grid_tile_point.x + 30 self.door_tile_point.y = move_grid_tile_point.y + 80 elif building_name == BuildingName.Shop0: self.building_type = BuildingType.PotionShop self.is_shop = True self.sprite.image = game.engine.get_image(ImageName.Buildings) self.sprite.anim_speed = 100 src_w = 140 src_h = 200 move_grid_hit_box_size_dims = get_move_grid_size_dims( src_w, src_h, game.move_grid_tile_size) self.tile_point_hit_box.w = move_grid_hit_box_size_dims.x self.tile_point_hit_box.h = move_grid_hit_box_size_dims.y src0 = create_rect(140, 0, src_w, src_h) self.sprite.srcs.push(src0) self.door_tile_point.x = move_grid_tile_point.x + 30 self.door_tile_point.y = move_grid_tile_point.y + 80 elif building_name == BuildingName.RecruitmentCenter0: self.building_type = BuildingType.RecruitmentShop self.sprite.image = game.engine.get_image(ImageName.Buildings) self.sprite.anim_speed = 100 src_w = 140 src_h = 200 move_grid_hit_box_size_dims = get_move_grid_size_dims( src_w, src_h, game.move_grid_tile_size) self.tile_point_hit_box.w = move_grid_hit_box_size_dims.x self.tile_point_hit_box.h = move_grid_hit_box_size_dims.y src0 = create_rect(280, 0, src_w, src_h) self.sprite.srcs.push(src0) self.door_tile_point.x = move_grid_tile_point.x + 30 self.door_tile_point.y = move_grid_tile_point.y + 80 elif building_name == BuildingName.TeleportationStone: self.sprite.image = game.engine.get_image(ImageName.Buildings) self.sprite.anim_speed = 150 src_w = 80 src_h = 160 move_grid_hit_box_size_dims = get_move_grid_size_dims( src_w, src_h, game.move_grid_tile_size) self.tile_point_hit_box.w = move_grid_hit_box_size_dims.x self.tile_point_hit_box.h = move_grid_hit_box_size_dims.y src = create_rect(0, 864, src_w, src_h) self.sprite.srcs.push(src) for i in range(6): src = create_rect(i * src_w, 864, src_w, src_h) self.sprite.srcs.push(src) else: building_name_as_int = cast(building_name, "int") print("Building.set_to. Building name not handled. BulidingName:", building_name_as_int) exit(1)