def fire(x, y, amount): _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) flags.register(_blood) timers.register(_blood) entities.trigger_event(_blood, 'set_flag', flag='alpha', value=amount) entities.trigger_event(_blood, 'set_flag', flag='alpha_max', value=amount) entities.trigger_event(_blood, 'set_char', char=' ') _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), amount) _color[1] = numbers.interp_velocity(_color[1], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), amount) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) #display._set_char('tiles', _x, _y, random.choice([',', '.', '^']), _color[0], _color[1]) entities.register_event(_blood, 'tick', _tick_fire) entities.register_event(_blood, 'position_changed', lambda e, x, y, **kwargs: char(x, y, flags.get_flag(e, 'alpha'))) entities.trigger_event(_blood, 'create_timer', time=120, repeat=-1, repeat_callback=lambda e: movement.push(e, random.randint(-1, 1), random.randint(-1, 1), time=1)) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) entities.trigger_event(_blood, 'set_position', x=_x, y=_y) #light(_x, _y, random.randint(5, 7), r=1.5, g=.1, b=.1) return _blood
def vapor(x, y, surface='effects', group='effects', start_alpha=0.6, fade_rate=0.095): if '--no-fx' in sys.argv: return _vapor = _create(x, y, surface=surface, group=group) _x, _y = (int(round(x)), int(round(y))) _vapor['fade_rate'] = fade_rate entities.trigger_event(_vapor, 'set_char', char=' ') _vapor['alpha'] = start_alpha _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], (255, 255, 255), start_alpha) _color[1] = numbers.interp_velocity(_color[1], (255, 255, 255), start_alpha) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) _muzzle_flash_move(_vapor) entities.trigger_event(_vapor, 'set_fore_color', color=_color[0]) entities.trigger_event(_vapor, 'set_back_color', color=_color[1]) entities.trigger_event(_vapor, 'create_timer', time=0, repeat=-1, repeat_callback=_vapor_fade) return _vapor
def muzzle_flash(x, y, direction, surface='effects', group='effects', start_alpha=0.4, no_move=False): if '--no-fx' in sys.argv: return _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) entities.trigger_event(_blood, 'set_char', char=random.choice([';', '3', '.', '^'])) _blood['alpha'] = start_alpha _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], (255, 255, 255), start_alpha) _color[1] = numbers.interp_velocity(_color[1], (255, 255, 255), start_alpha) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(_blood, 'set_direction', direction=direction+random.randint(-35, 35)) _muzzle_flash_move(_blood) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) if not no_move: entities.trigger_event(_blood, 'create_timer', time=2, repeat=random.randint(1, 3), repeat_callback=_muzzle_flash_move, exit_callback=_muzzle_delete) entities.trigger_event(_blood, 'create_timer', time=1, repeat=6, repeat_callback=_muzzle_flash_fade) return _blood
def _tick_fire(entity): _x, _y = movement.get_position(entity) _alpha = flags.get_flag(entity, 'alpha') _alpha += random.uniform(-.3, .3) _alpha = numbers.clip(_alpha, 0, 1) if not _alpha: #char(_x, _y, numbers.clip(flags.get_flag(entity, 'alpha_max') - random.uniform(.1, .2), 0, 1)) entities.delete_entity(entity) return #entities.trigger_event(entity, 'set_char', char=random.choice(['*', '&', '%'])) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), _alpha) _color[1] = numbers.interp_velocity(_color[1], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), _alpha) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(entity, 'set_fore_color', color=_color[0]) entities.trigger_event(entity, 'set_back_color', color=_color[1]) entities.trigger_event(entity, 'set_flag', flag='alpha', value=_alpha)
def smoke(x, y, amount, start_amount=0.0, decay_amount=1.0): _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) _fore_color = random.choice([constants.BLACK_1, constants.BLACK_2, constants.BLACK_3]) _back_color = random.choice([constants.BLACK_1, constants.BLACK_2, constants.BLACK_3]) amount = numbers.clip(amount + random.uniform(-.1, .1), 0, 1) entities.trigger_event(_blood, 'set_char', char=' ') flags.register(_blood) flags.set_flag(_blood, 'alpha', value=start_amount) flags.set_flag(_blood, 'decay', value=decay_amount) flags.set_flag(_blood, 'alpha_mode', value=0) flags.set_flag(_blood, 'alpha_max', value=amount) flags.set_flag(_blood, 'fore_color', value=_fore_color) flags.set_flag(_blood, 'back_color', value=_back_color) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], _fore_color, amount) _color[1] = numbers.interp_velocity(_color[1], _back_color, amount) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) entities.register_event(_blood, 'tick', _tick_smoke) return _blood
def _muzzle_flash_fade(entity): entity['alpha'] -= 0.07 _x, _y = movement.get_position(entity) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], (255, 255, 255), entity['alpha']) _color[1] = numbers.interp_velocity(_color[1], (255, 255, 255), entity['alpha']) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(entity, 'set_fore_color', color=_color[0]) entities.trigger_event(entity, 'set_back_color', color=_color[1])
def blood(x, y, surface='effects', group='effects'): _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) entities.trigger_event(_blood, 'set_char', char=random.choice([';', '3', '.', '^'])) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], random.choice([constants.BLOOD_1, constants.BLOOD_2, constants.BLOOD_3]), 0.4) _color[1] = numbers.interp_velocity(_color[1], random.choice([constants.BLOOD_1, constants.BLOOD_2, constants.BLOOD_3]), 0.4) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) return _blood
def _vapor_fade(entity): entity['alpha'] -= entity['fade_rate'] if entity['alpha'] <= 0: entities.delete_entity(entity) return _x, _y = movement.get_position(entity) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], (255, 255, 255), entity['alpha']) _color[1] = numbers.interp_velocity(_color[1], (255, 255, 255), entity['alpha']) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(entity, 'set_fore_color', color=_color[0]) entities.trigger_event(entity, 'set_back_color', color=_color[1])
def _tick_smoke(entity): _x, _y = movement.get_position(entity) _alpha = flags.get_flag(entity, 'alpha') _alpha_mode = flags.get_flag(entity, 'alpha_mode') _alpha_max = flags.get_flag(entity, 'alpha_max') _fore_color = flags.get_flag(entity, 'fore_color') _back_color = flags.get_flag(entity, 'back_color') _decay_mod = flags.get_flag(entity, 'decay') if _alpha_mode: _alpha -= random.uniform(.001 * _decay_mod, .005 * _decay_mod) if _alpha <= 0: display._set_char('tiles', _x, _y, ' ', (0, 0, 0), None) entities.delete_entity(entity) return else: _alpha += random.uniform(.01, .05) if _alpha > _alpha_max: _alpha_mode = 1 _alpha = numbers.clip(_alpha, 0, 1) #entities.trigger_event(entity, 'set_char', char=random.choice(['*', '&', '%'])) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], _fore_color, _alpha) _color[1] = numbers.interp_velocity(_color[1], _back_color, _alpha) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(entity, 'set_fore_color', color=_color[0]) entities.trigger_event(entity, 'set_back_color', color=_color[1]) entities.trigger_event(entity, 'set_flag', flag='alpha', value=_alpha) entities.trigger_event(entity, 'set_flag', flag='alpha_mode', value=_alpha_mode)
def draw_map_grid(selected_grid=None, fade=1.0): _shader = [] _shader.append(numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader.append(numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader.append(numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader[0] += 1.35 * fade _shader[1] += 1.35 * fade _shader[2] += 1.25 * fade display.apply_surface_shader("map", _shader, constants.STRAT_MAP_WIDTH, constants.STRAT_MAP_HEIGHT) display.blit_surface_viewport("map", 0, 0, constants.STRAT_MAP_WIDTH, constants.STRAT_MAP_HEIGHT) for x in range(constants.STRAT_MAP_WIDTH / constants.MAP_CELL_SPACE): for y in range(constants.STRAT_MAP_HEIGHT / constants.MAP_CELL_SPACE): _tile = world_strategy.MAP["grid"][x, y] if ( x == controls.get_mouse_pos()[0] / constants.MAP_CELL_SPACE and y == controls.get_mouse_pos()[1] / constants.MAP_CELL_SPACE ): _hover = True else: _hover = False for _x in range(constants.MAP_CELL_SPACE): for _y in range(constants.MAP_CELL_SPACE): _d_x = (x * constants.MAP_CELL_SPACE) + _x _d_y = (y * constants.MAP_CELL_SPACE) + _y _back_color = None if _tile["is_ownable"]: if _tile["owned_by"] == "Terrorists": _fore_color = (200, 0, 0) _back_color = (125, 0, 0) elif _tile["owned_by"] == "Rogues": _fore_color = (0, 200, 0) _back_color = (0, 125, 0) else: _fore_color = (180, 180, 180) _back_color = (100, 100, 100) if (x, y) == selected_grid: _fore_color = ( int(round(_fore_color[0] * 1.2)), int(round(_fore_color[1] * 1.2)), int(round(_fore_color[2] * 1.2)), ) _back_color = ( int(round(_back_color[0] * 1.2)), int(round(_back_color[1] * 1.2)), int(round(_back_color[2] * 1.2)), ) if not _x + _y: if _hover or (x, y) == selected_grid: _char = chr(201) _fore_color = (255, 255, 255) else: _char = chr(218) elif _x == constants.MAP_CELL_SPACE - 1 and not _y: if _hover or (x, y) == selected_grid: _char = chr(187) _fore_color = (255, 255, 255) else: _char = chr(191) elif not _x and _y == constants.MAP_CELL_SPACE - 1: if _hover or (x, y) == selected_grid: _char = chr(200) _fore_color = (255, 255, 255) else: _char = chr(192) elif _x + _y == (constants.MAP_CELL_SPACE - 1) * 2: if _hover or (x, y) == selected_grid: _char = chr(188) _fore_color = (255, 255, 255) else: _char = chr(217) elif ( _y > 0 and _y < constants.MAP_CELL_SPACE - 1 and (not _x or _x == constants.MAP_CELL_SPACE - 1) ): _char = chr(179) elif ( _x > 0 and _x < constants.MAP_CELL_SPACE - 1 and (not _y or _y == constants.MAP_CELL_SPACE - 1) ): _char = chr(196) else: _char = "." display.write_char( "map_markers", _d_x, _d_y, _char, fore_color=_fore_color, back_color=_back_color ) else: if _hover or (x, y) == selected_grid: if not _x + _y: _char = chr(201) elif _x == constants.MAP_CELL_SPACE - 1 and not _y: _char = chr(187) elif not _x and _y == constants.MAP_CELL_SPACE - 1: _char = chr(200) elif _x + _y == (constants.MAP_CELL_SPACE - 1) * 2: _char = chr(188) else: _char = " " _color = display.get_color_at("map", _d_x, _d_y)[1] display.write_char( "map_markers", _d_x, _d_y, _char, back_color=( int(round(_color[0] * 1.4)), int(round(_color[1] * 1.4)), int(round(_color[2] * 1.4)), ), )
def draw_map_grid(selected_grid=None, fade=1.0): _shader = [] _shader.append( numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader.append( numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader.append( numpy.zeros((constants.STRAT_MAP_HEIGHT, constants.STRAT_MAP_WIDTH), dtype=numpy.float)) _shader[0] += 1.35 * fade _shader[1] += 1.35 * fade _shader[2] += 1.25 * fade display.apply_surface_shader('map', _shader, constants.STRAT_MAP_WIDTH, constants.STRAT_MAP_HEIGHT) display.blit_surface_viewport('map', 0, 0, constants.STRAT_MAP_WIDTH, constants.STRAT_MAP_HEIGHT) for x in range(constants.STRAT_MAP_WIDTH / constants.MAP_CELL_SPACE): for y in range(constants.STRAT_MAP_HEIGHT / constants.MAP_CELL_SPACE): _tile = world_strategy.MAP['grid'][x, y] if x == controls.get_mouse_pos( )[0] / constants.MAP_CELL_SPACE and y == controls.get_mouse_pos( )[1] / constants.MAP_CELL_SPACE: _hover = True else: _hover = False for _x in range(constants.MAP_CELL_SPACE): for _y in range(constants.MAP_CELL_SPACE): _d_x = (x * constants.MAP_CELL_SPACE) + _x _d_y = (y * constants.MAP_CELL_SPACE) + _y _back_color = None if _tile['is_ownable']: if _tile['owned_by'] == 'Terrorists': _fore_color = (200, 0, 0) _back_color = (125, 0, 0) elif _tile['owned_by'] == 'Rogues': _fore_color = (0, 200, 0) _back_color = (0, 125, 0) else: _fore_color = (180, 180, 180) _back_color = (100, 100, 100) if (x, y) == selected_grid: _fore_color = int(round( _fore_color[0] * 1.2)), int( round(_fore_color[1] * 1.2)), int( round(_fore_color[2] * 1.2)) _back_color = int(round( _back_color[0] * 1.2)), int( round(_back_color[1] * 1.2)), int( round(_back_color[2] * 1.2)) if not _x + _y: if _hover or (x, y) == selected_grid: _char = chr(201) _fore_color = (255, 255, 255) else: _char = chr(218) elif _x == constants.MAP_CELL_SPACE - 1 and not _y: if _hover or (x, y) == selected_grid: _char = chr(187) _fore_color = (255, 255, 255) else: _char = chr(191) elif not _x and _y == constants.MAP_CELL_SPACE - 1: if _hover or (x, y) == selected_grid: _char = chr(200) _fore_color = (255, 255, 255) else: _char = chr(192) elif _x + _y == (constants.MAP_CELL_SPACE - 1) * 2: if _hover or (x, y) == selected_grid: _char = chr(188) _fore_color = (255, 255, 255) else: _char = chr(217) elif _y > 0 and _y < constants.MAP_CELL_SPACE - 1 and ( not _x or _x == constants.MAP_CELL_SPACE - 1): _char = chr(179) elif _x > 0 and _x < constants.MAP_CELL_SPACE - 1 and ( not _y or _y == constants.MAP_CELL_SPACE - 1): _char = chr(196) else: _char = '.' display.write_char('map_markers', _d_x, _d_y, _char, fore_color=_fore_color, back_color=_back_color) else: if _hover or (x, y) == selected_grid: if not _x + _y: _char = chr(201) elif _x == constants.MAP_CELL_SPACE - 1 and not _y: _char = chr(187) elif not _x and _y == constants.MAP_CELL_SPACE - 1: _char = chr(200) elif _x + _y == (constants.MAP_CELL_SPACE - 1) * 2: _char = chr(188) else: _char = ' ' _color = display.get_color_at('map', _d_x, _d_y)[1] display.write_char( 'map_markers', _d_x, _d_y, _char, back_color=(int(round(_color[0] * 1.4)), int(round(_color[1] * 1.4)), int(round(_color[2] * 1.4))))
def char(x, y, amount): _color = list(display.get_color_at('tiles', x, y)) _color[0] = numbers.interp_velocity(_color[0], random.choice([constants.DARKER_BLACK_1, constants.DARKER_BLACK_2, constants.DARKER_BLACK_3]), amount) _color[1] = numbers.interp_velocity(_color[1], random.choice([constants.DARKER_BLACK_1, constants.DARKER_BLACK_2, constants.DARKER_BLACK_3]), amount) display._set_char('tiles', x, y, random.choice([',', '.', '^']), _color[0], _color[1])