Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About MottMan

  • Rank
  1. I'm using SDL.image.h for my image loading (IMG_Load(filename.c_str());) and am wondering if there is a way to load images from a specified directory? Example: C:\Documents and Settings\[name]\Desktop\[game]\[art] It would be very helpful organizationally. If anyone has any ideas or advice please let me know. Thanks in advance.
  2. I'll probably go the pointer route as it isn't really necessary for me to have copies (I don't use STL containers like list often so I learned something new). Thanks for your help. Fingers crossed that also solves my other problem.
  3. How do I prevent that from happening?
  4. I'm having a very strange problem where my program terminates (the window closes) but the program is still being ran. I have narrowed this down due to a second obstacle being created (as when it is commented out the program terminates properly) but I have no clue as to why. 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.
  5. MottMan

    [SDL] Efficient collision detection?

    If I understand correctly there should be a piece of data in an obstacle and the player that identifies it's location on a grid (possibly an array) so that the collision detection function can see what obstacles are near the player and might be causing a collision?
  6. MottMan

    [SDL] Efficient collision detection?

    Thanks Glancing at the source it seems overly complicated for what I need it for but should be helpful nonetheless.
  7. MottMan

    [SDL] Efficient collision detection?

    I'm more interested in writing it myself. Could you provide a link to an example? I'm not worrying (or required to worry) about velocity, speed, or any other variables other than location. If you hit a wall, you should stop. I'm working with 2D strictly, yes.
  8. I have been using the following code to check for collision detection for the player and the wall: void Player::move() { player_outline.x += xVel; if (...check_collision(player_outline, wall_outline)) player_outline.x -= xVel; player_outline.y += yVel; if (...check_collision(player_outline, wall_outline)) player_outline.y -= yVel; } This works fine but if there are a lot of different walls, barrels, obstacles, then the if statement will become quite large and system hogging. Is there a more efficient way to determine what to check/how to check for collision? I'm sure there must be. Thanks in advance.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!