game.h
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
/**
*Include allegro and the std library
**/
#include <stdlib.h>
#include "allegro.h"
/**Sprite bitmap**/
BITMAP* ship;
BITMAP* enemy;
BITMAP* laser;
BITMAP* enemyLaser;
/**
*DEFINE SOME MAIN GAME CONSTANTS
**/
#define WIDTH 640
#define HEIGHT 480
#define LIVES 4
/**
*DEFINE SOME COLORS
**/
#define TAN makecol(255,242,169)
#define BURST makecol(255,189,73)
#define BLACK makecol(0,0,0)
#define WHITE makecol(255,255,255)
#define GRAY makecol(128,128,128)
#define GREEN makecol(0,255,0)
/**
*DEFINE SPRITE FILES WE NEED TO LOAD
**/
#define SHIP "ship.bmp"
/**
*Buffer
**/
BITMAP* buffer;
/**
*Define some variables
**/
int score = 0;//Players score
/**
*DEFINE A SPRITE STRUCTURE
**/
typedef struct SPRITE{
int dir;
int x,y;
int Xspeed,Yspeed;
}SPRITE;
SPRITE* Ship;
#endif // GAME_H_INCLUDED
main.cpp
#include "game.h"
/**
*Draw everything to the screen
**/
void draw(){
acquire_screen();
draw_sprite(screen,buffer,0,0);
draw_sprite(screen,ship,100,300);
release_screen();
rest(50);
}
/**
*Handles movement of our players ship
**/
void moveShip(){
if(key[KEY_RIGHT]){
--Ship->x;
}
}
/**
*SETUP OUR GAME
**/
void GameSetup(){
draw();
}
void Enemy_Handle(){}
int main()
{
//Initialize Allegro
allegro_init();
/**Set color depth to 32**/
set_color_depth(32);
//Set the resolution to 640 x 480 with SAFE autodetection.
set_gfx_mode(GFX_SAFE, WIDTH, HEIGHT, 0, 0);
//Install the keyboard handler
install_keyboard();
buffer = create_bitmap(WIDTH,HEIGHT);
ship = load_bitmap(SHIP,NULL);
GameSetup();
//Loop until escape is pressed
while(! key[KEY_ESC])
poll_keyboard();
moveShip();
return 0;
}
END_OF_MAIN();

Find content
Not Telling