Changeset 222


Ignore:
Timestamp:
Jan 18, 2011, 2:04:03 AM (10 years ago)
Author:
sam
Message:

Add support for rotated views and stretched tiles.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/deushax/debugsprite.cpp

    r221 r222  
    3737    data->game = game;
    3838    Ticker::Ref(game);
    39     data->tiler = Tiler::Register("art/test/character-dress.png", 32, 32);
     39    data->tiler = Tiler::Register("art/test/character-dress.png",
     40                                  32, 32, sqrtf(2));
    4041    data->x = 320;
    4142    data->y = 206;
  • trunk/deushax/game.cpp

    r221 r222  
    7070{
    7171    if (!data->scene)
    72         data->scene = new Scene();
     72        data->scene = new Scene(45.0f);
    7373    return data->scene;
    7474}
  • trunk/deushax/mapviewer.cpp

    r220 r222  
    7070{
    7171    if (!data->scene)
    72         data->scene = new Scene();
     72        data->scene = new Scene(45.0f);
    7373    return data->scene;
    7474}
  • trunk/monsterz/debugboard.cpp

    r221 r222  
    4141    data->game = game;
    4242    Ticker::Ref(game);
    43     data->background = Tiler::Register("monsterz/background.png", 640, 480);
    44     data->board = Tiler::Register("monsterz/board.png", 384, 384);
    45     data->tiler = Tiler::Register("monsterz/tiles.png", 48, 48);
     43    data->background = Tiler::Register("monsterz/background.png", 640, 480, 1.0f);
     44    data->board = Tiler::Register("monsterz/board.png", 384, 384, 1.0f);
     45    data->tiler = Tiler::Register("monsterz/tiles.png", 48, 48, 1.0f);
    4646}
    4747
     
    5555    Entity::TickDraw(deltams);
    5656
    57     data->game->GetScene()->AddTile((data->background << 16) | 0, 0, 980, 0, 0);
    58     data->game->GetScene()->AddTile((data->board << 16) | 0, 24, 841, 1, 0);
     57    data->game->GetScene()->AddTile((data->background << 16) | 0, 0, 1050, 0, 0);
     58    data->game->GetScene()->AddTile((data->board << 16) | 0, 24, 912, 1, 0);
    5959
    6060    for (int j = 0; j < 8; j++)
     
    6464        id += (id % 5) / 4;
    6565        data->game->GetScene()->AddTile((data->tiler << 16) | id,
    66                                         i * 48 + 24, j * 48 + 107, 0, 1);
     66                                        i * 48 + 24, j * 48 + 177, 2, 0);
    6767    }
    6868}
  • trunk/monsterz/game.cpp

    r221 r222  
    7171{
    7272    if (!data->scene)
    73         data->scene = new Scene();
     73        data->scene = new Scene(0.0f);
    7474    return data->scene;
    7575}
  • trunk/src/map.cpp

    r221 r222  
    1616#include <cstring>
    1717#include <cstdlib>
     18#include <cmath>
    1819#include <ctype.h>
    1920
     
    127128        {
    128129            /* This is a tileset image file. Associate it with firstgid. */
    129             data->tilers[data->ntilers] = Tiler::Register(str, 32, 32);
     130            data->tilers[data->ntilers] = Tiler::Register(str, 32, 32,
     131                                                          sqrtf(2));
    130132            data->ntilers++;
    131133            //fprintf(stderr, "new tiler %s\n", str);
  • trunk/src/scene.cpp

    r221 r222  
    5454    Tile *tiles;
    5555    int ntiles;
     56    float angle;
    5657};
    5758
     
    6061 */
    6162
    62 Scene::Scene()
     63Scene::Scene(float angle)
    6364{
    6465    data = new SceneData();
    6566    data->tiles = 0;
    6667    data->ntiles = 0;
     68    data->angle = angle;
    6769}
    6870
     
    105107    f += 0.05f;
    106108    glTranslatef(320.0f, 240.0f, 0.0f);
    107     glRotatef(-45.0f, 1.0f, 0.0f, 0.0f);
     109    glRotatef(-data->angle, 1.0f, 0.0f, 0.0f);
    108110#if 0
    109111    glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
  • trunk/src/scene.h

    r221 r222  
    2424{
    2525public:
    26     Scene();
     26    Scene(float angle);
    2727    ~Scene();
    2828
  • trunk/src/tiler.cpp

    r221 r222  
    3434 */
    3535
    36 int Tiler::Register(char const *path, int w, int h)
     36int Tiler::Register(char const *path, int w, int h, float dilate)
    3737{
    3838    int id = data->tilesets.MakeSlot(path);
     
    4040    if (!data->tilesets.GetEntity(id))
    4141    {
    42         TileSet *tileset = new TileSet(path, w, h);
     42        TileSet *tileset = new TileSet(path, w, h, dilate);
    4343        data->tilesets.SetEntity(id, tileset);
    4444    }
  • trunk/src/tiler.h

    r221 r222  
    2323{
    2424public:
    25     static int Register(char const *path, int w, int h);
     25    static int Register(char const *path, int w, int h, float dilate);
    2626    static void Deregister(int id);
    2727
  • trunk/src/tileset.cpp

    r221 r222  
    4444    int *tiles;
    4545    int w, h, nw, nh, ntiles;
    46     float tx, ty;
     46    float dilate, tx, ty;
    4747
    4848    SDL_Surface *img;
     
    5454 */
    5555
    56 TileSet::TileSet(char const *path, int w, int h)
     56TileSet::TileSet(char const *path, int w, int h, float dilate)
    5757{
    5858    data = new TileSetData();
     
    7979    data->w = w;
    8080    data->h = h;
     81    data->dilate = dilate;
    8182    /* FIXME: check for non-zero here */
    8283    data->nw = data->img->w / w;
     
    135136    float tx = data->tx * ((id & 0xffff) % data->nw);
    136137    float ty = data->ty * ((id & 0xffff) / data->nw);
     138    float dilate = data->dilate;
    137139
    138     float sqrt2 = sqrtf(2.0f);
    139140    int off = o ? data->h : 0;
    140141    int dx = data->w;
     
    147148        glBegin(GL_QUADS);
    148149            glTexCoord2f(tx, ty);
    149             glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off));
     150            glVertex3f(x, dilate * (y - dy - off), dilate * (z + off));
    150151            glTexCoord2f(tx + data->tx, ty);
    151             glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off));
     152            glVertex3f(x + dx, dilate * (y - dy - off), dilate * (z + off));
    152153            glTexCoord2f(tx + data->tx, ty + data->ty);
    153             glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z);
     154            glVertex3f(x + dx, dilate * (y - dy2), dilate * z);
    154155            glTexCoord2f(tx, ty + data->ty);
    155             glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z);
     156            glVertex3f(x, dilate * (y - dy2), dilate * z);
    156157        glEnd();
    157158    }
  • trunk/src/tileset.h

    r221 r222  
    2929{
    3030public:
    31     TileSet(char const *path, int w, int h);
     31    TileSet(char const *path, int w, int h, float dilate);
    3232    virtual ~TileSet();
    3333
Note: See TracChangeset for help on using the changeset viewer.