- Treballant en les colisions

This commit is contained in:
2023-03-06 12:31:49 +01:00
parent 53212f4bfa
commit 2942b85de7
3 changed files with 78 additions and 1 deletions

View File

@@ -26,7 +26,20 @@ int sx=1, sy=0;
bool game::loop()
{
if (input::keyDown(SDL_SCANCODE_LEFT) && box->pos.x>0) { box->pos.x--; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_LEFT) && box->pos.x>0) {
box->pos.x--;
actor::actor_t *other = actor::get_collision(box);
if (other)
{
other->push |= 1;
box->pos.x++;
}
else
{
actor::setDirty(box);
}
}
if (input::keyDown(SDL_SCANCODE_RIGHT) && box->pos.x<42) { box->pos.x++; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_UP) && box->pos.y>0) { box->pos.y--; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_DOWN) && box->pos.y<42) { box->pos.y++; actor::setDirty(box); }