void drawtank(int num)
{
int x = tanks[num].x;
int y = tanks[num].y;
int dir = tanks[num].dir;
//draw tank body and turret
rectfill(screen, x-11, y-11, x+11, y+11, tanks[num].color);
rectfill(screen, x-6, y-6, x+6, y+6, 7);
//draw the treads based on orientation
if (dir == 0 || dir == 2)
{
rectfill(screen, x-16, y-16, x-11, y+16, 8);
rectfill(screen, x+11, y-16, x+16, y+16, 8);
}
else
if (dir == 1 || dir == 3)
{
rectfill(screen, x-16, y-16, x+16, y-11, 8);
rectfill(screen, x-16, y+16, x+16, y+11, 8);
}
//draw the turret based on direction
switch (dir)
{
case 0:
rectfill(screen, x-1, y, x+1, y-16, 8);
break;
case 1:
rectfill(screen, x, y-1, x+16, y+1, 8);
break;
case 2:
rectfill(screen, x-1, y, x+1, y+16, 8);
break;
case 3:
rectfill(screen, x, y-1, x-16, y+1, 8);
break;
}
}
That is allegro 4 code. It draws a tank using filled rectangles only.
0: Move toward the northwest
1: Move toward the southwest
2: Move toward the northeast
3: Move toward the southeast
is this how directions work in allegro everytime..
context-: if (dir==0...and so on)
0 is north.
You've got to learn how to read code for yourself that's the true mark of a coder, being able to read someone else's code.
It has nothing to do with allegro, except that y decreases going up the screen.
EDIT
Welcome to allegro by the way.
If you use <code>code goes here</code> tags, you can highlight your code, and it will provide (outdated) links to the manual, like so :