Code Search for Developers
 
 
  

worldpos.h from FreePop at Krugle


Show worldpos.h syntax highlighted

/***************************************************************************
                          worldpos.h  -  description
                             -------------------
    begin                : Thu Nov 14 2002
    copyright            : (C) 2002 by Brendon Higgins
    email                : freepop-devel@lists.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef WORLDPOS_H_INCLUDED
#define WORLDPOS_H_INCLUDED

#include <boost/operators.hpp>
#include <utility>

class MapPos;
class MapTilePos;
class Rotation;
class CL_OutputSource;
class CL_InputSource;

/**
 * An accurate position on a specific tile on the map.
 * Represents a position on the map. Contains a position on a tile
 * and the coordinates of that tile. Encompasses the properties
 * of both a MapPos and a MapTilePos.
 * \see MapPos, MapTilePos
 */
class WorldPos:
    boost::equality_comparable<WorldPos,
    boost::additive<WorldPos,
    boost::multiplicative<WorldPos, float
    > > > {
private:
    /**
     * Coords.
     */
    float x, y;

public:
    /**
     * Default constructor (0, 0).
     */
    WorldPos();
    
    /**
     * Constructor.
     * \param mx Map x coordinate.
     * \param my Map y coordinate.
     * \param tx MapTile x coordinate.
     * \param ty MapTile y coordinate.
     */
    WorldPos(int mx, int my, float tx, float ty);

    /**
     * Constructor.
     * \param wx World x coordinate.
     * \param wy World y coordinate.
     */
    WorldPos(float wx, float wy);

    /**
     * Copy constructor.
     */
    WorldPos(const WorldPos& p);

    /**
     * Converting copy constructor.
     */
    explicit WorldPos(const MapPos& p);

    /**
     * Assignment operator.
     */
    WorldPos& operator=(const WorldPos& p);

    /**
     * Accessor.
     */
    float getX() const;

    /**
     * Accessor.
     */
    float getY() const;

    /**
     * Mutator.
     */
    void setX(float nx);

    /**
     * Mutator.
     */
    void setY(float ny);

    /**
     * Accessor.
     */
    int getMapX() const;

    /**
     * Accessor.
     */
    int getMapY() const;

    /**
     * Accessor.
     */
    float getTileX() const;

    /**
     * Accessor.
     */
    float getTileY() const;

    /**
     * Does this point to the same tile as \p p?
     * \return true if this and the given MapPos point to the
     * same tile.
     */
    bool sameTile(const MapPos& p) const;

    /**
     * Is the \p pos within \p rangeSq of this?
     * \param pos The pos to check.
     * \param rangeSq The square of the range.
     */
    bool near(const WorldPos& pos, float rangeSq) const;

    /**
     * Equality.
     */
    bool operator==(const WorldPos& p) const;

    /**
     * Movement.
     */
    WorldPos& operator+=(const WorldPos& p);

    /**
     * Direction.
     */
    WorldPos& operator-=(const WorldPos& p);

    /**
     * Make length of this from pos (0, 0) become 1. Normalise size.
     */
    void normalise();

    /**
     * Size.
     */
    WorldPos& operator*=(float n);

    /**
     * Size.
     */
    WorldPos& operator/=(float n);

    /**
     * Calculate the square of the distance between this and \p p.
     */
    float distanceSquared(const WorldPos& p) const;

    /**
     * Cast. This will never return (1, 1).
     */
    MapTilePos getTile() const;

    /**
     * Cast.
     */
    MapPos getMap() const;

    /**
     * Spins the pos.
     * \param r Amount
     * \param width Width of the map.
     * \param height Height of the map.
     */
    void rotate(const Rotation& r, int width, int height);

    /**
     * Return the two positions that make up this WorldPos.
     */
    std::pair<MapPos, MapTilePos> split() const;

    /**
     * Inject this class into \p os.
     */
    void inject(CL_OutputSource& os) const;
    
    /**
     * Read a WorldPos from \p is and return it.
     */
    static WorldPos extract(CL_InputSource& is);
};

/**
 * Adding a MapPos and a MapTilePos to get a complete WorldPos.
 */
WorldPos operator+(const MapPos& mp, const MapTilePos& tp);

/**
 * Write a WorldPos to an ostream. Useful for debugging.
 */
std::ostream& operator<<(std::ostream& os, const WorldPos& p);

#endif /* ndef WORLDPOS_INCLUDED */




See more files for this project here

FreePop

FreePop is a multi-platform tile-based game based on the great old game Populous 2 by Bullfrog Productions Ltd., but much improved.

Project homepage: http://sourceforge.net/projects/freepop
Programming language(s): C++
License: other

  client/
    Makefile.am
    client.cpp
    client.h
    clientmisc.cpp
    clientmisc.h
    clientstate.cpp
    clientstate.h
    connectstate.cpp
    connectstate.h
    cropsclient.cpp
    cropsclient.h
    entityclient.cpp
    entityclient.h
    entityclientfactory.cpp
    entityclientfactory.h
    firecolumnclient.cpp
    firecolumnclient.h
    gamestate.cpp
    gamestate.h
    loadstate.cpp
    loadstate.h
    mapclient.cpp
    mapclient.h
    maptileclient.cpp
    maptileclient.h
    messagebox.cpp
    messagebox.h
    oversprite.cpp
    oversprite.h
    paintable.cpp
    paintable.h
    pausefader.cpp
    pausefader.h
    peepclient.cpp
    peepclient.h
    peepmagnetclient.cpp
    peepmagnetclient.h
    playerclient.cpp
    playerclient.h
    playeroptionsdialog.cpp
    playeroptionsdialog.h
    rockclient.cpp
    rockclient.h
    swampclient.cpp
    swampclient.h
    townclient.cpp
    townclient.h
    treeclient.cpp
    treeclient.h
    worldclient.cpp
    worldclient.h
  server/
    Makefile.am
    contagion.cpp
    contagion.h
  Makefile.am
  common.cpp
  common.h
  corner.cpp
  corner.h
  crops.cpp
  crops.h
  entity.cpp
  entity.h
  entityfactory.cpp
  entityfactory.h
  firecolumn.cpp
  firecolumn.h
  gridmap.h
  identity.cpp
  identity.h
  map.cpp
  map.h
  mappos.cpp
  mappos.h
  maptile.cpp
  maptile.h
  maptilepos.cpp
  maptilepos.h
  misc.h
  peep.cpp
  peep.h
  peepmagnet.cpp
  peepmagnet.h
  player.cpp
  player.h
  rock.cpp
  rock.h
  rotation.cpp
  rotation.h
  rules.cpp
  rules.h
  slope.cpp
  slope.h
  swamp.cpp
  swamp.h
  tempo.cpp
  tempo.h
  town.cpp
  town.h
  tree.cpp
  tree.h
  worldpos.cpp
  worldpos.h