~ubuntu-branches/ubuntu/natty/balder2d/natty

« back to all changes in this revision

Viewing changes to src/collisionmask.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bjørn Hansen
  • Date: 2008-06-15 17:15:38 UTC
  • mfrom: (1.1.1 upstream) (3.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080615171538-e407e07wbtdy0qs8
Tags: 1.0-1
* new upstream release
* update for guichan 8.1 (Closes: #482584)
* use physicsfs to make data/config/map/aiscript loading more flexible
* new skins for menus
* fix typo in control file long description (Closes: #458401)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <SDL/SDL.h>
22
22
#include <SDL/SDL_image.h>
23
 
#include "../include/collisionmask.h"
 
23
#include "collisionmask.h"
 
24
#include "imageloader.h"
24
25
#include <string>
25
26
 
26
27
using namespace Balder;
31
32
        filename += mapname;
32
33
        filename += "/";
33
34
        filename += "geometry.png";
34
 
        SDL_Surface *field = IMG_Load(filename.c_str());
 
35
        SDL_Surface *field = ImageLoader::LoadImage(filename.c_str());
35
36
        if (!field) throw "invalid surface used to create collision mask";
36
37
        width = field->w;
37
38
        height = field->h;
38
39
        // allocate memory for the mask
39
40
        mask = new bool[width * height];
40
 
        
 
41
 
41
42
        int bpp = field->format->BytesPerPixel;
42
43
        for (int x = 0; x < width; x++)
43
44
        {
50
51
            else mask[y*width + x] = false;
51
52
        }
52
53
    }
53
 
    SDL_FreeSurface(field);
 
54
    ImageLoader::FreeImage(filename.c_str());
54
55
}
55
56
 
56
57
CollisionMask::~CollisionMask()
63
64
bool CollisionMask::TestPixel ( int x, int y )
64
65
{
65
66
    // first, make sure the point is within the collision field
66
 
    if (x > width || x < 0 || y > height || y < 0) return false;
 
67
    if (x > width-1 || x < 0 || y > height-1 || y < 0) return false;
67
68
    return mask[y*width + x];
68
69
}