diff options
author | Ian C <ianc@noddybox.co.uk> | 2018-11-01 12:44:48 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2018-11-01 12:44:48 +0000 |
commit | 82896a389cdd43984a4f1cb73d7a262ad60f26be (patch) | |
tree | dc824381fc64c71b9148d3a0939061065b93b2c8 /xd.c | |
parent | 9ce31abc265f7fc87b7ee4a5c727110328ab3c44 (diff) |
Added firework demo.
Diffstat (limited to 'xd.c')
-rw-r--r-- | xd.c | 132 |
1 files changed, 131 insertions, 1 deletions
@@ -175,10 +175,11 @@ static void GravityDemo(void); static void SnowDemo(void); static void RoadDemo(void); static void CoasterDemo(void); +static void FireworkDemo(void); /* ---------------------------------------- GLOBAL VARS */ -#define NO_DEMOS 21 +#define NO_DEMOS 22 static int demo=NO_DEMOS-1; @@ -291,6 +292,11 @@ static DemoInfo demotbl[NO_DEMOS]= CoasterDemo, UsesPixmap }, + { + "Firework Demo", + FireworkDemo, + UsesPixmap + }, }; /* ---------------------------------------- X11 VARS @@ -4917,4 +4923,128 @@ static void CoasterDemo(void) #undef COASTER_POLE +/* ---------------------------------------- FIREWORK DEMO + */ + +#define MAX_FIREWORKS 10 +#define FIREWORK_SPARKS 100 +#define FIREWORK_COL 4 +#define DY_ADJ 0.008 + +static void FireworkDemo(void) +{ + static int init = FALSE; + + typedef struct + { + double x,y; + double dx,dy; + int life; + } Spark; + + typedef struct + { + int alive; + double x,y; + double dx,dy; + int life; + Spark spark[FIREWORK_SPARKS]; + } Firework; + + static Firework firework[MAX_FIREWORKS]; + static int colour[FIREWORK_COL]; + + int f,r; + + if (!init) + { + init=TRUE; + + colour[0] = white; + colour[1] = GetCol(255, 128, 128); + colour[2] = GetCol(128, 255, 128); + colour[3] = GetCol(128, 128, 255); + } + + Cls(); + + if (RND(100) > 95) + { + for(f = 0; f < MAX_FIREWORKS && firework[f].alive; f++) + { + } + + if (f < MAX_FIREWORKS) + { + firework[f].alive = TRUE; + firework[f].life = RND2(200, 100); + firework[f].y = height; + firework[f].x = RND2(width - 100, 100); + firework[f].dx = (RND(200) / 100.0) - 1.0; + firework[f].dy = -(RND(300) / 100.0); + } + } + + for(f = 0; f < MAX_FIREWORKS; f++) + { + if (firework[f].alive) + { + if (firework[f].life > 0) + { + firework[f].x += firework[f].dx; + firework[f].y += firework[f].dy; + firework[f].dy += DY_ADJ; + firework[f].life--; + + FCircle(firework[f].x, firework[f].y, 2, + colour[RND(FIREWORK_COL)]); + + if (firework[f].life == 0) + { + for(r = 0; r < FIREWORK_SPARKS; r++) + { + firework[f].spark[r].life = RND2(200, 150); + firework[f].spark[r].x = firework[f].x; + firework[f].spark[r].y = firework[f].y; + firework[f].spark[r].dx = (RND(300) / 100.0) - 1.5; + firework[f].spark[r].dy = (RND(300) / 100.0) - 1.5; + } + } + } + else + { + int all_dead = TRUE; + + for(r = 0; r < FIREWORK_SPARKS; r++) + { + if (firework[f].spark[r].life > 0) + { + all_dead = FALSE; + + firework[f].spark[r].x += firework[f].spark[r].dx; + firework[f].spark[r].y += firework[f].spark[r].dy; + firework[f].spark[r].dy += DY_ADJ; + firework[f].spark[r].life--; + + Plot(firework[f].spark[r].x, + firework[f].spark[r].y, + colour[RND(FIREWORK_COL)]); + } + } + + if (all_dead) + { + firework[f].alive = FALSE; + } + } + } + } +} + +#undef MAX_FIREWORKS +#undef FIREWORK_SPARKS +#undef FIREWORK_COL +#undef DY_ADJ + + /* END OF FILE */ |