generated from sigonasr2/CPlusPlusProjectTemplate
Add simple object to object collision
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ed6f4c7f4d
commit
adb5d9aceb
Binary file not shown.
15
object.h
15
object.h
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
|
|
||||||
|
extern std::vector<Object*> OBJECTS;
|
||||||
|
|
||||||
struct Interaction{
|
struct Interaction{
|
||||||
std::vector<std::string> messages={};
|
std::vector<std::string> messages={};
|
||||||
Item*item=nullptr;
|
Item*item=nullptr;
|
||||||
@ -53,7 +55,18 @@ class Object{
|
|||||||
bool Collision(vd2d pos) {
|
bool Collision(vd2d pos) {
|
||||||
GAME->SetDrawTarget(layer::COLLISION);
|
GAME->SetDrawTarget(layer::COLLISION);
|
||||||
Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y);
|
Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y);
|
||||||
return collisionData!=MAGENTA;
|
if (collisionData!=MAGENTA) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
for (int i=0;i<OBJECTS.size();i++) {
|
||||||
|
if (OBJECTS[i]!=this) {
|
||||||
|
if (std::abs(OBJECTS[i]->GetPosWithOrigin().x-pos.x)+std::abs(OBJECTS[i]->GetPosWithOrigin().y-pos.y)<4) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
//A grid version of the constructor. used ONLY for battle setups.
|
//A grid version of the constructor. used ONLY for battle setups.
|
||||||
Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
|
Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user