1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * |
---|
5 | * This software was released into the Public Domain. As with most public |
---|
6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
7 | * Jonathan Clark. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "config.h" |
---|
11 | |
---|
12 | #define PARTICLE_SIZE 2 // 2x2 block of pixels |
---|
13 | |
---|
14 | class particle |
---|
15 | { |
---|
16 | public : |
---|
17 | unsigned char *pict; |
---|
18 | int x,y; |
---|
19 | particle *left,*right,*up,*down; |
---|
20 | particle(int X, int Y, int size); |
---|
21 | ~particle() { free(pict); } |
---|
22 | } ; |
---|
23 | |
---|
24 | particle::particle(int X, int Y, image *im, int size); |
---|
25 | { |
---|
26 | x=X; y=Y; |
---|
27 | left=right=up=down=NULL; |
---|
28 | pict=(unsigned char *)malloc(size*size); |
---|
29 | } |
---|
30 | |
---|
31 | class particle_image |
---|
32 | { |
---|
33 | int particles; |
---|
34 | particle *top; |
---|
35 | int size; |
---|
36 | public : |
---|
37 | particle_image(image *im, int particle_size); // im will be erased! |
---|
38 | } ; |
---|
39 | |
---|
40 | |
---|
41 | particle_image::particle_image(image *im, int particle_size) |
---|
42 | { |
---|
43 | int x,y,py,p; |
---|
44 | unsigned char *sl,*sl2; |
---|
45 | top=NULL; |
---|
46 | size=particle_size; |
---|
47 | |
---|
48 | int matw=(im->width()+size-1)/size,math=(im->height()+size-1)/size; |
---|
49 | particle *matrix[matw*math]; |
---|
50 | |
---|
51 | |
---|
52 | // break the image up into particles and store in a big matrix |
---|
53 | for (y=0;y<im->height();y++) |
---|
54 | { |
---|
55 | sl=im->scan_line(y); |
---|
56 | py=y/size; |
---|
57 | for (x=0;x<im->width();x++,sl+=px) |
---|
58 | { |
---|
59 | px=x/size; |
---|
60 | sl2=matrix[py*matw+px]->pict+(y%size)*size; // address of particle image memory |
---|
61 | |
---|
62 | int copy_size; |
---|
63 | |
---|
64 | memset(sl2,0,size); |
---|
65 | |
---|
66 | if (*sl) |
---|
67 | { |
---|
68 | px=x/size; |
---|
69 | py=y/size; |
---|
70 | } |
---|
71 | |
---|
72 | } |
---|
73 | if (px<0) // couldn't find any non-blank pixels |
---|
74 | particles=0; |
---|
75 | else |
---|
76 | add_particle_line(px,py,im); |
---|
77 | } |
---|