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
|
#include <allegro.h>
#include "Asteroid.h"
#include "Ship.h"
#define DOWN_RIGHT 0
#define UP_RIGHT 1
#define DOWN_LEFT 2
#define UP_LEFT 3
ARock::ARock()
{
srand(time(NULL));
arock_x = rand() % 360 + 10;
arock_y = rand() % 200 + 20;
direction = rand() % 4;
Asteroid = load_bitmap("AsterRock.bmp",NULL);
}
ARock::~ARock()
{
destroy_bitmap(Asteroid);
}
void ARock::blitaster(BITMAP*buffer)
{
masked_blit(Asteroid,buffer,0,0,arock_x+400,arock_y+10, 800,600);
masked_blit(Asteroid,buffer,0,0,arock_x+96,arock_y+180, 800,600);
}
void ARock::asteroidmove()
{
switch(direction)
{
case DOWN_RIGHT:
++arock_x;
++arock_y;
break;
case UP_RIGHT:
++arock_x;
--arock_y;
break;
case DOWN_LEFT:
--arock_x;
++arock_y;
break;
case UP_LEFT:
--arock_x;
--arock_y;
break;
}
}
void ARock::asteroidcollide()
{
if(arock_y <= 30 || arock_y >= 560)
{
++direction;
}
else
{
--direction;
}
if(arock_x <= 0 || arock_x >= 560)
{
direction = (direction + 2) % 4;
}
}
|