Reputation: 33
I am trying to create a very basic endless runner gamer and i am stuck with collision detection's. I am programming for a GBA emulator using notepad++. The code below is my main game while loop. The sprites are 4x4 tiles and each tile is 8x8 pixels. Below the main loop is the code for gravity acting down on the sprite. 'setObject(0,...) is the character sprite setObject(1,...) is the platform sprite. Thanks for any help in advance.
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);
}
Upvotes: 0
Views: 314