Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:33:24+00:00 2026-05-30T23:33:24+00:00

LeftCollision in CheckCollision() goes true, when ever Object1 collides with Object2(square which is scrolling

  • 0

LeftCollision in CheckCollision() goes true, when ever Object1 collides with Object2(square which is scrolling from right to left of screen) left side. But in the GameObject::Update()
Leftcollision never updates to True, though it changes to true in the CheckCollision section!!

What i want is, whenever the LeftCollision is true, Update should stop, until it becomes false again!!

Below is the code for Header file and CPP file!!

The problem is with LeftCollision updation!! Why is the value not reflected in the Update if condition!!

    #pragma once

#include <iostream>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_primitives.h>
#include "Globals.h"

class GameObject
{
private :
    int ID;
    bool alive;
    bool collidable;

protected :


    float velX;
    float velY;

    int dirX;
    int dirY;

    int boundX;
    int boundY;

    int maxFrame;
    int curFrame;
    int frameCount;
    int frameDelay;
    int frameWidth;
    int frameHeight;
    int animationColumns;
    int animationDirection;

    ALLEGRO_BITMAP *image;

public :
    float x;
    float y;
    bool LeftCollision;
    bool pause;

    GameObject();
    void virtual Destroy();

    void Init(float x, float y, float velX, float velY, int dirX, int dirY, int boundX, int boundY);
    void virtual Update();
    void virtual Render();

    float GetX() {return x;}
    float GetY() {return y;}

    void SetX(float x) {GameObject ::x = x;}
    void SetY(float y) {GameObject ::y = y;}

    int GetBoundX() {return boundX;}
    int GetBoundY() {return boundY;}

    int GetID() {return ID;}
    void SetID(int ID) {GameObject::ID = ID;}

    bool GetAlive() {return alive;}
    void SetAlive(bool alive) {GameObject :: alive = alive;}

    bool GetCollidable() {return collidable;}
    void SetCollidable(bool collidable) {GameObject :: collidable = collidable;}

    bool CheckCollisions(GameObject *otherObject);
    void virtual Collided(int objectID);
    bool Collidable();

};




 #include "GameObject.h"

GameObject :: GameObject()
{
    x = 0;
    y = 0;

    velX = 0;
    velY = 0;

    dirX = 0;
    dirY = 0;

    boundX = 0;
    boundY = 0;

    LeftCollision = false;


    maxFrame = 0;
    curFrame = 0;
    frameCount = 0;
    frameDelay = 0;
    frameWidth = 0;
    frameHeight = 0;
    animationColumns = 0;
    animationDirection = 0;

    image = NULL;

    alive = true;
    collidable = true;
}

void GameObject :: Destroy()
{

}

void GameObject ::  Init(float x, float y, float velX, float velY, int dirX, int dirY, int boundX, int boundY)
{
    GameObject :: x = x;
    GameObject :: y = y;

    GameObject :: velX = velX;
    GameObject :: velY = velY;

    GameObject :: dirX = dirX;
    GameObject :: dirY = dirY;

    GameObject :: boundX = boundX;
    GameObject :: boundY = boundY;
}
void GameObject :: Update()
{
    if(LeftCollision == false)
    {
        x += velX * dirX;
        y += velY * dirY;
    }
}
void GameObject :: Render()
{
}

bool GameObject :: CheckCollisions(GameObject *otherObject)
{
    float oX = otherObject->GetX();
    float oY = otherObject->GetY();

    int obX = otherObject->GetBoundX();
    int obY = otherObject->GetBoundY();


    if( x + boundX > oX - obX &&
        x - boundX < oX + obX &&
        y + boundY > oY - obY &&
        y - boundY < oY + obY && otherObject->GetID() == TRIANGLE)
    {
        return true;
    }
    else if(((oX < x + boundX + 14)&&(oX+ 40 >x - boundX))&&!((oY < y + boundY)&&(oY+40 > y - boundY)) 
        && otherObject->GetID() == SQUARE)
    {
        y = oY - boundX - 10;
        //x = oX + 40;
        return true;
    }
    else if((oX < x + boundX + 14) && (oX > x - boundX) && otherObject->GetID() == SQUARE)
    {
        LeftCollision = true;
        return false;
    }
    else
    {
        return false;
        LeftCollision = false;
    }
}
void GameObject :: Collided(int objectID)
{

}
bool GameObject :: Collidable()
{
    return alive && collidable;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:33:26+00:00Added an answer on May 30, 2026 at 11:33 pm

    Is this part of your problem – returning without setting the value

        else
        {
            return false;
            LeftCollision = false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.