00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025 #include "gfx.h"
00026
00027 extern u_char star[];
00028
00029 typedef struct {
00030 int x;
00031 int y;
00032 int z;
00033 int sx, sy;
00034 } star_t;
00035
00036 void star_randomize(star_t* st) {
00037 st->x = i2f((rand() & 63) - 32);
00038 st->y = i2f((rand() & 63) - 32);
00039 st->z = 64;
00040 }
00041
00042 void star_move(star_t* st) {
00043 int x, y, z;
00044 z = (st->z -= 2);
00045 x = f2i(divfx(st->x, z)) + 128;
00046 y = f2i(divfx(st->y, z)) + 96;
00047 if (z < 1 || x < 0 || x >= MODE2_WIDTH || y < 0 || y >= MODE2_HEIGHT) {
00048 star_randomize(st);
00049 z = st->z;
00050 x = f2i(divfx(st->x, z)) + 128;
00051 y = f2i(divfx(st->y, z)) + 96;
00052 }
00053 st->sx = x;
00054 st->sy = y;
00055 }
00056
00057 #define MAX_STARS 16
00058
00059 main() {
00060 u_char c;
00061 star_t *st, stars[MAX_STARS];
00062
00063 set_color(15, 1, 1);
00064
00065
00066 set_mode(mode_2);
00067
00068
00069 fill(MODE2_ATTR, 0xf1, MODE2_MAX);
00070
00071
00072 for (c=0; c < MAX_STARS; c++) {
00073 st = stars + c;
00074 star_randomize(st);
00075 st->z = (rand() & 63) << 2;
00076 }
00077
00078
00079
00080 set_sprite_mode(sprite_default);
00081 set_sprite_8(0, star);
00082
00083
00084 while (!get_trigger(0)) {
00085
00086 for (st=stars, c=0; c < MAX_STARS; c++, st++)
00087 star_move(st);
00088
00089
00090 for (st=stars, c=0; c < MAX_STARS; c++, st++)
00091 put_sprite_8(c, st->sx, st->sy, 0, 15);
00092 }
00093
00094 set_mode(mode_0);
00095 }
00096
00097 #asm
00098
00099 psect data
00100
00101 global _star
00102 _star:
00103 defb 128, 0, 0, 0, 0, 0, 0, 0
00104 defb 0, 0, 0, 0, 0, 0, 0, 0
00105 defb 0, 0, 0, 0, 0, 0, 0, 0
00106 defb 0, 0, 0, 0, 0, 0, 0, 0
00107 #endasm