From: Daniel Karbach Date: Thu, 18 Oct 2012 19:04:10 +0000 (+0200) Subject: some commenting on the map classes X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=fb9bd716a1740e41efbb08a3bfa42e441d64c693;p=l2e.git some commenting on the map classes --- diff --git a/src/map/Area.h b/src/map/Area.h index 3c370ab..9da3083 100644 --- a/src/map/Area.h +++ b/src/map/Area.h @@ -16,6 +16,9 @@ namespace map { +/// Defines a rectangular section of a map. +/// Tiles are rendered ltr with a row break each width tiles. +/// Missing tiles in the last row are possible but don't fool yourself. class Area { public: @@ -23,12 +26,17 @@ public: ~Area() { } public: + /// Get the width in tiles. int Width() const { return width; } + /// Get the height in tiles. int Height() const { return numTiles / width + (numTiles % width ? 1 : 0); } + /// Get the size in tiles. geometry::Vector Size() const { return geometry::Vector(Width(), Height()); } + /// Get a tile by tile coordinates (not pixel coordinates!). Tile *TileAt(const geometry::Vector &); const Tile *TileAt(const geometry::Vector &) const; + /// Get the default battle background for this area. SDL_Surface *BattleBackground() { return battlebg; } void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector &offset) const; diff --git a/src/map/Entity.h b/src/map/Entity.h index cc30c95..8d5c6a5 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -19,6 +19,8 @@ namespace map { +/// An entity that can be placed on a map, moved around, animated, and possibly +/// interact with the player. class Entity { public: @@ -39,53 +41,96 @@ public: }; public: + /// Pixel resolved position of the entity's top left corner on the map. geometry::Vector &Position() { return position; } const geometry::Vector &Position() const { return position; } + /// Velocity of the entity in pixels per second. geometry::Vector &Velocity() { return velocity; } const geometry::Vector &Velocity() const { return velocity; } + /// Offset of the entity's sprite's to left corner relative to Position(). geometry::Vector &SpriteOffset() { return spriteOffset; } const geometry::Vector &SpriteOffset() const { return spriteOffset; } + /// Reset the entity to the stored tile coordinates (usually set when + /// loading game data). void ResetPosition(const geometry::Vector &tileSize) { position = tilePosition * tileSize; } + /// Set the animation to use for animated entities. + /// For orientable entities, the animation should have north, south, east, + /// and west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively. + /// If the entity can carry, row offset 2 is used. + /// If the entity can push, row offset 4 is used. void SetAnimation(const graphics::Animation *a); + /// Start the animation on a global timer. void StartAnimation(app::Application &ctrl); + /// Start the animation on a state timer. void StartAnimation(app::State &ctrl); + /// Stop the animation. void StopAnimation(); + /// Check if an animation is running. bool AnimationRunning() const { return runner.Running(); } + /// Set the sprite used for the non-animated state. + /// For orientable entities, the sprite should have north, south, east, and + /// west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively. void SetSprite(const graphics::Sprite *s) { sprite = s; } + /// Change the entity's orientation to given one. + /// If the entity is moving, velocity is changed accordingly. void SetOrientation(Orientation); Orientation GetOrientation() const { return orientation; } + /// Set the entity's speed in pixels per second. + /// This speed is then combined with the orientation to form a velocity. void SetSpeed(float); + /// Change to a natural, relaxed animation state (row offset 0). void SetHandsFree(); + /// Change animation to represent a carrying thingamabob (row offset 2). void SetCarrying(); + /// Set a pushy animation state (row offset 4). void SetPushing(); + /// Set some basic boolean properties. + /// Parameter should be a combination from the Flags enum. void SetFlags(int f) { flags = f; } + /// Check if the entity is blocking other entities from occupying its tile. bool Blocking() const { return !(flags & FLAG_NONBLOCKING); } + /// Check if a battle should be launched when stepping onto a neighboring + /// tile. bool Hostile() const { return partyLayout && numMonsters > 0; } + /// Check if this entity can be pushed around. bool Pushable() const { return flags & FLAG_PUSHABLE; } + /// Check if the entity's orientation has any effect on the column rendered + /// from the animation or sprite. bool CanTurn() const { return !(flags & FLAG_FIXED_ORIENTATION); } + /// Set a layout in battle for the party described by SetMonsters(). void SetPartyLayout(battle::PartyLayout *l) { partyLayout = l; } + /// Get the layout in battle for the party described by + /// Monsters{Begin,End}(). battle::PartyLayout *PartyLayout() { return partyLayout; } + /// Add monsters. This will cause the entity to be Hostile() and result in a + /// battle scene with given monsters when touched. void SetMonsters(battle::Monster *m, int num) { monsters = m; numMonsters = num; } battle::Monster *MonstersBegin() { return monsters; } battle::Monster *MonstersEnd() { return monsters + numMonsters; } + /// Get an entity that should follow in this one's steps or 0 if none. Entity *Follower() { return follower; } const Entity *Follower() const { return follower; } + /// Add an entity that follows this one. + /// If this already has a follower, it is added to that one instead. void AddFollower(Entity *); + /// Remove given entity from this entity or its follower. void RemoveFollower(Entity *); + /// Check if position locks into grid defined by given tileSize. bool TileLock(const geometry::Vector &tileSize) const; + /// Integrate this entity's physical properties over given time interval. void Update(float deltaT); void Render(SDL_Surface *, const geometry::Vector &offset) const; diff --git a/src/map/Map.h b/src/map/Map.h index a985d84..b751d5e 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -1,5 +1,5 @@ /* - * Map.h + * Map.h * * Created on: Sep 29, 2012 * Author: holy @@ -17,6 +17,15 @@ namespace map { +/// Represents a single map in the game. +/// Maps are made up of uniform areas of tiles. +/// The looks of a tile is defined by the Tileset() sprite with Tile::Offset() +/// as the column and row in the sprite. +/// Maps can be propulated with triggers and entities. Those are or use with +/// MapState and are not handled by the map itself. +/// Positions are expressed either as pixel or tile coordinates depending on +/// function purpose with (0|0) being the top left corner and positive values +/// extending to the right and down respectively. class Map { public: @@ -24,19 +33,31 @@ public: ~Map() { } public: + /// The sprite used as the tileset. const graphics::Sprite *Tileset() const { return tileset; } + /// Returns the Area at given pixel coordinates or 0 if off the map. Area *AreaAt(const geometry::Vector &); const Area *AreaAt(const geometry::Vector &) const; + /// Returns the Tile at given pixel coordinates or 0 if off the map. Tile *TileAt(const geometry::Vector &); const Tile *TileAt(const geometry::Vector &) const; + /// Returns the Trigger at given pixel coordinates or 0 if off the map. + /// Multiple triggers are not supported. The first one found is returned. Trigger *TriggerAt(const geometry::Vector &); + /// The battle background image for this map if neither the tile nor the + /// area has one specified. SDL_Surface *BattleBackgroundAt(const geometry::Vector &); + /// Convert coordinates pixel to tile. geometry::Vector TileCoordinates(const geometry::Vector &) const; Entity *EntitiesBegin() { return entities; } Entity *EntitiesEnd() { return entities + numEntities; } + /// Render the map. + /// Entities are not rendered by this function. void Render(SDL_Surface *dest, const geometry::Vector &offset) const; + /// Render a debugging overlay that includes collision and trigger + /// information. void RenderDebug(SDL_Surface *dest, const geometry::Vector &offset) const; static void CreateTypeDescription(); diff --git a/src/map/MapState.h b/src/map/MapState.h index 1b53d77..136e1b0 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -21,6 +21,7 @@ namespace map { +/// Shows a map and its entities an optionally control a single entity. class MapState : public app::State , public common::ScriptHost {