Pārlūkot izejas kodu

Start to handle differences between vertical and horizontal tiles.

legacy
Sam Hocevar sam pirms 14 gadiem
vecāks
revīzija
2edd7f4dbf
7 mainītis faili ar 46 papildinājumiem un 14 dzēšanām
  1. +1
    -1
      src/debugsprite.cpp
  2. +31
    -3
      src/scene.cpp
  3. +1
    -1
      src/sdlinput.cpp
  4. +2
    -2
      src/tiler.cpp
  5. +1
    -1
      src/tiler.h
  6. +9
    -5
      src/tileset.cpp
  7. +1
    -1
      src/tileset.h

+ 1
- 1
src/debugsprite.cpp Parādīt failu

@@ -53,7 +53,7 @@ void DebugSprite::TickRender(float delta_time)
Asset::TickRender(delta_time);

data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 32, 1);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 0, 1);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 200, 0, 1);
}

DebugSprite::~DebugSprite()


+ 31
- 3
src/scene.cpp Parādīt failu

@@ -7,7 +7,19 @@
# include "config.h"
#endif

#include <stdlib.h>
#include <cstdlib>
#include <cmath>

#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#if defined __APPLE__ && defined __MACH__
# include <OpenGL/gl.h>
#else
# define GL_GLEXT_PROTOTYPES
# include <GL/gl.h>
#endif

#include "scene.h"
#include "tiler.h"
@@ -15,7 +27,7 @@
struct Tile
{
uint32_t prio, code;
int x, y;
int x, y, z, o;
};

/*
@@ -64,6 +76,8 @@ void Scene::AddTile(uint32_t code, int x, int y, int z, int o)
data->tiles[data->ntiles].code = code;
data->tiles[data->ntiles].x = x;
data->tiles[data->ntiles].y = y;
data->tiles[data->ntiles].z = z;
data->tiles[data->ntiles].o = o;
data->ntiles++;
}

@@ -71,8 +85,22 @@ void Scene::Render() // XXX: rename to Blit()
{
qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);

// XXX: debug stuff
glPushMatrix();
static float f = 0.0f;
f += 0.05f;
glTranslatef(320.0f, 240.0f, 0.0f);
glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
glRotatef(30.0f * sinf(f), 0.0f, 0.0f, 1.0f);
//glRotatef(30.0f, 0.0f, 0.0f, 1.0f);
glTranslatef(-320.0f, -240.0f, 0.0f);

for (int i = 0; i < data->ntiles; i++)
Tiler::Render(data->tiles[i].code, data->tiles[i].x, data->tiles[i].y);
Tiler::BlitTile(data->tiles[i].code, data->tiles[i].x,
data->tiles[i].y, data->tiles[i].z, data->tiles[i].o);

glPopMatrix();
// XXX: end of debug stuff

free(data->tiles);
data->tiles = 0;


+ 1
- 1
src/sdlinput.cpp Parādīt failu

@@ -50,7 +50,7 @@ void SdlInput::TickGame(float delta_time)
/* Handle mouse input */
int mx, my;
SDL_GetMouseState(&mx, &my);
data->game->SetMouse(mx * (640 - 32) / 640, my * (480 - 32) / 480);
data->game->SetMouse(mx * (640 - 32) / 320 - 320, my * (480 - 32) / 240 - 240);

/* Handle keyboard and WM input */
SDL_Event event;


+ 2
- 2
src/tiler.cpp Parādīt failu

@@ -94,10 +94,10 @@ void Tiler::Deregister(int id)
data->tilesets[id] = NULL;
}

void Tiler::Render(uint32_t code, int x, int y)
void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
{
int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */

data->tilesets[id]->BlitTile(code & 0xffff, x, y);
data->tilesets[id]->BlitTile(code & 0xffff, x, y, z, o);
}


+ 1
- 1
src/tiler.h Parādīt failu

@@ -20,7 +20,7 @@ public:
static int Register(char const *path);
static void Deregister(int id);

static void Render(uint32_t code, int x, int y);
static void BlitTile(uint32_t code, int x, int y, int z, int o);
};

#endif // __DH_TILER_H__


+ 9
- 5
src/tileset.cpp Parādīt failu

@@ -8,6 +8,7 @@
#endif

#include <cstdlib>
#include <cmath>

#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
@@ -108,23 +109,26 @@ char const *TileSet::GetName()
return data->name;
}

void TileSet::BlitTile(uint32_t id, int x, int y)
void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
{
float tx = .0625f * (id & 0xf);
float ty = .0625f * ((id >> 4) & 0xf);

float sqrt2 = sqrtf(2.0f);
int off = o ? 32 : 0;

if (!data->img)
{
glBindTexture(GL_TEXTURE_2D, data->texture);
glBegin(GL_QUADS);
glTexCoord2f(tx, ty);
glVertex2f(x, y);
glVertex3f(x, sqrt2 * (y + off), sqrt2 * (z + off));
glTexCoord2f(tx + .0625f, ty);
glVertex2f(x + 32, y);
glVertex3f(x + 32, sqrt2 * (y + off), sqrt2 * (z + off));
glTexCoord2f(tx + .0625f, ty + .0625f);
glVertex2f(x + 32, y + 32);
glVertex3f(x + 32, sqrt2 * (y + 32), sqrt2 * z);
glTexCoord2f(tx, ty + .0625f);
glVertex2f(x, y + 32);
glVertex3f(x, sqrt2 * (y + 32), sqrt2 * z);
glEnd();
}
}


+ 1
- 1
src/tileset.h Parādīt failu

@@ -35,7 +35,7 @@ public:
/* New methods */
char const *GetName();

void BlitTile(uint32_t id, int x, int y);
void BlitTile(uint32_t id, int x, int y, int z, int o);

private:
TileSetData *data;


Notiek ielāde…
Atcelt
Saglabāt