delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/10/21:26:19

Message-ID: <387A90E0.85327532@sympatico.ca>
From: BRAD MURPHY <bjmurphy AT sympatico DOT ca>
X-Mailer: Mozilla 4.05 [en]C-SYMPA (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: PREVIOUS ? CODE!!
Lines: 185
Date: Tue, 11 Jan 2000 02:15:03 GMT
NNTP-Posting-Host: 206.172.197.185
X-Trace: news20.bellglobal.com 947556903 206.172.197.185 (Mon, 10 Jan 2000 21:15:03 EDT)
NNTP-Posting-Date: Mon, 10 Jan 2000 21:15:03 EDT
Organization: Sympatico
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

   Here is the source code that a couple of people e-mailed me and asked
for, but since this code is from the vivace tutorial, I would expect
that it is correct and that I am just doing something wrong when I
compile.  I include both the .c files with my project, and I add 'alleg'
in my libraries(Rhide).  Any help would be appreciated.  Some of the
many errors I get when trying to compile this are listed in the message
I wrote yesterday (Sunday).

///////////////////////051s.h//////////////////////////////
// Header for the Vivace example 51single
extern int end_game;
extern BITMAP *dblbuffer;

int  main (void);
void init(void);
void input(void);
void process(void);
void output(void);
void shutdown(void);
void show_double_buffer(void);
/////////////////////////////051sc.h//////////////////////////////////////////////////////////////////////////////////////////////////

// Header containing standard reusable functions to move a circle
typedef struct circle_t CIRCLE_T;

struct circle_t {
   int x,y,r;         // x, y, radius
   int col;           // colour
   int xs,ys;         // x speed, y speed
   int dx,dy;         // drawn x, drawn y
   };

CIRCLE_T *circle_init(int new_x, int new_y, int new_radius,
                      int new_col, int new_xs, int new_ys);
void circle_destroy (CIRCLE_T *circle);
void circle_draw (CIRCLE_T *circle, BITMAP *bmp);
void circle_update (CIRCLE_T *circle);
void circle_erase (CIRCLE_T *circle, BITMAP *bmp);
//////////////////051sc.c///////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <allegro.h>
#include "051sc.h"

CIRCLE_T *circle_init(int new_x, int new_y, int new_radius,
        int new_col, int new_xs, int new_ys)
    CIRCLE_T *temp;

    // Allocate memory for the circle. If unsuccessful, return NULL.
    temp = malloc(sizeof(CIRCLE_T));

    if (!temp)
 return NULL;
    temp->x = new_x;
    temp->y = new_y;
    temp->r = new_radius;
    temp->col = new_col;
    temp->xs = new_xs;
    temp->ys = new_ys;
    temp->dx = temp->dy = 0;
    return temp;
}

void circle_destroy(CIRCLE_T * circle)
{
    if (circle)
 free(circle);
}

void circle_draw(CIRCLE_T * circle, BITMAP * bmp)
{
    circlefill(bmp, circle->x, circle->y, circle->r, circle->col);
    circle->dx = circle->x;
    circle->dy = circle->y;
}

void circle_update(CIRCLE_T * circle)
{
    // First we update the position of the circle...
    circle->x += circle->xs;
    circle->y += circle->ys;
    // Now we see if it reached the maximum frame border
    if (circle->x > SCREEN_W - 5)
 circle->xs *= -1;

    if (circle->y > SCREEN_H - 5)
 circle->ys *= -1;
    if (circle->x < 5)
 circle->xs *= -1;
    if (circle->y < 5)
 circle->ys *= -1;
}

void circle_erase(CIRCLE_T * circle, BITMAP * bmp)
{
    circlefill(bmp, circle->dx, circle->dy, circle->r, 0);
}
///////////////////051s.c///////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <allegro.h>
#include "051s.h"
#include "051sc.h"

int end_game;   /* flag we'll set to end the game */
BITMAP *dblbuffer;
CIRCLE_T *moving_circle;

int main(void)
{
    allegro_init();  /* initialise the Allegro library */
    init();   /* initialise the game */
    end_game = 0;  /* reset flag */

    do {   /* loop */
 input();  /* get input */
 process();  /* process it */
 output();  /* give output */
    } while (end_game == 0); /* until the flag is set */

    shutdown();   /* shut down anything that needs it */
    allegro_exit();  /* just for luck */
    return 0;   /* tell the OS that all went well */
}
END_OF_MAIN()

void init(void)
{
    install_keyboard();

    if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) < 0) {
 printf("%s\n", allegro_error);
 exit(1);
    }
    dblbuffer = create_bitmap(SCREEN_W, SCREEN_H);
    if (dblbuffer == NULL) {
 allegro_exit();
 printf("Sorry, not enough memory");
 exit(2);
    }
    clear(dblbuffer);

    moving_circle = circle_init(SCREEN_W / 2, SCREEN_H / 2, 50, 3, 1,
0);
    if (moving_circle == NULL) {
 allegro_exit();
 printf("Sorry, not enough memory");
 exit(3);
    }
    circle_draw(moving_circle, dblbuffer);
    show_double_buffer();
}

void input(void)
{
    if (keypressed())
 end_game++;
}

void process(void)
{
    circle_update(moving_circle);
}

void output(void)
{
    circle_erase(moving_circle, dblbuffer);
    circle_draw(moving_circle, dblbuffer);

    show_double_buffer();
}

void shutdown(void)
{
    circle_destroy(moving_circle);
    destroy_bitmap(dblbuffer);
}

void show_double_buffer(void)
{
    vsync();
    blit(dblbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019