home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 2
/
DATAFILE_PDCD2.iso
/
utilities
/
codemaker
/
CodeMaker
/
Exemples
/
!Exemple0
/
c
/
!RunImage
next >
Wrap
Text File
|
1992-12-19
|
5KB
|
159 lines
/*
CodeMaker !Exemple0 : Main
Frank Lyonnet 1992
You can contact me on internet : lyonnet@ufrima.imag.fr .
lyonnet@imag.fr .
on french RTEL : bal ARCHETYPE .
by mail : Frank Lyonnet
420 , Chemin de la Cassine
73000 Chambéry
France
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "bbc.h"
#include "kernel.h"
#include "MyUtils.h"
#include "ScreUtils.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 256
#define OFFSET1 0
#define OFFSET2 SCREEN_WIDTH*SCREEN_HEIGHT
#define MAX_SPEED 5
#define SPRITE_N_MAX 400
typedef struct SPRITE
{
int XCoords;
int YCoords;
int XSpeed;
int YSpeed;
int Width;
int Height;
void (*Display_routine)(int Adr);
} sprite;
static sprite Sprite[SPRITE_N_MAX];
static int SpriteNumber;
extern void display_bleu0(int Adr);
static void update_sprites()
{
int i;
for(i=0;i<SpriteNumber;i++)
{
Sprite[i].XCoords+=Sprite[i].XSpeed;
Sprite[i].YCoords+=Sprite[i].YSpeed;
if(Sprite[i].XCoords<0)
{
Sprite[i].XSpeed=-Sprite[i].XSpeed;
Sprite[i].XCoords=0;
};
if(Sprite[i].XCoords>SCREEN_WIDTH-Sprite[i].Width)
{
Sprite[i].XSpeed=-Sprite[i].XSpeed;
Sprite[i].XCoords=SCREEN_WIDTH-Sprite[i].Width;
};
if(Sprite[i].YCoords<Sprite[i].Height)
{
Sprite[i].YSpeed=-Sprite[i].YSpeed;
Sprite[i].YCoords=Sprite[i].Height;
};
if(Sprite[i].YCoords>=SCREEN_HEIGHT)
{
Sprite[i].YSpeed=-Sprite[i].YSpeed;
Sprite[i].YCoords=SCREEN_HEIGHT-1;
};
}
}
static void init_sprites()
{
int i;
for(i=0;i<SpriteNumber;i++)
{
Sprite[i].Width=29;
Sprite[i].Height=29;
Sprite[i].Display_routine=&display_bleu0;
Sprite[i].XCoords=(int)((double)rand()/(double)RAND_MAX*(double)(SCREEN_WIDTH-Sprite[i].Width));
Sprite[i].YCoords=(int)((double)rand()/(double)RAND_MAX*(double)(SCREEN_HEIGHT-Sprite[i].Height))+Sprite[i].Height;
Sprite[i].XSpeed=0;
while(Sprite[i].XSpeed==0)
Sprite[i].XSpeed=(int)((double)rand()/(double)RAND_MAX*(double)(MAX_SPEED+MAX_SPEED/2))-MAX_SPEED/2;
Sprite[i].YSpeed=0;
while(Sprite[i].YSpeed==0)
Sprite[i].YSpeed=(int)((double)rand()/(double)RAND_MAX*(double)(MAX_SPEED+MAX_SPEED/2))-MAX_SPEED/2;
};
}
int main()
{
int i,SAdr1,SAdr2;
bbc_mode(15);
bbc_mode(13);
bbc_vdu(23);
bbc_vdu(1);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
bbc_vdu(0);
set_screen(OFFSET1);
SAdr1=get_screen_adr();
set_screen(OFFSET2);
SAdr2=get_screen_adr();
srand((unsigned int)time(NULL));
if (is_ram8())
SpriteNumber=80;
else
SpriteNumber=130;
init_sprites();
cache_off();
while(mouse_buttons()==0)
{
set_screen(OFFSET1);
clear_screen13(SAdr2);
update_sprites();
for(i=0;i<SpriteNumber;i++)
(*Sprite[i].Display_routine)(SAdr2+SCREEN_WIDTH*SCREEN_HEIGHT-(Sprite[i].YCoords+1)*SCREEN_WIDTH+Sprite[i].XCoords);
_kernel_osbyte(19,0,0);
set_screen(OFFSET2);
clear_screen13(SAdr1);
update_sprites();
for(i=0;i<SpriteNumber;i++)
(*Sprite[i].Display_routine)(SAdr1+SCREEN_WIDTH*SCREEN_HEIGHT-(Sprite[i].YCoords+1)*SCREEN_WIDTH+Sprite[i].XCoords);
_kernel_osbyte(19,0,0);
};
cache_on();
}