ManaPlus
actor.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2010 The Mana Developers
4  * Copyright (C) 2011-2018 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "being/actor.h"
23 
24 #include "resources/map/map.h"
25 
26 #include "debug.h"
27 
29  mPixelX(0),
30  mPixelY(0),
31  mMap(nullptr),
32  mPos(),
33  mYDiff(0),
34  mMapActor()
35 {
36 }
37 
39 {
40  if (mMap != nullptr)
41  {
43  mMap = nullptr;
44  }
45 }
46 
47 void Actor::setMap(Map *const map)
48 {
49  // Remove Actor from potential previous map
50  if (mMap != nullptr)
52 
53  mMap = map;
54 
55  // Add Actor to potential new map
56  if (mMap != nullptr)
57  mMapActor = mMap->addActor(this);
58 }
59 
60 int Actor::getTileX() const
61 {
62  if (mMap == nullptr ||
63  mMap->getTileWidth() == 0)
64  {
65  return 0;
66  }
67 
68  return getPixelX() / mMap->getTileWidth();
69 }
70 
71 int Actor::getTileY() const
72 {
73  if (mMap == nullptr ||
74  mMap->getTileHeight() == 0)
75  {
76  return 0;
77  }
78 
79  return getPixelY() / mMap->getTileHeight();
80 }
81 
83 {
84  mPos = pos;
87 }
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:824
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:817
int getTileHeight() const
Definition: map.h:183
Definition: vector.h:38
Vector mPos
Definition: actor.h:139
Actors::iterator mMapActor
Definition: actor.h:143
int mPixelX
Definition: actor.h:132
virtual int getPixelY() const
Definition: actor.h:92
#define CAST_S32
Definition: cast.h:29
Actor()
Definition: actor.cpp:28
virtual ~Actor()
Definition: actor.cpp:38
#define nullptr
Definition: localconsts.h:44
virtual void setMap(Map *const map)
Definition: actor.cpp:47
int mPixelY
Definition: actor.h:133
int getPixelX() const
Definition: actor.h:86
Definition: map.h:71
float x
Definition: vector.h:208
virtual int getTileY() const
Definition: actor.cpp:71
virtual int getTileX() const
Definition: actor.cpp:60
virtual void setPixelPositionF(const Vector &pos)
Definition: actor.cpp:82
std::string mMap
Definition: gamerecv.cpp:45
int getTileWidth() const
Definition: map.h:177
float y
Definition: vector.h:208
#define restrict
Definition: localconsts.h:164
#define restrict2
Definition: localconsts.h:165
Map * mMap
Definition: actor.h:138