Allegro problem

Here's the problem... I only want to move the box.. However, the box always lost, when the circle is trying to push the box....

Is there any problem here??

--------------------------------------------------------------------------------
#include <allegro.h>

BITMAP *area;
BITMAP *box;

int x = 9;
int y = 9;

int tempx;
int tempy;

int actionboard[20][20] = {{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, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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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, 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, 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}};


void board(){
area = create_bitmap(400, 400);
box = load_bitmap("box.bmp", NULL);

for (int i = 0; i < 20; i++){
for (int j = 0; j < 20; j++){
if (actionboard[i][j] == 0) {
rectfill (area, (20 * j), (20 * i), (20 * j) + 20, (20 * i) + 20, makecol(175, 60, 70));
}else if (actionboard[i][j] == 1){
rectfill (area, (20 * j), (20 * i), (20 * j) + 20, (20 * i) + 20, makecol(0, 0, 0));
}
}
}

for (int i = 0; i < 20; i++){
for (int j = 0; j < 20; j++){
if (actionmove[i][j] == 2){
circlefill (area, (20 * j) + 10, (20 * i) + 10, 10, makecol(255, 255, 255));
}else if (actionmove[i][j] == 3){
rect (area, (20 * j) - 1, (20 * i) - 1, (20 * j) + 21, (20 * i) + 21, makecol(0, 0, 0));
rectfill (area, (20 * j), (20 * i), (20 * j) + 20, (20 * i) + 20, makecol(175, 175, 255));
}else if (actionmove[i][j] == 4){
draw_sprite(area, box, (20 * j), (20 * i));
}
}
}

draw_sprite(screen, area, 120, 40);
}

void move(){
tempy = y;
tempx = x;

if (key[KEY_LEFT] && actionboard[y-1][x] == 0){
if (actionmove[y-1][x] != 4){
y--;
}
else if (actionmove[y-1][x] == 4 && actionboard[y-2][x] == 0){
actionmove[y-2][x] = 4;
draw_sprite (area, box, x * 20, (y - 2) * 20);
y--;
}
}
else if (key[KEY_RIGHT] && actionboard[y+1][x] == 0){
if (actionmove[y+1][x] != 4){
y++;
}
else if (actionmove[y+1][x] == 4 && actionboard[y+2][x] == 0){
actionmove[y+2][x] = 4;
draw_sprite (area, box, x * 20, (y + 2) * 20);
y++;
}
}
else if (key[KEY_UP] && actionboard[y][x-1] == 0){
if (actionmove[y][x-1] != 4){
x--;
}
else if (actionmove[y][x-1] == 4 && actionboard[y][x-2] == 0){
actionmove[y][x-2] = 4;
draw_sprite (area, box, (x - 2) * 20, y * 20);
x--;
}
}
else if (key[KEY_DOWN] && actionboard[y][x+1] == 0){
if (actionmove[y][x+1] != 4){
x++;
}
else if (actionmove[y][x+1] == 4 && actionboard[y][x+2] == 0){
actionmove[y][x+2] = 4;
draw_sprite (area, box, (x + 2) * 20, y * 20);
x++;
}
}
rectfill (area, (20 * tempy), (20 * tempx), (20 * tempy) + 20, (20 * tempx) + 20, makecol(175, 60, 70));
circlefill (area, (20 * y) + 10, (20 * x) + 10, 10, makecol(255, 255, 255));

actionmove[tempy][tempx] = 0;
actionmove[y][x] = 4;

draw_sprite (screen, area, 120, 40);

rest(100);
}
int main(){
allegro_init();
install_keyboard();

set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0);
clear_to_color(screen, makecol(175, 175, 255));

board();

do{
move();
} while (!key[KEY_ESC]);

readkey();

return 0;
}
END_OF_MAIN();
Try Allegro forum :)
I never liked allegro, have you considered using SDL instead?
K, I ll try allegro forum...
^_^...
I had a quick skim over your code if you ever come back lol - you need to keep redrawing your square on the screen after the circle touches it. Other wise chucks of it will fade away when you touch them as the square has only been displayed to the screen once.

So every time you move your ball you need to draw_sprite(your square) then draw_sprite(your ball) for your example.
Topic archived. No new replies allowed.