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