Mail Archives: djgpp/1999/09/19/04:54:31
From: | chris_mears AT softhome DOT net (Chris Mears)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Allegro & GDB
|
Organization: | CHOAM
|
Message-ID: | <37e98883.7765166@wingate>
|
X-Newsreader: | Forte Agent 1.5/32.452
|
MIME-Version: | 1.0
|
Lines: | 151
|
NNTP-Posting-Host: | slmel67p09.ozemail.com.au
|
X-Trace: | ozemail.com.au 937724729 203.108.11.137 (Sun, 19 Sep 1999 17:05:29 EST)
|
NNTP-Posting-Date: | Sun, 19 Sep 1999 17:05:29 EST
|
Distribution: | world
|
Date: | Sun, 19 Sep 1999 07:05:34 GMT
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hi all,
In the middle of the night, I had the idea to write a bouncy-ball
program in Allegro. I did, and it seems to work pretty well.
However, when I run it under the debugger, GDB, the ball is not drawn
at all. I can't figure it out.
Does anyone know what's going on?
Thanks,
Chris
<file starts here>
/*
* Bouncy Ball.
* (Allegro)
*/
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#define MAX_SPEED 4
#define BALL_SIZE 25
#define SCREEN_X 640
#define SCREEN_Y 480
#define COLOR_DEPTH 16
struct ball
{
int x;
int y;
int xSpeed;
int ySpeed;
int width;
int height;
BITMAP* pic;
BITMAP* buffer;
};
void init_ball(struct ball* b);
void move_ball(struct ball* b);
void draw_ball(struct ball* b, BITMAP* bmp);
void erase_ball(struct ball* b, BITMAP* bmp);
int main(void)
{
struct ball b;
BITMAP* vscreen;
allegro_init();
install_keyboard();
install_timer();
printf("Loading graphics mode...\n");
printf("Attempting to use resolution %dx%d\n", SCREEN_X, SCREEN_Y);
set_color_depth(COLOR_DEPTH);
if (set_gfx_mode(GFX_AUTODETECT, SCREEN_X, SCREEN_Y, 0, 0) < 0)
{
printf("Graphics mode could not be initialised...\n");
printf("Allegro says: %s\n", allegro_error);
abort();
}
init_ball(&b);
vscreen = create_bitmap(SCREEN_W, SCREEN_H);
if (vscreen == NULL)
{
abort();
}
clear(vscreen);
while (!keypressed())
{
move_ball(&b);
draw_ball(&b, vscreen);
blit(vscreen, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
erase_ball(&b, vscreen);
}
clear_keybuf();
return 0;
}
void init_ball(struct ball* b)
{
b->x = rand() % (SCREEN_W - b->width);
b->y = rand() % (SCREEN_H - b->height);
b->xSpeed = (rand() % MAX_SPEED) + 1;
b->ySpeed = (rand() % MAX_SPEED) + 1;
b->pic = create_bitmap(BALL_SIZE, BALL_SIZE);
if (COLOR_DEPTH == 8)
clear_to_color(b->pic, MASK_COLOR_8);
else if (COLOR_DEPTH == 16)
clear_to_color(b->pic, MASK_COLOR_16);
else
clear(b->pic);
circlefill(b->pic, BALL_SIZE / 2 + 1, BALL_SIZE / 2 + 1, BALL_SIZE
/ 2,
makecol(255, 255, 255));
b->buffer = create_bitmap(BALL_SIZE, BALL_SIZE);
clear(b->buffer); /* Redundant. */
b->width = BALL_SIZE;
b->height = BALL_SIZE;
}
void move_ball(struct ball* b)
{
if ((b->x + b->width + b->xSpeed) > SCREEN_W)
b->xSpeed = -((rand() % MAX_SPEED) + 1);
if ((b->y + b->height + b->ySpeed) > SCREEN_H)
b->ySpeed = -((rand() % MAX_SPEED) + 1);
if ((b->x + b->xSpeed) < 0)
b->xSpeed = (rand() % MAX_SPEED) + 1;
if ((b->y + b->ySpeed) < 0)
b->ySpeed = (rand() % MAX_SPEED) + 1;
b->x += b->xSpeed;
b->y += b->ySpeed;
}
void draw_ball(struct ball* b, BITMAP* bmp)
{
blit(bmp, b->buffer, b->x, b->y, 0, 0, b->width, b->height);
masked_blit(b->pic, bmp, 0, 0, b->x, b->y, b->width, b->height);
}
void erase_ball(struct ball* b, BITMAP* bmp)
{
blit(b->buffer, bmp, 0, 0, b->x, b->y, b->width, b->height);
}
<file ends here>
- Raw text -