Mail Archives: djgpp/1997/08/05/14:56:57
Hi everyone!
I'm a newbie at Allegro but i have a little problem.
I have made a little program with 4 buttons and you
push them an a sprite moves on the screen. You control
the movement by using the four buttons. The problem is
that when i move around the sprite it leave line of itself
in strange places over the screen. For example when i move
it up suddenly a line from the sprite appears 20-30 pixels up...
I hope someone can help me.. This is the program, i apologize
if it's too long.
/* Test.c */
#include <stdio.h>
#include <stdlib.h>
#include <allegro.h>
#include "gui_dat.h"
DATAFILE *gui_data;
BITMAP *tmp_bmp;
PALETTE *norm_pal;
BITMAP *player;
BITMAP *back_player;
int player_x = 200;
int player_y = 200;
int step = 4;
void redraw_player(int p_direct);
int left_button_proc(int msg, DIALOG *d, int c);
int right_button_proc(int msg, DIALOG *d, int c);
int up_button_proc(int msg, DIALOG *d, int c);
int down_button_proc(int msg, DIALOG *d, int c);
DIALOG the_dialog[] =
{
/*(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags)
(d1) (d2) (dp) */
{ left_button_proc, 100, 100, 20, 20, 34, 75, 0, D_EXIT,
0, 0, "<" },
{ right_button_proc, 120, 100, 20, 20, 34, 75, 0, D_EXIT,
0, 0, ">" },
{ up_button_proc, 110, 80, 20, 20, 34, 75, 0, D_EXIT,
0, 0, "^" },
{ down_button_proc, 110, 120, 20, 20, 34, 75, 0, D_EXIT,
0, 0, "v" },
{ NULL, 0, 0, 0, 0, 34, 75, 0, 0,
0, 0, NULL}
};
void redraw_player(int p_direct)
{
if (p_direct != 0)
blit(back_player, screen, 0, 0, player_x, player_y, player->w, player->h);
if (p_direct == 8) player_y -= step;
if (p_direct == 2) player_y += step;
if (p_direct == 4) player_x -= step;
if (p_direct == 6) player_x += step;
blit(screen, back_player, player_x, player_y, 0, 0, player->w, player->h);
draw_sprite(screen, player, player_x, player_y);
}
int left_button_proc(int msg, DIALOG *d, int c)
{
int ret;
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
redraw_player(4);
return D_REDRAW;
}
return ret;
}
int right_button_proc(int msg, DIALOG *d, int c)
{
int ret;
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
redraw_player(6);
return D_REDRAW;
}
return ret;
}
int up_button_proc(int msg, DIALOG *d, int c)
{
int ret;
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
redraw_player(8);
return D_REDRAW;
}
return ret;
}
int down_button_proc(int msg, DIALOG *d, int c)
{
int ret;
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
redraw_player(2);
return D_REDRAW;
}
return ret;
}
int main()
{
allegro_init();
install_keyboard();
fade_out(3);
install_mouse();
install_timer();
gui_data = load_datafile("gui.dat");
norm_pal = (PALETTE *)gui_data[button_pal].dat;
player = (BITMAP *)gui_data[normal_button].dat;
back_player = create_bitmap(player->w, player->h);
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
set_pallete(*norm_pal);
tmp_bmp = (BITMAP *)gui_data[background].dat;
blit(tmp_bmp, screen, 0, 0, 0, 0, tmp_bmp->w, tmp_bmp->h);
redraw_player(0);
do_dialog(the_dialog, -1);
readkey();
return 0;
}
- Raw text -