def __init__(self): Tk.__init__(self) self.title("Andantino - Hexagon Grid") self.can = Canvas(self, width=config.width, height=config.height, bg="#60ace6") self.size = config.size self.state = 0 self.start = 1 self.can.pack(padx=0) self.hexagons = [] self.hexagons_board = [] self.hexagons_white = [] self.hex_append = [] self.list_of_neigh = [] self.hexagons_black = [] self.neigh_append = [] self.hex_closest1 = [] self.first_n = [] self.hex_glob = [] self.glob_inter = [] self.first_hex = [] self.glob_line = [] self.initGrid(config.rows, config.cols, self.size) # print("number of hexes in total : " + str(len(self.hexagons))) self.create_hexes_board() draw.draw_player(self.can, self.hexagons_board, self.size) self.can.bind("<Button-1>", self.click_pos) frame = Frame() frame.pack() draw.draw_board(self.can, self.hexagons_board, self.size) draw.draw_neighb(self.can, self.add_first_hex(), self.size)
def all_drawing(): for objects in scene_1.scene_object_for_drawing: if type(objects) is player.Player: draw.draw_player(win,objects) if type(objects) is tarakan.Tarakan: if objects.health >= 0: draw.tarakan(win, objects) objects.dinamics(player_1) player_1.get_damage(objects)
def lets_play(run): win = pygame.display.set_mode((1000, 1000)) player = player_config.Player(500, 500, 40, 20) #x, y, half_wight, half_hight for i in range(0, 5): room = scene.Room(i) while (player.health > 0) and (room.gate.victory == 0) and run: pygame.time.delay(10) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False actions(pygame.key.get_pressed(), player) player.damage() draw.room(win) #рисуем локацию draw.draw_player(win, player) for tar in room.tarakanS: if tar.type == 0: tar.picture_move = pygame.image.load( os.path.join('/home/andrey/levin-927_game/', 'tarakan_left.png')) elif tar.type == 1: tar.picture_move = pygame.image.load( os.path.join('/home/andrey/levin-927_game/', 'clop')) elif tar.type == 2: tar.picture_move = pygame.image.load( os.path.join('/home/andrey/levin-927_game/', 'srider')) elif tar.type == 3: tar.picture_move = pygame.image.load( os.path.join('/home/andrey/levin-927_game/', 'bee')) draw.tarakan(win, tar, player) tar.dinamics(player) player.get_damage(tar) if tar.health <= 0: room.tarakanS.remove(tar) if room.time_before_create > 0: room.time_before_create -= 1 if len(room.tarakanS) == 0: if room.number_wave > room.list_enemies[0]: draw.gate(win, room.gate.coordinates) room.output(player) else: draw.pip(win) if (abs(player.x - 500) < 25) and (abs(player.y - 500) < 25): room.create_enemies(scene.list_enemies) pygame.display.update() if room.gate.victory == 0: break '''
def drawing_exit_room(self): pygame.time.delay(10) for event in pygame.event.get(): if event.type == pygame.QUIT: self.parameter = 'Exit' draw.room(self.win, self.map, self.player.x, self.player.y) #рисуем локацию draw.draw_player(self.win, self.player) draw.draw_stats(self.win, self.player) if self.players_status == 'pair': #рисуем локацию draw.draw_player(self.win, self.player2) draw.gate(self.win, self.room.gate.coordinates, self.map) draw.items(self.win, self.room.items) draw.FPS(self.win, self.fps['value']) self.fps_upd() pygame.display.update()
def drawing_battle(self): pygame.time.delay(10) for event in pygame.event.get(): if event.type == pygame.QUIT: self.parameter = 'Exit' draw.room(self.win, self.map, self.player.x, self.player.y) #рисуем локацию draw.draw_player(self.win, self.player) draw.draw_stats(self.win, self.player) if self.players_status == 'pair': #рисуем локацию draw.draw_player(self.win, self.player2) for tar in self.room.tarakanS: draw.tarakan(self.win, tar) if (len(self.room.tarakanS) == 0) and (self.room.number_wave <= self.room.list_enemies[0]): draw.pip(self.win) draw.FPS(self.win, self.fps['value']) self.fps_upd() pygame.display.update()
elif event.type == pygame.KEYDOWN: if 258 <= event.key <= 260 or 50 <= event.key <= 52: #载入相应数量的角色 click_sound.play() role.append(pygame.image.load('image/role/小e.jpg')) role.append(pygame.image.load('image/role/皮卡丘.jpg')) if event.key == 259 or event.key == 51: role.append(pygame.image.load('image/role/可达鸭.jpg')) elif event.key == 260 or event.key == 52: role.append(pygame.image.load('image/role/可达鸭.jpg')) role.append(pygame.image.load('image/role/小黄鸡.jpg')) screen.blit(map_screen, (0, 0)) for i in range(len(role)): #初始化游戏玩家 role[i] = pygame.transform.scale(role[i], role_size) player.append(Player(i)) player[i].local = local_init[i] draw_player(screen, player, role, stop_picture) status = 2 elif status == 2: #掷骰子 for i in range(6): # 绘制骰子动画 screen.blit(picture_dice[i], (500, 400)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == 273: dice_answer = get_dice() status = 3 pygame.display.update() elif status == 3: #玩家行走
astronaut.location[0] -= astronaut.speed elif keys[pygame.K_RIGHT]: astronaut.frame = (astronaut.frame + 1) % 5 astronaut.direction = "right" astronaut.location[0] += astronaut.speed elif keys[pygame.K_UP]: astronaut.frame = (astronaut.frame + 1) % 5 astronaut.direction = "up" astronaut.location[1] -= astronaut.speed elif keys[pygame.K_DOWN]: astronaut.frame = (astronaut.frame + 1) % 5 astronaut.direction = "down" astronaut.location[1] += astronaut.speed # Simple collision test if cockpit[int(player_to_grid_y), int(player_to_grid_x)] not in walkable_spaces: astronaut.location = old_location # Draw everything screen.blit(bg_image, (0, 0)) #draw.draw_floor(screen, cockpit, room_offset) draw.draw_room(screen, cockpit, room_offset) draw.draw_player(screen, astronaut) #draw.draw_room(screen, cockpit, room_offset) # Update the screen pygame.display.flip() clock.tick(FPS) pygame.quit()
def main(): global directory, level, output if len(sys.argv) == 1: wadfile = DEFAULT_WADFILE else: wadfile = sys.argv[1] if len(sys.argv) > 2: level = sys.argv[2] if len(sys.argv) > 3: output = sys.argv[3] directory, is_doom_two = wad.read_wadfile(wadfile) if not level: #raw_level = input("Enter map to load > ") #level = raw_level.strip() level = "E1M1" #if not output: # raw_output = input("Enter file to dump map to > ") # output = raw_output.strip() level_data = directory[level + '_DATA'] things = level_data['THINGS'] player_thing = next(t for t in things if t.thing_type == 1) draw.cam_x = player_thing.x_pos draw.cam_y = player_thing.y_pos draw.flip_func = flip init() clock = pygame.time.Clock() font = pygame.font.Font('freesansbold.ttf', 14) print("Calculating pvs") sect_mgr = portal.SectorManager(level_data['NODES'], level_data['SSECTORS']) sect_mgr.generate_portal_sector_graph() #global_pvs = pvs.calc_pvs(False, level_data) #level_data['PVS'] = global_pvs print("finished calculating pvs") sys.exit(1) #sect_pvs = pvs.calc_pvs(0, True, level_data) #print("got pvs for sector 0: ") #print(str(sect_pvs)); #wad.dump_level_data(output, level_data) while (True): draw.clear_col_buffer() span_buffer.clear_span_buffer() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYUP: if event.key == pygame.K_z: draw.zoom += 1 elif event.key == pygame.K_x: draw.zoom -= 1 elif event.key == pygame.K_b: draw.backface_culling = not draw.backface_culling elif event.key == pygame.K_f: tbl = { (False, False): (False, True), (False, True): (True, False), (True, False): (True, True), (True, True): (False, False) } draw.bsp_node_frustum_culling, draw.seg_frustum_culling = ( tbl[(draw.bsp_node_frustum_culling, draw.seg_frustum_culling)]) elif event.key == pygame.K_p: draw.pvs_check = not draw.pvs_check elif event.key == pygame.K_o: draw.draw_outline = not draw.draw_outline elif event.key == pygame.K_t: draw.show_render_traversal = not draw.show_render_traversal elif event.key == pygame.K_q: pygame.quit() sys.exit() if draw.zoom <= 0: draw.zoom = 1 keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: draw.cam_angle -= .08 elif keys[pygame.K_RIGHT]: draw.cam_angle += .08 move = False if keys[pygame.K_UP]: move = True factor = 10 elif keys[pygame.K_DOWN]: move = True factor = -10 if move: draw.cam_x += (math.sin(draw.cam_angle) * factor) draw.cam_y += (math.cos(draw.cam_angle) * factor) # erase the screen topdown_draw_surf.fill(BLACK) if draw.draw_outline: persp_draw_surf.fill(BLACK) draw.draw_stats.reset() nodes_traversed = 0 def node_callback(node, level, on_left): nonlocal nodes_traversed nodes_traversed += 1 #draw.draw_bsp_node(node, level, topdown_draw_surf, RED, draw_left=on_left, draw_right=(not on_left)) ssect_callback = lambda ssect: None cur_subsector_num = bsp.find_subsector_idx_for_position( level_data, draw.cam_x, draw.cam_y, node_callback) cur_subsector = level_data['SSECTORS'][cur_subsector_num] cur_sector_idx = wad.get_subsector_sector_idx(cur_subsector, level_data) cur_sector = level_data['SECTORS'][cur_sector_idx] #print("current sector: {}".format(cur_sector_idx)) target_height = cur_sector.floor_height + draw.EYE_HEIGHT if draw.cam_z > target_height: draw.cam_z -= 25 elif draw.cam_z < target_height: draw.cam_z = target_height #draw.cam_z = cur_sector.floor_height + draw.EYE_HEIGHT def draw_node_callback(node, visiting_left, visiting_right): draw.draw_stats.nodes_traversed += 1 if draw.show_render_traversal: draw.draw_bsp_node(node, level, topdown_draw_surf, TRANS_GREEN, draw_left=visiting_left, draw_right=visiting_right) def bound_func(ssect_idx, ssect): draw.ssect_draw_visible_segs(level_data, topdown_draw_surf, persp_draw_surf, ssect) if not draw.draw_outline: draw.fill_floors(persp_draw_surf) #bsp.traverse_all_bsp_nodes(level_data, #ssect_callback=bound_func) #bsp.traverse_bsp_front_to_back(level_data, # draw.cam_x, draw.cam_y, cur_subsector, # draw_node_callback, # ssect_callback = bound_func) bsp.iterate_cur_pvs(level_data, draw.cam_x, draw.cam_y, cur_subsector_num, draw_node_callback, ssect_callback=bound_func) draw.draw_player(topdown_draw_surf, color=RED) def stats_func(): line = 0 def draw_font_line(st): nonlocal line text_surf = font.render(st, True, GREEN) scale_surf.blit(text_surf, (1, line)) line += 15 fps = clock.get_fps() draw_stats = draw.draw_stats draw_font_line("drawing map {}".format(level)) draw_font_line("{} nodes traversed".format( draw_stats.nodes_traversed)) draw_font_line( "pvs {}".format("enabled" if draw.pvs_check else "disabled")) draw_font_line("backface culling {}".format( "enabled" if draw.backface_culling else "disabled")) draw_font_line("bsp frustum culling {}".format( "enabled" if draw.bsp_node_frustum_culling else "disabled")) draw_font_line("seg frustum culling {}".format( "enabled" if draw.seg_frustum_culling else "disabled")) draw_font_line("{} subsectors processed".format( draw_stats.ssectors_processed)) draw_font_line("{} segs backface culled".format( draw_stats.segs_backface_culled)) draw_font_line("{} segs transformed".format( draw_stats.segs_transformed)) draw_font_line("{} segs fully clipped".format( draw_stats.segs_fully_clipped)) draw_font_line("{} segs drawn".format(draw_stats.segs_drawn)) draw_font_line("{} ms".format(int(1000 / max(1, fps)))) """ print("------------------") print("seg v1: {}".format(draw_stats.seg_v1)) print("seg v2: {}".format(draw_stats.seg_v2)) print("player: {}".format((draw.cam_x, draw.cam_y))) print("player angle: {}".format(math.degrees(draw.cam_angle))) print("player mod angle: {}".format(math.degrees(draw.cam_angle) % 360)) print("player adjusted angle: {}".format(math.degrees(draw_stats.adjusted_angle))) print("player vector: {}".format(draw_stats.player_vector)) print("seg dx dy: {},{}".format(draw_stats.seg_dx, draw_stats.seg_dy)) print("seg normal: {}".format(draw_stats.seg_normal)) print("seg normal angle: {}".format(draw_stats.seg_normal_angle)) print("seg player dot product: {}".format(draw_stats.seg_dot_product)) print("vec from player to seg v1: {}".format(draw_stats.seg_dv1)) print("vec from player to seg v1: {}".format(draw_stats.seg_dv2)) print("angle from player to seg v1: {}".format(draw_stats.seg_v1_angle)) print("angle from player to seg v2: {}".format(draw_stats.seg_v2_angle)) print("rotated v1: {}".format(draw_stats.seg_r1)) print("rotated v2: {}".format(draw_stats.seg_r2)) print("angle from player to rot seg v1: {}".format(draw_stats.seg_rot_v1_angle)) print("angle from player to rot seg v2: {}".format(draw_stats.seg_rot_v2_angle)) print("v1 fov pos: {}".format(draw_stats.v1_fov_pos)) print("v2 fov pos: {}".format(draw_stats.v2_fov_pos)) print("------------------") """ #print("max_y_depth: {}".format(draw_stats.max_y_depth)) flip(stats_func) clock.tick(60)