firework: add fw_purple

This commit is contained in:
Vince Weaver 2018-09-04 22:34:52 -04:00
parent 08b0ab894d
commit 648e8ac3b3
3 changed files with 251 additions and 74 deletions

View File

@ -6,7 +6,7 @@ SDL_LIBS= `sdl-config --libs`
SDL_INCLUDE= `sdl-config --cflags`
GR_SIM = ../gr-sim.a
all: fireworks lines image_load hgr_view
all: fireworks fw_purple lines image_load hgr_view
###
@ -40,8 +40,16 @@ fireworks: fireworks.o $(GR_SIM)
fireworks.o: fireworks.c
$(CC) $(CFLAGS) -c fireworks.c
###
fw_purple: fw_purple.o $(GR_SIM)
$(CC) $(LFLAGS) $(SDL_LIBS) -o fw_purple fw_purple.o $(GR_SIM)
fw_purple.o: fw_purple.c
$(CC) $(CFLAGS) -c fw_purple.c
####
clean:
rm -f *~ *.o fireworks lines image_load hgr_view
rm -f *~ *.o fireworks lines image_load hgr_view fw_purple

View File

@ -5,33 +5,31 @@
#include "gr-sim.h"
// Based on BASIC program posted by FozzTexx
// 100 REM Fireworks by FozzTexx, originally written in 1987
// Constants: BT/RT is screen size, MG is margin
//120 REM Variables:
//130 REM XV/YV are velocity, PK is highest point of rocket
// Based on BASIC program posted by FozzTexx, originally written in 1987
//140 REM MS is max steps, CS is current step, X/Y/X1/Y1/X2/Y2 is rocket position
//150 REM CL is Apple II hi-res color group
const int ysize=191,xsize=280,mg=24;
int cl;
int ms;
double x1,x2=0,ypos1,y2=0,cs,pk;
const int ysize=160,xsize=280,margin=24;
int color_group;
int max_steps;
double x_even_older,x_old=0,y_even_older,y_old=0,cs,peak;
double xpos,ypos,x_velocity,y_velocity;
double i,n;
void routine_370(void) {
hplot(xpos+x2+n,ypos+y2+n);
hplot(xpos+x2-n,ypos+y2-n);
hplot(xpos+x2+n,ypos+y2-n);
hplot(xpos+x2-n,ypos+y2+n);
hplot(xpos+x_old+n,ypos+y_old+n); // NE
hplot(xpos+x_old-n,ypos+y_old-n); // SW
hplot(xpos+x2,ypos+y2+(n*1.5));
hplot(xpos+x2+(n*1.5),ypos+y2);
hplot(xpos+x_old+n,ypos+y_old-n); // SE
hplot(xpos+x_old-n,ypos+y_old+n); // NW
hplot(xpos+x2,ypos+y2-(n*1.5));
hplot(xpos+x2-(n*1.5),ypos+y2);
hplot(xpos+x_old,ypos+y_old+(n*1.5)); // N
hplot(xpos+x_old+(n*1.5),ypos+y_old); // E
hplot(xpos+x_old,ypos+y_old-(n*1.5)); // S
hplot(xpos+x_old-(n*1.5),ypos+y_old); // W
}
@ -43,76 +41,78 @@ int main(int argc, char **argv) {
home();
// 160 HGR:POKE 49234,0:REM Poke hides 4 line text area
hgr();
//
soft_switch(MIXCLR); // Full screen
label_180:
cl=random()%2;
x_velocity=(random()%3)+1;
y_velocity=-((random()%5)+3);
color_group=random()%2; // HGR color group (PG or BO)
x_velocity=(random()%3)+1; // x velocity = 1..3
y_velocity=-((random()%5)+3); // y velocity = -3..-7
ms=(random()%25)+40;
xpos=(random()%(xsize-mg*2))+mg;
ypos=ysize;
pk=ypos;
max_steps=(random()%25)+40; // 40..64
xpos=(random()%(xsize-margin*2))+margin;
// margin .. xsize-margin
ypos=ysize; // start at ground
peak=ypos; // peak starts at ground?
/* Aim towards center of screen */
if (xpos>xsize/2) x_velocity=-x_velocity;
//210 REM Draw rocket
/* Draw rocket */
for(cs=1;cs<=max_steps;cs++) {
y_even_older=y_old;
y_old=ypos;
x_even_older=x_old;
x_old=xpos;
for(cs=1;cs<=ms;cs++) {
ypos1=y2;
y2=ypos;
x1=x2;
x2=xpos;
/* Move rocket */
xpos=xpos+x_velocity;
ypos=ypos+y_velocity;
y_velocity=y_velocity+0.12;
if (ypos<pk) pk=ypos;
/* adjust Y velocity, slow it down */
y_velocity=y_velocity+0.125;
/* if we went higher, adjust peak */
if (ypos<peak) peak=ypos;
/* check if out of bounds and stop moving */
if (xpos<=mg) {
cs=ms;
// printf("X too small!\n");
if (xpos<=margin) {
cs=max_steps; // too far left
}
if (xpos>=(xsize-mg)) {
cs=ms;
// printf("X too big!\n");
if (xpos>=(xsize-margin)) {
cs=max_steps; // too far right
}
if (ypos<=mg) {
cs=ms;
// printf("Y too small!\n");
if (ypos<=margin) {
cs=max_steps; // too far up
}
// if falling downward
if (y_velocity>0) {
if (ypos>=ysize-mg) {
cs=ms;
// printf("Y too big %d > %d\n",y,ysize-mg);
// if too close to ground, explode
if (ypos>=ysize-margin) {
cs=max_steps;
}
// if fallen a bit past peak, explode
if (ypos>ysize-(ysize-peak)/2) {
cs=max_steps;
}
if (ypos>ysize-(ysize-pk)/2) cs=ms;
}
// printf("cs=%d,ms=%d\n",cs,ms);
if (cs<ms) {
hcolor_equals(cl*4+3);
hplot(x2,y2);
// if not done, draw rocket
if (cs<max_steps) {
hcolor_equals(color_group*4+3);
hplot(x_old,y_old);
hplot_to(xpos,ypos);
// printf("C=%d, %d,%d to %d,%d... yv=%d\n",cl*4+3,
// x2,y2,x,y,y_velocity);
}
hcolor_equals(cl*4);
hplot(x1,ypos1);
hplot_to(x2,y2);
//
// printf("C=%d, %d,%d to %d,%d\n",cl*4,
// x1,ypos1,x2,y2);
// erase with proper color black
hcolor_equals(color_group*4);
hplot(x_even_older,y_even_older);
hplot_to(x_old,y_old);
grsim_update();
ch=grsim_input();
@ -123,21 +123,28 @@ label_180:
label_290:
//280 REM Draw explosion near X2,Y2
x2=floor(x2);
y2=floor(y2);
xpos=(random()%20)-10;
ypos=(random()%20)-10;
hcolor_equals(cl*4+3);
hplot(xpos+x2,ypos+y2);
/* Draw explosion near x_old, y_old */
x_old=floor(x_old);
y_old=floor(y_old);
xpos=(random()%20)-10; // x +/- 10
ypos=(random()%20)-10; // y +/- 10
hcolor_equals(color_group*4+3); // draw white (with fringes)
hplot(xpos+x_old,ypos+y_old); // draw at center of explosion
/* Spread the explosion */
for(i=1;i<=9;i++) {
/* Draw spreading dots in white */
if (i<9) {
n=i;
hcolor_equals(cl*4+3);
hcolor_equals(color_group*4+3);
routine_370();
}
/* erase old */
n=i-1;
hcolor_equals(cl*4);
hcolor_equals(color_group*4);
routine_370();
grsim_update();
@ -146,6 +153,7 @@ label_290:
usleep(100000);
}
/* randomly draw more explosions */
if (random()%2) goto label_290;
goto label_180;
@ -153,5 +161,3 @@ label_290:
return 0;
}

163
gr-sim/hgr/fw_purple.c Normal file
View File

@ -0,0 +1,163 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "gr-sim.h"
// Based on BASIC program posted by FozzTexx, originally written in 1987
//140 REM MS is max steps, CS is current step, X/Y/X1/Y1/X2/Y2 is rocket position
//150 REM CL is Apple II hi-res color group
const int ysize=160,xsize=280,margin=24;
int color_group;
int max_steps;
double x_even_older,x_old=0,y_even_older,y_old=0,cs,peak;
double xpos,ypos,x_velocity,y_velocity;
double i,n;
void routine_370(void) {
hplot(xpos+x_old+n,ypos+y_old+n); // NE
hplot(xpos+x_old-n,ypos+y_old-n); // SW
hplot(xpos+x_old+n,ypos+y_old-n); // SE
hplot(xpos+x_old-n,ypos+y_old+n); // NW
hplot(xpos+x_old,ypos+y_old+(n*1.5)); // N
hplot(xpos+x_old+(n*1.5),ypos+y_old); // E
hplot(xpos+x_old,ypos+y_old-(n*1.5)); // S
hplot(xpos+x_old-(n*1.5),ypos+y_old); // W
}
int main(int argc, char **argv) {
int ch;
grsim_init();
home();
hgr();
soft_switch(MIXCLR); // Full screen
label_180:
color_group=random()%2; // HGR color group (PG or BO)
x_velocity=(random()%3)+1; // x velocity = 1..3
y_velocity=-((random()%5)+3); // y velocity = -3..-7
max_steps=(random()%25)+40; // 40..64
xpos=(random()%(xsize-margin*2))+margin;
// margin .. xsize-margin
ypos=ysize; // start at ground
peak=ypos; // peak starts at ground?
/* Aim towards center of screen */
if (xpos>xsize/2) x_velocity=-x_velocity;
/* Draw rocket */
for(cs=1;cs<=max_steps;cs++) {
y_even_older=y_old;
y_old=ypos;
x_even_older=x_old;
x_old=xpos;
/* Move rocket */
xpos=xpos+x_velocity;
ypos=ypos+y_velocity;
/* adjust Y velocity, slow it down */
y_velocity=y_velocity+0.125;
/* if we went higher, adjust peak */
if (ypos<peak) peak=ypos;
/* check if out of bounds and stop moving */
if (xpos<=margin) {
cs=max_steps; // too far left
}
if (xpos>=(xsize-margin)) {
cs=max_steps; // too far right
}
if (ypos<=margin) {
cs=max_steps; // too far up
}
// if falling downward
if (y_velocity>0) {
// if too close to ground, explode
if (ypos>=ysize-margin) {
cs=max_steps;
}
// if fallen a bit past peak, explode
if (ypos>ysize-(ysize-peak)/2) {
cs=max_steps;
}
}
// if not done, draw rocket
if (cs<max_steps) {
hcolor_equals(color_group*4+3);
hplot(x_old,y_old);
hplot_to(xpos,ypos);
}
// erase with proper color black
hcolor_equals(color_group*4);
hplot(x_even_older,y_even_older);
hplot_to(x_old,y_old);
grsim_update();
ch=grsim_input();
if (ch=='q') exit(0);
usleep(100000);
}
label_290:
/* Draw explosion near x_old, y_old */
x_old=floor(x_old);
y_old=floor(y_old);
xpos=(random()%20)-10; // x +/- 10
ypos=(random()%20)-10; // y +/- 10
hcolor_equals(color_group*4+3); // draw white (with fringes)
hplot(xpos+x_old,ypos+y_old); // draw at center of explosion
/* Spread the explosion */
for(i=1;i<=9;i++) {
/* Draw spreading dots in white */
if (i<9) {
n=i;
hcolor_equals(color_group*4+3);
routine_370();
}
/* erase old */
n=i-1;
hcolor_equals(color_group*4);
routine_370();
grsim_update();
ch=grsim_input();
if (ch=='q') break;
usleep(100000);
}
/* randomly draw more explosions */
if (random()%2) goto label_290;
goto label_180;
return 0;
}