Update of /cvsroot/super-tux/supertux/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27449/src
Modified Files:
collision.cpp tile.cpp tile.h
Log Message:
Added slope tiles.
Doesn't work that well, maybe they shouldn't have the solid attribute.
Index: tile.h
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/tile.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- tile.h 14 Jun 2004 22:45:23 -0000 1.29
+++ tile.h 22 Jun 2004 12:34:14 -0000 1.30
@@ -81,6 +81,9 @@
int next_tile;
int anim_speed;
+
+ /** This is the angle of the slope. Set to 0, if this is no slope. */
+ float slope_angle;
/** Draw a tile on the screen: */
static void draw(const Vector& pos, unsigned int c, Uint8 alpha = 255);
Index: collision.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/collision.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- collision.cpp 1 Jun 2004 21:09:37 -0000 1.27
+++ collision.cpp 22 Jun 2004 12:34:13 -0000 1.28
@@ -26,6 +26,12 @@
#include "tilemap.h"
#include "tile.h"
+struct TileInfo
+{
+ Tile *tile;
+ int x, y;
+} tileinfo;
+
bool rectcollision(const base_type& one, const base_type& two)
{
return (one.x >= two.x - one.width + 1 &&
@@ -52,11 +58,18 @@
int max_x = int(base.x + base.width);
int max_y = int(base.y + base.height);
+ tileinfo.tile = NULL;
+
for(int x = starttilex; x*32 < max_x; ++x) {
for(int y = starttiley; y*32 < max_y; ++y) {
Tile* tile = tilemap.get_tile(x, y);
if(tile && tile->attributes & Tile::SOLID)
+ {
+ tileinfo.tile = tile;
+ tileinfo.x = x*32;
+ tileinfo.y = y*32;
return true;
+ }
}
}
@@ -175,6 +188,21 @@
if(collision_object_map(*old))
{
+ if(tileinfo.tile->slope_angle != 0)
+ { // in case this is a slope, set the right Y position
+ // left-right slope:
+ if(tileinfo.tile->slope_angle > 0 && tileinfo.tile->slope_angle < M_PI/2)
+ current->y = tileinfo.y - current->height +
+ (tileinfo.x - current->x)*tan(M_PI/2 - tileinfo.tile->slope_angle)
+ - 1;
+ // right-left slope:
+ if(tileinfo.tile->slope_angle > M_PI/2 && tileinfo.tile->slope_angle < M_PI)
+ current->y = tileinfo.y - current->height +
+ (current->x - tileinfo.x)*tan(M_PI - tileinfo.tile->slope_angle)
+ - 1;
+ }
+ else
+ {
switch(h)
{
case 1:
@@ -225,6 +253,7 @@
}
break;
}
+ }
}
if((xd > 0 && current->x < orig_x) || (xd < 0 && current->x > orig_x))
Index: tile.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/tile.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- tile.cpp 15 Jun 2004 12:18:59 -0000 1.31
+++ tile.cpp 22 Jun 2004 12:34:14 -0000 1.32
@@ -147,6 +147,14 @@
reader.read_int("anim-speed", anim_speed);
reader.read_int("next-tile", next_tile);
+ slope_angle = 0;
+ reader.read_float("slope-angle", slope_angle);
+ if(slope_angle != 0)
+ { // convert angle to radians from degrees:
+ slope_angle = (slope_angle * M_PI) / 180;
+ attributes |= SOLID;
+ }
+
// FIXME: make images and editor_images a sprite
images = create_surfaces(reader.read_lisp("images"));
editor_images = create_surfaces(reader.read_lisp("editor-images"));
|