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 7053623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:31:39+00:00 2026-05-28T03:31:39+00:00

i am getting a REALLY annoying error. i literally looked everywhere for it! i

  • 0

i am getting a REALLY annoying error. i literally looked everywhere for it! i even went back and changed all of my

if (case)
    // to-do

to

if (case)
{
    // to-do
}

i don’t ask a lot of questions like this, but i am really getting frustrated, and i am almost positive it is something simple that i am not seeing.

here is the error:

entity.cpp: In member function ‘virtual void Entity::clean()’:
entity.cpp:148: error: a function-definition is not allowed here before ‘{’ token
entity.cpp:394: error: expected ‘}’ at end of input

here is my class code:

#include "./entity.hpp"

std::vector<Entity *> Entity::entity_list_;
std::vector<EntityCollision> EntityCollision::collision_list_;

EntityCollision::EntityCollision()
{
  a_ = NULL;
  b_ = NULL;
}

Entity::Entity()
{
  image_buffer_ = NULL;
  x_ = y_ = 0.0f;
  width_ = height_ = 0;
  animation_state_ = 0;
  move_left_ = false;
  move_right_ = false;
  type_ = ENTITY_TYPE_GENERIC;
  flags_ = ENTITY_FLAG_GRAVITY;
  dead_ = false;
  speed_x_ = 0;
  speed_y_ = 0;
  max_speed_x_ = 0;
  max_speed_y_ = 0;
  column_x_ = 0;
  column_y_ = 0;
  column_width_ = 0;
  column_height_ = 0;
}

Entity::~Entity()
{
}

bool Entity::init(const std::string &image_file, int width, int height, int max_frames)
{
  if ((image_buffer_ = Surface::mount_image(image_file)) == NULL)
    {
      return false;
    }

  animation_helper_.max_frames_ = max_frames;

  width_ = width;
  height_ = height;
  return Surface::set_color_key(255, 0, 255, image_buffer_);
}

void Entity::render(SDL_Surface *dest)
{
  if (image_buffer_ == NULL || dest == NULL)
    {
      return;
    }

  Surface::draw(x_ - CameraManager::camera_controller_.x(),
        y_ - CameraManager::camera_controller_.y(),
        current_frame_column_ * width_,
        (current_frame_row_ + animation_helper_.current_frame()) * height_,
        width_, height_,
        image_buffer_,
        dest);
}

void Entity::animate()
{
  if (move_left_)
    {
      current_frame_column_ = 0;
    }
  else if (move_right_)
    {
      current_frame_column_ = 1;
    }

  animation_helper_.animate();
}

void Entity::collision(Entity *entity)
{
}

void Entity::update()
{
  /* if the entity isn't moving left or right */
  if (move_left_ == false && move_right_ == false)
    {
      stop(); // stop movement
    }

  if (move_left_) // if it wants to move left
    {
      accel_x_ = -0.5; // move negatively down x axis
    }
  else if (move_right_)
    {
      accel_x_ = 0.5; // move positively up the x axis
    }

  /* if gravity is applied to the entity */
  if (flags_ & ENTITY_FLAG_GRAVITY)
    {
      accel_y_ = 0.75f; // it will fall
    }

  /* set the entity's speed */
  speed_x_ += accel_x_ * FPSManager::fps_controller_.speed_factor();
  speed_y_ += accel_y_ * FPSManager::fps_controller_.speed_factor();

  /* make sure the entity won't move too fast */
  if (speed_x_ > max_speed_x_)
    {
      speed_x_ = max_speed_x_;
    }

  if (speed_x_ < -max_speed_x_)
    {
      speed_x_ = -max_speed_x_;
    }

  if (speed_y_ > max_speed_y_)
    {
      speed_y_ = max_speed_y_;
    }

  if (speed_y_ < -max_speed_y_)
    {
      speed_y_ = -max_speed_y_;
    }

  animate(); // animate the entity
  move(speed_x_, speed_y_); // now move it
}

void Entity::clean()
{
  if (image_buffer_) // if the image buffer has an image on it
    {
      SDL_FreeSurface(image_buffer_); // get rid of it!
    }

  image_buffer_ = NULL; // just set it to null if it doesn't :\
}

void Entity::move(float x, float y)
{
  /* if thee entity  doesn't want to move, why try? */
  if (x == 0 && y == 0)
    {
      return;
    }

  double new_x = 0; // the x position increment
  double new_y = 0; // the y position increment

  /* give us the correct movement per second */
  x *= FPSManager::fps_controller_.speed_factor();
  y *= FPSManager::fps_controller_.speed_factor();

  if (y != 0) // if we should move up or down
    {
      if (y >= 0) // down in this case
      {
        new_y = FPSManager::fps_controller_.speed_factor();
      }
        else // up in this case
      {
        new_y = -FPSManager::fps_controller_.speed_factor();
      }
    }

  while (true)
    {
      if (flags_ & ENTITY_FLAG_GHOST) // is the entity a ghost?
      {
        /* notify the entity of other collisions */
        valid_pos((int) (x_ + new_x), (int) (y_ + new_y));
        /* move regardless of the results */
        x_ += new_x_;
        y_ += new_y_;
      }
      else
      {
        /* if the new y position is valid (empty) */
        if (valid_pos((int) (x_ + new_x), (int) y_))
          {
            x_ += new_x; // move the entity
          }
        else
          {
            speed_x_ = 0;
          }

      /* if the new y position is valid (empty) */
      if (valid_pos((int) x_, (int) (y_ + new_y)))
        {
          y_ += new_y; // move the entity
        }
      else
        {
          speed_y_ = 0;
        }
    }

      /* decrease x by new_x until it reaches 0 */
      x += -new_x;

      /* decrease y by new_y until it reaches 0 */
      y += -new_y;

      if (new_x > 0 && x <= 0)
      {
        new_x = 0;
      }

      if (new_x < 0 && x >= 0)
      {
        new_x = 0;
      }

      if (new_y > 0 && y <= 0)
      {
        new_y = 0;
      }

      if (new_y < 0 && y >= 0)
      {
        new_y = 0;
      }

      /* if the entity reached it's new position on the x axis */
      if (x == 0)
      {
        new_x = 0; // don't move left || right anymore
      }

      /* if the entity reached it's new position on the y axis */
      if (y == 0)
      {
        new_y = 0; // don't move up || down anymore
      }

      /* when we finally come to a stop */
      if (x == 0 && y == 0)
      {
        break; // break out of the loop
      }

      if (new_x == 0 && new_y == 0)
      {
        break;
      }
    }
}

void Entity::stop()
{
  if (speed_x_ > 0)
    {
      accel_x_ = -1;
    }

  if (speed_x_ < 0)
    {
      accel_x_ = 1;
    }

  if (speed_x_ < 2.0f && speed_x_ > -2.0f)
    {
      accel_x_ = 0;
      speed_x_ = 0;
    }
}

bool Entity::collides(int o_x, int o_y, int o_w, int o_h)
{
  int left1, left2;
  int right1, right2;
  int top1, int top2;
  int bottom1, int bottom2;

  int t_x = (int) x_ + column_x_;
  int t_y = (int) y_ + column_y_;

  left1 = t_x;
  left2 = o_x;

  right1 = left1 + width_ - 1 - column_width_;
  right2 = o_x + o_w - 1;

  top1 = t_y;
  top2 = o_y;

  bottom1 = top1 + height_ - 1 - column_height_;
  bottom2 = o_y + o_h - 1;

  if (bottom1 < top2)
    {
      return false;
    }

  if (top1 > bottom2)
    {
      return false;
    }

  if (right1 < left2)
    {
      return false;
    }

  if (left1 > right2)
    {
      return false;
    }

  return true;
}

bool valid_pos(int x, int y)
{
  bool _return = true;

  int start_x = (x + column_x_) / TILE_SIZE;
  int start_y = (y + column_y_) / TILE_SIZE;

  int end_x = ((x + column_x_) + width_ - column_width_ - 1) / TILE_SIZE;
  int end_y = ((x + column_y_) + height_ - column_height_ - 1) / TILE_SIZE;

  for (int i_y = start_y; i_y < end_y; i_y++)
    {
      for (int i_x = start_x; i_x < end_x; i_x++)
      {
        Tile *tile = MapManager::map_control_.get_tile(i_x * TILE_SIZE,
                             i_y * TILE_SIZE);
        if (valid_pos_tile(tile) == false)
          {
            _return = false;
          }
      }
    }

  if (flags_ & ENTITY_FLAG_MAPONLY)
    {
    }
  else
    {
      for (int i = 0; i < entity_list_.size(); i++)
      {
        if (!valid_pos_entity(entity_list_[i], x, y))
          {
            _return = false;
          }
      }
    }

  return _return;
}

bool valid_pos(Tile *t)
{
  if (t == NULL)
    {
      return true;
    }

  if (tile->type_id_ == TILE_TYPE_BLOCK)
    {
      return false;
    }

  return true;
}

bool valid_pos(Entity *e, int x, int y)
{
  if ((this != e) && (e != NULL) && (e->dead_ == false) &&
      (e->flags_ ^ ENTITY_FLAG_MAPONLY) &&
      (e->collides(x + column_x, y + column_y,
          width_ - column_width_ - 1,
           height_ - column_height_ - 1) == true))
    {
      EntityCollision ec;
      ec.a_ = this;
      ec.b_ = e;

      EntityCollision::collision_list_.push_back(ec);
      return false;
    }

  return true;
}

thanks

edit: i don’t know why some of the indentation broke. fixing it now.

  • 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-28T03:31:40+00:00Added an answer on May 28, 2026 at 3:31 am
      image_buffer_ = NULL; // just set it to null if it doesn't :\
    }
    

    Placing a backslash at the end of a line splices it with the line that follows, which, effectively, comments out the closing bracket in your function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been getting a really annoying error about an std::out_of_range when calling substr.
I'm getting a really annoying error, saying I'm getting a null pointer exception but
I'm getting a really strange error when making a method call: /* input.cpp */
This is getting really really annoying. I start debugging my web app using Visual
I'm playing with Paul Graham's arc , and it's getting really annoying that the
Im getting really lost on how to use HttpContext.User. I read everywhere that its
im gettin this really annoying error message. I know Im only new to this
This is getting really annoying for me. I only have this line for my
So I'm getting really sick of E*TRADE and, being a developer, would love to
What are some options for getting really fast 'Find in Files' searching in VIM?

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.