main.cpp
#include "file_handling.h"
#include "maintenance.h"
#include "timer.h"
#include "objects.h"
#include "globals.h"
#include <list>
int main(int argc, char *argv[])
{
bool quit = false;
if (!init())
return 0;
std::list <Obstacle> ALL_OBSTACLES;
Obstacle wall(250, 125, 85, 140, "wall.bmp");
// Obstacle another_wall(100, 300, 85, 140, "wall.bmp"); <--- this is causing the problem!!@#!@
ALL_OBSTACLES.push_front(wall);
// ALL_OBSTACLES.push_front(another_wall);
Player character(0, 0, PLAYER_WIDTH, PLAYER_HEIGHT, "player.bmp");
Timer fps;
if (!load_files())
return 0;
while (quit == false)
{
while (SDL_PollEvent(&event))
{
character.handle_input();
if (event.type == SDL_QUIT)
quit = true;
}
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
character.move(ALL_OBSTACLES);
character.show();
wall.show();
// another_wall.show();
SDL_Flip(screen);
if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
SDL_Delay((1000/FRAMES_PER_SECOND) - fps.get_ticks());
}
//keepWndow();
clean_up();
return 0;
}
objects.h
#ifndef OBJECTS_H_INCLUDED
#define OBJECTS_H_INCLUDED
#include "file_handling.h"
#include "collision_detection.h"
#include "globals.h"
#include "SDL/SDL.h"
#include <list>
#include <string>
#include <fstream>
//////////////////
/////OBSTACLE/////
//////////////////
class Obstacle
{
public:
Obstacle(int x, int y, int w, int h, std::string filename);
~Obstacle();
SDL_Rect obstacle_outline;
int segment;
void update_obsSeg();
void show();
private:
SDL_Surface *obstacle;
};
Obstacle::Obstacle(int x, int y, int w, int h, std::string filename)
{
obstacle = load_image(filename.c_str());
obstacle_outline.x = x;
obstacle_outline.y = y;
obstacle_outline.w = w;
obstacle_outline.h = h;
update_obsSeg();
}
Obstacle::~Obstacle()
{
SDL_FreeSurface(obstacle);
}
void Obstacle::show()
{
apply_surface(obstacle_outline.x, obstacle_outline.y, obstacle, screen);
}
void Obstacle::update_obsSeg()//Used in constructor
{
segment = segment_update(obstacle_outline);
}
#endif // OBJECTS_H_INCLUDED
If anyone has any idea of suggestions to try to fix the problem it would be much appreciated. Thanks in advance.