More rearrangement, particle drawing in own function

This commit is contained in:
Simon 2010-08-26 14:46:56 +01:00
parent f426ee42e7
commit bb88587d9d
11 changed files with 3475 additions and 3396 deletions

141
air.c Normal file
View File

@ -0,0 +1,141 @@
#include <math.h>
#include "air.h"
#include "powder.h"
#include "defines.h"
float kernel[9];
float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL];
float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL];
float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL];
float cb_vx[YRES/CELL][XRES/CELL], cb_ovx[YRES/CELL][XRES/CELL];
float cb_vy[YRES/CELL][XRES/CELL], cb_ovy[YRES/CELL][XRES/CELL];
float cb_pv[YRES/CELL][XRES/CELL], cb_opv[YRES/CELL][XRES/CELL];
float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL];
void make_kernel(void)
{
int i, j;
float s = 0.0f;
for(j=-1; j<2; j++)
for(i=-1; i<2; i++)
{
kernel[(i+1)+3*(j+1)] = expf(-2.0f*(i*i+j*j));
s += kernel[(i+1)+3*(j+1)];
}
s = 1.0f / s;
for(j=-1; j<2; j++)
for(i=-1; i<2; i++)
kernel[(i+1)+3*(j+1)] *= s;
}
void update_air(void)
{
int x, y, i, j;
float dp, dx, dy, f, tx, ty;
for(y=1; y<YRES/CELL; y++)
for(x=1; x<XRES/CELL; x++)
{
dp = 0.0f;
dp += vx[y][x-1] - vx[y][x];
dp += vy[y-1][x] - vy[y][x];
pv[y][x] *= PLOSS;
pv[y][x] += dp*TSTEPP;
}
for(y=0; y<YRES/CELL-1; y++)
for(x=0; x<XRES/CELL-1; x++)
{
dx = dy = 0.0f;
dx += pv[y][x] - pv[y][x+1];
dy += pv[y][x] - pv[y+1][x];
vx[y][x] *= VLOSS;
vy[y][x] *= VLOSS;
vx[y][x] += dx*TSTEPV;
vy[y][x] += dy*TSTEPV;
if(bmap[y][x]==1 || bmap[y][x+1]==1 ||
bmap[y][x]==8 || bmap[y][x+1]==8 ||
(bmap[y][x]==7 && !emap[y][x]) ||
(bmap[y][x+1]==7 && !emap[y][x+1]))
vx[y][x] = 0;
if(bmap[y][x]==1 || bmap[y+1][x]==1 ||
bmap[y][x]==8 || bmap[y+1][x]==8 ||
(bmap[y][x]==7 && !emap[y][x]) ||
(bmap[y+1][x]==7 && !emap[y+1][x]))
vy[y][x] = 0;
}
for(y=0; y<YRES/CELL; y++)
for(x=0; x<XRES/CELL; x++)
{
dx = 0.0f;
dy = 0.0f;
dp = 0.0f;
for(j=-1; j<2; j++)
for(i=-1; i<2; i++)
if(y+j>0 && y+j<YRES/CELL-1 &&
x+i>0 && x+i<XRES/CELL-1 &&
bmap[y+j][x+i]!=1 &&
bmap[y+j][x+i]!=8 &&
(bmap[y+j][x+i]!=7 || emap[y+j][x+i]))
{
f = kernel[i+1+(j+1)*3];
dx += vx[y+j][x+i]*f;
dy += vy[y+j][x+i]*f;
dp += pv[y+j][x+i]*f;
}
else
{
f = kernel[i+1+(j+1)*3];
dx += vx[y][x]*f;
dy += vy[y][x]*f;
dp += pv[y][x]*f;
}
tx = x - dx*0.7f;
ty = y - dy*0.7f;
i = (int)tx;
j = (int)ty;
tx -= i;
ty -= j;
if(i>=2 && i<XRES/CELL-3 &&
j>=2 && j<YRES/CELL-3)
{
dx *= 1.0f - VADV;
dy *= 1.0f - VADV;
dx += VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
dy += VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
dx += VADV*tx*(1.0f-ty)*vx[j][i+1];
dy += VADV*tx*(1.0f-ty)*vy[j][i+1];
dx += VADV*(1.0f-tx)*ty*vx[j+1][i];
dy += VADV*(1.0f-tx)*ty*vy[j+1][i];
dx += VADV*tx*ty*vx[j+1][i+1];
dy += VADV*tx*ty*vy[j+1][i+1];
}
if(bmap[y][x] == 4)
{
dx += fvx[y][x];
dy += fvy[y][x];
}
if(dp > 256.0f) dp = 256.0f;
if(dp < -256.0f) dp = -256.0f;
if(dx > 256.0f) dx = 256.0f;
if(dx < -256.0f) dx = -256.0f;
if(dy > 256.0f) dy = 256.0f;
if(dy < -256.0f) dy = -256.0f;
ovx[y][x] = dx;
ovy[y][x] = dy;
opv[y][x] = dp;
}
memcpy(vx, ovx, sizeof(vx));
memcpy(vy, ovy, sizeof(vy));
memcpy(pv, opv, sizeof(pv));
}

21
air.h
View File

@ -1,14 +1,21 @@
#ifndef AIR_H #ifndef AIR_H
#define AIR_H #define AIR_H
#include "defines.h"
float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL]; extern float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL];
float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL]; extern float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL];
float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL]; extern float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL];
float cb_vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL]; extern float cb_vx[YRES/CELL][XRES/CELL], cb_ovx[YRES/CELL][XRES/CELL];
float cb_vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL]; extern float cb_vy[YRES/CELL][XRES/CELL], cb_ovy[YRES/CELL][XRES/CELL];
float cb_pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL]; extern float cb_pv[YRES/CELL][XRES/CELL], cb_opv[YRES/CELL][XRES/CELL];
float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL]; extern float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL];
extern float kernel[9];
void make_kernel(void);
void update_air(void);
#endif #endif

View File

@ -28,4 +28,12 @@ static unsigned char ZSIZE = ZSIZE_D;
typedef unsigned char uint8; typedef unsigned char uint8;
extern int legacy_enable;
extern int sys_pause;
extern int framerender;
extern int mousex, mousey;
extern int death;
#endif #endif

View File

@ -1,16 +1,21 @@
#include <math.h>
#include <SDL/SDL.h>
#include "defines.h" #include "defines.h"
#include "air.h" #include "air.h"
#include "powder.h" #include "powder.h"
#include "graphics.h" #include "graphics.h"
#include "font.h" #include "font.h"
#include "misc.h" #include "misc.h"
#include <math.h>
#include <SDL/SDL.h>
unsigned cmode = 3; unsigned cmode = 3;
SDL_Surface *sdl_scrn; SDL_Surface *sdl_scrn;
int sdl_scale = 1; int sdl_scale = 1;
unsigned char fire_r[YRES/CELL][XRES/CELL];
unsigned char fire_g[YRES/CELL][XRES/CELL];
unsigned char fire_b[YRES/CELL][XRES/CELL];
pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f) pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f)
{ {
int i,j,x,y,w,h,r,g,b,c; int i,j,x,y,w,h,r,g,b,c;
@ -1095,4 +1100,673 @@ void xor_rect(pixel *vid, int x, int y, int w, int h)
xor_pixel(x, y+i, vid); xor_pixel(x, y+i, vid);
xor_pixel(x+w-1, y+i, vid); xor_pixel(x+w-1, y+i, vid);
} }
}
void draw_parts(pixel *vid)
{
int i, j, x, y, t, nx, ny, r, a, cr,cg,cb, s, rt, fe, nt, lpv, nearp, pavg;
float mv, dx, dy, ix, iy, lx, ly, d, pp;
float pt = R_TEMP;
for(i = 0; i<NPART; i++){
t = parts[i].type;
nx = (int)(parts[i].x+0.5f);
ny = (int)(parts[i].y+0.5f);
if(cmode!=CM_HEAT)
{
if(t==PT_STKM) //Just draw head here
{
char buff[10]; //Buffer for HP
if(mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head
{
sprintf(buff, "%3d", (int)parts[i].life); //Show HP
drawtext(vid, mousex-8-2*(parts[i].life<100)-2*(parts[i].life<10), mousey-12, buff, 255, 255, 255, 255);
}
for(r=-2; r<=1; r++) //Here I use r variable not as I should, but I think you will excuse me :-p
{
s = XRES+BARSIZE;
vid[(ny-2)*s+nx+r] = ptypes[(int)player[2]].pcolors;
vid[(ny+2)*s+nx+r+1] = ptypes[(int)player[2]].pcolors;
vid[(ny+r+1)*s+nx-2] = ptypes[(int)player[2]].pcolors;
vid[(ny+r)*s+nx+2] = ptypes[(int)player[2]].pcolors;
}
draw_line(vid , nx, ny+3, player[3], player[4], 255, 255, 255, s);
draw_line(vid , player[3], player[4], player[7], player[8], 255, 255, 255, s);
draw_line(vid , nx, ny+3, player[11], player[12], 255, 255, 255, s);
draw_line(vid , player[11], player[12], player[15], player[16], 255, 255, 255, s);
isplayer = 1; //It's a secret. Tssss...
}
if(t==PT_MWAX&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,224,224,170,255);
else if (abs(y) != 0 && abs(x) != 0)
blendpixel(vid,x+nx,y+ny,224,224,170,20);
else
blendpixel(vid,x+nx,y+ny,224,224,170,40);
}
}
}
else if(t==PT_ACID)
{
if(parts[i].life>255) parts[i].life = 255;
if(parts[i].life<47) parts[i].life = 48;
s = (255/((parts[i].life-46)*28));
if(s==0) s = 1;
cr = PIXR(ptypes[t].pcolors)/s;
cg = PIXG(ptypes[t].pcolors)/s;
cb = PIXB(ptypes[t].pcolors)/s;
if(cmode==6){
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,cr,cg,cb,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,cr,cg,cb,40);
}
}
} else {
blendpixel(vid, nx, ny, cr, cg, cb, 255);
}
if(cmode==4)
{
blendpixel(vid, nx+1, ny, cr, cg, cb, 223);
blendpixel(vid, nx-1, ny, cr, cg, cb, 223);
blendpixel(vid, nx, ny+1, cr, cg, cb, 223);
blendpixel(vid, nx, ny-1, cr, cg, cb, 223);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 112);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 112);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 112);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 112);
}
}
else if(t==PT_OILL&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,64,64,16,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,64,64,16,40);
}
}
}
else if(t==PT_NEUT)
{
if(cmode == 3||cmode==4 || cmode==6)
{
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
cg = 8;
cb = 12;
x = nx/CELL;
y = ny/CELL;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
}
else
{
cr = 0x20;
cg = 0xE0;
cb = 0xFF;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
} else if(t==PT_PLUT&&cmode == 6)
{
int tempx;
int tempy;
cr = 0x40;
cg = 0x70;
cb = 0x20;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
for(tempx = 2; tempx < 10; tempx++) {
for(tempy = 2; tempy < 10; tempy++) {
blendpixel(vid, nx+tempx, ny-tempy, cr, cg, cb, 5);
blendpixel(vid, nx-tempx, ny+tempy, cr, cg, cb, 5);
blendpixel(vid, nx+tempx, ny+tempy, cr, cg, cb, 5);
blendpixel(vid, nx-tempx, ny-tempy, cr, cg, cb, 5);
}
}
} else if(t==PT_URAN&&cmode == 6)
{
int tempx;
int tempy;
cr = 0x70;
cg = 0x70;
cb = 0x20;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
for(tempx = 2; tempx < 10; tempx++) {
for(tempy = 2; tempy < 10; tempy++) {
blendpixel(vid, nx+tempx, ny-tempy, cr, cg, cb, 5);
blendpixel(vid, nx-tempx, ny+tempy, cr, cg, cb, 5);
blendpixel(vid, nx+tempx, ny+tempy, cr, cg, cb, 5);
blendpixel(vid, nx-tempx, ny-tempy, cr, cg, cb, 5);
}
}
} else if(t==PT_SLTW&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,64,80,240,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,64,80,240,50);
}
}
}
else if(t==PT_PHOT)
{
if(cmode == 3||cmode==4 || cmode==6)
{
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
cg = 12;
cb = 12;
cr = 12;
x = nx/CELL;
y = ny/CELL;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
}
else
{
cr = 0xFF;
cg = 0xFF;
cb = 0xFF;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
}
else if(t==PT_SWCH && parts[i].life == 10)
{
x = nx;
y = ny;
blendpixel(vid,x,y,17,217,24,255);
}
else if(t==PT_LNTG&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,128,160,223,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,128,160,223,50);
}
}
}
else if(t==PT_SMKE)
{
if(cmode == 3||cmode==4 || cmode==6)
{
x = nx/CELL;
y = ny/CELL;
cg = 10;
cb = 10;
cr = 10;
cg += fire_g[y][x];
if(cg > 50) cg = 50;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 50) cb = 50;
fire_b[y][x] = cb;
cr += fire_r[y][x];
if(cr > 50) cr = 50;
fire_r[y][x] = cr;
}
else
{
for(x=-3; x<4; x++)
{
for(y=-3; y<4; y++)
{
if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2))
blendpixel(vid,x+nx,y+ny,100,100,100,30);
if(abs(x)+abs(y) <=3 && abs(x)+abs(y))
blendpixel(vid,x+nx,y+ny,100,100,100,10);
if (abs(x)+abs(y) == 2)
blendpixel(vid,x+nx,y+ny,100,100,100,20);
}
}
}
}
else if(t==PT_WATR&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,32,48,208,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,32,48,208,50);
}
}
} else if(t==PT_DSTW&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,32,48,208,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,32,48,208,50);
}
}
}
else if(t==PT_NITR&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,32,224,16,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,32,224,16,50);
}
}
}
else if(t==PT_LRBD&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,170,170,170,100);
else if (abs(y) != 0 || abs(x) != 0)
blendpixel(vid,x+nx,y+ny,170,170,170,50);
}
}
}
else if(t==PT_NBLE&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,235,73,23,100);
else if (abs(y) != 0 && abs(x) != 0)
blendpixel(vid,x+nx,y+ny,235,73,23,30);
else
blendpixel(vid,x+nx,y+ny,235,73,23,50);
}
}
}
else if(t==PT_GASS&&cmode == 6)
{
for(x=-1; x<=1; x++)
{
for(y=-1; y<=1; y++)
{
if ((abs(x) == 0) && (abs(y) == 0))
blendpixel(vid,x+nx,y+ny,255,255,0,180);
else if (abs(y) != 0 && abs(x) != 0)
blendpixel(vid,x+nx,y+ny,255,255,0,50);
else
blendpixel(vid,x+nx,y+ny,255,255,0,80);
}
}
}
else if(t==PT_WTRV)
{
if(cmode == 3||cmode==4 || cmode==6)
{
x = nx/CELL;
y = ny/CELL;
cg = PIXG(ptypes[t].pcolors)/3;
cb = PIXB(ptypes[t].pcolors)/3;
cr = PIXR(ptypes[t].pcolors)/3;
cg += fire_g[y][x];
if(cg > PIXG(ptypes[t].pcolors)/2) cg = PIXG(ptypes[t].pcolors)/2;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > PIXB(ptypes[t].pcolors)/2) cb = PIXB(ptypes[t].pcolors)/2;
fire_b[y][x] = cb;
cr += fire_r[y][x];
if(cr > PIXR(ptypes[t].pcolors)/2) cr = PIXR(ptypes[t].pcolors)/2;
fire_r[y][x] = cr;
}
else
{
for(x=-3; x<4; x++)
{
for(y=-3; y<4; y++)
{
if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2))
blendpixel(vid,x+nx,y+ny, PIXR(ptypes[t].pcolors)/1.6, PIXG(ptypes[t].pcolors)/1.6, PIXB(ptypes[t].pcolors)/1.6, 30);
if(abs(x)+abs(y) <=3 && abs(x)+abs(y))
blendpixel(vid,x+nx,y+ny, PIXR(ptypes[t].pcolors)/1.6, PIXG(ptypes[t].pcolors)/1.6, PIXB(ptypes[t].pcolors)/1.6, 10);
if (abs(x)+abs(y) == 2)
blendpixel(vid,x+nx,y+ny, PIXR(ptypes[t].pcolors)/1.6, PIXG(ptypes[t].pcolors)/1.6, PIXB(ptypes[t].pcolors)/1.6, 20);
}
}
}
}
else if(t==PT_THDR)
{
if(cmode == 3||cmode==4 || cmode==6)
{
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
cg = 16;
cb = 20;
cr = 12;
x = nx/CELL;
y = ny/CELL;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
}
else
{
cr = 0xFF;
cg = 0xFF;
cb = 0xA0;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
}
else if(t==PT_LCRY)
{
if(cmode == 3||cmode==4 || cmode==6)
{
//cr = R/8;
//cg = G/8;
//cb = B/8;
vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(0x50+(parts[i].life*10), 0x50+(parts[i].life*10), 0x50+(parts[i].life*10));
//x = nx/CELL;
//y = ny/CELL;
//cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg;
//cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb;
//cr += fire_r[y][x]; if(cr > 255) cr = 255; fire_r[y][x] = cr;
}
else
{
cr = 0x50+(parts[i].life*10);
cg = 0x50+(parts[i].life*10);
cb = 0x50+(parts[i].life*10);
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
} else if(t==PT_PLSM)
{
float ttemp = parts[i].life;
int caddress = restrict_flt(restrict_flt(ttemp, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
uint8 R = plasma_data[caddress];
uint8 G = plasma_data[caddress+1];
uint8 B = plasma_data[caddress+2];
if(cmode == 3||cmode==4 || cmode==6)
{
cr = R/8;
cg = G/8;
cb = B/8;
x = nx/CELL;
y = ny/CELL;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
}
else
{
cr = R;
cg = G;
cb = B;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
}
else if(t==PT_FIRE && parts[i].life)
{
if(cmode == 3||cmode==4 || cmode==6)
{
cr = parts[i].life / 4;
cg = parts[i].life / 16;
cb = parts[i].life / 32;
if(cr>255) cr = 255;
if(cg>192) cg = 212;
if(cb>128) cb = 192;
x = nx/CELL;
y = ny/CELL;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
}
else
{
cr = parts[i].life * 8;
cg = parts[i].life * 2;
cb = parts[i].life;
if(cr>255) cr = 255;
if(cg>192) cg = 212;
if(cb>128) cb = 192;
blendpixel(vid, nx, ny, cr, cg, cb, 255);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
blendpixel(vid, nx, ny+1, cr, cg, cb, 96);
blendpixel(vid, nx, ny-1, cr, cg, cb, 96);
blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
}
else if(t==PT_LAVA && parts[i].life)
{
cr = parts[i].life * 2 + 0xE0;
cg = parts[i].life * 1 + 0x50;
cb = parts[i].life/2 + 0x10;
if(cr>255) cr = 255;
if(cg>192) cg = 192;
if(cb>128) cb = 128;
blendpixel(vid, nx, ny, cr, cg, cb, 255);
blendpixel(vid, nx+1, ny, cr, cg, cb, 64);
blendpixel(vid, nx-1, ny, cr, cg, cb, 64);
blendpixel(vid, nx, ny+1, cr, cg, cb, 64);
blendpixel(vid, nx, ny-1, cr, cg, cb, 64);
if(cmode == 3||cmode==4 || cmode==6)
{
cr /= 32;
cg /= 32;
cb /= 32;
x = nx/CELL;
y = ny/CELL;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
}
}
else if(t==PT_LAVA || t==PT_SPRK)
{
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
if(cmode == 3 || cmode==4 || cmode==6)
{
if(t == PT_LAVA)
{
cr = 3;
cg = i%2;
cb = 0;
}
else
{
cr = 8;
cg = 12;
cb = 16;
}
x = nx/CELL;
y = ny/CELL;
cr += fire_r[y][x];
if(cr > 255) cr = 255;
fire_r[y][x] = cr;
cg += fire_g[y][x];
if(cg > 255) cg = 255;
fire_g[y][x] = cg;
cb += fire_b[y][x];
if(cb > 255) cb = 255;
fire_b[y][x] = cb;
}
}
else
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
}
else
{
float ttemp = parts[i].temp+(-MIN_TEMP);
int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/512) ) *3, 0.0f, (512.0f*3)-3);
uint8 R = color_data[caddress];
uint8 G = color_data[caddress+1];
uint8 B = color_data[caddress+2];
if(t==PT_STKM) //Stick man should be visible in heat mode
{
char buff[10]; //Buffer for HP
if(mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head
{
sprintf(buff, "%3d", (int)parts[i].life); //Show HP
drawtext(vid, mousex-8-2*(parts[i].life<100)-2*(parts[i].life<10), mousey-12, buff, 255, 255, 255, 255);
}
for(r=-2; r<=1; r++)
{
s = XRES+BARSIZE;
vid[(ny-2)*s+nx+r] = PIXRGB (R, G, B);
vid[(ny+2)*s+nx+r+1] = PIXRGB (R, G, B);
vid[(ny+r+1)*s+nx-2] = PIXRGB (R, G, B);
vid[(ny+r)*s+nx+2] = PIXRGB (R, G, B);
}
draw_line(vid , nx, ny+3, player[3], player[4], R, G, B, s);
draw_line(vid , player[3], player[4], player[7], player[8], R, G, B, s);
draw_line(vid , nx, ny+3, player[11], player[12], R, G, B, s);
draw_line(vid , player[11], player[12], player[15], player[16], R, G, B, s);
}
else
{
vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(R, G, B);
//blendpixel(vid, nx+1, ny, R, G, B, 255);
}
}
if(cmode == 4&&t!=PT_FIRE&&t!=PT_PLSM&&t!=PT_NONE&&t!=PT_ACID)
{
uint8 R = PIXR(ptypes[t].pcolors);
uint8 G = PIXG(ptypes[t].pcolors);
uint8 B = PIXB(ptypes[t].pcolors);
//if(vid[(ny-1)*YRES+(nx-1)]!=0){
// blendpixel(vid, nx, ny-1, R, G, B, 46);
//}
blendpixel(vid, nx+1, ny, R, G, B, 223);
blendpixel(vid, nx-1, ny, R, G, B, 223);
blendpixel(vid, nx, ny+1, R, G, B, 223);
blendpixel(vid, nx, ny-1, R, G, B, 223);
blendpixel(vid, nx+1, ny-1, R, G, B, 112);
blendpixel(vid, nx-1, ny-1, R, G, B, 112);
blendpixel(vid, nx+1, ny+1, R, G, B, 112);
blendpixel(vid, nx-1, ny+1, R, G, B, 112);
}
}
} }

View File

@ -1,6 +1,8 @@
#ifndef GRAPHICS_H #ifndef GRAPHICS_H
#define GRAPHICS_H #define GRAPHICS_H
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "defines.h"
#include "hmap.h"
#ifdef PIX16 #ifdef PIX16
#define PIXELSIZE 2 #define PIXELSIZE 2
@ -40,6 +42,10 @@ extern unsigned cmode;
extern SDL_Surface *sdl_scrn; extern SDL_Surface *sdl_scrn;
extern int sdl_scale; extern int sdl_scale;
extern unsigned char fire_r[YRES/CELL][XRES/CELL];
extern unsigned char fire_g[YRES/CELL][XRES/CELL];
extern unsigned char fire_b[YRES/CELL][XRES/CELL];
pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f); pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f);
void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch); void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch);

7
hmap.h

File diff suppressed because one or more lines are too long

15
interface.c Normal file
View File

@ -0,0 +1,15 @@
#include "powder.h"
#include "interface.h"
void menu_count(void)
{
int i=0;
msections[SC_WALL].itemcount = UI_WALLCOUNT-4;
msections[SC_SPECIAL].itemcount = 4;
for(i=0; i<PT_NUM; i++)
{
msections[ptypes[i].menusection].itemcount+=ptypes[i].menu;
}
}

View File

@ -63,4 +63,5 @@ static menu_section msections[] =
{"\xCC", "Special", 0}, {"\xCC", "Special", 0},
}; };
void menu_count(void);
#endif #endif

3388
main.c

File diff suppressed because it is too large Load Diff

2547
powder.c

File diff suppressed because it is too large Load Diff

View File

@ -397,4 +397,63 @@ static unsigned char can_move[PT_NUM][PT_NUM] =
/* e t r l e l a p r e s x m i e k w d t t t d d v t w t w d l t t n x n n u l l m d N d s n a r m d e E y y M H E s l l R T*/ /* e t r l e l a p r e s x m i e k w d t t t d d v t w t w d l t t n x n n u l l m d N d s n a r m d e E y y M H E s l l R T*/
}; };
extern int isplayer;
extern float player[20];
extern particle *parts;
extern particle *cb_parts;
extern unsigned char bmap[YRES/CELL][XRES/CELL];
extern unsigned char emap[YRES/CELL][XRES/CELL];
extern unsigned char cb_bmap[YRES/CELL][XRES/CELL];
extern unsigned char cb_emap[YRES/CELL][XRES/CELL];
extern int pfree;
extern unsigned pmap[YRES][XRES];
unsigned cb_pmap[YRES][XRES];
int try_move(int i, int x, int y, int nx, int ny);
void kill_part(int i);
#ifdef WIN32
extern _inline int create_part(int p, int x, int y, int t);
#else
extern inline int create_part(int p, int x, int y, int t);
#endif
#ifdef WIN32
extern _inline void delete_part(int x, int y);
#else
extern inline void delete_part(int x, int y);
#endif
#ifdef WIN32
extern _inline int is_wire(int x, int y);
#else
extern inline int is_wire(int x, int y);
#endif
#ifdef WIN32
extern _inline int is_wire_off(int x, int y);
#else
extern inline int is_wire_off(int x, int y);
#endif
void set_emap(int x, int y);
#ifdef WIN32
_inline int parts_avg(int ci, int ni);
#else
inline int parts_avg(int ci, int ni);
#endif
int nearest_part(int ci, int t);
void update_particles_i(pixel *vid, int start, int inc);
void update_particles(pixel *vid);
#endif #endif