Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __WIN32
- #include <SDL.h>
- #include <SDL_image.h>
- #undef main
- #else
- #include <SDL/SDL.h>
- #include <SDL/SDL_image.h>
- #undef main
- #endif
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include<vector>
- #include<deque>
- #include<math.h>
- #include<string>
- #include<map>
- #include "luawrap.h"
- #include "fileio.h"
- #include "soundloader.h"
- #include "audiomanager.h"
- #define WIDTH 400
- #define HEIGHT 300
- #define SCALE 2
- audiomanager* AudioMan;
- int tileframe = 0;
- struct framelimiter{
- Uint32 ticks;
- Uint32 tickprev;
- int framerate;
- int framecnt;
- /*int tracker[5000];
- int trackerhead;
- int trackertail;
- int dur;
- int advance_val( int val ){
- return (val + 1) % 5000;
- }
- int get_distance(){
- if( trackerhead >= trackertail ) return trackerhead - trackertail;
- return 5000 + trackerhead - trackertail;
- }
- int pop(){
- int r = tracker[trackertail];
- dur -= tracker[trackertail];
- trackertail = advance_val( trackertail );
- return r;
- }
- void push(int val){
- dur += val;
- tracker[trackerhead] = val;
- trackerhead = advance_val( trackerhead );
- }*/
- framelimiter( int fps ){
- ticks = SDL_GetTicks();
- tickprev = SDL_GetTicks();
- framerate = fps;
- framecnt = 0;
- //trackerhead = trackertail = 0;
- //dur = 0;
- }
- void tick(){
- framecnt ++;
- Uint32 s = SDL_GetTicks();
- int diff = s - tickprev;
- //push(diff);
- int tosleep = (framecnt * 1000 / framerate) - (s - ticks);
- //printf("%d\n", tosleep );
- //while( dur > 2000 ){
- // ticks += pop();
- // framecnt--;
- //}
- if( framecnt > 10000000 ){
- framecnt = 0;
- ticks = SDL_GetTicks();
- }
- tickprev = s;
- if( tosleep > 0 )
- SDL_Delay( tosleep );
- }
- };
- class fatalerror{
- std::string txt;
- public:
- fatalerror(std::string s){
- txt = s;
- }
- const char* text(){
- return txt.c_str();
- }
- };
- GLuint glLoadImageFile( const char* fname, int& width, int& height ){
- SDL_Surface* surface = IMG_Load( fname );
- SDL_DisplayFormat( surface );
- width = surface->w;
- height = surface->h;
- GLuint texture;
- glGenTextures( 1, &texture );
- glBindTexture( GL_TEXTURE_2D, texture );
- gluBuild2DMipmaps( GL_TEXTURE_2D, 4, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
- SDL_FreeSurface( surface );
- return texture;
- }
- struct image;
- struct image{
- //static std::map<std::string, int> imagemap;
- static std::vector<image> imagevector;
- GLuint texture;
- int texw, texh;
- int xoffset, yoffset, xspace, yspace, tilewidth, tileheight;
- std::string fname;
- int id;
- operator int(){ return id; }
- static image& get( int name ){
- return imagevector[external_to_local(name)];
- }
- static int local_to_external(int input){
- return input + 1;
- }
- static int external_to_local(int input){
- return input - 1;
- }
- static int add( const char* fname, int w, int h, int xo, int yo, int xs, int ys ){
- printf("Loading %s\n", fname );
- image i;
- i.texture = glLoadImageFile( fname, i.texw, i.texh );
- i.xoffset = xo;
- i.yoffset = yo;
- i.xspace = xs;
- i.yspace = ys;
- i.tilewidth = w;
- i.tileheight = h;
- i.fname = fname;
- i.id = local_to_external(imagevector.size());
- imagevector.push_back( i );
- return i.id;
- }
- void render( int collumn, int row, int xoff, int yoff ){
- if(!glIsTexture( texture ) ){
- texture = glLoadImageFile( fname.c_str(), texw, texh );
- }
- if(!glIsTexture( texture ) ){
- throw(fatalerror("Failed to load "+fname));
- }
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,texture);
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- // when texture area is large, bilinear filter the original
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
- glBegin( GL_TRIANGLE_STRIP );
- double xc = (xoffset + collumn * (xspace + tilewidth))/((double)texw);
- double yc = (yoffset + row * (yspace + tileheight))/((double)texh);
- double ww = tilewidth / ((double)texw);
- double hh = tileheight / ((double)texh);
- glTexCoord2d( xc + ww, yc ); glVertex2d( xoff + tilewidth, yoff );
- glTexCoord2d( xc, yc ); glVertex2d( xoff, yoff );
- glTexCoord2d( xc + ww, yc + hh ); glVertex2d( xoff + tilewidth, yoff + tileheight );
- glTexCoord2d( xc, yc + hh ); glVertex2d( xoff, yoff + tileheight );
- glEnd();
- glDisable(GL_TEXTURE_2D);
- }
- };
- //std::map<std::string, int> image::imagemap;
- std::vector<image> image::imagevector;
- struct sprite{
- static std::map<std::string, int> spritemap;
- static std::vector<sprite> spritevector;
- static int local_to_external(int input){
- return input + 1;
- }
- static int external_to_local(int input){
- return input - 1;
- }
- static sprite& get(std::string name){
- int t = external_to_local(spritemap[name]);
- //if( t < 0 ) throw(5);
- return spritevector[t];
- }
- static sprite& get(int name){
- return spritevector[external_to_local(name)];
- }
- std::string name;
- int img, collumn, row, length, originx, originy;
- int id;
- operator int(){ return id; }
- static int add(const char* name, int img, int x, int y, int l, int origx, int origy ){
- printf("Loading %s\n", name );
- sprite s;
- s.name = name;
- s.img = img;
- s.collumn = x;
- s.row = y;
- s.length = l;
- s.originx = origx;
- s.originy = origy;
- s.id = local_to_external(spritevector.size());
- spritevector.push_back( s );
- spritemap[name] = s.id;
- return s.id;
- }
- void draw( int frame ){
- image::get( img ).render( collumn + (frame % length), row, -originx, -originy );
- }
- };
- std::map<std::string, int> sprite::spritemap;
- std::vector<sprite> sprite::spritevector;
- struct tileset{
- static std::map<std::string, int> tilesetmap;
- static std::vector<tileset> tilesetvector;
- static int local_to_external(int input){
- return input + 1;
- }
- static int external_to_local(int input){
- return input - 1;
- }
- static tileset& get(std::string name){
- return tilesetvector[external_to_local(tilesetmap[name])];
- }
- static tileset& get(int name){
- return tilesetvector[external_to_local(name)];
- }
- std::string name;
- std::vector<int> sprites;
- int id;
- operator int(){ return id; }
- static int add(const char* name, int sprit ){
- printf("Loading %s\n", name );
- tileset t;
- t.name = name;
- t.sprites.push_back( sprit );
- t.id = local_to_external(tilesetvector.size());
- tilesetvector.push_back( t );
- tilesetmap[name] = t.id;
- return t.id;
- }
- static int add_animation(const char* name){
- printf("Loading %s\n", name );
- tileset t;
- t.name = name;
- t.id = local_to_external(tilesetvector.size());
- tilesetvector.push_back( t );
- tilesetmap[name] = t.id;
- return t.id;
- }
- static int add_animation_frame(int id, int sprit){
- tilesetvector[external_to_local(id)].sprites.push_back(sprit);
- return id;
- }
- static int add_animation_finish(int id){
- return id;
- }
- void draw( int frame, int type ){
- sprite::get(sprites[frame % sprites.size()]).draw( type );
- }
- };
- std::map<std::string, int> tileset::tilesetmap;
- std::vector<tileset> tileset::tilesetvector;
- struct sound{
- //decoder* d;
- static std::map<std::string, int> soundmap;
- static std::vector<sound> soundvector;
- static int local_to_external(int input){
- return input + 1;
- }
- static int external_to_local(int input){
- return input - 1;
- }
- static sound& get(std::string name){
- return soundvector[external_to_local(soundmap[name])];
- }
- static sound& get(int name){
- return soundvector[external_to_local(name)];
- }
- int id, loops, volume;
- std::string fname;
- std::string name;
- int audio;
- operator int(){ return id; }
- static int add(const char* fname, const char* name, int loops, int volume ){
- printf("Loading %s\n", fname );
- sound s;
- s.loops = loops;
- s.volume = volume;
- s.fname = fname;
- s.name = name;
- s.audio = AudioMan->load( fname );
- (*AudioMan)[s.audio]->loop(s.loops);
- s.id = local_to_external(soundvector.size());
- soundvector.push_back( s );
- soundmap[name] = s.id;
- return s.id;
- }
- void play(){
- (*AudioMan)[audio]->seek( SEEK_SET, 0 );
- (*AudioMan)[audio]->play(true);
- }
- void stop(){
- (*AudioMan)[audio]->play(false);
- }
- void setrip( double val ){
- (*AudioMan)[audio]->setrip(val);
- }
- };
- std::map<std::string, int> sound::soundmap;
- std::vector<sound> sound::soundvector;
- struct level{
- static std::map<std::string, int> levelmap;
- static std::vector<level> levelvector;
- static int local_to_external(int input){
- return input + 1;
- }
- static int external_to_local(int input){
- return input - 1;
- }
- static level& get(std::string name){
- return levelvector[external_to_local(levelmap[name])];
- }
- static level& get(int name){
- return levelvector[external_to_local(name)];
- }
- struct tile{
- int idx;
- int type;
- int hazard;
- tile(){
- idx = -1;
- type = -1;
- hazard = false;
- }
- };
- std::vector<tile> tiles;
- int id, width, height;
- std::string fname;
- std::string name;
- operator int(){ return id; }
- void set_tile( int x, int y, tile t ){
- tiles[x+y*width] = t;
- }
- tile& get_tile( int x, int y ){
- return tiles[x+y*width];
- }
- struct object{
- std::string type;
- int x, y;
- };
- std::vector<object> objs;
- static int add_tile( level* self, int x, int y, const char* type, int idx, int hazard ){
- //printf("Adding Tile: %d %d, %s, %d\n", x, y, type, idx);
- tile t;
- t.idx = idx;
- t.type = tileset::get( type ).id;
- t.hazard = hazard;
- self->set_tile( x, y, t );
- return 0;
- }
- static int add_object( level* self, const char* type, int x, int y ){
- printf("Adding Object: %s, %d %d\n", type, x, y);
- object o;
- o.type = type;
- o.x = x;
- o.y = y;
- self->objs.push_back( o );
- return 0;
- }
- static int set_dimension( level* self, int x, int y){
- printf("Setting Dimensions: %d %d\n", x, y);
- self->width = x;
- self->height = y;
- self->tiles.clear();
- self->tiles.resize( x * y );
- return 0;
- }
- static int add(const char* fname, const char* name ){
- printf("Loading %s\n", fname );
- level l;
- l.fname = fname;
- l.name = name;
- l.id = local_to_external(levelvector.size());
- levelvector.push_back( l );
- levelmap[name] = l.id;
- std::string dumper ="\n\n\n\
- set_dimensions( self, width, height )\n\
- for i=1,#level do\n\
- add_tile( self, level[i][1], level[i][2], level[i][3], level[i][4], level[i][5] )\n\
- end\n\
- for i=1,#objects do\n\
- add_object( self, objects[i][1], objects[i][2], objects[i][3])\n\
- end\n";
- std::string re = read_file_to_buffer( fname ).c_str()+dumper;
- //printf("\n\n%s\n\n",re.c_str());
- Lua L(re.c_str(), fname, 0);
- L.set("self", &(levelvector[external_to_local(l.id)]));
- L.funcreg<int, level*, int, int, const char*, int, int, add_tile>( "add_tile" );
- L.funcreg<int, level*, const char*, int, int, add_object>( "add_object" );
- L.funcreg<int, level*, int, int, set_dimension>( "set_dimensions" );
- L.run();
- return l.id;
- }
- void draw(){
- glColor3ub(255,255,255);
- for( int i = 0; i < width; ++i ){
- for( int j = 0; j < height; ++j ){
- if( get_tile( i, j ).type != -1 ){
- glPushMatrix();
- glTranslated( i * 16,j * 16, 0 );
- tileset::get(get_tile( i, j ).type).draw(tileframe, get_tile( i, j ).idx);
- glPopMatrix();
- }
- }
- }
- }
- void unload();
- void load();
- };
- std::map<std::string, int> level::levelmap;
- std::vector<level> level::levelvector;
- level* levelloaded = 0;
- class entity{
- public:
- struct position{
- double x, y;
- double rotation;
- double xscale;
- double imageindex;
- double imagespeed;
- int spriteindex;
- int visible;
- position(){
- x = y = rotation = xscale = imageindex = imagespeed = spriteindex = 0;
- visible = 1;
- }
- //double timestamp;
- };
- class biezercurve{
- std::vector<position> points;
- public:
- biezercurve( std::deque<position> p ){
- while( p.size() > 0 ){
- points.push_back( p.back() );
- p.pop_back();
- }
- }
- position get( double time ){
- /*position p = {0};
- if( points.size() == 0 ) return p;
- if( points.size() == 1 ) return points[0];
- std::deque<position> positions;
- for( size_t i = 0; i < points.size() - 1; ++i ){
- p.x = points[i].x + ( points[i+1].x - points[i].x ) * time;
- p.y = points[i].y + ( points[i+1].y - points[i].y ) * time;
- p.rotation = points[i].rotation + ( points[i+1].rotation - points[i].rotation ) * time;
- p.xscale = points[i].xscale + ( points[i+1].xscale - points[i].xscale ) * time;
- p.imageindex = points[i].imageindex + ( points[i+1].imageindex - points[i].imageindex ) * time;
- int t = (int)(time*points.size());
- if( t >= points.size() ) t = points.size() - 1;
- if( t < 0 ) t = 0;
- if( time < 0 ) t = 0;
- p.spriteindex = points[t].spriteindex;
- positions.push_front( p );
- }
- if( positions.size() == 1 ) return positions.back();
- biezercurve subbiezer(positions);
- return subbiezer.get( time );*/
- position p;
- int i = (points.size()-1) * time;
- int k = points.size();
- if( i >= points.size()-1 || time >= 1 ) return points[points.size()-1];
- if( i <= 0 ) return points[0];
- time = time / ( 1.0/(points.size()-1) );
- time -= floor( time );
- p.x = points[i].x + ( points[i+1].x - points[i].x ) * time;
- p.y = points[i].y + ( points[i+1].y - points[i].y ) * time;
- p.rotation = points[i].rotation + ( points[i+1].rotation - points[i].rotation ) * time;
- p.xscale = points[i].xscale + ( points[i+1].xscale - points[i].xscale ) * time;
- p.xscale = points[i].xscale;
- p.imageindex = points[i].imageindex + ( points[i+1].imageindex - points[i].imageindex ) * time;
- p.imagespeed = points[i].imagespeed + ( points[i+1].imagespeed - points[i].imagespeed ) * time;
- p.spriteindex = points[i].spriteindex;
- p.visible = points[i].visible;
- return p;
- }
- };
- private:
- //position location;
- std::deque<position> history;
- bool timeaffects;
- public:
- //static std::map<std::string, int> entitymap;
- //static std::vector<entity> entityvector;
- double w, h;
- int type;
- double xspeed, yspeed;
- position location;
- entity( position Location, bool affectedbytime = true ){
- location = Location;
- timeaffects = affectedbytime;
- }
- entity( double x, double y, double rotation = 0, bool affectedbytime = true ){
- position p;
- p.rotation = rotation;
- p.x = x;
- p.y = y;
- p.xscale = 1;
- p.imagespeed = 1;
- p.visible = true;
- location = p;
- timeaffects = affectedbytime;
- //printf("aa: %f\n\n", location.y);
- }
- void updatetime( double time ){
- //location.timestamp = time;
- if( timeaffects )
- history.push_back( location );
- }
- void rewind( double amt ){
- if( timeaffects )
- {
- biezercurve b( history );
- location = b.get(amt);
- }
- }
- void rewindclear(){
- history.clear();
- }
- void draw(){
- if( !location.visible) return;
- glMatrixMode(GL_MODELVIEW);
- //double d = sqrt( 50 );
- //glColor3ub( rand()%256, rand()%256, rand()%256 );
- ///////////////if( timeaffects )
- glColor3ub(255,255,255);
- //else
- //glColor3ub(166,100,100);
- glPushMatrix();
- // glTranslated(1, 1, 0 );
- glTranslated( location.x, location.y, 0 );
- glRotated( location.rotation, 0, 0, 1 );
- glScaled( location.xscale, 1, 1 );
- /*glBegin( GL_TRIANGLE_STRIP );
- glVertex2d( 5, -5 );
- glVertex2d( -5, -5 );
- glVertex2d( 5, 5 );
- glVertex2d( -5, 5 );
- glEnd();*/
- sprite::get(location.spriteindex).draw(location.imageindex);
- location.imageindex+= location.imagespeed;;
- glPopMatrix();
- //printf("%f, %f, %f\n", location.x, location.y, location.rotation);
- }
- virtual void onframe() = 0;
- virtual void reset() = 0;
- virtual void collide_left( entity* other, double sp ) = 0;
- virtual void collide_right( entity* other, double sp ) = 0;
- virtual void collide_top( entity* other, double sp ) = 0;
- virtual void collide_bottom( entity* other, double sp ) = 0;
- };
- //std::map<std::string, int> entity::entitymap;
- //std::vector<entity> entity::entityvector;
- int print(const char* s, const char* o, int a, int b ){
- printf(s);
- return 1;
- }
- int print2(const char* s){
- printf(s);
- return 1;
- }
- std::vector<entity*> entities;
- struct trapdoor : entity{
- bool opened;
- std::string color;
- trapdoor( int x, int y, std::string color ): entity( x, y, 0, true ){
- opened = false;
- location.spriteindex = sprite::get("trapdoor_" + color);
- trapdoor::color = color;
- w = 16;
- h = 2;
- location.imagespeed = 0;
- location.imageindex = 0;
- entities.push_back( this );
- type = 3;
- }
- void collide_left(entity* other, double speed){
- /*if( !opened ){
- other->xspeed = 0;
- other->location.x = location.x - w - other->w;
- }*/
- }
- void collide_right(entity* other, double speed){
- /*if( !opened ){
- other->xspeed = 0;
- other->location.x = location.x + w + other->w;
- }*/
- }
- void collide_top(entity* other, double speed){
- if( !opened ){
- if( other->type == 1 ){
- other->yspeed = 0;
- other->location.y = location.y - h;
- }
- else{
- other-> yspeed = 0;
- other->location.y = location.y - other->h - h;
- }
- }
- }
- void collide_bottom(entity* other, double speed){
- if( !opened ){
- other->location.y = location.y + h + other->h;
- other->yspeed = 0;
- }
- }
- void reset(){
- opened = false;
- }
- void onframe(){
- updatetime(0);
- if( location.imageindex < 1 ){
- opened = false;
- location.imagespeed = 0;
- location.imageindex = 0;
- }
- if( location.imageindex >= sprite::get(location.spriteindex).length - 1 )
- location.imagespeed = 0;
- }
- void open(){
- if( !opened ){
- location.imagespeed = 1;
- location.imageindex = 1;
- opened = true;
- }
- }
- };
- struct button : entity{
- std::string color;
- bool onbutton = false;
- button( int x, int y, std::string color ): entity( x, y, 0, true ){
- location.spriteindex = sprite::get("button_" + color);
- button::color = color;
- w = 7;
- h = 1;
- location.imagespeed = 0;
- location.imageindex = 0;
- entities.push_back( this );
- type = 4;
- onbutton = false;
- }
- void collide_left(entity* other, double speed){}
- void collide_right(entity* other, double speed){}
- void collide_top(entity* other, double speed){
- if( location.imageindex == 0 )
- location.imageindex = 1;
- location.imagespeed = 1;
- if( !onbutton ){
- for( size_t i = 0; i < entities.size(); ++i ){
- if( entities[i]->type == 3 ){
- trapdoor* t = (trapdoor*)entities[i];
- if( t->color == color )
- t->open();
- }
- }
- }
- onbutton = true;
- }
- void collide_bottom(entity* other, double speed){}
- void reset(){}
- void onframe(){
- updatetime(0);
- if( location.imageindex == 0 ){
- location.imagespeed = 0;
- }
- if( !onbutton && location.imageindex > 0 ){
- location.imagespeed = -1;
- }
- if( location.imageindex >= sprite::get(location.spriteindex).length - 1 ){
- location.imagespeed = 0;
- location.imageindex = sprite::get(location.spriteindex).length - 1;
- }
- onbutton = false;
- }
- };
- double timemult = 1.1;
- int mytime = 0;
- struct dilator : entity{
- double amount;
- bool cangrab;
- dilator( int x, int y, double amt ): entity( x, y, 0, false ){
- location.spriteindex = sprite::get("pickup_dilator");
- w = 8;
- h = 8;
- location.imagespeed = 0;
- location.imageindex = 0;
- amount = amt;
- entities.push_back( this );
- type = 5;
- cangrab = true;
- }
- void collide_left(entity* other, double speed){}
- void collide_right(entity* other, double speed){}
- void collide_top(entity* other, double speed){
- if( cangrab && other->type == 1 ){
- cangrab = false;
- timemult *=amount;
- amount = 1;
- location.visible = false;
- }
- }
- void collide_bottom(entity* other, double speed){}
- void reset(){}
- void onframe(){
- updatetime(0);
- }
- };
- struct roomexit : entity{
- std::string linkedroom;
- roomexit( int x, int y, std::string link ): entity( x, y, 0, false ){
- location.spriteindex = sprite::get("exit");
- w = 8;
- h = 48/2;
- location.imagespeed = 0;
- location.imageindex = 0;
- linkedroom = link;
- entities.push_back( this );
- type = 7;
- }
- void collide_left(entity* other, double speed){}
- void collide_right(entity* other, double speed){}
- void collide_top(entity* other, double speed){
- levelloaded->unload();
- level::get( linkedroom ).load();
- }
- void collide_bottom(entity* other, double speed){}
- void reset(){}
- void onframe(){
- updatetime(0);
- }
- };
- struct crate : entity {
- double gravity;
- bool onground;
- crate( int x, int y ) : entity( x, y, 0, false ){
- location.x = x;
- location.y = y;
- location.rotation = 0;
- location.imageindex = 0;
- location.spriteindex = sprite::get("block");
- onground = false;
- xspeed = yspeed = 0;
- gravity = .04;
- entities.push_back( this );
- w = h = 15.5;
- type = 2;
- }
- void reset(){
- onground = false;
- xspeed = yspeed = 0;
- }
- void collide_left(entity* other, double speed){
- if( other->type == 1 ){
- xspeed = .3*speed;
- other->xspeed = 0;
- other->location.x = location.x - w - other->w;
- }
- else{
- other->location.x = location.x - w - other->w;
- other->xspeed = 0;
- xspeed = .3*speed;
- }
- }
- void collide_right(entity* other, double speed){
- if( other->type == 1 ){
- xspeed = .3*speed;
- other->xspeed = 0;
- other->location.x = location.x + w + other->w;
- }
- else{
- other->location.x = location.x + w + other->w;
- other->xspeed = 0;
- xspeed = .3*speed;
- }
- }
- void collide_top(entity* other, double speed){
- if( other->type == 1 ){
- yspeed += .3*speed;
- other->yspeed = 0;
- other->location.y = location.y - h;
- }
- else{
- other-> yspeed = 0;
- other->location.y = location.y - other->h - h;
- yspeed += .3*speed;
- }
- }
- void collide_bottom(entity* other, double speed){
- if( other->type == 1 ){
- yspeed += .3*speed;
- other->yspeed = 0;
- printf("%f\t%f\n", location.y, location.y + h+32);
- other->location.y = location.y + h+32;
- }
- else{
- other->location.y = location.y + h + other->h;
- other->yspeed = 0;
- yspeed += .3*speed;
- }
- }
- void onframe(){
- updatetime(0);
- if( xspeed == 0 ) location.x = floor( location.x );
- if( onground ) xspeed *= .98;
- yspeed += gravity;
- location.x += xspeed;
- location.y += yspeed;
- if( levelloaded != 0 ){
- int px = location.x / 16;
- int py = location.y / 16;
- onground = false;
- for( int i = px - 2; i <= px + 2; ++i ){
- for( int j = py - 3; j <= py + 3; ++j ){
- if( levelloaded->get_tile(i, j).type == -1 ) continue;
- int hazard = levelloaded->get_tile(i, j).hazard;
- if( (location.y + h >= j * 16 && location.y - h < (j+1) * 16) ){
- if( (location.x+w-1 > i * 16 && location.x-w+1 < (i+1)*16 ) ){
- if( yspeed >= 0 && levelloaded->get_tile(i, j-1).type == -1 ){
- onground=true;
- yspeed = 0;
- location.y = ( j ) * 16 - h;
- }
- if( yspeed < 0 && levelloaded->get_tile(i, j+1).type == -1){
- //printf("\n\n\nBONK\n\n\n");
- yspeed = 0;
- location.y = ( j + 1 ) * 16+1 + h;
- }
- }
- }
- if((location.y + h > j * 16 && location.y - h < (j+1) * 16) ){
- if( location.x - w <= (i+1)*16 && location.x + w > i*16 ){
- if( xspeed < 0 && levelloaded->get_tile(i + 1, j).type == -1 ){
- location.x = i * 16 + 16 + w;
- xspeed = 0;
- }
- }
- if( location.x + w >= i*16 && location.x - w < (i+1)*16 ){
- if( xspeed > 0&& levelloaded->get_tile(i - 1, j).type == -1 ){
- location.x = i * 16 - 1 - w;
- xspeed = 0;
- }
- }
- }
- }
- }
- }
- if( levelloaded != 0 ){
- int px = location.x / 16;
- int py = location.y / 16;
- for( size_t i = 0; i < entities.size(); ++i ){
- if( entities[i] == this ) continue;
- if( (location.y+h >= entities[i]->location.y-entities[i]->h && location.y - h < entities[i]->location.y+entities[i]->h) ){
- if( (location.x+w-5 > entities[i]->location.x-entities[i]->w && location.x-w+5 < entities[i]->location.x+entities[i]->w ) ){
- if( yspeed < 0){
- entities[i]->collide_bottom( this, yspeed );
- }
- }
- }
- if( (location.y+h >= entities[i]->location.y-entities[i]->h && location.y - h < entities[i]->location.y+entities[i]->h) ){
- if( (location.x+w-4 > entities[i]->location.x-entities[i]->w && location.x-w+4 < entities[i]->location.x+entities[i]->w ) ){
- if( yspeed >= 0){
- entities[i]->collide_top( this, yspeed );
- if( yspeed == 0 ){
- onground = true;
- }
- }
- }
- }
- if((location.y + h > entities[i]->location.y-entities[i]->h+1 && location.y - h < entities[i]->location.y+entities[i]->h - 1) ){
- if( location.x - w + 1 <= entities[i]->location.x+entities[i]->w && location.x + w - 1> entities[i]->location.x-entities[i]->w ){
- if( xspeed < 0){
- entities[i]->collide_right( this, xspeed );
- }
- }
- if( location.x + w - 1 >= entities[i]->location.x-entities[i]->w && location.x - w + 1 < entities[i]->location.x+entities[i]->w ){
- if( xspeed > 0 ){
- entities[i]->collide_left( this, xspeed );
- }
- }
- }
- }
- }
- }
- };
- struct player : entity{
- double gravity;
- int sprite_idle;
- int sprite_run_start;
- int sprite_run;
- int sprite_jump;
- int sprite_ascending;
- int sprite_descend_start;
- int sprite_descending;
- int sprite_impact;
- int sprite_throw;
- int xmovement;
- bool onground;
- int cntr;
- void collide_left(entity* other, double speed){
- }
- void collide_right(entity* other, double speed){
- }
- void collide_top(entity* other, double speed){
- }
- void collide_bottom(entity* other, double speed){
- }
- player( int x, int y ) : entity( x, y, 0, true ){
- sprite_idle = sprite::get( "player_idle" ).id;
- sprite_run_start = sprite::get( "player_run_start" ).id;
- sprite_run = sprite::get( "player_run" ).id;
- sprite_jump = sprite::get( "player_jump" ).id;
- sprite_ascending = sprite::get( "player_ascending" ).id;
- sprite_descend_start = sprite::get( "player_descend_start" ).id;
- sprite_descending = sprite::get( "player_descending" ).id;
- sprite_impact = sprite::get( "player_impact" ).id;
- sprite_throw = sprite::get( "player_throw" ).id;
- location.x = x;
- location.y = y;
- location.rotation = 0;
- location.imageindex = 0;
- location.spriteindex = sprite_idle;
- xmovement=0;
- onground = false;
- xspeed = yspeed = 0;
- gravity = .04;
- cntr = 0;
- w = 10;
- h = 32;
- type = 1;
- entities.push_back(this);
- }
- void move_left(){
- xmovement = xmovement | 1;
- //printf("a %d\n", xmovement);
- }
- void move_right(){
- xmovement |= 2;
- }
- void move_left_halt(){
- xmovement &= ~1;
- }
- void move_right_halt(){
- xmovement &= ~2;
- }
- void move_jump(){
- if( onground && (location.spriteindex == sprite_idle || location.spriteindex == sprite_run || location.spriteindex == sprite_run_start )){
- location.spriteindex = sprite_jump;
- location.imageindex = 0;
- }
- }
- void reset(){
- xspeed = yspeed = 0;
- xmovement=0;
- onground = false;
- }
- void onframe(){
- //printf("sprite: %d\t%d\t%d\t%d\n", location.spriteindex, sprite_descend_start, sprite_descending, sprite_impact );
- //if( cntr == 0 )
- updatetime(0);
- cntr = ( cntr + 1 ) % 3;
- yspeed += gravity;
- location.x += xspeed;
- location.y += yspeed;
- if( levelloaded != 0 ){
- int px = location.x / 16;
- int py = location.y / 16;
- onground = false;
- for( int i = px - 2; i <= px + 2; ++i ){
- for( int j = py - 3; j <= py + 3; ++j ){
- if( levelloaded->get_tile(i, j).type == -1 ) continue;
- int hazard = levelloaded->get_tile(i, j).hazard;
- if( (location.y >= j * 16 && location.y - 32 < (j+1) * 16) ){
- if( (location.x+8 > i * 16 && location.x-8 < (i+1)*16 ) ){
- if( yspeed >= 0 && levelloaded->get_tile(i, j-1).type == -1 ){
- onground=true;
- yspeed = 0;
- location.y = ( j ) * 16;
- if( hazard ) printf("OW OW OW\n");
- if( location.spriteindex == sprite_descending ){
- location.spriteindex = sprite_impact;
- location.imageindex = 0;
- sound::get( "land" ).play();
- }
- else if( location.spriteindex == sprite_descend_start ){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- }
- if( yspeed < 0 && levelloaded->get_tile(i, j+1).type == -1){
- //printf("\n\n\nBONK\n\n\n");
- yspeed = 0;
- location.y = ( j + 3 ) * 16+1;
- if( hazard ) printf("OW OW OW\n");
- }
- }
- if((location.y > j * 16 +1 && location.y - 32 < (j+1) * 16 - 1) ){
- if( location.x - 10 <= (i+1)*16 && location.x + 10 > i*16 ){
- if( xspeed < 0 && levelloaded->get_tile(i + 1, j).type == -1 ){
- location.x = i * 16 + 26;
- xspeed = 0;
- if( hazard ) printf("OW OW OW\n");
- }
- }
- if( location.x + 10 >= i*16 && location.x - 10 < (i+1)*16 ){
- if( xspeed > 0&& levelloaded->get_tile(i - 1, j).type == -1 ){
- location.x = i * 16 - 11;
- xspeed = 0;
- if( hazard ) printf("OW OW OW\n");
- }
- }
- }
- }
- }
- /*if( (location.y > j * 16 && location.y - 32 <= (j+1) * 16) && (location.x+10 > i * 16 && location.x < (i+1)*16 ) ){
- onground=true;
- yspeed = 0;
- location.y = ( j ) * 16;
- if( location.spriteindex == sprite_descending ){
- location.spriteindex = sprite_impact;
- location.imageindex = 0;
- }
- else if( location.spriteindex == sprite_descend_start ){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- }
- }*/
- }
- /*double tx = location.x / 16;
- double ty = location.y / 16;
- int hitbot = ty>py && ((levelloaded->get_tile(px, py).type != -1) || ( floor( location.x ) != location.x && levelloaded->get_tile(px+1, py).type != -1 ));
- int hitleft = tx<px &&((levelloaded->get_tile(px, py).type != -1)||(levelloaded->get_tile(px, py-1).type != -1));
- int hitright = tx>px && ((levelloaded->get_tile(px+1, py).type != -1)||(levelloaded->get_tile(px+1, py-1).type != -1)) ;
- int hittop = ty<py && ((levelloaded->get_tile(px, py - 2).type != -1) || ( floor( location.x ) != location.x && levelloaded->get_tile(px+1, py -2).type != -1 ));
- onground=false;
- if( hitbot ){
- }
- if( hitright ){
- xspeed = 0;
- location.x = px;
- }
- if( hitleft ){
- xspeed = 0;
- location.x = px;
- }*/
- }
- if( levelloaded != 0 ){
- int px = location.x / 16;
- int py = location.y / 16;
- for( size_t i = 0; i < entities.size(); ++i ){
- if( (location.y >= entities[i]->location.y-entities[i]->h && location.y - 32 < entities[i]->location.y+entities[i]->h) ){
- if( (location.x+5 > entities[i]->location.x-entities[i]->w && location.x-5 < entities[i]->location.x+entities[i]->w ) ){
- if( yspeed < 0){
- entities[i]->collide_bottom( this, yspeed );
- }
- }
- }
- if( (location.y >= entities[i]->location.y-entities[i]->h && location.y - 32 < entities[i]->location.y+entities[i]->h) ){
- if( (location.x+5 > entities[i]->location.x-entities[i]->w && location.x-5 < entities[i]->location.x+entities[i]->w ) ){
- if( yspeed >= 0){
- entities[i]->collide_top( this, yspeed );
- if( yspeed == 0 ){
- onground = true;
- if( location.spriteindex == sprite_descending ){
- location.spriteindex = sprite_impact;
- location.imageindex = 0;
- sound::get( "land" ).play();
- }
- else if( location.spriteindex == sprite_descend_start ){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- }
- }
- }
- if((location.y > entities[i]->location.y-entities[i]->h+2 && location.y - 32 < entities[i]->location.y+entities[i]->h - 2) ){
- if( location.x - 8 <= entities[i]->location.x+entities[i]->w && location.x + 8 > entities[i]->location.x-entities[i]->w ){
- if( xspeed < 0){
- entities[i]->collide_right( this, xspeed );
- }
- }
- if( location.x + 8 >= entities[i]->location.x-entities[i]->w && location.x - 8 < entities[i]->location.x+entities[i]->w ){
- if( xspeed > 0 ){
- entities[i]->collide_left( this, xspeed );
- }
- }
- }
- }
- }
- }
- if( onground ){
- if( location.spriteindex != sprite_jump )
- xspeed = 0;
- else
- xspeed *= .99;
- }
- //printf("%d", onground);
- //printf("sprite: %d\t%d\t%d\t%d\n", location.spriteindex, sprite_descend_start, sprite_descending, sprite_impact );
- if( (xmovement & 1) && onground && ( location.spriteindex == sprite_idle || location.spriteindex == sprite_run ) ){
- xspeed += -.6;
- if( location.spriteindex == sprite_idle ){ location.spriteindex = sprite_run_start; location.imageindex = 2; }
- location.xscale = -1;
- //printf("h4h4h4");
- }
- if( (xmovement & 2) && onground && ( location.spriteindex == sprite_idle || location.spriteindex == sprite_run ) ){
- xspeed += .6;
- location.xscale = 1;
- if( location.spriteindex == sprite_idle ){ location.spriteindex = sprite_run_start; location.imageindex = 2; }
- //printf("h5h5h5");
- }
- //printf("Image Index: %f\n", xspeed );
- if( (xmovement & 1) && !onground ){
- xspeed += -.008;
- if( location.spriteindex == sprite_idle ){ location.spriteindex = sprite_run_start; location.imageindex = 2; }
- location.xscale = -1;
- }
- if( (xmovement & 2) && !onground ){
- xspeed += .008;
- location.xscale = 1;
- if( location.spriteindex == sprite_idle ){ location.spriteindex = sprite_run_start; location.imageindex = 2; }
- }
- //printf("Image Index: %f\n", xspeed );
- if( yspeed > 0 && location.spriteindex != sprite_descending ){
- if( location.spriteindex != sprite_descend_start ){
- location.spriteindex = sprite_descend_start;
- location.imageindex = 0;
- }
- if( location.spriteindex == sprite_descend_start && location.imageindex >= sprite::get(sprite_descend_start).length - 1 ){
- location.spriteindex = sprite_descending;
- location.imageindex = 0;
- }
- }
- if( location.spriteindex == sprite_impact && location.imageindex == sprite::get(sprite_impact).length - 1){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- if( location.spriteindex == sprite_jump && location.imageindex == 4){
- yspeed = -1.9;
- //location.y --;
- sound::get( "jump" ).play();
- }
- if( location.spriteindex == sprite_jump && location.imageindex == sprite::get(sprite_jump).length - 1){
- location.spriteindex = sprite_ascending;
- location.imageindex = 0;
- }
- if( onground && location.spriteindex == sprite_ascending ){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- if( location.spriteindex == sprite_run_start && location.imageindex >= sprite::get(sprite_run_start).length - 1 ){
- //printf("Image Index: %f\n", xspeed );
- if( xspeed != 0){
- location.spriteindex = sprite_run;
- location.imageindex = 0;
- }
- else{
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- }
- if( location.spriteindex == sprite_run && xspeed == 0 ){
- location.spriteindex = sprite_idle;
- location.imageindex = 0;
- }
- }
- };
- bool timeresetting = false;
- struct checkpoint : entity{
- checkpoint( int x, int y ): entity( x, y, 0, false ){
- location.spriteindex = sprite::get("pickup_checkpoint");
- w = 8;
- h = 8;
- location.imagespeed = 0;
- location.imageindex = 0;
- entities.push_back( this );
- type = 6;
- }
- void collide_left(entity* other, double speed){}
- void collide_right(entity* other, double speed){}
- void collide_top(entity* other, double speed){
- timeresetting = true;
- }
- void collide_bottom(entity* other, double speed){}
- void reset(){}
- void onframe(){
- updatetime(0);
- }
- };
- bool hasdrawnnumber = false;
- int hasdrawnnumbertube;
- int hasdrawnnumbernum;
- void drawnumber(int number, int padding, int drawnum = true){
- if( !hasdrawnnumber ){
- hasdrawnnumbernum = sprite::get("numbers").id;
- hasdrawnnumbertube = sprite::get("tube").id;
- hasdrawnnumber = true;
- }
- glTranslated( padding*21.0/2.0-10+5,0,0 );
- for( int i = 0; i < padding; ++i ){
- sprite::get(hasdrawnnumbertube).draw( 0 );
- if( drawnum )
- sprite::get(hasdrawnnumbernum).draw( number%10 );
- number /= 10;
- glTranslated( -21,0,0 );
- if( i == 1 )
- glTranslated( -10,0,0 );
- }
- }
- void level::unload(){
- for( int i = 0; i < entities.size(); ++i ){
- delete entities[i];
- }
- entities.clear();
- timemult = 1.1;
- levelloaded = 0;
- }
- player* playa = 0;
- void level::load(){
- timemult = 1.1;
- levelloaded = this;
- for( int i = 0; i < objs.size(); ++i ){
- if( objs[i].type == "player" ){
- playa = new player(objs[i].x, objs[i].y);
- }
- else if( objs[i].type == "crate" ){
- new crate(objs[i].x, objs[i].y);
- }
- else if( objs[i].type.substr(0, 6) == "button" ){
- new button(objs[i].x, objs[i].y, objs[i].type.substr(6) );
- }
- else if( objs[i].type.substr(0, 8) == "trapdoor" ){
- new trapdoor(objs[i].x, objs[i].y, objs[i].type.substr(8) );
- }
- else if( objs[i].type == "dilator" ){
- new dilator(objs[i].x, objs[i].y, .5 );
- }
- else if( objs[i].type == "checkpoint" ){
- new checkpoint(objs[i].x, objs[i].y ) ;
- }
- else if( objs[i].type.substr(0, 5) == "exit_" ){
- new roomexit(objs[i].x, objs[i].y, objs[i].type.substr(5) );
- }
- }
- }
- int main(){
- const SDL_VideoInfo* info = 0;
- if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) return 1;
- if( !(info = SDL_GetVideoInfo( ))) return 2;
- IMG_Init(IMG_INIT_PNG);
- int bpp = info->vfmt->BitsPerPixel;
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
- SDL_Surface* screen;
- if( !(screen=SDL_SetVideoMode( WIDTH*SCALE, HEIGHT*SCALE, bpp, SDL_OPENGL | SDL_RESIZABLE ) )) return 3;
- glOrtho( 0, WIDTH, HEIGHT, 0, -pow( 2, 15 ) , pow( 2, 15 ) );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity( );
- glPixelStorei(GL_UNPACK_ALIGNMENT,4);
- glTexEnvf( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- AudioMan = new audiomanager();
- std::string buff = read_file_to_buffer( "loadscript.lua" );
- printf("%s", buff.c_str());
- Lua L( buff.c_str(), "Configuration", 0 );
- L.funcreg<int, const char*, int, int, int, int, int, int, image::add >("image_strip_add");
- L.funcreg<int, const char*, int, int, int, int, int, int, sprite::add >("sprite_add");
- L.funcreg<int, const char*, const char*, int, int, sound::add >("sound_add");
- L.funcreg<int, const char*, int, tileset::add >("tileset_add");
- L.funcreg<int, const char*, tileset::add_animation >("tileset_animation_start");
- L.funcreg<int, int, int, tileset::add_animation_frame >("tileset_animation_add");
- L.funcreg<int, int, tileset::add_animation_finish >("tileset_animation_finish");
- L.funcreg<int, const char*, const char*, level::add >("level_add");
- //L.funcreg<int, const char*, const char*, int, int, print >("p_rint");
- //L.funcreg<int, const char*, print2 >("p_rint");
- L.run();
- //entity e(200, 20);
- //double gravity = .05;
- // double vs = 0;
- // double hs = 1;
- //int frames = 0;
- //e.location.spriteindex = sprite::get("trapdoor_red").id;
- // e.location.imageindex = 0;
- double camerax, cameray, cameraxp, camerayp;
- SDL_Event event;
- sound::get("bgm").play();
- //level l = level::get("test");
- framelimiter FPS(16);
- /*player p( 16*9, 16*20 );
- crate c1( 16*19, 16*17 );
- //crate c2( 16*13, 16*17 );
- crate c3( 16*22, 16*13 );
- crate c4( 16*22, 16*13 );
- crate c5( 16*22, 16*13 );
- crate c6( 16*22, 16*13 );
- button b1 ( 16*28, 16*18, "red");
- button b2 ( 16*22, 16*25, "green");
- checkpoint ch1 ( 16*32, 16*16 );
- dilator d1 ( 16*36, 16*17, .5 );
- trapdoor t1 ( 16*22, 16*20+1, "red");
- trapdoor t2 ( 16*22, 16*14+1, "green");*/
- //levelloaded = &
- level::get("lvl1").load();
- camerax = cameraxp = -playa->location.x+WIDTH/2;
- cameray = camerayp = -playa->location.y+HEIGHT/2+20;
- double frames = 0;
- bool rewinding = false;
- double rewindcount = 0;
- /*bool chopping = false;
- double chopnum = 0;
- while( true ){
- while(SDL_PollEvent(&event)) {
- switch( event.type ){
- case SDL_KEYDOWN:{
- switch( event.key.keysym.sym ){
- case SDLK_SPACE: chopping = true;
- default: break;
- }
- } break; //major facepalm
- case SDL_KEYUP:{
- switch( event.key.keysym.sym ){
- case SDLK_SPACE: chopping = false;
- default: break;
- }
- }
- default: break;
- }
- }
- if( chopping ){ sound::get("bgm").setrip( (cos(chopnum * 3.14159*10)+1)/3.0+.2); }
- else sound::get("bgm").setrip( 0 );
- chopnum += .021;
- FPS.tick();
- }*/
- unsigned int flasher = 0;
- while( true ){
- flasher++;
- camerax = camerax + ( (-playa->location.x+WIDTH/2) - camerax ) / 4;
- cameray = cameray + ( (-playa->location.y+HEIGHT/2+20) - cameray ) / 4;
- FPS.tick();
- tileframe++;
- while(SDL_PollEvent(&event)) {
- if( !rewinding ){
- switch( event.type ){
- case SDL_KEYDOWN:{
- switch( event.key.keysym.sym ){
- case SDLK_LEFT: playa->move_left(); break;
- case SDLK_RIGHT: playa->move_right(); break;
- case SDLK_UP: playa->move_jump(); break;
- //case SDLK_SPACE: t1.open(); break;
- default: break;
- }
- } break; //major facepalm
- case SDL_KEYUP:{
- switch( event.key.keysym.sym ){
- case SDLK_LEFT: playa->move_left_halt(); break;
- case SDLK_RIGHT: playa->move_right_halt(); break;
- default: break;
- }
- }
- default: break;
- }
- }
- }
- if( !rewinding ){
- for( int i = 0; i < 10; ++i ){
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->onframe();
- }
- }
- rewindcount = 0;
- frames+=timemult;
- }
- else{
- if( rewindcount > 1 ) rewindcount = 1;
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->rewind( rewindcount );
- }
- rewindcount+=.021;
- frames--;
- sound::get("bgm").setrip( (cos(rewindcount * 3.14159*10)+1)/3.0+.2);
- }
- if( frames > 200 ){
- rewinding = true;
- rewindcount = 0;
- sound::get("rewind").play();
- sound::get("bgm").setrip( .5);
- frames = 0;
- }
- if( rewindcount >= 1 ){
- rewinding = false;
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->rewindclear();
- }
- frames=0;
- playa->reset();
- sound::get("bgm").setrip( 0);
- }
- if( timeresetting ){
- timeresetting = false;
- playa->rewindclear();
- playa->updatetime(1);
- playa->updatetime(1);
- if( frames > 50 ){
- rewinding = true;
- rewindcount = 0;
- sound::get("rewind").play();
- sound::get("bgm").setrip( .5);
- }
- else {
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->rewind( 1 );
- }
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->rewindclear();
- }
- }
- frames = 0;
- }
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
- glClearColor( 0,0,0,0 );
- glColor3ub(122, 10, 10);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2d( WIDTH, 0 );
- glVertex2d( 0, 0 );
- glColor3ub(85, 5, 5);
- glVertex2d( WIDTH, HEIGHT );
- glColor3ub(40, 0, 0);
- glVertex2d( 0, HEIGHT );
- glEnd();
- if( rewinding ){
- glTranslated(WIDTH/2, HEIGHT/2, 0);
- glRotated( (rand()%10-5) * (1-rewindcount), 0, 0, 1 );
- glTranslated(-WIDTH/2, -HEIGHT/2, 0);
- }
- glTranslated( ((int)(camerax)), ((int)(cameray)), 0 );
- levelloaded->draw();
- for( size_t k = 0; k < entities.size(); ++k ){
- entities[k]->draw();
- }
- glPopMatrix();
- glPushMatrix();
- glColor3ub(255,255,255);
- glTranslated(WIDTH/2, 20, 0 );
- if( !rewinding ){
- //drawnumber( 1099-frames*110/20, 4 );
- drawnumber( 1000-frames*100/20, 4 );
- }
- else{
- drawnumber( 0, 4, flasher % 10 < 5 );
- }
- glPopMatrix();
- SDL_GL_SwapBuffers( );
- //SDL_Delay(30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement