def gamelogic(layer, tilesets): x = 0 y = 0 for data in layer['data']: if data > 0: for t in tilesets: if (t['firstgid'] <= data): tileset = t break id = data - t['firstgid'] + 1 if id == 1: #block c = Entity() c.set_collider(Collider()) c.set_position(sf.Vector2(x, y)) elif id == 2: #blob spawn m = Blob() m.set_position(sf.Vector2(x, y)) elif id == 6: #purple spawn m = Purple() m.set_position(sf.Vector2(x, y)) elif id == 10: #purple spawn m = Witch() m.set_position(sf.Vector2(x, y)) elif id == 3: #player spawn p = Player() p.set_position(sf.Vector2(x, y)) Scene.current().camera.set_parent(p) x += 1 if (x >= layer['width']): x = 0 y += 1
def init_player(race, prof, name): consts = Constants.consts race_dict = consts[race] prof_dict = consts[prof] hp = race_dict['hp'] + prof_dict['hp_bonus'] defense = race_dict['defense'] + prof_dict['def_bonus'] power = race_dict['power'] + prof_dict['power_bonus'] xp = 0 armor = 0 mana = race_dict['mana'] + prof_dict['mana_bonus'] magic = race_dict['magic'] + prof_dict['magic_bonus'] fighting = race_dict['fighting'] + prof_dict['fighting_bonus'] shielding = race_dict['shielding'] + prof_dict['shielding_bonus'] conjuring = race_dict['conjuring'] + prof_dict['conjuring_bonus'] archery = race_dict['archery'] + prof_dict['archery_bonus'] transmutations = race_dict['transmutations'] + prof_dict['transmutations_bonus'] hexes = race_dict['hexes'] + prof_dict['hexes_bonus'] speed = race_dict['speed'] mana_regen = race_dict['mana_regen'] fighter_component = Fighter(hp, defense, power, xp, armor, mana, magic, death_function=DeathFunctions.player_death, fighting=fighting, shielding=shielding, conjuring=conjuring, archery=archery, transmutations=transmutations, hexes=hexes, speed=speed, mana_regen=mana_regen) fighter_component.stealthiness = race_dict['stealthiness'] inv_component = Inventory() player = Entity(0, 0, consts['player_tile'], name, libtcod.white, blocks=True, fighter=fighter_component, race=race, prof=prof, inventory=inv_component) player.level = 1 player.isplayer = True return player
def place_objects(self, world, room, max_monsters, monster_chances): consts = Constants.consts num_monsters = libtcod.random_get_int(0, 0, max_monsters) for i in range(num_monsters): x = libtcod.random_get_int(0, room.x1 + 1, room.x2 - 1) y = libtcod.random_get_int(0, room.y1 + 1, room.y2 - 1) if not Entity.is_blocked(x, y, world.tilemap, world.objects): choice = self.random_choice(monster_chances) monster = None if choice == 'mchance_orc': time_c = TimeObject() ai_c = BasicAi(world) fighter_c = Fighter( hp=10, defense=2, power=3, xp=5, armor=0, mana=0, magic=0, death_function=DeathFunctions.monster_death, fighting=0) monster = Entity(x, y, consts['orc_tile'], 'orc', libtcod.white, blocks=True, fighter=fighter_c, ai=ai_c, timeobj=time_c) elif choice == 'mchance_snake': pass else: pass if monster is not None: world.objects.append(monster) monster.timeobj.register()
def run(): global wave # SPAWN if len(store.get("enemy_mtx")) == 0: wave += 1 enemy_mtx = [] level = randint(1, 3) enemy_type = randint(1, 5) boss_type = randint(1, 2) level_constructor = open("./src/assets/levels/level" + str(level) + ".txt", "r") line = level_constructor.readline() lin = 0 while lin < 17: for col in range(len(line)): if line[col] == "1" or (line[col] == "2" and wave % 3 == 0): if line[col] == "1": enemy = Entity( window, "./src/assets/actors/enemies/minion{}/running_right.png".format( enemy_type ), 8, ) enemy.strenght = config.ENEMY_DAMAGE + get_strenght_minion(wave) enemy.velocity = config.ENEMY_VELOCITY + get_velocity(wave) enemy.life = config.ENEMY_LIFE + get_life_minion(wave) elif line[col] == "2" and wave % 3 == 0: enemy = Entity( window, "./src/assets/actors/enemies/boss{}/running_right.png".format( boss_type ), 8, ) enemy.strenght = config.BOSS_DAMAGE + get_strenght_boss(wave) enemy.life = config.BOSS_LIFE + get_life_boss(wave) enemy.velocity = config.BOSS_VELOCITY + get_velocity(wave) enemy.is_boss = True enemy.set_position( col * (config.WIDTH / 22) + (config.WIDTH / 22) / 2 - enemy.animation.width / 2, lin * (config.HEIGHT / 17) + (config.HEIGHT / 17) / 2 - enemy.animation.height, ) enemy_mtx.append(enemy) line = level_constructor.readline() lin += 1 store.dispatch("enemy_mtx", value=enemy_mtx) # MOVEMENT for enemy in store.get("enemy_mtx"): enemy_direction = math.Vector2( store.get("player").animation.x - enemy.animation.x, store.get("player").animation.y - enemy.animation.y, ) enemy_direction.normalize_ip() enemy_direction *= enemy.velocity + wave enemy.move(enemy_direction) # COLISSION for enemy1 in range(len(store.get("enemy_mtx"))): for enemy2 in range(enemy1 + 1, len(store.get("enemy_mtx"))): if store.get("enemy_mtx")[enemy1].animation.collided( store.get("enemy_mtx")[enemy2].animation ): if store.get("enemy_mtx")[enemy1].distance_to( store.get("player") ) < store.get("enemy_mtx")[enemy2].distance_to(store.get("player")): new_vel_length = ( store.get("enemy_mtx")[enemy2].velocity_vector.length() - 30 ) if new_vel_length == 0: new_vel_length = 1 store.get("enemy_mtx")[enemy2].velocity_vector.normalize_ip() store.get("enemy_mtx")[enemy2].velocity_vector *= new_vel_length store.get("enemy_mtx")[enemy2].move( store.get("enemy_mtx")[enemy2].velocity_vector ) else: new_vel_length = ( store.get("enemy_mtx")[enemy1].velocity_vector.length() - 30 ) if new_vel_length == 0: new_vel_length = 1 store.get("enemy_mtx")[enemy1].velocity_vector.normalize_ip() store.get("enemy_mtx")[enemy1].velocity_vector *= new_vel_length store.get("enemy_mtx")[enemy1].move( store.get("enemy_mtx")[enemy1].velocity_vector ) # DRAW for enemy in store.get("enemy_mtx"): enemy.update() enemy.render() store.dispatch("wave", value=wave)
from pygame import math from classes.entity import Entity from environment import config from environment.instances import window, keyboard, store player = Entity(window, "./src/assets/actors/jorge/idle_right.png", 8) player.set_position(10, window.height / 2) vel_vector = math.Vector2(0, 0) store.dispatch("player", value=player) def reset(): global vel_vector player.__init__(window, "./src/assets/actors/jorge/idle_right.png", 8) player.set_position(10, window.height / 2) vel_vector = math.Vector2(0, 0) store.dispatch("player", value=player) def run(): global vel_vector # DEFAULT player.set_state("idle") vel_vector.update(0, 0)
the_surface = pygame.display.get_surface() bad_guy_color = pygame.color.Color('red') archer_color = pygame.color.Color('green') has_focus = 0 last_pressed_keys = pygame.key.get_pressed() screen.fill(black) radius = 25 good_guy_pos = [radius, size[1] - radius] bad_guy_pos = [size[0] - radius, size[1] - radius] my_bow = MAX_BOW_STR do_it = True bad_guy = Entity(Vector(bad_guy_pos), screen) archer_pos = Vector(good_guy_pos) archer_population = ArcherPopulation(screen, archer_pos, num_archers=25, target=bad_guy) while do_it: screen.fill(black) # print(type(screen)) # print(dir(screen)) bad_guy.position.x = random.randrange(int(screen.get_width() * .75), screen.get_width()) # bad_guy.position.y = random.randrange(int(screen.get_height() * .75), screen.get_height()) # archer_pos.x = random.randrange(0, int(screen.get_width() * .25)) # archer_pos.y = random.randrange(int(screen.get_height() * .75), screen.get_height())
build_light_walker, destroy_light_walker, build_lw_cell_2, \ destroy_lw_cell_2, build_lw_cell_3, build_lw_cell_4, \ build_lw_cell_5, build_lw_cell_6, build_lw_cell_7 from static.variables import * from classes.entity import Entity from classes.game_map import GameMap from classes.map_shapes import Rect colors = { 'dark_wall' : tcod.Color(100, 0, 0), 'dark_ground' : tcod.Color(50, 50, 150) } con = tcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) player = Entity(int(screen_width / 2), int(screen_height / 2), '@', tcod.white, player=True) npc = Entity(int(screen_width / 2), int(screen_height / 2), ' ', tcod.white, player=False) entities = [player] room = Rect(player.x - 15, player.y - 15, 15, 15) def render_map(): # Draw all the tiles in the game map for y in range(game_map.height): for x in range(game_map.width): wall = game_map.tiles[x][y].block_sight if wall: tcod.console_set_char_background(con, x, y, colors.get('dark_wall'), tcod.BKGND_SET) else: tcod.console_set_char_background(con, x, y, colors.get('dark_ground'), tcod.BKGND_SET)
# the dict! Using just for colors d = { 1: (255, 175, 0), # blueish color 2: (0, 255, 0), # green 3: (0, 0, 255) } # red episode_rewards = [] aggr_episode_rewards = {'ep': [], 'avg': [], 'min': [], 'max': []} q_table = QTable(SIZE, start_q_table) for episode in range(HM_EPISODES): # Crie os individuos player = Entity(SIZE) door = Entity(SIZE) enemy = Entity(SIZE) # se necessário renderize a tela e imprima certas informações if episode % SHOW_EVERY == 0: print(f"on #{episode}, epsilon is {epsilon}") print( f"{SHOW_EVERY} ep mean: {np.mean(episode_rewards[-SHOW_EVERY:])}") show = True else: show = False episode_reward = 0 for i in range(200): # observação é uma tupla que contem a distância relativa entre o jogador e o alimento e o inimigo no formato (7, 2) observation = (player - door, player - enemy)