[Add] Some area code. Have fun.

This commit is contained in:
Rtch90 2012-09-02 15:39:38 +01:00
parent 5069ed5635
commit 531e46357b
3 changed files with 101 additions and 0 deletions

View File

@ -27,6 +27,7 @@ HEADERS += ../src/Actor/Player.h \
../src/Level/Level.h \ ../src/Level/Level.h \
../src/Level/Layer.h \ ../src/Level/Layer.h \
../src/Level/Tileset.h \ ../src/Level/Tileset.h \
../src/Level/AreaMap.h \
../src/Main/Game.h \ ../src/Main/Game.h \
../src/Math/Timer.h \ ../src/Math/Timer.h \
../src/Math/Rect.h \ ../src/Math/Rect.h \
@ -78,6 +79,7 @@ SOURCES += ../src/Actor/Player.cpp \
../src/Level/Tileset.cpp \ ../src/Level/Tileset.cpp \
../src/Level/Level.cpp \ ../src/Level/Level.cpp \
../src/Level/Layer.cpp \ ../src/Level/Layer.cpp \
../src/Level/AreaMap.cpp \
../src/Main/Game.cpp \ ../src/Main/Game.cpp \
../src/Main/main.cpp \ ../src/Main/main.cpp \
../src/Math/Vec2.cpp \ ../src/Math/Vec2.cpp \

48
src/Level/AreaMap.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "AreaMap.h"
// Pragma warnings give me warnings............. -- Allanis.
//#pragma warning(disable:4103)
//#pragma warning(disable:4786)
AreaMap::AreaMap(int sizeX, int sizeY) {
_impl = new AreaMapImpl(sizeX, sizeY);
}
AreaMap::~AreaMap(void) {
delete _impl;
}
int AreaMap::GetAreaValue(int x, int y, int areaMask) {
return (_impl->_areamap[x + y * _impl->_sizeX] & areaMask);
}
bool AreaMap::IsAreaValue(int x, int y, int areaMask, int value) const {
if((_impl->_areamap[x + y * _impl->_sizeX] & areaMask) == value)
return true;
else
return false;
}
bool AreaMap::IsAreaAnyValue(int x, int y, int areaMask) const {
if((_impl->_areamap[x + y * _impl->_sizeX] & areaMask) != 0)
return true;
else
return false;
}
void AreaMap::SetAreaValue(int x, int y, int areaMask, int value) {
_impl->_areamap[x + y * _impl->_sizeX] = ((_impl->_areamap[x + y * _impl->_sizeX] & (~areaMask)) | value);
}
void AreaMap::FillAreaValue(int areaMask, int value) {
unsigned int size = _impl->_sizeX * _impl->_sizeY;
for(unsigned int i = 0; i < size; i++) {
_impl->_areamap[i] = ((_impl->_areamap[i] & (~areaMask)) | value);
}
}
AREAMAP_DATATYPE* AreaMap::GetInternalBuffer(void) {
return _impl->_areamap;
}

51
src/Level/AreaMap.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#define AREAMAP_DATATYPE unsigned short
#define AREAMAP_MAX_DATA_VALUE 0xffff
class AreaMapImpl {
private:
AreaMapImpl(int sizeX, int sizeY) {
_sizeX = sizeX;
_sizeY = sizeY;
_areamap = new AREAMAP_DATATYPE[sizeX * sizeY];
for(int i = 0; i < sizeX * sizeY; i++) {
_areamap[i] = 0;
}
}
~AreaMapImpl(void) {
delete [] _areamap;
}
int _sizeX, _sizeY;
AREAMAP_DATATYPE* _areamap;
friend class AreaMap;
};
class AreaMap {
public:
AreaMap(int sizeX, int sizeY);
~AreaMap(void);
// Returns the unshifted value.. You should shift that if you want
// get it between 0-n.
int GetAreaValue(int x, int y, int areaMask);
bool IsAreaValue(int x, int y, int areaMask, int value) const;
bool IsAreaAnyValue(int x, int y, int areaMask) const;
// Expects an unshifted value, (Like the one returned by GetAreaValue),
// if you have a value between 0-n, shift it first before using this..
void SetAreaValue(int x, int y, int areaMask, int value);
// Same as above, but this applied to the entire area..
void FillAreaValue(int areaMask, int value);
// Mainly for saving and load hacking.
AREAMAP_DATATYPE* GetInternalBuffer(void);
private:
AreaMapImpl* _impl;
};