Public feed #725948

Mine

public text v1 · immutable
Raw Edit
·published 2007-10-04 19:53 UTC
rendered paste body
#ifndef Map_Class_H
#define Map_Class_H

#include "SDL_Side_G.h"


const int MapSizeX=50;
const int MapSizeY=50;

class Map
{
    private:
    char MapData[ MapSizeX*MapSizeY ];
    SDL_Surface *Tiles[20];
    int TileSizeX;
    int TileSizeY;
    int ScreenX;
    int ScreenY;
    int OffsetX;
    int OffsetY;
    
    
    public:
    
    
    int SetOffset(int SizeX,int SizeY);
    int SetTileSize(int SizeX,int SizeY);
    //Formula is SizeZ*2 + 1 BE CAREFUL
    int SetScreenSize(int SizeX,int SizeY);
    int LoadTiles();
    int DrawOnScreen(Coordinates PlayerLoc );
    int LoadMap(char *location);
    
};

int Map::SetOffset(int SizeX,int SizeY)
{
    //OMG ASSHILE ERROR CHECKING TARGH IS NOOB!
    if(SizeX <= 0 || SizeY <= 0) return 1;    
    
    OffsetX = SizeX;
    OffsetY = SizeY;
    
}


int Map::SetScreenSize(int SizeX,int SizeY)
{
    //OMG ASSHILE ERROR CHECKING TARGH_ IS NOOB!
    if(SizeX <= 0 || SizeY <= 0) return 1;

    ScreenX = SizeX;
    ScreenY = SizeY;
    
}

int Map::SetTileSize(int SizeX,int SizeY)
{
    //OMG ASSHILE ERROR CHECKING TARGHAN IS NOOB!
    if(SizeX <= 0 || SizeY <= 0) return 1;

    TileSizeX = SizeX;
    TileSizeY = SizeY;
};

int Map::LoadTiles()
{
     Tiles[0] = SDL_LoadImage("Grass.bmp");
     if(Tiles[0]== NULL) return 1;
     Tiles[1] = SDL_LoadImage("Slayer.bmp");
     if(Tiles[1]== NULL) return 1;
     
     return 0;
};

//Warning No out of bounds check
int Map::DrawOnScreen(Coordinates PlayerLoc )
{
    //PlayerLoc.X -= ScreenX/2;
    //PlayerLoc.Y -= ScreenY/2;
    
    
    int MaxX = ScreenY*2+1;
    int MaxY = ScreenX*2+1;
    
    //ApplyImage(0 ,0 ,Tiles[MapData[ MapSizeX*MapSizeY ] -'0'] ,Screen );
    
    int X = 0;
    int Y = 0;    
    
    while(X < MaxX )
    {
        Y=0;
        while(Y < MaxY )
        {
            ApplyImage
            (
                X*TileSizeX +OffsetX ,Y*TileSizeY +OffsetY, 
                Tiles[ MapData[ (PlayerLoc.Y - (ScreenY+1) + Y)*MapSizeX +  (PlayerLoc.X - (ScreenX+1) + X) ]-'0' ],
                Screen
            );
            Y++;
        }
        X++;
    }
    
    
    return 0;
}

int Map::LoadMap( char *location)
{ 
  int Length = MapSizeX*MapSizeY;
  
  FILE *INPUT = fopen(location, "r");
  if( fread(MapData, 1, Length, INPUT) != Length )
  {
      //Phailed :(
      return 1;    
  }
  fclose( INPUT);
  
  return 0;
};

#endif