我正在尝试创建一个非常基本的无尽跑步游戏玩家,但我被碰撞检测困住了。我正在使用 notepad++ 为 GBA 模拟器编程。下面的代码是我的主要游戏 while 循环。精灵是 4x4 瓦片,每个瓦片是 8x8 像素。主循环下方是重力作用于精灵的代码。'setObject(0,...) 是角色精灵 setObject(1,...) 是平台精灵。感谢您提前提供任何帮助。
while (true)
{
const uint8_t currentKeys = REG_KEYINPUT;
if (frame % 4 == 0) //change player sprite every 4 frame
{
if (run != 14) //when last sprite is reached reset to original values
{
run = run + 2; //change run to next sprite
}
else
{
run = 0;
frame = 0;
score ++; //adding one to score variable everytime loop is entered
}
}
SetObject(0,
ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(80), //calling from spritesheet Stickmen
ATTR1_SIZE(2) | ATTR1_X(108),
ATTR2_ID8(run)); //calling sprite
SetObject(1,
ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(112),
ATTR1_SIZE(2) | ATTR1_X(108),
ATTR2_ID8(100));
if (currentKeys != prevKeys)
{
if ((currentKeys & KEY_UP) == 0)
{
jumpY = -6.0f;
}
}
frame += 1;
prevKeys = currentKeys;
//DrawScore();
Physics();
WaitVSync();
UpdateObjects();
}
return 0;
}
void Physics()
{
playerY = playerY + jumpY; // setting player to PlayersY + the jumpY value attained by user
jumpY = jumpY + gravity; // because jump is negative, adding gravity cause it to fall down the screen
SetObjectY(0, playerY);
}