Changeset 218 for trunk


Ignore:
Timestamp:
Jan 17, 2011, 2:22:07 PM (10 years ago)
Author:
sam
Message:

The Tile size can now be specified upon TileSet load. Add a sample
with the Monsterz tiles.

Location:
trunk
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      .auto
      aclocal.m4
      autom4te.cache
      config.h
      config.h.in
      config.log
      config.status
      configure
      libtool
      Makefile
      Makefile.in
      stamp-h1
  • trunk/art

    • Property svn:ignore set to
      Makefile.in
      Makefile
  • trunk/art/test

    • Property svn:ignore set to
      Makefile
      Makefile.in
  • trunk/gfx

    • Property svn:ignore set to
      Makefile
      Makefile.in
  • trunk/gfx/font

    • Property svn:ignore set to
      Makefile
      Makefile.in
  • trunk/maps

    • Property svn:ignore set to
      Makefile
      Makefile.in
  • trunk/src

    • Property svn:ignore set to
      .deps
      Makefile
      Makefile.in
  • trunk/src/Makefile.am

    r208 r218  
    1212    debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \
    1313    debugrecord.cpp debugrecord.h debugstats.cpp debugstats.h \
    14     debugsphere.cpp debugsphere.h
     14    debugsphere.cpp debugsphere.h debugboard.cpp debugboard.h
    1515libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1616
  • trunk/src/debugsprite.cpp

    r210 r218  
    3737    data->game = game;
    3838    Ticker::Ref(game);
    39     data->tiler = Tiler::Register("art/test/character-dress.png");
     39    data->tiler = Tiler::Register("art/test/character-dress.png", 32);
    4040    data->x = 320;
    4141    data->y = 206;
  • trunk/src/map.cpp

    r186 r218  
    122122        {
    123123            /* This is a tileset image file. Associate it with firstgid. */
    124             data->tilers[data->ntilers] = Tiler::Register(str);
     124            data->tilers[data->ntilers] = Tiler::Register(str, 32);
    125125            data->ntilers++;
    126126            //fprintf(stderr, "new tiler %s\n", str);
  • trunk/src/test-map.cpp

    r208 r218  
    1010#include <cstdio>
    1111#include <cmath>
     12#if defined _WIN32
     13#   include <direct.h>
     14#endif
    1215
    1316#include <SDL.h>
     
    1619#include "sdlinput.h"
    1720#include "debugfps.h"
     21#include "debugboard.h"
    1822#include "debugsprite.h"
    1923#include "debugsphere.h"
     
    5054
    5155    /* Create a game */
     56#if defined _WIN32
     57    _chdir(".."); /* Temporary Win32 hack */
     58#endif
    5259    Game *game = new Game("maps/testmap.tmx");
     60    game->SetMouse(160, 96);
    5361
    5462    /* Register an input driver and some debug stuff */
     
    5664    new DebugFps();
    5765    new DebugSprite(game);
     66    new DebugBoard(game);
    5867    new DebugSphere();
    5968    //new DebugRecord("lolengine.ogg");
  • trunk/src/tiler.cpp

    r172 r218  
    2929 */
    3030
    31 int Tiler::Register(char const *path)
     31int Tiler::Register(char const *path, int size)
    3232{
    3333    int id = data->tilesets.MakeSlot(path);
     
    3535    if (!data->tilesets.GetEntity(id))
    3636    {
    37         TileSet *tileset = new TileSet(path);
     37        TileSet *tileset = new TileSet(path, size);
    3838        data->tilesets.SetEntity(id, tileset);
    3939    }
  • trunk/src/tiler.h

    r138 r218  
    1818{
    1919public:
    20     static int Register(char const *path);
     20    static int Register(char const *path, int size);
    2121    static void Deregister(int id);
    2222
  • trunk/src/tileset.cpp

    r210 r218  
    3838    char *name;
    3939    int *tiles;
    40     int nw, nh, ntiles;
     40    int size, nw, nh, ntiles;
    4141    float tx, ty;
    4242
     
    4949 */
    5050
    51 TileSet::TileSet(char const *path)
     51TileSet::TileSet(char const *path, int size)
    5252{
    5353    data = new TileSetData();
     
    6767    }
    6868
    69     data->nw = data->img->w / 32;
    70     data->nh = data->img->h / 32;
     69    if (size <= 0)
     70        size = 32;
     71
     72    data->size = size;
     73    data->nw = data->img->w / size;
     74    data->nh = data->img->h / size;
    7175    data->ntiles = data->nw * data->nh;
    72     data->tx = 32.0f / data->img->w;
    73     data->ty = 32.0f / data->img->h;
     76    data->tx = (float)size / data->img->w;
     77    data->ty = (float)size / data->img->h;
    7478
    7579    drawgroup = DRAWGROUP_BEFORE;
     
    121125
    122126    float sqrt2 = sqrtf(2.0f);
    123     int off = o ? 32 : 0;
     127    int off = o ? data->size : 0;
     128    int dx = data->size;
     129    int dy = data->size * 38 / 32; /* Magic... fix this one day */
     130    int dy2 = data->size * 70 / 32;
    124131
    125132    if (!data->img)
     
    128135        glBegin(GL_QUADS);
    129136            glTexCoord2f(tx, ty);
    130             glVertex3f(x, sqrt2 * (y - 38 - off), sqrt2 * (z + off));
     137            glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off));
    131138            glTexCoord2f(tx + data->tx, ty);
    132             glVertex3f(x + 32, sqrt2 * (y - 38 - off), sqrt2 * (z + off));
     139            glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off));
    133140            glTexCoord2f(tx + data->tx, ty + data->ty);
    134             glVertex3f(x + 32, sqrt2 * (y - 70), sqrt2 * z);
     141            glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z);
    135142            glTexCoord2f(tx, ty + data->ty);
    136             glVertex3f(x, sqrt2 * (y - 70), sqrt2 * z);
     143            glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z);
    137144        glEnd();
    138145    }
  • trunk/src/tileset.h

    r210 r218  
    2424{
    2525public:
    26     TileSet(char const *path);
     26    TileSet(char const *path, int size);
    2727    virtual ~TileSet();
    2828
  • trunk/tools

    • Property svn:ignore set to
      .deps
      make-font
      Makefile
      Makefile.in
Note: See TracChangeset for help on using the changeset viewer.