NotQuiteParadise2

nqp.core package

Submodules

nqp.core.assets module

class Assets(game: Game)[source]

Bases: object

DO NOT USE. Use visuals.py instead

__init__(game: Game)[source]
create_fancy_font(text: str, pos: pygame.Vector2 = <Vector2(0, 0)>, line_width: int = 0, font_effects: Optional[List[FontEffects]] = None) FancyFont[source]

Create a FancyFont instance. If line_width isnt given then will default to full screen.

create_font(font_type: nqp.core.constants.FontType, text: str, pos: pygame.math.Vector2 = (0, 0), line_width: int = 0) nqp.ui_elements.generic.font.Font[source]

Create a font instance.

get_image(folder_name: str, image_name: str, desired_dimensions: pygame.math.Vector2 = (16, 16), copy: bool = False) pygame.Surface[source]

Get the specified image and resize if dimensions provided. Dimensions are in (width, height) format.

A transparent surface can be returned by folder_name = “debug” and image_name = “blank”.

load_image_dir(path, format='list')[source]

Load images in a directory with specified format.

load_tileset(path)[source]

Loads a tileset from a spritesheet.

nqp.core.audio module

class Audio(game: Game)[source]

Bases: object

The Audio Engine. It manages all sound interactions

__init__(game: Game)[source]
play_sound(sound_name: str, loops: int = 0, max_time: float = - 1, fade_in_ms: float = - 1, allow_duplicates: bool = True)[source]

Play sound.

Parameters
  • sound_name – the name of the sound

  • loops – how many loops. set to INFINITE to make the sound loop infinitely. Can still be stopped.

  • max_time – how long the sound can play for. -1 means until end.

  • fade_in_ms – how long the sound will take to get to full volume. -1 means start at full.

  • allow_duplicates – when the same sound can be played while this is still active.

update(delta_time: float)[source]

nqp.core.constants module

class AnimationState(value)[source]

Bases: enum.IntEnum

An enumeration.

FINISHED = 3
PAUSED = 2
PLAYING = 1
class ChooseRoomState(value)[source]

Bases: enum.IntEnum

An enumeration.

CHOOSE_ROOM = 2
IDLE = 1
INSPECT_STATS = 3
class Colour(value)[source]

Bases: enum.Enum

An enumeration.

BLACK = (0, 0, 0)
BLOOD_RED = (143, 3, 3)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
GREY_SMOKE = (63, 58, 71)
RED = (255, 0, 0)
WHITE = (255, 255, 255)
class ColourPalette(value)[source]

Bases: enum.Enum

An enumeration.

ACCENT = (107, 74, 107)
CONTRAST = (235, 202, 113)
MAIN_DARK = (12, 13, 12)
MAIN_LIGHT = (62, 63, 59)
MAIN_MID = (55, 44, 71)
class CombatState(value)[source]

Bases: enum.IntEnum

An enumeration.

ACTION_CHOOSE_CARD = 4
ACTION_SELECT_TARGET_FREE = 5
DEFEAT = 7
IDLE = 1
UNIT_CHOOSE_CARD = 2
UNIT_SELECT_TARGET = 3
VICTORY = 8
WATCH = 6
class DamageType(value)[source]

Bases: enum.IntEnum

An enumeration.

MAGICAL = 2
MUNDANE = 1
class Direction(value)[source]

Bases: enum.IntEnum

An enumeration.

DOWN = 2
LEFT = 3
RIGHT = 4
UP = 1
class EntityFacing(value)[source]

Bases: enum.IntEnum

An enumeration.

LEFT = 1
RIGHT = 2
class EventState(value)[source]

Bases: enum.IntEnum

An enumeration.

IDLE = 1
SHOW_RESULT = 2
class Flags(value)[source]

Bases: enum.IntEnum

An enumeration.

CHEATED = 2
GODMODE = 1
class FontEffects(value)[source]

Bases: enum.IntEnum

An enumeration.

FADE_IN = 1
FADE_OUT = 2
class FontType(value)[source]

Bases: enum.Enum

An enumeration.

DEFAULT = 1
DISABLED = 3
INSTRUCTION = 5
NEGATIVE = 2
NOTIFICATION = 6
POSITIVE = 4
class GameSpeed(value)[source]

Bases: enum.IntEnum

An enumeration.

FAST = 3
FASTEST = 5
NORMAL = 1
SLOW = 0
class GameState(value)[source]

Bases: enum.IntEnum

An enumeration.

EXITING = 3
LOADING = 1
PLAYING = 2
class GamepadAxes(value)[source]

Bases: enum.IntEnum

An enumeration.

DPAD_X = 5
DPAD_Y = 6
LEFT_X = 1
LEFT_Y = 2
RIGHT_X = 3
RIGHT_Y = 4
class GamepadButton(value)[source]

Bases: enum.IntEnum

An enumeration.

DOWN = 3
EAST = 6
LEFT = 2
LEFT_SHOULDER_1 = 11
LEFT_SHOULDER_2 = 12
LEFT_STICK = 15
NORTH = 5
RIGHT = 4
RIGHT_SHOULDER_1 = 13
RIGHT_SHOULDER_2 = 14
RIGHT_STICK = 16
SELECT_OR_BACK = 9
SOUTH = 7
START = 10
UP = 1
WEST = 8
class HealingSource(value)[source]

Bases: enum.IntEnum

An enumeration.

OTHER = 2
SELF = 1
class InnState(value)[source]

Bases: enum.IntEnum

An enumeration.

CHOOSE_UNIT = 2
IDLE = 1
class InputType(value)[source]

Bases: enum.IntEnum

An enumeration.

KEYS = 2
MOUSE = 3
NONE = 1
class PostCombatState(value)[source]

Bases: enum.IntEnum

An enumeration.

BOSS_VICTORY = 3
DEFEAT = 1
VICTORY = 2
class RewardType(value)[source]

Bases: enum.IntEnum

An enumeration.

ACTION = 2
RESOURCE = 4
UNIT = 1
UPGRADE = 3
class SceneType(value)[source]

Bases: enum.IntEnum

An enumeration.

DEV_DATA_EDITOR = 4
MAIN_MENU = 1
RUN_SETUP = 3
VIEW_TROUPE = 2
WORLD = 6
class StatModifiedStatus(value)[source]

Bases: enum.IntEnum

An enumeration.

NEGATIVE = 3
NONE = 1
POSITIVE = 2
POSITIVE_AND_NEGATIVE = 4
class TextRelativePosition(value)[source]

Bases: enum.IntEnum

An enumeration.

ABOVE_IMAGE = 1
BELOW_IMAGE = 2
LEFT_OF_IMAGE = 4
RIGHT_OF_IMAGE = 3
class TrainingState(value)[source]

Bases: enum.IntEnum

An enumeration.

CHOOSE_TARGET_UNIT = 3
CHOOSE_UPGRADE = 2
IDLE = 1
class WindowType(value)[source]

Bases: enum.IntEnum

An enumeration.

BASIC = 1
FANCY = 2
class WorldState(value)[source]

Bases: enum.IntEnum

An enumeration.

CHOOSE_NEXT_ROOM = 1
COMBAT = 2
EVENT = 3
INN = 4
MOVING_NEXT_ROOM = 5
POST_COMBAT = 6
TRAINING = 7

nqp.core.data module

class Data(game: Game)

Bases: object

Raw data that doesnt change. Usually pulled from external files.

__init__(game: Game)
create_effect(data: Dict[str, Any], params: Dict[str:Any])

Return Effect from data found in data files

create_item(name: str)

Return Item by name

Parameters

name – Short name, same as the item filename without extension

Returns

New Item entity id

get_combat_occur_rate(id_: str) int

Get the combat occur rate based on the tier. Lower means less often.

get_event_occur_rate(id_: str) int

Get the event occur rate based on the tier. Lower means less often.

get_unit_occur_rate(unit_type: str) int

Get the unit occur rate based on the tier. Lower means less often.

get_units_by_category(factions: List[str], tiers: List[int] = None) List[str]

Return list of unit types for all units with a matching faction and tier.

load_all_data()

Reload all data

load_yaml(path: Union[str, pathlib.Path]) Any

Load YAML data with the SafeLoader

nqp.core.debug module

class Debugger(game: Game)[source]

Bases: object

__init__(game: Game)[source]
disable_profiling(dump_data: bool = False)[source]

Turn off current profiling. Dump data to file if required.

draw(surface: pygame.Surface)[source]

Draw debug info

enable_profiling(duration: int = 999)[source]

Enable profiling. Create profiler if one doesnt exist

initialise_logging()[source]

Initialise logging.

kill_logging()[source]

Kill logging resources

kill_profiler()[source]

Kill profiling resource

static performance_test(method_descs: List[str], old_methods: List[Tuple[Union[str, Callable], str]], new_methods: List[Tuple[Union[str, Callable], str]], num_runs: int = 1000, repeats: int = 3) str[source]

Run performance testing on a collection of methods/functions. Returns a formatted string detailing performance of old, new and % change between them.

method_descs are used as descriptions only. old_methods/new_methods expects a list of tuples that are (method_to_test, setup). Setup can be an empty string but is usually an import. Index in each list much match, i.e. method_name[0] is the alias of the methods in old_methods[0] and new_methods[0].

Outputs as “Access Trait: 0.00123 -> 0.00036(71.00033%)”.

example usage: method_descs = [“Set Var”, “Access Skill”] old_methods = [(“x = 1”, “”),(“library.get_skill_data(‘lunge’)”, “”)] new_methods = [(“x = ‘one’”, “”), (“library2.SKILLS.get(‘lunge’)”, “from scripts.engine import library2”)] print( performance_test(method_descs, old_methods, new_methods) )

print_values_to_console()[source]

Print the debuggers stats.

toggle_debug_info()[source]

Toggle whether the debug info is shown

toggle_dev_console_visibility()[source]
update(delta_time: float)[source]
class Timer(label=None)[source]

Bases: object

Context manager to document program time

__init__(label=None)[source]

nqp.core.definitions module

nqp.core.game module

nqp.core.input module

class ControllerConfig(deadzone: 'float', axes: 'Mapping[int, GamepadAxes]', hat: 'Mapping[int, Tuple[GamepadButton, GamepadButton]]', buttons: 'Mapping[int, GamepadButton]')[source]

Bases: object

__init__(deadzone: float, axes: Mapping[int, nqp.core.constants.GamepadAxes], hat: Mapping[int, Tuple[nqp.core.constants.GamepadButton, nqp.core.constants.GamepadButton]], buttons: Mapping[int, nqp.core.constants.GamepadButton]) None
axes: Mapping[int, nqp.core.constants.GamepadAxes]
buttons: Mapping[int, nqp.core.constants.GamepadButton]
deadzone: float
hat: Mapping[int, Tuple[nqp.core.constants.GamepadButton, nqp.core.constants.GamepadButton]]
class Input(game: Game)[source]

Bases: object

__init__(game: Game)[source]
reset()[source]

Set all input to false.

soft_reset()[source]

Resets inputs that should only be activated for 1 frame.

unload_chars()[source]
update(delta_time: float)[source]

nqp.core.memory module

class Memory(game: Game)[source]

Bases: object

Game related values that persist outside of individual “scenes”. E.g. achievements.

__init__(game: Game)[source]
add_flag(flag: str | Enum)[source]
check_for_flag(flag: str | Enum) bool[source]

Check if a flag exists

property game_speed: float
generate_id() int[source]

Create unique ID for an instance, such as a unit.

initialise_run(troupe: Troupe, gold: int, rations: int, morale: int, charisma: int, leadership: int)[source]

Initialise the run’s values.

remove_flag(flag: str | Enum)[source]
set_game_speed(speed: Union[float, nqp.core.constants.GameSpeed])[source]

Set the game speed. 1 is default.

nqp.core.queries module

nqp.core.rng module

class RNG(game: Game)[source]

Bases: random.Random

Initialize an instance.

Optional argument x controls seeding, as for Random.seed().

__init__(game: Game)[source]

Initialize an instance.

Optional argument x controls seeding, as for Random.seed().

roll(min_value: int = 0, max_value: int = 99) int[source]

Roll for a number between min and max. Can handle negative numbers.

set_seed(seed: int)[source]

Set the seed for randomness.

nqp.core.scheduler module

class ScheduledItem(func: Callable, last_ts: float, next_ts: float, interval: float, repeat: bool)[source]

Bases: object

Describes a scheduled callback.

__init__(func: Callable, last_ts: float, next_ts: float, interval: float, repeat: bool) None
func: Callable
interval: float
last_ts: float
next_ts: float
repeat: bool
class Scheduler(time_function: typing.Callable = <built-in function perf_counter>)[source]

Bases: object

Class for scheduling functions.

Probably not thread safe.

The function should have a prototype that includes dt as the first argument, which gives the elapsed time, in time units, since the last clock tick.

def callback(dt):

pass

Items will be scheduled and rescheduled in such a way to prevent several items from running during the same tick. Enabling a “soft” reschedule means that item is tolerant to having the interval slightly modified.

Initialise a Scheduler, with optional custom time function.

Parameters

time_function – Return the elapsed time

__init__(time_function: typing.Callable = <built-in function perf_counter>)[source]

Initialise a Scheduler, with optional custom time function.

Parameters

time_function – Return the elapsed time

call_scheduled_functions(dt: float)[source]

Call scheduled functions that elapsed on the last update_time.

Parameters
  • dt – The elapsed time since the last update to pass to each

  • function. (scheduled) –

get_counter() float[source]

Get internal counter value

get_idle_time() Optional[float][source]

Get the time until the next item is scheduled.

Returns

Time until the next scheduled event in time units, or None if there is no events scheduled.

get_interval() float[source]

Get the average amount of time passed between each tick.

Useful for calculating FPS if this clock is used with the display. Returned value is averaged from last 10 ticks.

Value will be 0.0 if before 1st tick.

Returns

Average amount of time passed between each tick

get_running_time() float[source]

Get time clock has been running

get_schedule() List[nqp.core.scheduler.ScheduledItem][source]

Return copy of the schedule.

schedule(func: Callable, delay: float, interval: float, repeat: bool, soft: bool)[source]
schedule_interval(func: Callable, interval: float = 0.0, delay: float = 0.0, soft: bool = False)[source]

Schedule a function to run on an interval.

NOTE! If delay==0.0, then the interval will start the next frame, meaning, the callback will happen the next tick, and then follow the interval. If you want to avoid this, then set delay to the same value as the interval.

Items are rescheduled after they are executed. That means that by default, the interval of items may not be consistent with the initial time with was scheduled.

If the interval is not specified, the function will be executed every time the scheduler is ticked.

Parameters
  • func – Function to be called

  • interval – Repeat on this interval

  • delay – Delay in time unit until it is called for first time

  • soft – See notes about Soft Scheduling

Returns

Reference to scheduled item

schedule_once(func: Callable, delay: float = 0.0, soft: bool = False) nqp.core.scheduler.ScheduledItem[source]

Schedule a function to be run once sometime in the future.

If the delay is not specified, the function will be executed during the next tick.

Parameters
  • func – Function to be called

  • delay – Delay in time unit until it is called

  • soft – See notes about Soft Scheduling

Returns

Reference to scheduled item.

set_time(time_stamp: float) float[source]

Set the clock manually and do not call scheduled functions.

Parameters

time_stamp – This will become the new value of the clock.

Returns

The number of time units since the last update, or 0.0 if this was the first update.

tick() float[source]

Cause clock to update and call scheduled functions.

This updates the clock’s internal measure of time and returns the difference since the last update (or since the clock was created).

Will call any scheduled functions that have elapsed.

Returns

The number of time units since the last “tick”, or 0 if this was the first tick.

unschedule(func) None[source]

Remove a function from the schedule.

NOTE: do not unschedule own function during function call

If the function appears in the schedule more than once, all occurrences are removed. If the function was not scheduled, no error is raised.

Parameters

func – The function to remove from the schedule.

remove(items, func)[source]

Remove scheduled items with func func from list remove_from and return True if it was removed

nqp.core.systems module

apply_damage(game: Game)[source]

Consume damage components and apply their value to the Entity, applying any mitigations. Dodge may negate damage.

draw_entities(surface: pygame.Surface, shift: pygame.math.Vector2 = (0, 0))[source]

Draw all entities

process_ai(delta_time: float)[source]

Update Entity ai.

process_attack(game: Game)[source]

Execute any outstanding attacks.

process_death(game: Game)[source]

Update Entity’s sprites and intentions.

process_healing()[source]

Process all the Healing Received components, applying healing where allowed.

process_movement(delta_time: float, game: Game)[source]

Update an Entity’s position towards their target.

push_entities_away_from_one_another(delta_time: float, game: Game)[source]

Force overlapping units away from one another.

nqp.core.utility module

angle_to(start_pos: pygame.math.Vector2, end_pos: pygame.math.Vector2) float[source]

Find the angle to another position.

clamp(value: nqp.core.utility._V, min_value: nqp.core.utility._V, max_value: nqp.core.utility._V) nqp.core.utility._V[source]

Return the value, clamped between min and max.

clip(surface, x, y, x_size, y_size) pygame.Surface[source]

Clip a subsurface from a surface.

distance_to(start_pos: pygame.math.Vector2, end_pos: pygame.math.Vector2) float[source]

Find the distance to another position.

get_direction(angle: float, move_distance: float) pygame.math.Vector2[source]

Find the direction based on the angle and distance

grid_down(selected: int, width: int, height: int)[source]
grid_left(selected: int, width: int, height: int)[source]
grid_right(selected: int, width: int, height: int)[source]
grid_up(selected: int, width: int, height: int)[source]
itr(iterable)[source]

An iteration tool for easy removal.

lerp(initial_value: float, target_value: float, lerp_fraction: float) float[source]

Linear interpolation between initial and target by amount. Fraction clamped between 0 and 1. >=0.99 is treated as 1 to handle float imprecision.

next_number_in_loop(start: int, loop_size: int) int[source]
offset(list_: List, offset_, offset_mult=1)[source]
percent_to_float(percent_string: str)[source]

Convert string representation of percent into a float

previous_number_in_loop(start: int, loop_size: int) int[source]

If at max loop size, returns loop size -1.

scene_to_scene_type(scene) nqp.core.constants.SceneType[source]

Take a Scene and return the relevant SceneType

swap_colour(img, old_c, new_c)[source]

nqp.core.visual module

class Visual(game: Game)[source]

Bases: object

Store and manage images.

__init__(game: Game)[source]
create_animation(animation_name: str, frame_set_name: str, loop: bool = True, uses_simulation_time: bool = True) nqp.base_classes.animation.Animation[source]

Create a new animation and add it to the internal update list.

create_fancy_font(text: str, pos: pygame.Vector2 = (0, 0), line_width: int = 0, font_effects: Optional[List[FontEffects]] = None) FancyFont[source]

Create a FancyFont instance. If line_width isnt given then will default to full screen.

create_font(font_type: nqp.core.constants.FontType, text: str, pos: pygame.math.Vector2 = <Vector2(0, 0)>, line_width: int = 0) nqp.ui_elements.generic.font.Font[source]

Create a font instance.

get_image(image_name: str, size: pygame.math.Vector2 = (16, 16), copy: bool = False) nqp.base_classes.image.Image[source]

Get an image from the library. If a size is specified and it differs to the size held then the image is resized before returning. If copy = True then a copy of the image held in the library is provided. Remember to use a copy if you want to amend the image, otherwise the copy in the library is amended.

A transparent surface is available with the name “blank”.

update(delta_time: float)[source]

nqp.core.window module

class Window(game: Game)[source]

Bases: object

__init__(game: Game)[source]
property centre: Tuple[Union[int, float], Union[int, float]]
property height: int
refresh()[source]

Clear screen.

update()[source]

Update internal timer

property width: int

Module contents