All pastes #631768 Raw Edit

Unnamed

public cpp v1 · immutable
#631768 ·published 2007-07-24 09:49 UTC
rendered paste body
#include <allegro.h>#include <fstream>#include <string>#include <sstream>using namespace std;volatile bool close_button_pressed = false;int playerx = 5;int playery = 5;int tilex = 32;int tiley = 32;int gamespeed = 12;int mapx = 1;int mapy = 1;int mapsizex = 20;int mapsizey = 11;char map1[20][12];char map2[20][12];char map3[20][12];char map4[20][12];BITMAP *buffer;BITMAP *mainhud;BITMAP *grass;BITMAP *water;BITMAP *sand;BITMAP *lava;BITMAP *rocklava;BITMAP *tree;BITMAP *deadtree;BITMAP *mountain;BITMAP *teleport;void close_button_handler() {     close_button_pressed = true;     simulate_keypress(KEY_ESC);}END_OF_FUNCTION(close_button_handler);void load_allegro() {    allegro_init();    install_keyboard();    install_timer();        LOCK_FUNCTION(close_button_handler);        set_color_depth(16);    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,480,0,0);    set_window_title("MMORPG Client");     set_close_button_callback(close_button_handler);}void load_map(int mapx, int mapy) {     ostringstream out1;     out1 << "data/maps/" << mapx << mapy << "/1.txt";     ifstream mapfile1(out1.str().c_str());     int y = 0;     string mapline;     if (mapfile1.is_open()) {        while (!mapfile1.eof() && y < 12) {            getline(mapfile1,mapline);            for(int i = 0; i < 20; i++) {                    map1[i][y] = mapline[i];                    }            y++;        }        mapfile1.close();     }          ostringstream out2;     out2 << "data/maps/" << mapx << mapy << "/2.txt";     ifstream mapfile2(out2.str().c_str());     y = 0;     if (mapfile2.is_open()) {        while (!mapfile2.eof() && y < 12) {            getline(mapfile2,mapline);            for(int i = 0; i < 20; i++) {                    map2[i][y] = mapline[i];                    }            y++;        }        mapfile2.close();     }          ostringstream out3;     out3 << "data/maps/" << mapx << mapy << "/3.txt";     ifstream mapfile3(out3.str().c_str());     y = 0;     if (mapfile3.is_open()) {        while (!mapfile3.eof() && y < 12) {            getline(mapfile3,mapline);            for(int i = 0; i < 20; i++) {                    map3[i][y] = mapline[i];                    }            y++;        }        mapfile3.close();     }          ostringstream out4;     out4 << "data/maps/" << mapx << mapy << "/4.txt";     ifstream mapfile4(out4.str().c_str());     y = 0;     if (mapfile4.is_open()) {        while (!mapfile4.eof() && y < 12) {            getline(mapfile4,mapline);            for(int i = 0; i < 20; i++) {                    map4[i][y] = mapline[i];                    }            y++;        }        mapfile4.close();     }}void draw_tiles() {     for(int x=0; x <= mapsizex; x++) {         for(int y=0; y <= mapsizey; y++) {             if(map1[x][y] == 'g') {                  draw_sprite(buffer, grass, x*tiley, y*tilex);                                         } else if (map1[x][y] == 'w') {                 draw_sprite(buffer, water, x*tiley, y*tilex);                                          } else if (map1[x][y] == 'l') {                 draw_sprite(buffer, lava, x*tiley, y*tilex);                  } else if (map1[x][y] == 'r') {                 draw_sprite(buffer, rocklava, x*tiley, y*tilex);              } else if (map1[x][y] == 's') {                 draw_sprite(buffer, sand, x*tiley, y*tilex);              }                                     if (map2[x][y] == 't') {                 draw_sprite(buffer, tree, x*tiley, y*tilex);                                          } else if (map2[x][y] == 'd') {                 draw_sprite(buffer, deadtree, x*tilex, y*tilex);              } else if (map2[x][y] == 'm') {                 draw_sprite(buffer, mountain, x*tilex, y*tilex);             }         }          }}void draw_hud() {     draw_sprite(buffer, mainhud, 1, 384);    }int main(int argc, char *argv[]) {    load_allegro();    BITMAP *playerpic;    playerpic = load_bitmap("data/images/players/player.bmp", NULL);    grass = load_bitmap("data/images/ground/grass.bmp", NULL);    water = load_bitmap("data/images/ground/water.bmp", NULL);    sand = load_bitmap("data/images/ground/sand.bmp", NULL);    lava = load_bitmap("data/images/ground/lava.bmp", NULL);    rocklava = load_bitmap("data/images/ground/rocklava.bmp", NULL);    tree = load_bitmap("data/images/plants/tree.bmp", NULL);    deadtree = load_bitmap("data/images/plants/deadtree.bmp", NULL);    mountain = load_bitmap("data/images/rocks/mountain.bmp", NULL);    teleport = load_bitmap("data/images/teleport.bmp", NULL);    mainhud = load_bitmap("data/images/gui/hud.bmp", NULL);    buffer = create_bitmap(640,480);    load_map(mapx,mapy);     	while(!close_button_pressed) {		if(key[KEY_RIGHT]) {             if(map3[playerx+1][playery] == 't') {               playerx = 1;               mapx++;               load_map(mapx,mapy);                                      } else {               if(playerx < 19 && map4[playerx+1][playery] == 'o') { playerx++; }            }            clear_keybuf();		}		else if(key[KEY_LEFT]) {            if(map3[playerx-1][playery] == 't') {               playerx = 18;               mapx--;               load_map(mapx,mapy);                                      } else {               if(playerx > 1 && map4[playerx-1][playery] == 'o') { playerx--; }            }			clear_keybuf();		}		else if(key[KEY_UP]) {            if(map3[playerx][playery-1] == 't') {               playery = 10;               mapy--;               load_map(mapx,mapy);                                      } else {               if(playerx > 1 && map4[playerx][playery-1] == 'o') { playery--; }            }            clear_keybuf();		}		else if(key[KEY_DOWN]) {            if(map3[playerx][playery+1] == 't') {               playery = 1;               mapy++;               load_map(mapx,mapy);                                      } else {               if(playery < 13 && map4[playerx][playery+1] == 'o') { playery++; }            }            clear_keybuf();        }		draw_tiles();		draw_hud();		draw_sprite(buffer, playerpic, playerx*tilex+1, playery*tiley+1);		blit(buffer, screen, 0,0,0,0,640,480);		clear_bitmap(buffer);        readkey();	}    release_screen();	destroy_bitmap(playerpic);	destroy_bitmap(buffer);	return 0;}END_OF_MAIN()