我正在使用自己的逻辑和原始引擎制作快板游戏。我试图使重力和接触阵列中的瓷砖。为了能够从另一个类更改一个类的值,我必须使用引用符号“&”。编译后我收到此错误 ISO C++ 禁止在gravity.cpp 的第29 行进行指针和整数之间的比较 这是gravity 类和gravity.cpp 以及player.h 和player.cpp 的头文件。
重力.h
#ifndef GRAVITY_H
#define GRAVITY_H
#include<allegro.h>
#include<fstream>
#include "Global.h"
class Gravity
{
public:
Gravity();
~Gravity();
bool canJump,JumpAgain,OnSolidTile,Collision;
int GravSpeed;
void LoadMap(const char*filename);
void Init();
void Grav_Collision(int &x,int &y,int &x2,int &y2,int Gravspeed,bool canJump,bool JumpAgain,bool OnSolidTile,bool Collision);
private:
int loadCounterX,loadCounterY;
int ColMap[100][100];
int MapSizeX,MapSizeY;
};
#endif // GRAVITY_H
Gravity.cpp Error is on this file #include "gravity.h" // 类的头文件
Gravity::Gravity()
{
}
Gravity::~Gravity()
{
}
void Gravity::Init()
{
loadCounterX = loadCounterY = 0;
};
void Gravity::Grav_Collision(int &x,int &y,int &x2,int &y2,int Gravspeed,bool canJump,bool JumpAgain,bool OnSolidTile,bool Collision)
{
for(int i = 0;i < MapSizeX;i++)
{
for(int j = 0;j < MapSizeY;j++)
{
if(ColMap[i][j] = 1)
{
//Collision
if(&y2 < j*BlockSize)--**This IS where the error is found **--
{
Collision = true;
}
else
{
Collision = false;
}
}
}
}
};
void Gravity::LoadMap(const char*filename)
{
std::ifstream openfile (filename);
if (openfile.is_open())
{
openfile >> MapSizeX >> MapSizeY;
while (!openfile.eof())
{
openfile >> ColMap[loadCounterX][loadCounterY];
loadCounterX ++;
if (loadCounterX >= MapSizeX)
{
loadCounterX = 0;
loadCounterY ++;
}
}
loadCounterX = loadCounterY = 0;
}
else
{
allegro_message ("NO Collision FILE");
}
};
播放器.h
#ifndef PLAYER_H
#define PLAYER_H
#include <allegro.h>
#include "Global.h"
class player
{
public:
player();
~player();
void Init();
void Update();
void Draw(BITMAP*buffer,int c1,int c2,int c3);
void Input();
//Variable
int x;
int x2;
int y;
int y2;
int speed;
char dir;
BITMAP*buffer;
private:
int c1;
int c2;
int c3;
};
#endif // PLAYER_H
播放器.cpp
#include "player.h" // class's header file
// class constructor
player::player()
{
// insert your code here
}
// class destructor
player::~player()
{
// insert your code here
}
void player::Init()
{
x = 9;
y = 9;
speed = 1;
dir = 0;
};
void player::Draw(BITMAP*buffer,int c1,int c2,int c3)
{
textprintf(buffer, font, x-30, y-10, makecol(255,0,0), "x: %03i", x);
textprintf(buffer, font, x-30, y-20, makecol(255,0,0), "y: %03i", y);
rectfill(buffer,x,y,x + 5,y + 5,makecol(c1,c2,c3));
};
void player::Input()
{
//Input
if(KLeft && x >= 0)
{
dir = 'l';
}
else if(KRIGHT && x <= SW)
{
dir = 'r';
}
else if(KUP && y >= 0)
{
dir = 'u';
}
else if(KDOWN && y <= SH)
{
dir = 'd';
}
else
{
dir = 'e';
}
//Output
if(dir == 'l')
{
x += -speed;
}
if(dir == 'r')
{
x += speed;
}
if(dir == 'u')
{
y += -speed;
}
if(dir == 'd')
{
y += speed;
}
};
void player::Update()
{
player::Input();
};