source: abuse/trunk/src/smoosh.cpp @ 112

Last change on this file since 112 was 56, checked in by Sam Hocevar, 12 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 1.6 KB
Line 
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#include "jmalloc.hpp"
13#define PARTICLE_SIZE 2            // 2x2 block of pixels
14
15class particle
16{
17public :
18  unsigned char *pict;
19  int x,y;
20  particle *left,*right,*up,*down;
21  particle(int X, int Y, int size);
22  ~particle() { jfree(pict); }
23} ;
24
25particle::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 *)jmalloc(size*size,"Particle");
30}
31
32class particle_image
33{
34  int particles;
35  particle *top;
36  int size;
37public :
38  particle_image(image *im, int particle_size);       // im will be erased!
39} ;
40
41
42particle_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}
Note: See TracBrowser for help on using the repository browser.