DonPedro

Members
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About DonPedro

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. I think I know what you are about. I should create a new project with minimalistic player physics. In this case, create basic map class and try to collide.
  2. That's right. I'm not even looking for ready-to-paste. I'm looking for some, you know, advices, maybe examples, for that what can help me, to understand what I should change in my thinking. I don't exactly understand what do you mean about these 3 smallser simpler steps.
  3. Em, there should be /64. My mistake. Code in a IDE is good. I'll fix it in a post. In player I want it to works like this : bool rightBot = Getter::getMap()->checkCollisionRB(posX - Getter::getMap()->getPosX() + moveSpeed, posY - Getter::getMap()->getPosY(), getHitBoxX(), getHitBoxY()); bool rightCenter = Getter::getMap()->checkCollisionRC(posX - Getter::getMap()->getPosX() + moveSpeed, posY - Getter::getMap()->getPosY(), getHitBoxX(), getHitBoxY()/2); bool rightTop = Getter::getMap()->checkCollisionRT(posX - Getter::getMap()->getPosX() + moveSpeed, posY - Getter::getMap()->getPosY(), getHitBoxX()); if (velX > 0) { if(!rightCenter && !rightTop && !rightBot) { if (posX >= (Getter::getFM()->getW() / 2) - getHitBoxX() && Getter::getMap()->getMoveMap()) { Getter::getMap()->MoveMap(-velX, 0); } else posX += velX; moveAnim = true; } } Right now, it doesn't do nothing bout the move right, because bool checkCollision() is empty.
  4. Hi! I'm trying to implement collision for my 2d platformer game.I understand basic meanings of how to detect it. I don't know how to implement it correctly though. That's how I render my map : void MapScreen::Draw(SDL_Renderer*renderer) { for (int y = 0; y <= map.size(); ++y) { for (int x = 0; x < map[y].size(); ++x) { if(map[y][x] != 0) { SDL_Rect DestRect = {x * 64, y * 64, 64, 64 }; SDL_Rect sourceRect = {map[y][x] * 64, 0, 64, 64 }; tileSet[0]->Draw(renderer, sourceRect, DestRect); } } } } And that's how I would like to detect a collision. GetBlockID returns where on a map the block is set. Getter::getFM() returns instance for fileManager class ->getH() returns window height value. Int x, int y, int hitboxX, int hitboxX - these are player coordinates and width and height of the sprite. Vector2* GameplayScreen::getBlockID(int x, int y) { return new Vector2(x < 0 ? 0 : x / 64, y > Getter::getFM()->getH() ? 0 : (y + 64) / 64); } bool GameplayScreen::checkCollision(Vector2* v2) { } bool GameplayScreen::checkCollisionRB(int x, int y, int hitBoxX, int hitBoxY) { return checkCollision(getBlockID(x + hitBoxX, y + hitBoxY)); } bool GameplayScreen::checkCollisionLB(int x, int y, int hitBoxY) { return checkCollision(getBlockID(x, y + hitBoxY)); } bool GameplayScreen::checkCollisionRT(int x, int y, int hitBoxX) { return checkCollision(getBlockID(x + hitBoxX, y)); } bool GameplayScreen::checkCollisionLT(int x, int y) { return checkCollision(getBlockID(x, y)); } bool GameplayScreen::checkCollisionRC(int x, int y,int hitBoxX, int hitBoxY) { return checkCollision(getBlockID(x + hitBoxX, y + hitBoxY)); } bool GameplayScreen::checkCollisionLC(int x, int y,int hitBoxY) { return checkCollision(getBlockID(x, y + hitBoxY)); } In player class movement method, I want to say : "if not collision you can move, if there is, you can't". Like : if(!Getter::getMap()->checkCollisionLC){ movement things }