1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <iostream>
#include <allegro.h>
BITMAP *bufferSPR;
BITMAP *wallSPR;
BITMAP *bizzleSPR;
void buildLevel(int);
int main(){
int x=0;
int y=0;
int a=0;
int b=0;
int c=0;
char *levelload = new char[10000];
char debugx[2];
char debugy[2];
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 640, 0, 0);
bufferSPR = create_bitmap(640, 640);
wallSPR = load_bitmap( "wall.bmp",0);
bizzleSPR = load_bitmap("bizzle.bmp",0);
int map = 1;
buildLevel(map);
//read in room
std::ifstream levelin;
levelin.open("save.txt");
if(!levelin.is_open())
{
return 0;
}
levelin.getline(levelload,10000);
levelin.close();
a=b=c=0;
while ( !key[KEY_ESC] ){
//move
if (key[KEY_UP]){
if(levelload[(y*100)-100]!='0'&&((y*100)-100)>=0){
y--;}
}
else if (key[KEY_DOWN]){
if(levelload[(y*100)+100]!='0'&&((y*100)+100)<=10000){
y++;}
}
else if (key[KEY_RIGHT]){
if(levelload[x+1]!='0'&&x+1<=10000){
x++;}
}
else if (key[KEY_LEFT]){
if(levelload[x-1]!='0'&&x-1>=0){
x--;}
}
//print room chunk to buffer
while(a<=400){
if(c==20){
b++;
c=0;
}
if(levelload[((b+y)*100)+(c+x)]=='0'){
draw_sprite(bufferSPR,wallSPR,c*32,b*32);
}
c++;
a++;}
a=b=c=0;
//draw bizzle
draw_sprite(bufferSPR,bizzleSPR,0,0);
//debug text
itoa(x,debugx,10);
itoa(y,debugy,10);
textprintf(bufferSPR,font,32,0,makecol(255,0,255),"%i",x);
textprintf(bufferSPR,font,32,10,makecol(255,0,255),"%i",y);
textprintf(bufferSPR,font,42,0,makecol(255,0,255),"%c",levelload[x+1]);
textprintf(bufferSPR,font,42,10,makecol(255,0,255),"%c",levelload[(y*100)+100]);
//draw buffer
blit(bufferSPR,screen,0,0,0,0,640,640);
rest(100);
clear(bufferSPR);
}
destroy_bitmap(bufferSPR);
return 0;
}
END_OF_MAIN();
|