Changeset 138


Ignore:
Timestamp:
Aug 19, 2010, 2:58:28 AM (10 years ago)
Author:
sam
Message:

Start to handle differences between vertical and horizontal tiles.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugsprite.cpp

    r133 r138  
    5454
    5555    data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 32, 1);
    56     data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 0, 1);
     56    data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 200, 0, 1);
    5757}
    5858
  • trunk/src/scene.cpp

    r133 r138  
    88#endif
    99
    10 #include <stdlib.h>
     10#include <cstdlib>
     11#include <cmath>
     12
     13#ifdef WIN32
     14#   define WIN32_LEAN_AND_MEAN
     15#   include <windows.h>
     16#endif
     17#if defined __APPLE__ && defined __MACH__
     18#   include <OpenGL/gl.h>
     19#else
     20#   define GL_GLEXT_PROTOTYPES
     21#   include <GL/gl.h>
     22#endif
    1123
    1224#include "scene.h"
     
    1628{
    1729    uint32_t prio, code;
    18     int x, y;
     30    int x, y, z, o;
    1931};
    2032
     
    6577    data->tiles[data->ntiles].x = x;
    6678    data->tiles[data->ntiles].y = y;
     79    data->tiles[data->ntiles].z = z;
     80    data->tiles[data->ntiles].o = o;
    6781    data->ntiles++;
    6882}
     
    7286    qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);
    7387
     88    // XXX: debug stuff
     89    glPushMatrix();
     90    static float f = 0.0f;
     91    f += 0.05f;
     92    glTranslatef(320.0f, 240.0f, 0.0f);
     93    glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
     94    glRotatef(30.0f * sinf(f), 0.0f, 0.0f, 1.0f);
     95    //glRotatef(30.0f, 0.0f, 0.0f, 1.0f);
     96    glTranslatef(-320.0f, -240.0f, 0.0f);
     97
    7498    for (int i = 0; i < data->ntiles; i++)
    75         Tiler::Render(data->tiles[i].code, data->tiles[i].x, data->tiles[i].y);
     99        Tiler::BlitTile(data->tiles[i].code, data->tiles[i].x,
     100                        data->tiles[i].y, data->tiles[i].z, data->tiles[i].o);
     101
     102    glPopMatrix();
     103    // XXX: end of debug stuff
    76104
    77105    free(data->tiles);
  • trunk/src/sdlinput.cpp

    r117 r138  
    5151    int mx, my;
    5252    SDL_GetMouseState(&mx, &my);
    53     data->game->SetMouse(mx * (640 - 32) / 640, my * (480 - 32) / 480);
     53    data->game->SetMouse(mx * (640 - 32) / 320 - 320, my * (480 - 32) / 240 - 240);
    5454
    5555    /* Handle keyboard and WM input */
  • trunk/src/tiler.cpp

    r100 r138  
    9595}
    9696
    97 void Tiler::Render(uint32_t code, int x, int y)
     97void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
    9898{
    9999    int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */
    100100
    101     data->tilesets[id]->BlitTile(code & 0xffff, x, y);
     101    data->tilesets[id]->BlitTile(code & 0xffff, x, y, z, o);
    102102}
    103103
  • trunk/src/tiler.h

    r100 r138  
    2121    static void Deregister(int id);
    2222
    23     static void Render(uint32_t code, int x, int y);
     23    static void BlitTile(uint32_t code, int x, int y, int z, int o);
    2424};
    2525
  • trunk/src/tileset.cpp

    r105 r138  
    99
    1010#include <cstdlib>
     11#include <cmath>
    1112
    1213#ifdef WIN32
     
    109110}
    110111
    111 void TileSet::BlitTile(uint32_t id, int x, int y)
     112void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
    112113{
    113114    float tx = .0625f * (id & 0xf);
    114115    float ty = .0625f * ((id >> 4) & 0xf);
     116
     117    float sqrt2 = sqrtf(2.0f);
     118    int off = o ? 32 : 0;
    115119
    116120    if (!data->img)
     
    119123        glBegin(GL_QUADS);
    120124            glTexCoord2f(tx, ty);
    121             glVertex2f(x, y);
     125            glVertex3f(x, sqrt2 * (y + off), sqrt2 * (z + off));
    122126            glTexCoord2f(tx + .0625f, ty);
    123             glVertex2f(x + 32, y);
     127            glVertex3f(x + 32, sqrt2 * (y + off), sqrt2 * (z + off));
    124128            glTexCoord2f(tx + .0625f, ty + .0625f);
    125             glVertex2f(x + 32, y + 32);
     129            glVertex3f(x + 32, sqrt2 * (y + 32), sqrt2 * z);
    126130            glTexCoord2f(tx, ty + .0625f);
    127             glVertex2f(x, y + 32);
     131            glVertex3f(x, sqrt2 * (y + 32), sqrt2 * z);
    128132        glEnd();
    129133    }
  • trunk/src/tileset.h

    r106 r138  
    3636    char const *GetName();
    3737
    38     void BlitTile(uint32_t id, int x, int y);
     38    void BlitTile(uint32_t id, int x, int y, int z, int o);
    3939
    4040private:
Note: See TracChangeset for help on using the changeset viewer.