Skip to content

Latest commit

 

History

History
233 lines (161 loc) · 5.62 KB

world.md

File metadata and controls

233 lines (161 loc) · 5.62 KB

agarnet.world

Cell

Cell.__init__(*args, **kwargs)

See Cell.update() for the arguments.

Cell attributes

Cell.cid

Unique ID of the cell. Positive (non-zero).

Cell.color

Tuple of floats (r, g, b), where each channel is between 0.0 and 1.0.

Cell.is_agitated

Sent by server.

Unknown meaning. Open an issue if you know what it's for.

Cell.is_ejected_mass

True iff the cell has no name and its size is between 37 and 38.

Cell.is_food

True iff the cell has no name and its size is below 20.

Cell.is_virus

Sent by server.

Official client renders these cells with a spiked border.

Cell.mass

mass = size * size / 100

Do not confuse with size.

Cell.name

String. Can be empty for player-controlled cells.

Cell.pos

Vec instance. Server sends integer coordinates.

Cell.size

The cell's radius. Do not confuse with mass.

Cell methods

Cell.__lt__(other)

Compares by mass and cid in this order.

Cell.same_player(other)

Compares name and color.

Returns True if both are owned by the same player.

Cell.update(*args, **kwargs)

Parameters:

  • cid=-1
  • x=0
  • y=0
  • size=0
  • name=''
  • color=(1, 0, 1)
  • is_virus=False
  • is_agitated=False

See the attributes above for their descriptions.

World

World.cell_class

The class this world uses when creating cells.

Override this for storing custom data per cell or extending its functionality.

Defaults to agarnet.world.Cell.

class MyCustomCellClass(agarnet.world.Cell):
    @property
    def has_skin(self):  # some custom method example
        return self.name in special_names

my_world.cell_class = MyCustomCellClass

World attributes

World.cells

A dict mapping cell IDs to their instances.

World.leaderboard_groups

List of angles (float) for the pie chart in teams mode.

World.leaderboard_names

List of (cid, name) pairs, from top to bottom (1st to 10th).

The cids seem to always be the lowest ID of that player.

The name can be an empty string. The official client then displays "An unnamed cell" instead.

World.top_left

Vec of the top left corner coordinates.

World.bottom_right

Vec of the bottom right corner coordinates.

World.center

Vec of the center of the world rectangle.

World.size

Vec(width, height)

World methods

World.__eq__(other)

Compares two worlds by comparing their leaderboards.

World.create_cell(cid)

Creates a new cell in the world.

Override to use a custom cell class.

World.reset()

Clears the cells and leaderboards, and sets all corners to Vec(0, 0).

Player

Player attributes

Player.center

The center of all controlled cells.

Player.is_alive

True iff own_ids is not empty.

Player.is_spectating

not self.is_alive

Player.nick

String.

Player.own_cells

All controlled cell instances.

Generated from own_ids, so use list(player.own_cells) or loop over it once.

Player.own_ids

All controlled cell IDs.

Player.scale

Calculated in cells_changed().

Player.total_mass

Combined mass of all controlled cells.

Player.total_size

Combined size of all controlled cells.

Player.visible_area

Calculated like in the official client.

Returns (Vec(left, top), Vec(right, bottom)).

Player.world

The world that the player's cells are in.

Player methods

Player.cells_changed()

Calculates total_size, total_mass, scale, and center.

Has to be called when the controlled cells (own_ids) change.

Player.reset()

Clears nick and own_ids, sets center to world.center, and then calls cells_changed().