4 screen.
setPos(0, 0, 1000, 1000);
7 activeCam = activeLens = 0;
18 tiles.empty(); tiles.clear();
21 row.empty(); row.clear();
27 tmp.
setPos(c*w, r*h, w, h);
28 tmp.setDestSize(w, h);
41 Object splicedScreen = screen;
42 if(activeCam & col.
outOfBoundsOf(entities[mainEntityID], camera)) {
44 cout <<
"out" << endl;
45 if(activeCam && col.
isAbove(entities[mainEntityID], camera) && my>0) {
setCoord(
getX()+mx,
getY()-my); none=
false; }
46 if(activeCam && col.
isBelow(entities[mainEntityID], camera) && my<0) {
setCoord(
getX()+mx,
getY()-my); none=
false; }
48 if(activeCam && col.
isLeftOf(entities[mainEntityID], camera) && mx<0) {
setCoord(
getX()+mx,
getY()-my); none=
false; }
49 if(none) moveEntity(mainEntityID, mx, my);
50 if(!none) camera.setPosCoord(camera.getPosX()+mx, camera.getPosY()-my);
52 moveEntity(mainEntityID, mx, my);
59 void Level::moveEntity(
int id,
int mx,
int my) {
60 entities[id].setPosCoord(entities[
id].getPosX()+mx, entities[
id].getPosY()-my);
62 for(
int i=0; i<tilesToCol.size(); i++) {
63 if(tilesToCol[i].isSolid()) {
64 if(col.
isTouching(entities[
id], tilesToCol[i])) {
65 entities[id].setPosCoord(entities[
id].getPosX()-mx, entities[
id].getPosY()+my);
66 camera.setPosCoord(camera.getPosX()+mx, camera.getPosY()-my);
74 vector<Tile> tilesToRender;
75 for(
int r=0; r<tiles.size(); r++) {
76 for(
int c=0; c<tiles[r].size(); c++) {
78 tiles[r][c].setDisplayable(
true);
79 tiles[r][c].setDestCoord(tiles[r][c].getPosX()-screen.getPosX(), tiles[r][c].getPosY()-screen.getPosY());
80 tilesToRender.push_back(tiles[r][c]);
82 tiles[r][c].setDisplayable(
false);
90 vector<Object> objectsToRender;
91 for(
int i=0; i<objects.size(); i++) {
93 objects[i].setDisplayable(
true);
94 objects[i].setDestCoord(objects[i].getPosX()-screen.getPosX(), objects[i].getPosY()-screen.getPosY());
95 objectsToRender.push_back(objects[i]);
97 objects[i].setDisplayable(
false);
100 return objectsToRender;
104 vector<Entity> entitiesToRender;
105 for(
int i=0; i<entities.size(); i++) {
107 entities[i].setDisplayable(
true);
108 entities[i].setDestCoord(entities[i].getPosX()-screen.getPosX(), entities[i].getPosY()-screen.getPosY());
109 entitiesToRender.push_back(entities[i]);
111 entities[i].setDisplayable(
false);
114 return entitiesToRender;
118 objects.push_back(o);
121 objects.insert(objects.end(), o.begin(), o.end());
125 entities.push_back(e);
126 return entities.size()-1;
129 entities.insert(entities.end(), e.begin(), e.end());
137 mainEntitySet =
true;
141 void Level::setCameraMargin(
int wm,
int hm) {
142 camera.
setPos(wm, hm, screen.getPosW()-wm-wm, screen.getPosH()-hm-hm);
145 void Level::centerCamera(
int percentage) {
146 int wsize = ((percentage/2)*screen.getPosW())/100;
147 int hsize = ((percentage/2)*screen.getPosH())/100;
148 setCameraMargin(wsize, hsize);
150 Object Level::getCamera() {
153 void Level::setLensMargin(
int wm,
int hm) {
154 lens.
setPos(camera.getPosX()+wm, camera.getPosY()+hm, camera.getPosW()-wm-wm, camera.getPosH()-hm-hm);
157 void Level::centerLens(
int percentage) {
158 int wsize = ((percentage/2)*camera.getPosW())/100;
159 int hsize = ((percentage/2)*camera.getPosH())/100;
160 setLensMargin(wsize, hsize);
This class stores information for an Object in the game.
bool isAbove(Object a, Object b)
Check if the first object is above the second object.
void create()
Create the Level based on the given stage.
bool isRightOf(Object a, Object b)
Check if the first object is to the right of the second object.
int setMainEntity(Entity e)
Set main Entity.
bool outOfBoundsOf(Object a, Object b)
Check if two object are not touching.
Map getMap() const
Get the Map.
vector< Object > getObjectsToRender()
Return the Objects that are currently on the screen.
double getY() const
Get the y coordinate.
double getX() const
Get the x coordinate.
void setValue(int v)
Set value of the tile. This is used when reading from a map file, etc.
int addEntity(Entity e)
Add Entity to Level.
vector< vector< int > > getMap() const
Get the vector of integers found in the file.
void setFrame(SDL_Rect i)
Set the frame with a given SDL_Rect.
vector< Entity > getEntitiesToRender()
Return the Entities that are currently on the screen.
void setCoord(double x, double y)
Set the coordinate of the Object with a given x and y.
vector< Tile > getTilesToRender()
Return the Tiles that are currently on the screen.
bool isBelow(Object a, Object b)
Check if the first object is below the second object.
void setCoord(double x, double y)
Set the coordinate for the screen with a given x and y.
int getY() const
Get the start y coordinate found in the file.
void addObject(Object o)
Add Object to Level.
Class for storing health, emotion, team, etc. of an Object.
Tileset getTileset() const
Get the Tileset.
void setScale(int w, int h)
Scale the Level by giving it the width and height to scale by.
An Object class that stores the a tile value and name.
void move(int mx, int my)
Move the screen by passing in how much to move on the x and y coordinates.
int getValue() const
Get the value of the Tile.
bool isLeftOf(Object a, Object b)
Check if the first object is to the left of the second object.
int getX() const
Get the start x coordinate found in the file.
void setPos(SDL_Rect i)
Set the position with a given SDL_Rect.
bool isTouching(Object a, Object b)
Check if two objects are touching.