Code:
#include <allegro.h>
#include <math.h>
#include <time.h>
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "alleg.lib")
#define MAPSIZE 30
#define GRID_WIDTH 15
#define GRID_HEIGHT 15
#define TILE_SIZE 32
#define MAX_BULLET 200
#define PLSPEED 6
#define GRAV 9.82
#define TILE_T 1
#define TILE_W 0
#define MAX_FUEL 100
float cx;
float cy;
int level[MAPSIZE][MAPSIZE]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0},
{0,1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
{0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
BITMAP*front[1];
BITMAP* player;
BITMAP *buffer;
BITMAP *skott1;
void drawMap( BITMAP *bmp );
volatile long speed_counter = 0;
void increment_speed_counter();
int pos(int x, int y)
{
return level[(y/TILE_SIZE)][(x/TILE_SIZE)%MAPSIZE];
}
float getangle(int musx,int musy,float xpos,float ypos)
{
float angle;
angle=atan2(ypos-musy,xpos-musx);
return angle;
}
int main()
{
allegro_init();
install_timer();
if(!install_mouse())
{
allegro_message( "error mouse\n % s\n" , allegro_error );
}
install_keyboard();
set_color_depth(16);
if( set_gfx_mode(GFX_AUTODETECT,480,480,0,0)<0)
{
allegro_message( "error gfx\n % s\n" , allegro_error );
if(set_gfx_mode(GFX_SAFE,480,480,0,0)<0)
{
allegro_message( "error gfxsafe\n % s\n" , allegro_error );
}
}
front[TILE_T]=load_bitmap("wall.bmp",0);
front[TILE_W]=load_bitmap("bg.bmp",0);
player=load_bitmap("pla.bmp",0);
buffer=create_bitmap(640,480);
float n=10.0;
float x=0;
float y=0;
float px=0;
float py=0;
float skottx;
float skotty;
float skottang;
float ang;
int fuel=MAX_FUEL;
int time=0;
time=clock();
int fired = 0;
px=240;
py=240;
while(!key[KEY_ESC])
{
(mouse_y>240)?(n++):n--;
ang=getangle(mouse_x,mouse_y,px,py);
//textprintf(screen,font,40,90,makecol(255,255,255),"%i",fuel);
//textprintf(screen,font,40,100,makecol(255,255,255),"%i",time);
if(mouse_b & 2&&mouse_y<py&&mouse_x<(px+50)&&mouse_x>(px-50)&&fuel>=0)
{
fuel--;
py-= PLSPEED *sin(ang);
}
if(fuel<=0)
{
time++;
if(time>120)
{
time=0;
fuel=MAX_FUEL;
}
}
if(mouse_b & 1&&!fired)
{
fired=1;
skottx=px;
skotty=py;
skottang = atan2(skotty - mouse_y , skottx - mouse_x);
}
if(fired)
{
skottx-=5 *cos(skottang);
skotty-=5 *sin(skottang);
if(pos((int)skottx,(int)skotty)==1) // or x see the difference?
fired=0;
}
if(pos(x,y+32)==0)
{
py++;
}
if(key[KEY_RIGHT]&&pos(x+31,y)==0)
{
cx+=4;
}
if(key[KEY_LEFT]&&pos(x-1,y)==0)
{
cx-=4;
}
textprintf(screen, font, 0, 0, 255, "X: %5d Y: %5d", mouse_x, (int)py);
x=cx +px;
y=cy +py;
putpixel(screen,mouse_x,mouse_y,700);
poll_mouse();
clear_bitmap(buffer);
drawMap( buffer );
if(fired)
{
circlefill(buffer,(int)skottx,(int)skotty,3,makecol(255,0,0));
}
draw_sprite(buffer,player,px,py);
show_mouse(screen);
blit(buffer,screen,0,0,0,0,640,480);
}
destroy_bitmap(front[0]);
destroy_bitmap(front[1]);
destroy_bitmap(buffer);
remove_mouse();
allegro_exit();
return 0;
}//main
END_OF_MAIN()
void drawMap( BITMAP *bmp )
{
for ( int i = 0; i < 30; i++ )
{
for ( int j = 0; j < 30; j++ )
{
int p =pos(i*TILE_SIZE+cx,j*TILE_SIZE+cy);
blit( front[p], buffer, 0, 0, ( i * 32 ) - ( (int)cx % 32 ), ( j * 32 ) - ( (int)cy % 32 ), 32, 32 );
}
}
}
and the pics are attached too