From 00d604820d4900a422efd43dd3dd0a6f225e4adf Mon Sep 17 00:00:00 2001 From: savask Date: Mon, 29 Aug 2011 23:47:22 +0700 Subject: [PATCH 1/9] Added fighters. --- includes/powder.h | 9 +- src/elements/figh.c | 7 + src/graphics.c | 1189 +++++++++++++++++++++++-------------------- src/main.c | 10 +- src/powder.c | 64 ++- 5 files changed, 727 insertions(+), 552 deletions(-) create mode 100644 src/elements/figh.c diff --git a/includes/powder.h b/includes/powder.h index 4e15dccf5..9bc823a48 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -210,7 +210,8 @@ #define PT_CLST 155 #define PT_WIRE 156 #define PT_GBMB 157 -#define PT_NUM 158 +#define PT_FIGH 158 +#define PT_NUM 159 #define R_TEMP 22 #define MAX_TEMP 9999 @@ -327,6 +328,7 @@ int update_CLST(UPDATE_FUNC_ARGS); int update_DLAY(UPDATE_FUNC_ARGS); int update_WIRE(UPDATE_FUNC_ARGS); int update_GBMB(UPDATE_FUNC_ARGS); +int update_FIGH(UPDATE_FUNC_ARGS); int update_CO2(UPDATE_FUNC_ARGS); int update_CBNW(UPDATE_FUNC_ARGS); int update_STOR(UPDATE_FUNC_ARGS); @@ -574,6 +576,7 @@ static const part_type ptypes[PT_NUM] = {"CLST", PIXPACK(0xE4A4A4), 0.7f, 0.02f * CFDS, 0.94f, 0.95f, 0.0f, 0.2f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 55, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Clay dust. Produces paste when mixed with water.", ST_SOLID, TYPE_PART, &update_CLST}, {"WIRE", PIXPACK(0xFFCC00), 0.0f, 0.00f * CFDS, 0.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 250, "WireWorld wires.",ST_SOLID,TYPE_SOLID,&update_WIRE}, {"GBMB", PIXPACK(0x1144BB), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 20, 1, 1, 30, SC_EXPLOSIVE, R_TEMP-2.0f +273.15f, 29, "Sticks to first object it touches then produces strong gravity push.", ST_NONE, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_GBMB}, + {"FIGH", PIXPACK(0x000000), 0.5f, 0.00f * CFDS, 0.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.00f * CFDS, 0, 0, 0, 0, 0, 1, 1, 50, SC_SPECIAL, R_TEMP+14.6f+273.15f, 0, "Fighter. Tries to kill stickmans.", ST_NONE, 0, &update_FIGH}, //Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Use Weight Section H Ins Description }; @@ -747,6 +750,7 @@ static part_transition ptransitions[PT_NUM] = /* CLST */ {IPL, NT, IPH, NT, ITL, NT, 1256.0f, PT_LAVA}, /* WIRE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, /* GBMB */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, + /* FIGH */ {IPL, NT, IPH, NT, ITL, NT, 620.0f, PT_FIRE}, }; #undef IPL #undef IPH @@ -977,6 +981,9 @@ extern int gravwl_timeout; extern float player[29]; extern float player2[29]; +extern float fighters[256][28]; +extern unsigned char fighcount; + extern int gravityMode; extern int airMode; diff --git a/src/elements/figh.c b/src/elements/figh.c new file mode 100644 index 000000000..c67ebf9c0 --- /dev/null +++ b/src/elements/figh.c @@ -0,0 +1,7 @@ +#include + +int update_FIGH(UPDATE_FUNC_ARGS) +{ + run_stickman(fighters[(unsigned char)parts[i].tmp], UPDATE_FUNC_SUBCALL_ARGS); + return 0; +} diff --git a/src/graphics.c b/src/graphics.c index fd6c2b2eb..9e863862e 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1017,25 +1017,103 @@ inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) if (!bn) { ba = *(rp++); - bn = 8; - } - drawpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3); - ba >>= 2; - bn -= 2; + bn = 8; } - return x + w; + drawpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3); + ba >>= 2; + bn -= 2; + } +return x + w; } int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a) { #ifdef OpenGL #else - int sx = x; - for (; *s; s++) +int sx = x; +for (; *s; s++) +{ + if (*s == '\n') + { + x = sx; + y += FONT_H+2; + } + else if (*s == '\b') + { + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'b': + r = g = 0; + b = 255; + break; + case 't': + b = 255; + g = 170; + r = 32; + break; + } + s++; + } + else + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); +} +#endif +return x; +} + +//Draw text with an outline +int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa) +{ +drawtext(vid, x-1, y-1, s, or, og, ob, oa); +drawtext(vid, x+1, y+1, s, or, og, ob, oa); + +drawtext(vid, x-1, y+1, s, or, og, ob, oa); +drawtext(vid, x+1, y-1, s, or, og, ob, oa); + +return drawtext(vid, x, y, s, r, g, b, a); +} +int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a) +{ +#ifdef OpenGL +#else +int sx = x; +int rh = 12; +int rw = 0; +int cw = x; +int wordlen; +int charspace; +while (*s) +{ + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx((char *)s, w-(x-cw)); + if (charspace=-1; s++) { if (*s == '\n') { x = sx; + rw = 0; y += FONT_H+2; } else if (*s == '\b') @@ -1065,56 +1143,13 @@ int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a r = g = 0; b = 255; break; - case 't': - b = 255; - g = 170; - r = 32; - break; } s++; } else - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); - } -#endif - return x; -} + { -//Draw text with an outline -int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa) -{ - drawtext(vid, x-1, y-1, s, or, og, ob, oa); - drawtext(vid, x+1, y+1, s, or, og, ob, oa); - - drawtext(vid, x-1, y+1, s, or, og, ob, oa); - drawtext(vid, x+1, y-1, s, or, og, ob, oa); - - return drawtext(vid, x, y, s, r, g, b, a); -} -int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a) -{ -#ifdef OpenGL -#else - int sx = x; - int rh = 12; - int rw = 0; - int cw = x; - int wordlen; - int charspace; - while (*s) - { - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx((char *)s, w-(x-cw)); - if (charspace=-1; s++) - { - if (*s == '\n') + if (x-cw>=w) { x = sx; rw = 0; @@ -1167,36 +1202,38 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i } x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } } +} - return rh; - #endif +return rh; +#endif } //draws a rectange, (x,y) are the top left coords. void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) { #ifdef OpenGL - glBegin(GL_LINE_LOOP); - glColor4ub(r, g, b, a); - glVertex2i(x, y); - glVertex2i(x+w, y); - glVertex2i(x+w, y+h); - glVertex2i(x, y+h); - glEnd(); +glBegin(GL_LINE_LOOP); +glColor4ub(r, g, b, a); +glVertex2i(x, y); +glVertex2i(x+w, y); +glVertex2i(x+w, y+h); +glVertex2i(x, y+h); +glEnd(); #else - int i; - for (i=0; i<=w; i++) - { - drawpixel(vid, x+i, y, r, g, b, a); - drawpixel(vid, x+i, y+h, r, g, b, a); - } - for (i=1; i=w && x+textwidth(s)>=w+5) - break; - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); - } - if (*s) - for (i=0; i<3; i++) - x = drawchar(vid, x, y, '.', r, g, b, a); - return x; +int i; +w += x-5; +for (; *s; s++) +{ + if (x+font_data[font_ptrs[(int)(*(unsigned char *)s)]]>=w && x+textwidth(s)>=w+5) + break; + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); +} +if (*s) + for (i=0; i<3; i++) + x = drawchar(vid, x, y, '.', r, g, b, a); +return x; } int textnwidth(char *s, int n) { - int x = 0; - for (; *s; s++) - { - if (!n) - break; - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - n--; - } - return x-1; +int x = 0; +for (; *s; s++) +{ + if (!n) + break; + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + n--; +} +return x-1; } void textnpos(char *s, int n, int w, int *cx, int *cy) { - int x = 0; - int y = 0; - int wordlen, charspace; - while (*s&&n) +int x = 0; +int y = 0; +int wordlen, charspace; +while (*s&&n) +{ + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-x); + if (charspace=-1; s++) + { + if (!n) { + break; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x>=w) { x = 0; y += FONT_H+2; } - for (; *s && --wordlen>=-1; s++) - { - if (!n) { - break; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x>=w) - { - x = 0; - y += FONT_H+2; - } - n--; - } + n--; } - *cx = x-1; - *cy = y; +} +*cx = x-1; +*cy = y; } int textwidthx(char *s, int w) { - int x=0,n=0,cw; - for (; *s; s++) - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+(cw/2) >= w) - break; - x += cw; - n++; - } - return n; +int x=0,n=0,cw; +for (; *s; s++) +{ + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+(cw/2) >= w) + break; + x += cw; + n++; +} +return n; } int textposxy(char *s, int width, int w, int h) { - int x=0,y=0,n=0,cw, wordlen, charspace; - while (*s) +int x=0,y=0,n=0,cw, wordlen, charspace; +while (*s) +{ + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) + return n++; + x += cw; + if (x>=width) { x = 0; y += FONT_H+2; } - for (; *s && --wordlen>=-1; s++) - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) - return n++; - x += cw; - if (x>=width) { - x = 0; - y += FONT_H+2; - } - n++; - } + n++; } - return n; +} +return n; } int textwrapheight(char *s, int width) { - int x=0, height=FONT_H+2, cw; - int wordlen; - int charspace; - while (*s) +int x=0, height=FONT_H+2, cw; +int wordlen; +int charspace; +while (*s) +{ + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + if (*s == '\n') { x = 0; height += FONT_H+2; } - for (; *s && --wordlen>=-1; s++) + else if (*s == '\b') { - if (*s == '\n') + s++; + } + else + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+cw>=width) { x = 0; height += FONT_H+2; } - else if (*s == '\b') - { - s++; - } - else - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+cw>=width) - { - x = 0; - height += FONT_H+2; - } - x += cw; - } + x += cw; } } - return height; +} +return height; } //the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented. @@ -1424,120 +1461,127 @@ inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag) { - char t[2]; - t[0] = ch; - t[1] = 0; - if (flag) - { - fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255); - drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255); - } - else - { - drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255); - drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255); - } +char t[2]; +t[0] = ch; +t[1] = 0; +if (flag) +{ + fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255); +} +else +{ + drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255); +} } void draw_air(pixel *vid) { - int x, y, i, j; - pixel c; +int x, y, i, j; +pixel c; - if (cmode == CM_PERS)//this should never happen anyway - return; +if (cmode == CM_PERS)//this should never happen anyway + return; - for (y=0; y 0.0f) - c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! - else - c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! - } - else if (cmode == CM_VEL) - { - c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green - clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (cmode == CM_HEAT && aheat_enable) - { - float ttemp = hv[y][x]+(-MIN_TEMP); - int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); - c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); - //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green - // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (cmode == CM_CRACK) - { - int r; - int g; - int b; - // velocity adds grey - r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); - b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - if (pv[y][x] > 0.0f) - { - r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); - } - else - { - b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); - } - } - for (j=0; j 0.0f) + c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! + else + c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! } + else if (cmode == CM_VEL) + { + c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green + clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (cmode == CM_HEAT && aheat_enable) + { + float ttemp = hv[y][x]+(-MIN_TEMP); + int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); + //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green + // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (cmode == CM_CRACK) + { + int r; + int g; + int b; + // velocity adds grey + r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); + b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + if (pv[y][x] > 0.0f) + { + r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + else + { + b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + } + for (j=0; jdx) +if (dy>dx) +{ + dx = dx+dy; + dy = dx-dy; + dx = dx-dy; + check = 1; +} + +e = (dy<<2)-dx; +for (i=0; i<=dx; i++) +{ + if (x>=0 && y>=0 && x=0) { - dx = dx+dy; - dy = dx-dy; - dx = dx-dy; - check = 1; - } - - e = (dy<<2)-dx; - for (i=0; i<=dx; i++) - { - if (x>=0 && y>=0 && x=0) - { - if (check==1) - x = x+sx; - else - y = y+sy; - e = e-(dx<<2); - } if (check==1) - y = y+sy; - else x = x+sx; - e = e+(dy<<2); + else + y = y+sy; + e = e-(dx<<2); } + if (check==1) + y = y+sy; + else + x = x+sx; + e = e+(dy<<2); +} } //adds color to a pixel, does not overwrite. void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a) { - pixel t; - if (x<0 || y<0 || x>=XRES || y>=YRES) - return; - t = vid[y*(XRES+BARSIZE)+x]; - r = (a*r + 255*PIXR(t)) >> 8; - g = (a*g + 255*PIXG(t)) >> 8; - b = (a*b + 255*PIXB(t)) >> 8; - if (r>255) - r = 255; - if (g>255) - g = 255; - if (b>255) - b = 255; - vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); +pixel t; +if (x<0 || y<0 || x>=XRES || y>=YRES) + return; +t = vid[y*(XRES+BARSIZE)+x]; +r = (a*r + 255*PIXR(t)) >> 8; +g = (a*g + 255*PIXG(t)) >> 8; +b = (a*b + 255*PIXB(t)) >> 8; +if (r>255) + r = 255; +if (g>255) + g = 255; +if (b>255) + b = 255; +vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); } //draws one of two colors, so that it is always clearly visible void xor_pixel(int x, int y, pixel *vid) { - int c; - if (x<0 || y<0 || x>=XRES || y>=YRES) - return; - c = vid[y*(XRES+BARSIZE)+x]; - c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); - if (c<512) - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0); - else - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); +int c; +if (x<0 || y<0 || x>=XRES || y>=YRES) + return; +c = vid[y*(XRES+BARSIZE)+x]; +c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); +if (c<512) + vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0); +else + vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); } //same as xor_pixel, but draws a line of it void xor_line(int x1, int y1, int x2, int y2, pixel *vid) { - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; +int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; +float e, de; +if (cp) +{ + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; +} +if (x1 > x2) +{ + y = x1; + x1 = x2; + x2 = y; y = y1; - sy = (y1= 0.5f) { - if (cp) - xor_pixel(y, x, vid); - else - xor_pixel(x, y, vid); - e += de; - if (e >= 0.5f) - { - y += sy; - e -= 1.0f; - } + y += sy; + e -= 1.0f; } } +} //same as blend_pixel, but draws a line of it void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) { - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; +int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; +float e, de; +if (cp) +{ + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; +} +if (x1 > x2) +{ + y = x1; + x1 = x2; + x2 = y; y = y1; - sy = (y1= 0.5f) { - if (cp) - blendpixel(vid, y, x, r, g, b, a); - else - blendpixel(vid, x, y, r, g, b, a); - e += de; - if (e >= 0.5f) - { - y += sy; - e -= 1.0f; - } + y += sy; + e -= 1.0f; } } +} //same as xor_pixel, but draws a rectangle void xor_rect(pixel *vid, int x, int y, int w, int h) { - int i; - for (i=0; i(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head { - char buff[20]; //Buffer for HP - pixel pc; - - if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head - { - sprintf(buff, "%3d", 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); - } - - if ((int)player[2](nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head { - char buff[20]; //Buffer for HP - pixel pc; - - if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head - { - sprintf(buff, "%3d", 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); - } - - if ((int)player2[2](nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", 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); + } + if ((int)figh[2](nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", 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); + } + + s = XRES+BARSIZE; + //head + draw_line(vid , nx, ny+2, nx+2, ny, R, G, B, s); + draw_line(vid , nx+2, ny, nx, ny-2, R, G, B, s); + draw_line(vid , nx, ny-2, nx-2, ny, R, G, B, s); + draw_line(vid , nx-2, ny, nx, ny+2, R, G, B, s); + //legs + draw_line(vid , nx, ny+3, figh[3], figh[4], R, G, B, s); + draw_line(vid , figh[3], figh[4], figh[7], figh[8], R, G, B, s); + draw_line(vid , nx, ny+3, figh[11], figh[12], R, G, B, s); + draw_line(vid , figh[11], figh[12], figh[15], figh[16], R, G, B, s); + } else { vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(R, G, B); @@ -4706,10 +4809,10 @@ pixel *prerender_save(void *save, int size, int *width, int *height) j=d[p++]; if (j0) { - if (j==PT_STKM || j==PT_STKM2) + if (j==PT_STKM || j==PT_STKM2 || j==PT_FIGH) { pixel lc, hc=PIXRGB(255, 224, 178); - if (j==PT_STKM) lc = PIXRGB(255, 255, 255); + if (j==PT_STKM || j==PT_FIGH) lc = PIXRGB(255, 255, 255); else lc = PIXRGB(100, 100, 255); //only need to check upper bound of y coord - lower bounds and x>8].ctype = t; @@ -836,7 +862,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a parts[i].pavg[0] = 0.0f; parts[i].pavg[1] = 0.0f; } - if (t!=PT_STKM&&t!=PT_STKM2)//set everything to default values first, except for stickman. + if (t!=PT_STKM&&t!=PT_STKM2&&t!=PT_FIGH)//set everything to default values first, except for stickman. { parts[i].x = (float)x; parts[i].y = (float)y; @@ -1003,12 +1029,36 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a create_part(-1,x,y,PT_SPAWN2); ISSPAWN2 = 1; } + if (t==PT_FIGH) + { + unsigned char cunt = 0; + while (cunt < 100 && cunt < (fighcount+1) && fighters[cunt][27]==1) cunt++; + if (cunt < 100 && fighters[cunt][27]==0) + { + parts[i].x = (float)x; + parts[i].y = (float)y; + parts[i].type = PT_FIGH; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 100; + parts[i].ctype = 0; + parts[i].tmp = cunt; + parts[i].temp = ptypes[t].heat; + STKM_init_legs(fighters[cunt], i); + fighters[cunt][27] = 1; + fighters[cunt][2] = PT_DUST; + fighcount++; + + return i; + } + return -1; + } if (t==PT_BIZR||t==PT_BIZRG) parts[i].ctype = 0x47FFFF; //and finally set the pmap/photon maps to the newly created particle if (t==PT_PHOT||t==PT_NEUT) photons[y][x] = t|(i<<8); - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT) + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_FIGH && t!=PT_PHOT && t!=PT_NEUT) pmap[y][x] = t|(i<<8); //Fancy dust effects for powder types @@ -1674,7 +1724,7 @@ void update_particles_i(pixel *vid, int start, int inc) (bmap[y/CELL][x/CELL]==WL_ALLOWGAS && !(ptypes[t].properties&TYPE_GAS)) || //&& ptypes[t].falldown!=0 && parts[i].type!=PT_FIRE && parts[i].type!=PT_SMKE && parts[i].type!=PT_HFLM) || (bmap[y/CELL][x/CELL]==WL_ALLOWENERGY && !(ptypes[t].properties&TYPE_ENERGY)) || (bmap[y/CELL][x/CELL]==WL_DETECT && (t==PT_METL || t==PT_SPRK)) || - (bmap[y/CELL][x/CELL]==WL_EWALL && !emap[y/CELL][x/CELL])) && (t!=PT_STKM) && (t!=PT_STKM2))) + (bmap[y/CELL][x/CELL]==WL_EWALL && !emap[y/CELL][x/CELL])) && (t!=PT_STKM) && (t!=PT_STKM2) && (t!=PT_FIGH))) { kill_part(i); continue; @@ -1736,7 +1786,7 @@ void update_particles_i(pixel *vid, int start, int inc) pGravX -= gravxf[(y*XRES)+x]; pGravY -= gravyf[(y*XRES)+x]; } - else if(t!=PT_STKM && t!=PT_STKM2 && !(ptypes[t].properties & TYPE_SOLID)) + else if(t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH && !(ptypes[t].properties & TYPE_SOLID)) { pGravX += gravxf[(y*XRES)+x]; pGravY += gravyf[(y*XRES)+x]; @@ -2838,7 +2888,7 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n; int wall = c - 100; - if (c==SPC_WIND){ + if (c==SPC_WIND || c==PT_FIGH) return 0; } if(c==SPC_PROP){ From 1eef119fdbb33007baa3042ceb9b4fc869655760 Mon Sep 17 00:00:00 2001 From: savask Date: Wed, 31 Aug 2011 21:20:31 +0700 Subject: [PATCH 2/9] Made stick mans' deadly check better. --- src/elements/stkm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elements/stkm.c b/src/elements/stkm.c index 85e6e4c29..0ac13e425 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -383,6 +383,8 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { //If legs touch something STKM_interact(playerp, i, (int)(playerp[7]+0.5), (int)(playerp[8]+0.5)); STKM_interact(playerp, i, (int)(playerp[15]+0.5), (int)(playerp[16]+0.5)); + STKM_interact(playerp, i, (int)(playerp[7]+0.5), (int)playerp[8]); + STKM_interact(playerp, i, (int)(playerp[15]+0.5), (int)playerp[16]); if (!parts[i].type) return 1; From 573bda09500297caf9ad48889f7b191f42d31526 Mon Sep 17 00:00:00 2001 From: savask Date: Sat, 15 Oct 2011 22:22:47 +0700 Subject: [PATCH 3/9] Added a simple AI to fighters. --- src/elements/figh.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/elements/figh.c b/src/elements/figh.c index c67ebf9c0..abed67408 100644 --- a/src/elements/figh.c +++ b/src/elements/figh.c @@ -2,6 +2,79 @@ int update_FIGH(UPDATE_FUNC_ARGS) { - run_stickman(fighters[(unsigned char)parts[i].tmp], UPDATE_FUNC_SUBCALL_ARGS); + float* figh = fighters[(unsigned char)parts[i].tmp]; + + float tarx, tary; + + parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man + + //Set target cords + if (player[27]) + { + if (player2[27]) + if ((pow(player[5]-x, 2) + pow(player[6]-y, 2))<= + (pow(player2[5]-x, 2) + pow(player2[6]-y, 2))) + { + tarx = player[5]; + tary = player[6]; + } + else + { + tarx = player2[5]; + tary = player2[6]; + } + else + { + tarx = player[5]; + tary = player[6]; + } + + parts[i].tmp2 = 1; + } + else + if (player2[27]) + { + tarx = player2[5]; + tary = player2[6]; + + parts[i].tmp2 = 1; + } + + switch (parts[i].tmp2) + { + case 1: + if ((pow(tarx-x, 2) + pow(tary-y, 2))<600) + { + if (figh[2] == PT_FIRE) + figh[0] = (int)figh[0] | 0x08; + } + + if ((pow(tarx-x, 2) + pow(tary-y, 2))<300) + { + if (figh[2] == PT_FIRE) + figh[0] = 0x08; + else + figh[0] = 0; + } + else + if (tarx Date: Sat, 15 Oct 2011 22:39:35 +0700 Subject: [PATCH 4/9] Fix one merging error, and adjusted fighters' array. --- includes/powder.h | 2 +- src/powder.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 9bc823a48..33b57948d 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -981,7 +981,7 @@ extern int gravwl_timeout; extern float player[29]; extern float player2[29]; -extern float fighters[256][28]; +extern float fighters[256][29]; extern unsigned char fighcount; extern int gravityMode; diff --git a/src/powder.c b/src/powder.c index e5680eb92..41f9196b4 100644 --- a/src/powder.c +++ b/src/powder.c @@ -2890,7 +2890,7 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) int wall = c - 100; if (c==SPC_WIND || c==PT_FIGH) return 0; - } + if(c==SPC_PROP){ prop_edit_ui(vid_buf, x, y); return 0; From 5652ecc5c20a6cce0745b20587ff4dfec8103ff3 Mon Sep 17 00:00:00 2001 From: savask Date: Sat, 15 Oct 2011 23:20:54 +0700 Subject: [PATCH 5/9] Some work on lightning for stick mans and fighters. --- src/elements/figh.c | 12 +++--------- src/main.c | 4 ++-- src/powder.c | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/elements/figh.c b/src/elements/figh.c index abed67408..74dcf14dc 100644 --- a/src/elements/figh.c +++ b/src/elements/figh.c @@ -45,17 +45,9 @@ int update_FIGH(UPDATE_FUNC_ARGS) case 1: if ((pow(tarx-x, 2) + pow(tary-y, 2))<600) { - if (figh[2] == PT_FIRE) + if (figh[2] == PT_FIRE || figh[2] == PT_LIGH) figh[0] = (int)figh[0] | 0x08; } - - if ((pow(tarx-x, 2) + pow(tary-y, 2))<300) - { - if (figh[2] == PT_FIRE) - figh[0] = 0x08; - else - figh[0] = 0; - } else if (tarx0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT) + if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) player[2] = sr; else player[2] = PT_DUST; } if (player2[27]==0) { - if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT) + if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) player2[2] = sr; else player2[2] = PT_DUST; diff --git a/src/powder.c b/src/powder.c index 41f9196b4..5e828ecf1 100644 --- a/src/powder.c +++ b/src/powder.c @@ -16,7 +16,7 @@ int lighting_recreate = 0; float player[29]; float player2[29]; -float fighters[256][28]; //255 is the maximum number of fighters +float fighters[256][29]; //255 is the maximum number of fighters unsigned char fighcount = 0; //Contains the number of fighters particle *parts; From 03902ec9a4c60e53a7f80649bcf3a1158a20465e Mon Sep 17 00:00:00 2001 From: savask Date: Sun, 23 Oct 2011 15:22:31 +0700 Subject: [PATCH 6/9] Made a special structure for stick mans. --- includes/powder.h | 24 +++- src/elements/figh.c | 48 +++---- src/elements/ligh.c | 2 +- src/elements/prto.c | 4 +- src/elements/stkm.c | 334 +++++++++++++++++++++---------------------- src/elements/stkm2.c | 4 +- src/graphics.c | 64 ++++----- src/interface.c | 40 +++--- src/main.c | 38 +++-- src/powder.c | 54 ++++--- 10 files changed, 310 insertions(+), 302 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 33b57948d..2cf88027a 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -250,6 +250,18 @@ // to call another update function with same arguments: #define UPDATE_FUNC_SUBCALL_ARGS i, x, y, surround_space, nt +struct playerst +{ + char comm; //command cell + char pcomm; //previous command + int elem; //element power + float legs[16]; //legs' positions + float accs[8]; //accelerations + char spwn; //if stick man was spawned + unsigned int frames; //frames since last particle spawn - used when spawning LIGH +}; +typedef struct playerst playerst; + int update_ACID(UPDATE_FUNC_ARGS); int update_ANAR(UPDATE_FUNC_ARGS); int update_AMTR(UPDATE_FUNC_ARGS); @@ -343,9 +355,9 @@ int update_LIGH(UPDATE_FUNC_ARGS); int update_MISC(UPDATE_FUNC_ARGS); int update_legacy_PYRO(UPDATE_FUNC_ARGS); int update_legacy_all(UPDATE_FUNC_ARGS); -int run_stickman(float* playerp, UPDATE_FUNC_ARGS); -void STKM_init_legs(float* playerp, int i); -void STKM_interact(float* playerp, int i, int x, int y); +int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS); +void STKM_init_legs(playerst* playerp, int i); +void STKM_interact(playerst* playerp, int i, int x, int y); struct particle @@ -978,10 +990,10 @@ extern int wire_placed; extern int gravwl_timeout; -extern float player[29]; -extern float player2[29]; +extern playerst player; +extern playerst player2; -extern float fighters[256][29]; +extern playerst fighters[256]; extern unsigned char fighcount; extern int gravityMode; diff --git a/src/elements/figh.c b/src/elements/figh.c index 74dcf14dc..fb172fb29 100644 --- a/src/elements/figh.c +++ b/src/elements/figh.c @@ -2,40 +2,40 @@ int update_FIGH(UPDATE_FUNC_ARGS) { - float* figh = fighters[(unsigned char)parts[i].tmp]; + playerst* figh = &fighters[(unsigned char)parts[i].tmp]; float tarx, tary; parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man //Set target cords - if (player[27]) + if (player.spwn) { - if (player2[27]) - if ((pow(player[5]-x, 2) + pow(player[6]-y, 2))<= - (pow(player2[5]-x, 2) + pow(player2[6]-y, 2))) + if (player2.spwn) + if ((pow(player.legs[2]-x, 2) + pow(player.legs[3]-y, 2))<= + (pow(player2.legs[2]-x, 2) + pow(player2.legs[3]-y, 2))) { - tarx = player[5]; - tary = player[6]; + tarx = player.legs[2]; + tary = player.legs[3]; } else { - tarx = player2[5]; - tary = player2[6]; + tarx = player2.legs[2]; + tary = player2.legs[3]; } else { - tarx = player[5]; - tary = player[6]; + tarx = player.legs[2]; + tary = player.legs[3]; } parts[i].tmp2 = 1; } else - if (player2[27]) + if (player2.spwn) { - tarx = player2[5]; - tary = player2[6]; + tarx = player2.legs[2]; + tary = player2.legs[3]; parts[i].tmp2 = 1; } @@ -45,29 +45,29 @@ int update_FIGH(UPDATE_FUNC_ARGS) case 1: if ((pow(tarx-x, 2) + pow(tary-y, 2))<600) { - if (figh[2] == PT_FIRE || figh[2] == PT_LIGH) - figh[0] = (int)figh[0] | 0x08; + if (figh->elem == PT_FIRE || figh->elem == PT_LIGH) + figh->comm = (int)figh->comm | 0x08; } else if (tarxcomm = 0x01; + if (!eval_move(PT_DUST, figh->legs[4]-4, figh->legs[5]-1, NULL) || !eval_move(PT_DUST, figh->legs[12]-4, figh->legs[13]-1, NULL)) + figh->comm = (int)figh->comm | 0x04; } else { - figh[0] = 0x02; - if (!eval_move(PT_DUST, figh[7]+4, figh[8]-1, NULL) || !eval_move(PT_DUST, figh[15]+4, figh[16]-1, NULL)) - figh[0] = (int)figh[0] | 0x04; + figh->comm = 0x02; + if (!eval_move(PT_DUST, figh->legs[4]+4, figh->legs[5]-1, NULL) || !eval_move(PT_DUST, figh->legs[12]+4, figh->legs[13]-1, NULL)) + figh->comm = (int)figh->comm | 0x04; } break; default: - figh[0] = 0; + figh->comm = 0; break; } - figh[1] = figh[0]; + figh->pcomm = figh->comm; run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS); return 0; diff --git a/src/elements/ligh.c b/src/elements/ligh.c index bfbcd0dca..9b2006965 100644 --- a/src/elements/ligh.c +++ b/src/elements/ligh.c @@ -165,7 +165,7 @@ int update_LIGH(UPDATE_FUNC_ARGS) } if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/10, MIN_TEMP, MAX_TEMP); - if (((r&0xFF)==PT_STKM && player[2]!=PT_LIGH) || ((r&0xFF)==PT_STKM2 && player2[2]!=PT_LIGH)) + if (((r&0xFF)==PT_STKM && player.elem!=PT_LIGH) || ((r&0xFF)==PT_STKM2 && player2.elem!=PT_LIGH)) { parts[r>>8].life-=powderful/100; } diff --git a/src/elements/prto.c b/src/elements/prto.c index e86891a89..dcbc53cc0 100644 --- a/src/elements/prto.c +++ b/src/elements/prto.c @@ -44,9 +44,9 @@ int update_PRTO(UPDATE_FUNC_ARGS) { else if (portalp[parts[i].tmp][randomness][nnx].type) { if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) - player[27] = 0; + player.spwn = 0; if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) - player2[27] = 0; + player2.spwn = 0; np = create_part(-1,x+rx,y+ry,portalp[parts[i].tmp][randomness][nnx].type); if (np<0) continue; parts[np] = portalp[parts[i].tmp][randomness][nnx]; diff --git a/src/elements/stkm.c b/src/elements/stkm.c index 0ac13e425..972bd86b8 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -1,7 +1,7 @@ #include int update_SPAWN(UPDATE_FUNC_ARGS) { - if (!player[27]) + if (!player.spwn) create_part(-1, x, y, PT_STKM); return 0; @@ -9,11 +9,11 @@ int update_SPAWN(UPDATE_FUNC_ARGS) { int update_STKM(UPDATE_FUNC_ARGS) { - run_stickman(player, UPDATE_FUNC_SUBCALL_ARGS); + run_stickman(&player, UPDATE_FUNC_SUBCALL_ARGS); return 0; } -int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { +int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { int r, rx, ry; float pp, d; float dt = 0.9;///(FPSB*FPSB); //Delta time in square @@ -21,8 +21,8 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { float gx, gy, dl, dr; if ((parts[i].ctype>0 && parts[i].ctype0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH) - playerp[2] = parts[i].ctype; - playerp[28]++; + playerp->elem = parts[i].ctype; + playerp->frames++; //Tempirature handling if (parts[i].temp<243) @@ -31,14 +31,14 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { parts[i].temp += 1; //Death - if (parts[i].life<1 || (pv[y/CELL][x/CELL]>=4.5f && playerp[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... + if (parts[i].life<1 || (pv[y/CELL][x/CELL]>=4.5f && playerp->elem != SPC_AIR) ) //If his HP is less that 0 or there is very big wind... { for (r=-2; r<=1; r++) { - create_part(-1, x+r, y-2, playerp[2]); - create_part(-1, x+r+1, y+2, playerp[2]); - create_part(-1, x-2, y+r+1, playerp[2]); - create_part(-1, x+2, y+r, playerp[2]); + create_part(-1, x+r, y-2, playerp->elem); + create_part(-1, x+r+1, y+2, playerp->elem); + create_part(-1, x-2, y+r+1, playerp->elem); + create_part(-1, x+2, y+r, playerp->elem); } kill_part(i); //Kill him return 1; @@ -71,116 +71,116 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { parts[i].vy -= gvy*dt; //Verlet integration - pp = 2*playerp[3]-playerp[5]+playerp[19]*dt*dt; - playerp[5] = playerp[3]; - playerp[3] = pp; - pp = 2*playerp[4]-playerp[6]+playerp[20]*dt*dt; - playerp[6] = playerp[4]; - playerp[4] = pp; + pp = 2*playerp->legs[0]-playerp->legs[2]+playerp->accs[0]*dt*dt; + playerp->legs[2] = playerp->legs[0]; + playerp->legs[0] = pp; + pp = 2*playerp->legs[1]-playerp->legs[3]+playerp->accs[1]*dt*dt; + playerp->legs[3] = playerp->legs[1]; + playerp->legs[1] = pp; - pp = 2*playerp[7]-playerp[9]+(playerp[21]+gvx)*dt*dt; - playerp[9] = playerp[7]; - playerp[7] = pp; - pp = 2*playerp[8]-playerp[10]+(playerp[22]+gvy)*dt*dt; - playerp[10] = playerp[8]; - playerp[8] = pp; + pp = 2*playerp->legs[4]-playerp->legs[6]+(playerp->accs[2]+gvx)*dt*dt; + playerp->legs[6] = playerp->legs[4]; + playerp->legs[4] = pp; + pp = 2*playerp->legs[5]-playerp->legs[7]+(playerp->accs[3]+gvy)*dt*dt; + playerp->legs[7] = playerp->legs[5]; + playerp->legs[5] = pp; - pp = 2*playerp[11]-playerp[13]+playerp[23]*dt*dt; - playerp[13] = playerp[11]; - playerp[11] = pp; - pp = 2*playerp[12]-playerp[14]+playerp[24]*dt*dt; - playerp[14] = playerp[12]; - playerp[12] = pp; + pp = 2*playerp->legs[8]-playerp->legs[10]+playerp->accs[4]*dt*dt; + playerp->legs[10] = playerp->legs[8]; + playerp->legs[8] = pp; + pp = 2*playerp->legs[9]-playerp->legs[11]+playerp->accs[5]*dt*dt; + playerp->legs[11] = playerp->legs[9]; + playerp->legs[9] = pp; - pp = 2*playerp[15]-playerp[17]+(playerp[25]+gvx)*dt*dt; - playerp[17] = playerp[15]; - playerp[15] = pp; - pp = 2*playerp[16]-playerp[18]+(playerp[26]+gvy)*dt*dt; - playerp[18] = playerp[16]; - playerp[16] = pp; + pp = 2*playerp->legs[12]-playerp->legs[14]+(playerp->accs[6]+gvx)*dt*dt; + playerp->legs[14] = playerp->legs[12]; + playerp->legs[12] = pp; + pp = 2*playerp->legs[13]-playerp->legs[15]+(playerp->accs[7]+gvy)*dt*dt; + playerp->legs[15] = playerp->legs[13]; + playerp->legs[13] = pp; - //Setting acceleration to 0 - playerp[19] = 0; - playerp[20] = 0; + //Setting accseleration to 0 + playerp->accs[0] = 0; + playerp->accs[1] = 0; - playerp[21] = 0; - playerp[22] = 0; + playerp->accs[2] = 0; + playerp->accs[3] = 0; - playerp[23] = 0; - playerp[24] = 0; + playerp->accs[4] = 0; + playerp->accs[5] = 0; - playerp[25] = 0; - playerp[26] = 0; + playerp->accs[6] = 0; + playerp->accs[7] = 0; - gx = (playerp[7] + playerp[15])/2 - gvy; - gy = (playerp[8] + playerp[16])/2 + gvx; - dl = pow(gx - playerp[7], 2) + pow(gy - playerp[8], 2); - dr = pow(gx - playerp[15], 2) + pow(gy - playerp[16], 2); + gx = (playerp->legs[4] + playerp->legs[12])/2 - gvy; + gy = (playerp->legs[5] + playerp->legs[13])/2 + gvx; + dl = pow(gx - playerp->legs[4], 2) + pow(gy - playerp->legs[5], 2); + dr = pow(gx - playerp->legs[12], 2) + pow(gy - playerp->legs[13], 2); //Go left - if (((int)(playerp[0])&0x01) == 0x01) + if (((int)(playerp->comm)&0x01) == 0x01) { if (dl>dr) { - if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) + if (!eval_move(PT_DUST, playerp->legs[4], playerp->legs[5], NULL)) { - playerp[21] = -3*gvy-3*gvx; - playerp[22] = 3*gvx-3*gvy; - playerp[19] = -gvy; - playerp[20] = gvx; + playerp->accs[2] = -3*gvy-3*gvx; + playerp->accs[3] = 3*gvx-3*gvy; + playerp->accs[0] = -gvy; + playerp->accs[1] = gvx; } } else { - if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + if (!eval_move(PT_DUST, playerp->legs[12], playerp->legs[13], NULL)) { - playerp[25] = -3*gvy-3*gvx; - playerp[26] = 3*gvx-3*gvy; - playerp[19] = -gvy; - playerp[20] = gvx; + playerp->accs[6] = -3*gvy-3*gvx; + playerp->accs[7] = 3*gvx-3*gvy; + playerp->accs[0] = -gvy; + playerp->accs[1] = gvx; } } } //Go right - if (((int)(playerp[0])&0x02) == 0x02) + if (((int)(playerp->comm)&0x02) == 0x02) { if (dllegs[4], playerp->legs[5], NULL)) { - playerp[21] = 3*gvy-3*gvx; - playerp[22] = -3*gvx-3*gvy; - playerp[19] = gvy; - playerp[20] = -gvx; + playerp->accs[2] = 3*gvy-3*gvx; + playerp->accs[3] = -3*gvx-3*gvy; + playerp->accs[0] = gvy; + playerp->accs[1] = -gvx; } } else { - if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + if (!eval_move(PT_DUST, playerp->legs[12], playerp->legs[13], NULL)) { - playerp[25] = 3*gvy-3*gvx; - playerp[26] = -3*gvx-3*gvy; - playerp[19] = gvy; - playerp[20] = -gvx; + playerp->accs[6] = 3*gvy-3*gvx; + playerp->accs[7] = -3*gvx-3*gvy; + playerp->accs[0] = gvy; + playerp->accs[1] = -gvx; } } } //Jump - if (((int)(playerp[0])&0x04) == 0x04 && - (!eval_move(PT_DUST, playerp[7], playerp[8], NULL) || !eval_move(PT_DUST, playerp[15], playerp[16], NULL))) + if (((int)(playerp->comm)&0x04) == 0x04 && + (!eval_move(PT_DUST, playerp->legs[4], playerp->legs[5], NULL) || !eval_move(PT_DUST, playerp->legs[12], playerp->legs[13], NULL))) { parts[i].vy -= 4*gvy; - playerp[22] -= gvy; - playerp[26] -= gvy; + playerp->accs[3] -= gvy; + playerp->accs[7] -= gvy; } //Charge detector wall if foot inside - if (bmap[(int)(playerp[8]+0.5)/CELL][(int)(playerp[7]+0.5)/CELL]==WL_DETECT) - set_emap((int)playerp[7]/CELL, (int)playerp[8]/CELL); - if (bmap[(int)(playerp[16]+0.5)/CELL][(int)(playerp[15]+0.5)/CELL]==WL_DETECT) - set_emap((int)(playerp[15]+0.5)/CELL, (int)(playerp[16]+0.5)/CELL); + if (bmap[(int)(playerp->legs[5]+0.5)/CELL][(int)(playerp->legs[4]+0.5)/CELL]==WL_DETECT) + set_emap((int)playerp->legs[4]/CELL, (int)playerp->legs[5]/CELL); + if (bmap[(int)(playerp->legs[13]+0.5)/CELL][(int)(playerp->legs[12]+0.5)/CELL]==WL_DETECT) + set_emap((int)(playerp->legs[12]+0.5)/CELL, (int)(playerp->legs[13]+0.5)/CELL); //Searching for particles near head for (rx=-2; rx<3; rx++) @@ -196,10 +196,10 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) { - playerp[2] = r&0xFF; //Current element + playerp->elem = r&0xFF; //Current element } if ((r&0xFF)==PT_TESC || (r&0xFF)==PT_LIGH) - playerp[2] = PT_LIGH; + playerp->elem = PT_LIGH; if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP { if (parts[i].life<=95) @@ -216,7 +216,7 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { kill_part(r>>8); } if (bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN) - playerp[2] = SPC_AIR; + playerp->elem = SPC_AIR; if ((r&0xFF)==PT_PRTI) STKM_interact(playerp, i, rx, ry); if (!parts[i].type)//STKM_interact may kill STKM @@ -224,31 +224,31 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { } //Head position - rx = x + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01); - ry = y - 3*(playerp[1] == 0); + rx = x + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01); + ry = y - 3*(playerp->pcomm == 0); //Spawn - if (((int)(playerp[0])&0x08) == 0x08) + if (((int)(playerp->comm)&0x08) == 0x08) { ry -= 2*(rand()%2)+1; r = pmap[ry][rx]; if (ptypes[r&0xFF].state == ST_SOLID) { create_part(-1, rx, ry, PT_SPRK); - playerp[28] = 0; + playerp->frames = 0; } else { int np = -1; - if (playerp[2] == SPC_AIR) - create_parts(rx + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0); - else if (playerp[2]==PT_LIGH && playerp[28]<30)//limit lightning creation rate + if (playerp->elem == SPC_AIR) + create_parts(rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0); + else if (playerp->elem==PT_LIGH && playerp->frames<30)//limit lightning creation rate np = -1; else - np = create_part(-1, rx, ry, playerp[2]); + np = create_part(-1, rx, ry, playerp->elem); if ( (np < NPART) && np>=0) { - if (playerp[2] == PT_PHOT) + if (playerp->elem == PT_PHOT) { int random = abs(rand()%3-1)*3; if (random==0) @@ -258,13 +258,13 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { else { parts[np].vy = 0; - if (((int)playerp[1])&(0x01|0x02)) - parts[np].vx = (((((int)playerp[1])&0x02) == 0x02) - (((int)(playerp[1])&0x01) == 0x01))*random; + if (((int)playerp->pcomm)&(0x01|0x02)) + parts[np].vx = (((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random; else parts[np].vx = random; } } - else if (playerp[2] == PT_LIGH) + else if (playerp->elem == PT_LIGH) { float angle; int power = 100; @@ -272,7 +272,7 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { angle = atan2(gvx, gvy)*180.0f/M_PI; else angle = rand()%360; - if (((int)playerp[1])&0x01) + if (((int)playerp->comm)&0x01) angle += 180; if (angle>360) angle-=360; @@ -283,72 +283,72 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { parts[np].temp=parts[np].life*power/2.5; parts[np].tmp2=1; } - else if (playerp[2] != SPC_AIR) + else if (playerp->elem != SPC_AIR) { - parts[np].vx -= -gvy*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01)); - parts[np].vy -= gvx*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01)); - parts[i].vx -= (ptypes[(int)playerp[2]].weight*parts[np].vx)/1000; + parts[np].vx -= -gvy*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01)); + parts[np].vy -= gvx*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01)); + parts[i].vx -= (ptypes[(int)playerp->elem].weight*parts[np].vx)/1000; } - playerp[28] = 0; + playerp->frames = 0; } } } //Simulation of joints - d = 25/(pow((playerp[3]-playerp[7]), 2) + pow((playerp[4]-playerp[8]), 2)+25) - 0.5; //Fast distance - playerp[7] -= (playerp[3]-playerp[7])*d; - playerp[8] -= (playerp[4]-playerp[8])*d; - playerp[3] += (playerp[3]-playerp[7])*d; - playerp[4] += (playerp[4]-playerp[8])*d; + d = 25/(pow((playerp->legs[0]-playerp->legs[4]), 2) + pow((playerp->legs[1]-playerp->legs[5]), 2)+25) - 0.5; //Fast distance + playerp->legs[4] -= (playerp->legs[0]-playerp->legs[4])*d; + playerp->legs[5] -= (playerp->legs[1]-playerp->legs[5])*d; + playerp->legs[0] += (playerp->legs[0]-playerp->legs[4])*d; + playerp->legs[1] += (playerp->legs[1]-playerp->legs[5])*d; - d = 25/(pow((playerp[11]-playerp[15]), 2) + pow((playerp[12]-playerp[16]), 2)+25) - 0.5; - playerp[15] -= (playerp[11]-playerp[15])*d; - playerp[16] -= (playerp[12]-playerp[16])*d; - playerp[11] += (playerp[11]-playerp[15])*d; - playerp[12] += (playerp[12]-playerp[16])*d; + d = 25/(pow((playerp->legs[8]-playerp->legs[12]), 2) + pow((playerp->legs[9]-playerp->legs[13]), 2)+25) - 0.5; + playerp->legs[12] -= (playerp->legs[8]-playerp->legs[12])*d; + playerp->legs[13] -= (playerp->legs[9]-playerp->legs[13])*d; + playerp->legs[8] += (playerp->legs[8]-playerp->legs[12])*d; + playerp->legs[9] += (playerp->legs[9]-playerp->legs[13])*d; - d = 36/(pow((playerp[3]-parts[i].x), 2) + pow((playerp[4]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (playerp[3]-parts[i].x)*d; - parts[i].vy -= (playerp[4]-parts[i].y)*d; - playerp[3] += (playerp[3]-parts[i].x)*d; - playerp[4] += (playerp[4]-parts[i].y)*d; + d = 36/(pow((playerp->legs[0]-parts[i].x), 2) + pow((playerp->legs[1]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (playerp->legs[0]-parts[i].x)*d; + parts[i].vy -= (playerp->legs[1]-parts[i].y)*d; + playerp->legs[0] += (playerp->legs[0]-parts[i].x)*d; + playerp->legs[1] += (playerp->legs[1]-parts[i].y)*d; - d = 36/(pow((playerp[11]-parts[i].x), 2) + pow((playerp[12]-parts[i].y), 2)+36) - 0.5; - parts[i].vx -= (playerp[11]-parts[i].x)*d; - parts[i].vy -= (playerp[12]-parts[i].y)*d; - playerp[11] += (playerp[11]-parts[i].x)*d; - playerp[12] += (playerp[12]-parts[i].y)*d; + d = 36/(pow((playerp->legs[8]-parts[i].x), 2) + pow((playerp->legs[9]-parts[i].y), 2)+36) - 0.5; + parts[i].vx -= (playerp->legs[8]-parts[i].x)*d; + parts[i].vy -= (playerp->legs[9]-parts[i].y)*d; + playerp->legs[8] += (playerp->legs[8]-parts[i].x)*d; + playerp->legs[9] += (playerp->legs[9]-parts[i].y)*d; - if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) + if (!eval_move(PT_DUST, playerp->legs[4], playerp->legs[5], NULL)) { - playerp[7] = playerp[9]; - playerp[8] = playerp[10]; + playerp->legs[4] = playerp->legs[6]; + playerp->legs[5] = playerp->legs[7]; } - if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + if (!eval_move(PT_DUST, playerp->legs[12], playerp->legs[13], NULL)) { - playerp[15] = playerp[17]; - playerp[16] = playerp[18]; + playerp->legs[12] = playerp->legs[14]; + playerp->legs[13] = playerp->legs[15]; } //This makes stick man "pop" from obstacles - if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) + if (!eval_move(PT_DUST, playerp->legs[4], playerp->legs[5], NULL)) { float t; - t = playerp[7]; playerp[7] = playerp[9]; playerp[9] = t; - t = playerp[8]; playerp[8] = playerp[10]; playerp[10] = t; + t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t; + t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t; } - if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + if (!eval_move(PT_DUST, playerp->legs[12], playerp->legs[13], NULL)) { float t; - t = playerp[15]; playerp[15] = playerp[17]; playerp[17] = t; - t = playerp[16]; playerp[16] = playerp[18]; playerp[18] = t; + t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t; + t = playerp->legs[13]; playerp->legs[13] = playerp->legs[15]; playerp->legs[15] = t; } //Keeping legs distance - if ((pow((playerp[7] - playerp[15]), 2) + pow((playerp[8]-playerp[16]), 2))<16) + if ((pow((playerp->legs[4] - playerp->legs[12]), 2) + pow((playerp->legs[5]-playerp->legs[13]), 2))<16) { float tvx, tvy; tvx = -gvy; @@ -356,15 +356,15 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { if (tvx || tvy) { - playerp[21] -= 0.2*tvx/hypot(tvx, tvy); - playerp[22] -= 0.2*tvy/hypot(tvx, tvy); + playerp->accs[2] -= 0.2*tvx/hypot(tvx, tvy); + playerp->accs[3] -= 0.2*tvy/hypot(tvx, tvy); - playerp[25] += 0.2*tvx/hypot(tvx, tvy); - playerp[26] += 0.2*tvy/hypot(tvx, tvy); + playerp->accs[6] += 0.2*tvx/hypot(tvx, tvy); + playerp->accs[7] += 0.2*tvy/hypot(tvx, tvy); } } - if ((pow((playerp[3] - playerp[11]), 2) + pow((playerp[4]-playerp[12]), 2))<16) + if ((pow((playerp->legs[0] - playerp->legs[8]), 2) + pow((playerp->legs[1]-playerp->legs[9]), 2))<16) { float tvx, tvy; tvx = -gvy; @@ -372,27 +372,27 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { if (tvx || tvy) { - playerp[19] -= 0.2*tvx/hypot(tvx, tvy); - playerp[20] -= 0.2*tvy/hypot(tvx, tvy); + playerp->accs[0] -= 0.2*tvx/hypot(tvx, tvy); + playerp->accs[1] -= 0.2*tvy/hypot(tvx, tvy); - playerp[23] += 0.2*tvx/hypot(tvx, tvy); - playerp[24] += 0.2*tvy/hypot(tvx, tvy); + playerp->accs[4] += 0.2*tvx/hypot(tvx, tvy); + playerp->accs[5] += 0.2*tvy/hypot(tvx, tvy); } } //If legs touch something - STKM_interact(playerp, i, (int)(playerp[7]+0.5), (int)(playerp[8]+0.5)); - STKM_interact(playerp, i, (int)(playerp[15]+0.5), (int)(playerp[16]+0.5)); - STKM_interact(playerp, i, (int)(playerp[7]+0.5), (int)playerp[8]); - STKM_interact(playerp, i, (int)(playerp[15]+0.5), (int)playerp[16]); + STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)(playerp->legs[5]+0.5)); + STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)(playerp->legs[13]+0.5)); + STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)playerp->legs[5]); + STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)playerp->legs[13]); if (!parts[i].type) return 1; - parts[i].ctype = playerp[2]; + parts[i].ctype = playerp->elem; return 0; } -void STKM_interact(float* playerp, int i, int x, int y) +void STKM_interact(playerst* playerp, int i, int x, int y) { int r; if (x<0 || y<0 || x>=XRES || y>=YRES || !parts[i].type) @@ -400,15 +400,15 @@ void STKM_interact(float* playerp, int i, int x, int y) r = pmap[y][x]; if (r) { - if ((r&0xFF)==PT_SPRK && playerp[2]!=PT_LIGH) //If on charge + if ((r&0xFF)==PT_SPRK && playerp->elem!=PT_LIGH) //If on charge { parts[i].life -= (int)(rand()*20/RAND_MAX)+32; } - if (ptypes[r&0xFF].hconduct && ((playerp[2]!=PT_LIGH && parts[r>>8].temp>=323) || parts[r>>8].temp<=243)) + if (ptypes[r&0xFF].hconduct && ((playerp->elem!=PT_LIGH && parts[r>>8].temp>=323) || parts[r>>8].temp<=243)) { parts[i].life -= 2; - playerp[22] -= 1; + playerp->accs[3] -= 1; } if ((r&0xFF)==PT_ACID) //If on acid @@ -431,37 +431,37 @@ void STKM_interact(float* playerp, int i, int x, int y) { portalp[parts[r>>8].tmp][count][nnx] = parts[i]; kill_part(i); - playerp[27] = 1;//stop SPWN creating a new STKM while he is in portal + playerp->spwn = 1;//stop SPWN creating a new STKM while he is in portal break; } } } } -void STKM_init_legs(float* playerp, int i) +void STKM_init_legs(playerst* playerp, int i) { int x, y; x = (int)(parts[i].x+0.5f); y = (int)(parts[i].y+0.5f); - playerp[3] = x-1; - playerp[4] = y+6; - playerp[5] = x-1; - playerp[6] = y+6; + playerp->legs[0] = x-1; + playerp->legs[1] = y+6; + playerp->legs[2] = x-1; + playerp->legs[3] = y+6; - playerp[7] = x-3; - playerp[8] = y+12; - playerp[9] = x-3; - playerp[10] = y+12; + playerp->legs[4] = x-3; + playerp->legs[5] = y+12; + playerp->legs[6] = x-3; + playerp->legs[7] = y+12; - playerp[11] = x+1; - playerp[12] = y+6; - playerp[13] = x+1; - playerp[14] = y+6; + playerp->legs[8] = x+1; + playerp->legs[9] = y+6; + playerp->legs[10] = x+1; + playerp->legs[11] = y+6; - playerp[15] = x+3; - playerp[16] = y+12; - playerp[17] = x+3; - playerp[18] = y+12; + playerp->legs[12] = x+3; + playerp->legs[13] = y+12; + playerp->legs[14] = x+3; + playerp->legs[15] = y+12; } diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c index b1aeb208f..e49f17039 100644 --- a/src/elements/stkm2.c +++ b/src/elements/stkm2.c @@ -1,14 +1,14 @@ #include int update_SPAWN2(UPDATE_FUNC_ARGS) { - if (!player2[27]) + if (!player2.spwn) create_part(-1, x, y, PT_STKM2); return 0; } int update_STKM2(UPDATE_FUNC_ARGS) { - run_stickman(player2, UPDATE_FUNC_SUBCALL_ARGS); + run_stickman(&player2, UPDATE_FUNC_SUBCALL_ARGS); return 0; } diff --git a/src/graphics.c b/src/graphics.c index 9e863862e..b0f38b908 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1933,8 +1933,8 @@ for (i = 0; i<=parts_lastActiveIndex; i++) { drawtext(vid, mousex-8-2*(parts[i].life<100)-2*(parts[i].life<10), mousey-12, buff, 255, 255, 255, 255); } - if ((int)player[2](nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head { sprintf(buff, "%3d", 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); } - if ((int)figh[2]elemelem].pcolors; + else pc = PIXPACK(0x8080FF); s = XRES+BARSIZE; //head draw_line(vid , nx, ny+2, nx+2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); @@ -1992,10 +1992,10 @@ for (i = 0; i<=parts_lastActiveIndex; i++) { draw_line(vid , nx, ny-2, nx-2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); draw_line(vid , nx-2, ny, nx, ny+2, PIXR(pc), PIXG(pc), PIXB(pc), s); //legs - draw_line(vid , nx, ny+3, figh[3], figh[4], 255, 255, 255, s); - draw_line(vid , figh[3], figh[4], figh[7], figh[8], 255, 255, 255, s); - draw_line(vid , nx, ny+3, figh[11], figh[12], 255, 255, 255, s); - draw_line(vid , figh[11], figh[12], figh[15], figh[16], 255, 255, 255, s); + draw_line(vid , nx, ny+3, figh->legs[0], figh->legs[1], 255, 255, 255, s); + draw_line(vid , figh->legs[0], figh->legs[1], figh->legs[4], figh->legs[5], 255, 255, 255, s); + draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], 255, 255, 255, s); + draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], 255, 255, 255, s); } if (cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY && t!=PT_PUMP && t!=PT_GPMP && t!=PT_PBCN && t!=PT_FILT && t!=PT_HSWC && t!=PT_PCLN && t!=PT_DEUT && t!=PT_WIFI && t!=PT_LIFE)//nothing display but show needed color changes { @@ -3887,10 +3887,10 @@ for (i = 0; i<=parts_lastActiveIndex; i++) { 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); + draw_line(vid , nx, ny+3, player.legs[0], player.legs[1], R, G, B, s); + draw_line(vid , player.legs[0], player.legs[1], player.legs[4], player.legs[5], R, G, B, s); + draw_line(vid , nx, ny+3, player.legs[8], player.legs[9], R, G, B, s); + draw_line(vid , player.legs[8], player.legs[9], player.legs[12], player.legs[13], R, G, B, s); } else if (t==PT_STKM2) //Stick man should be visible in heat mode { @@ -3910,15 +3910,15 @@ for (i = 0; i<=parts_lastActiveIndex; i++) { 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, player2[3], player2[4], R, G, B, s); - draw_line(vid , player2[3], player2[4], player2[7], player2[8], R, G, B, s); - draw_line(vid , nx, ny+3, player2[11], player2[12], R, G, B, s); - draw_line(vid , player2[11], player2[12], player2[15], player2[16], R, G, B, s); + draw_line(vid , nx, ny+3, player2.legs[0], player2.legs[1], R, G, B, s); + draw_line(vid , player2.legs[0], player2.legs[1], player2.legs[4], player2.legs[5], R, G, B, s); + draw_line(vid , nx, ny+3, player2.legs[8], player2.legs[9], R, G, B, s); + draw_line(vid , player2.legs[8], player2.legs[9], player2.legs[12], player2.legs[13], R, G, B, s); } else if (t==PT_FIGH) //Fighter should be visible in heat mode { char buff[10]; //Buffer for HP - float *figh = fighters[(unsigned char)parts[i].tmp]; + playerst *figh = &fighters[(unsigned char)parts[i].tmp]; if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head { @@ -3933,10 +3933,10 @@ for (i = 0; i<=parts_lastActiveIndex; i++) { draw_line(vid , nx, ny-2, nx-2, ny, R, G, B, s); draw_line(vid , nx-2, ny, nx, ny+2, R, G, B, s); //legs - draw_line(vid , nx, ny+3, figh[3], figh[4], R, G, B, s); - draw_line(vid , figh[3], figh[4], figh[7], figh[8], R, G, B, s); - draw_line(vid , nx, ny+3, figh[11], figh[12], R, G, B, s); - draw_line(vid , figh[11], figh[12], figh[15], figh[16], R, G, B, s); + draw_line(vid , nx, ny+3, figh->legs[0], figh->legs[1], R, G, B, s); + draw_line(vid , figh->legs[0], figh->legs[1], figh->legs[4], figh->legs[5], R, G, B, s); + draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], R, G, B, s); + draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], R, G, B, s); } else { diff --git a/src/interface.c b/src/interface.c index a41f2c223..2296822b5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2495,36 +2495,36 @@ int sdl_poll(void) //1 8 2 if (event.key.keysym.sym == SDLK_RIGHT) { - player[0] = (int)(player[0])|0x02; //Go right command + player.comm = (int)(player.comm)|0x02; //Go right command } if (event.key.keysym.sym == SDLK_LEFT) { - player[0] = (int)(player[0])|0x01; //Go left command + player.comm = (int)(player.comm)|0x01; //Go left command } - if (event.key.keysym.sym == SDLK_DOWN && ((int)(player[0])&0x08)!=0x08) + if (event.key.keysym.sym == SDLK_DOWN && ((int)(player.comm)&0x08)!=0x08) { - player[0] = (int)(player[0])|0x08; //Go left command + player.comm = (int)(player.comm)|0x08; //Go left command } - if (event.key.keysym.sym == SDLK_UP && ((int)(player[0])&0x04)!=0x04) + if (event.key.keysym.sym == SDLK_UP && ((int)(player.comm)&0x04)!=0x04) { - player[0] = (int)(player[0])|0x04; //Jump command + player.comm = (int)(player.comm)|0x04; //Jump command } if (event.key.keysym.sym == SDLK_d) { - player2[0] = (int)(player2[0])|0x02; //Go right command + player2.comm = (int)(player2.comm)|0x02; //Go right command } if (event.key.keysym.sym == SDLK_a) { - player2[0] = (int)(player2[0])|0x01; //Go left command + player2.comm = (int)(player2.comm)|0x01; //Go left command } - if (event.key.keysym.sym == SDLK_s && ((int)(player2[0])&0x08)!=0x08) + if (event.key.keysym.sym == SDLK_s && ((int)(player2.comm)&0x08)!=0x08) { - player2[0] = (int)(player2[0])|0x08; //Go left command + player2.comm = (int)(player2.comm)|0x08; //Go left command } - if (event.key.keysym.sym == SDLK_w && ((int)(player2[0])&0x04)!=0x04) + if (event.key.keysym.sym == SDLK_w && ((int)(player2.comm)&0x04)!=0x04) { - player2[0] = (int)(player2[0])|0x04; //Jump command + player2.comm = (int)(player2.comm)|0x04; //Jump command } break; @@ -2536,30 +2536,30 @@ int sdl_poll(void) sdl_zoom_trig = 0; if (event.key.keysym.sym == SDLK_RIGHT || event.key.keysym.sym == SDLK_LEFT) { - player[1] = player[0]; //Saving last movement - player[0] = (int)(player[0])&12; //Stop command + player.pcomm = player.comm; //Saving last movement + player.comm = (int)(player.comm)&12; //Stop command } if (event.key.keysym.sym == SDLK_UP) { - player[0] = (int)(player[0])&11; + player.comm = (int)(player.comm)&11; } if (event.key.keysym.sym == SDLK_DOWN) { - player[0] = (int)(player[0])&7; + player.comm = (int)(player.comm)&7; } if (event.key.keysym.sym == SDLK_d || event.key.keysym.sym == SDLK_a) { - player2[1] = player2[0]; //Saving last movement - player2[0] = (int)(player2[0])&12; //Stop command + player2.pcomm = player2.comm; //Saving last movement + player2.comm = (int)(player2.comm)&12; //Stop command } if (event.key.keysym.sym == SDLK_w) { - player2[0] = (int)(player2[0])&11; + player2.comm = (int)(player2.comm)&11; } if (event.key.keysym.sym == SDLK_s) { - player2[0] = (int)(player2[0])&7; + player2.comm = (int)(player2.comm)&7; } break; case SDL_MOUSEBUTTONDOWN: diff --git a/src/main.c b/src/main.c index f8587cabf..ed5b91cfa 100644 --- a/src/main.c +++ b/src/main.c @@ -980,21 +980,19 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char // no more particle properties to load, so we can change type here without messing up loading if (i && i<=NPART) { - if ((player[27] == 1 && ty==PT_STKM) || (player2[27] == 1 && ty==PT_STKM2)) + if ((player.spwn == 1 && ty==PT_STKM) || (player2.spwn == 1 && ty==PT_STKM2)) { parts[i-1].type = PT_NONE; } else if (parts[i-1].type == PT_STKM) { - //player[2] = PT_DUST; - STKM_init_legs(player, i-1); - player[27] = 1; + STKM_init_legs(&player, i-1); + player.spwn = 1; } else if (parts[i-1].type == PT_STKM2) { - //player2[2] = PT_DUST; - STKM_init_legs(player2, i-1); - player2[27] = 1; + STKM_init_legs(&player2, i-1); + player2.spwn = 1; } if (ver<48 && (ty==OLD_PT_WIND || (ty==PT_BRAY&&parts[i-1].life==0))) @@ -1116,8 +1114,8 @@ void clear_sim(void) memset(fighters, 0, sizeof(fighters)); fighcount = 0; ISSPAWN1 = ISSPAWN2 = 0; - player[27] = 0; - player2[27] = 0; + player.spwn = 0; + player2.spwn = 0; memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); memset(fire_r, 0, sizeof(fire_r)); memset(fire_g, 0, sizeof(fire_g)); @@ -1499,8 +1497,8 @@ int main(int argc, char *argv[]) pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); prepare_alpha(4, 1.0f); - player[2] = player2[2] = PT_DUST; - player[28] = player2[28] = 0; + player.elem = player2.elem = PT_DUST; + player.frames = player2.frames = 0; sprintf(ppmfilename, "%s.ppm", argv[2]); sprintf(ptifilename, "%s.pti", argv[2]); @@ -2146,7 +2144,7 @@ int main(int argc, char *argv[]) free(load_data); } } - if (sdl_key=='s' && ((sdl_mod & (KMOD_CTRL)) || !player2[27])) + if (sdl_key=='s' && ((sdl_mod & (KMOD_CTRL)) || !player2.spwn)) { if (it > 50) it = 50; @@ -2280,7 +2278,7 @@ int main(int argc, char *argv[]) bsy = 0; } } - if (sdl_key=='d' && ((sdl_mod & (KMOD_CTRL)) || !player2[27])) + if (sdl_key=='d' && ((sdl_mod & (KMOD_CTRL)) || !player2.spwn)) DEBUG_MODE = !DEBUG_MODE; if (sdl_key=='i') { @@ -2364,7 +2362,7 @@ int main(int argc, char *argv[]) } } - if (sdl_key=='w' && (!player2[27] || (sdl_mod & (KMOD_SHIFT)))) //Gravity, by Moach + if (sdl_key=='w' && (!player2.spwn || (sdl_mod & (KMOD_SHIFT)))) //Gravity, by Moach { ++gravityMode; // cycle gravity mode itc = 51; @@ -3623,19 +3621,19 @@ int main(int argc, char *argv[]) sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE); //Setting an element for the stick man - if (player[27]==0) + if (player.spwn==0) { if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) - player[2] = sr; + player.elem = sr; else - player[2] = PT_DUST; + player.elem = PT_DUST; } - if (player2[27]==0) + if (player2.spwn==0) { if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) - player2[2] = sr; + player2.elem = sr; else - player2[2] = PT_DUST; + player2.elem = PT_DUST; } } SDL_CloseAudio(); diff --git a/src/powder.c b/src/powder.c index 5e828ecf1..3343825e9 100644 --- a/src/powder.c +++ b/src/powder.c @@ -11,12 +11,10 @@ int wire_placed = 0; int lighting_recreate = 0; -//[0] is a command cell, [3]-[18] are legs positions, [19]-[26] are accelerations, [27] shows if player was spawned -//[28] is frames since last particle spawn - used when spawning LIGH -float player[29]; -float player2[29]; +playerst player; +playerst player2; -float fighters[256][29]; //255 is the maximum number of fighters +playerst fighters[256]; //255 is the maximum number of fighters unsigned char fighcount = 0; //Contains the number of fighters particle *parts; @@ -309,15 +307,15 @@ int try_move(int i, int x, int y, int nx, int ny) { if (parts[i].type == PT_STKM) { - player[27] = 0; + player.spwn = 0; } if (parts[i].type == PT_STKM2) { - player2[27] = 0; + player2.spwn = 0; } if (parts[i].type == PT_FIGH) { - fighters[(unsigned char)parts[i].tmp][27] = 0; + fighters[(unsigned char)parts[i].tmp].spwn = 0; fighcount--; } parts[i].type=PT_NONE; @@ -327,15 +325,15 @@ int try_move(int i, int x, int y, int nx, int ny) { if (parts[i].type == PT_STKM) { - player[27] = 0; + player.spwn = 0; } if (parts[i].type == PT_STKM2) { - player2[27] = 0; + player2.spwn = 0; } if (parts[i].type == PT_FIGH) { - fighters[(unsigned char)parts[i].tmp][27] = 0; + fighters[(unsigned char)parts[i].tmp].spwn = 0; fighcount--; } parts[i].type=PT_NONE; @@ -601,15 +599,15 @@ void kill_part(int i)//kills particle number i y = (int)(parts[i].y+0.5f); if (parts[i].type == PT_STKM) { - player[27] = 0; + player.spwn = 0; } if (parts[i].type == PT_STKM2) { - player2[27] = 0; + player2.spwn = 0; } if (parts[i].type == PT_FIGH) { - fighters[(unsigned char)parts[i].tmp][27] = 0; + fighters[(unsigned char)parts[i].tmp].spwn = 0; fighcount--; } if (parts[i].type == PT_SPAWN) @@ -648,14 +646,14 @@ inline void part_change_type(int i, int x, int y, int t)//changes the type of pa t = PT_NONE; if (parts[i].type == PT_STKM) - player[27] = 0; + player.spwn = 0; if (parts[i].type == PT_STKM2) - player2[27] = 0; + player2.spwn = 0; if (parts[i].type == PT_FIGH) { - fighters[(unsigned char)parts[i].tmp][27] = 0; + fighters[(unsigned char)parts[i].tmp].spwn = 0; fighcount--; } @@ -987,7 +985,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a } if (t==PT_STKM) { - if (player[27]==0) + if (player.spwn==0) { parts[i].x = (float)x; parts[i].y = (float)y; @@ -997,8 +995,8 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a parts[i].life = 100; parts[i].ctype = 0; parts[i].temp = ptypes[t].heat; - STKM_init_legs(player, i); - player[27] = 1; + STKM_init_legs(&player, i); + player.spwn = 1; } else { @@ -1009,7 +1007,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a } if (t==PT_STKM2) { - if (player2[27]==0) + if (player2.spwn==0) { parts[i].x = (float)x; parts[i].y = (float)y; @@ -1019,8 +1017,8 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a parts[i].life = 100; parts[i].ctype = 0; parts[i].temp = ptypes[t].heat; - STKM_init_legs(player2, i); - player2[27] = 1; + STKM_init_legs(&player2, i); + player2.spwn = 1; } else { @@ -1032,8 +1030,8 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a if (t==PT_FIGH) { unsigned char cunt = 0; - while (cunt < 100 && cunt < (fighcount+1) && fighters[cunt][27]==1) cunt++; - if (cunt < 100 && fighters[cunt][27]==0) + while (cunt < 100 && cunt < (fighcount+1) && fighters[cunt].spwn==1) cunt++; + if (cunt < 100 && fighters[cunt].spwn==0) { parts[i].x = (float)x; parts[i].y = (float)y; @@ -1044,9 +1042,9 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a parts[i].ctype = 0; parts[i].tmp = cunt; parts[i].temp = ptypes[t].heat; - STKM_init_legs(fighters[cunt], i); - fighters[cunt][27] = 1; - fighters[cunt][2] = PT_DUST; + STKM_init_legs(&fighters[cunt], i); + fighters[cunt].spwn = 1; + fighters[cunt].elem = PT_DUST; fighcount++; return i; From 8c25ef733c9fc1424a14e98ed20d2400bdfa5e3a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 26 Oct 2011 16:03:05 +0100 Subject: [PATCH 7/9] Revert "F1 to bring up intro message" This reverts commit f8d54e66dba5d8448d30f61f84883b4e7e6e1087. --- src/main.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index ed5b91cfa..3cccd434d 100644 --- a/src/main.c +++ b/src/main.c @@ -2415,22 +2415,10 @@ int main(int argc, char *argv[]) if (sdl_key==SDLK_SPACE) sys_pause = !sys_pause; if (sdl_key=='u') + aheat_enable = !aheat_enable; - if (sdl_key=='h' && !(sdl_mod & KMOD_LCTRL)) - { + if (sdl_key=='h') hud_enable = !hud_enable; - } - if (sdl_key==SDLK_F1 || (sdl_key=='h' && (sdl_mod & KMOD_LCTRL))) - { - if(!it) - { - it = 8047; - } - else - { - it = 0; - } - } if (sdl_key=='n') pretty_powder = !pretty_powder; if (sdl_key=='p') From e3a7b626ab6e8c97f8519c1bcca85667da6a265a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 26 Oct 2011 16:05:23 +0100 Subject: [PATCH 8/9] Revert "Revert "F1 to bring up intro message"" This reverts commit 8c25ef733c9fc1424a14e98ed20d2400bdfa5e3a. --- src/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 3cccd434d..ed5b91cfa 100644 --- a/src/main.c +++ b/src/main.c @@ -2415,10 +2415,22 @@ int main(int argc, char *argv[]) if (sdl_key==SDLK_SPACE) sys_pause = !sys_pause; if (sdl_key=='u') - aheat_enable = !aheat_enable; - if (sdl_key=='h') + if (sdl_key=='h' && !(sdl_mod & KMOD_LCTRL)) + { hud_enable = !hud_enable; + } + if (sdl_key==SDLK_F1 || (sdl_key=='h' && (sdl_mod & KMOD_LCTRL))) + { + if(!it) + { + it = 8047; + } + else + { + it = 0; + } + } if (sdl_key=='n') pretty_powder = !pretty_powder; if (sdl_key=='p') From 60de1cf5754d8132a7bf5b6868df34babe66397b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 26 Oct 2011 16:24:54 +0100 Subject: [PATCH 9/9] Fix graphics.c --- src/graphics.c | 1183 +++++++++++++++++++++++------------------------- 1 file changed, 564 insertions(+), 619 deletions(-) diff --git a/src/graphics.c b/src/graphics.c index b0f38b908..c208cfd7f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1017,103 +1017,25 @@ inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) if (!bn) { ba = *(rp++); - bn = 8; + bn = 8; + } + drawpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3); + ba >>= 2; + bn -= 2; } - drawpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3); - ba >>= 2; - bn -= 2; - } -return x + w; + return x + w; } int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a) { #ifdef OpenGL #else -int sx = x; -for (; *s; s++) -{ - if (*s == '\n') - { - x = sx; - y += FONT_H+2; - } - else if (*s == '\b') - { - switch (s[1]) - { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'b': - r = g = 0; - b = 255; - break; - case 't': - b = 255; - g = 170; - r = 32; - break; - } - s++; - } - else - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); -} -#endif -return x; -} - -//Draw text with an outline -int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa) -{ -drawtext(vid, x-1, y-1, s, or, og, ob, oa); -drawtext(vid, x+1, y+1, s, or, og, ob, oa); - -drawtext(vid, x-1, y+1, s, or, og, ob, oa); -drawtext(vid, x+1, y-1, s, or, og, ob, oa); - -return drawtext(vid, x, y, s, r, g, b, a); -} -int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a) -{ -#ifdef OpenGL -#else -int sx = x; -int rh = 12; -int rw = 0; -int cw = x; -int wordlen; -int charspace; -while (*s) -{ - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx((char *)s, w-(x-cw)); - if (charspace=-1; s++) + int sx = x; + for (; *s; s++) { if (*s == '\n') { x = sx; - rw = 0; y += FONT_H+2; } else if (*s == '\b') @@ -1143,13 +1065,56 @@ while (*s) r = g = 0; b = 255; break; + case 't': + b = 255; + g = 170; + r = 32; + break; } s++; } else - { + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); + } +#endif + return x; +} - if (x-cw>=w) +//Draw text with an outline +int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa) +{ + drawtext(vid, x-1, y-1, s, or, og, ob, oa); + drawtext(vid, x+1, y+1, s, or, og, ob, oa); + + drawtext(vid, x-1, y+1, s, or, og, ob, oa); + drawtext(vid, x+1, y-1, s, or, og, ob, oa); + + return drawtext(vid, x, y, s, r, g, b, a); +} +int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a) +{ +#ifdef OpenGL +#else + int sx = x; + int rh = 12; + int rw = 0; + int cw = x; + int wordlen; + int charspace; + while (*s) + { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx((char *)s, w-(x-cw)); + if (charspace=-1; s++) + { + if (*s == '\n') { x = sx; rw = 0; @@ -1202,38 +1167,36 @@ while (*s) } x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } } -} -return rh; -#endif + return rh; + #endif } //draws a rectange, (x,y) are the top left coords. void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) { #ifdef OpenGL -glBegin(GL_LINE_LOOP); -glColor4ub(r, g, b, a); -glVertex2i(x, y); -glVertex2i(x+w, y); -glVertex2i(x+w, y+h); -glVertex2i(x, y+h); -glEnd(); + glBegin(GL_LINE_LOOP); + glColor4ub(r, g, b, a); + glVertex2i(x, y); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glVertex2i(x, y+h); + glEnd(); #else -int i; -for (i=0; i<=w; i++) -{ - drawpixel(vid, x+i, y, r, g, b, a); - drawpixel(vid, x+i, y+h, r, g, b, a); -} -for (i=1; i=w && x+textwidth(s)>=w+5) - break; - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); -} -if (*s) - for (i=0; i<3; i++) - x = drawchar(vid, x, y, '.', r, g, b, a); -return x; + int i; + w += x-5; + for (; *s; s++) + { + if (x+font_data[font_ptrs[(int)(*(unsigned char *)s)]]>=w && x+textwidth(s)>=w+5) + break; + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); + } + if (*s) + for (i=0; i<3; i++) + x = drawchar(vid, x, y, '.', r, g, b, a); + return x; } int textnwidth(char *s, int n) { -int x = 0; -for (; *s; s++) -{ - if (!n) - break; - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - n--; -} -return x-1; + int x = 0; + for (; *s; s++) + { + if (!n) + break; + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + n--; + } + return x-1; } void textnpos(char *s, int n, int w, int *cx, int *cy) { -int x = 0; -int y = 0; -int wordlen, charspace; -while (*s&&n) -{ - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, w-x); - if (charspace=-1; s++) - { - if (!n) { - break; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x>=w) + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-x); + if (charspace=-1; s++) + { + if (!n) { + break; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x>=w) + { + x = 0; + y += FONT_H+2; + } + n--; + } } -} -*cx = x-1; -*cy = y; + *cx = x-1; + *cy = y; } int textwidthx(char *s, int w) { -int x=0,n=0,cw; -for (; *s; s++) -{ - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+(cw/2) >= w) - break; - x += cw; - n++; -} -return n; + int x=0,n=0,cw; + for (; *s; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+(cw/2) >= w) + break; + x += cw; + n++; + } + return n; } int textposxy(char *s, int width, int w, int h) { -int x=0,y=0,n=0,cw, wordlen, charspace; -while (*s) -{ - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, width-x); - if (charspace=-1; s++) - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) - return n++; - x += cw; - if (x>=width) { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) + return n++; + x += cw; + if (x>=width) { + x = 0; + y += FONT_H+2; + } + n++; + } } -} -return n; + return n; } int textwrapheight(char *s, int width) { -int x=0, height=FONT_H+2, cw; -int wordlen; -int charspace; -while (*s) -{ - wordlen = strcspn(s," .,!?\n"); - charspace = textwidthx(s, width-x); - if (charspace=-1; s++) - { - if (*s == '\n') + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) { - s++; - } - else - { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+cw>=width) + if (*s == '\n') { x = 0; height += FONT_H+2; } - x += cw; + else if (*s == '\b') + { + s++; + } + else + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x+cw>=width) + { + x = 0; + height += FONT_H+2; + } + x += cw; + } } } -} -return height; + return height; } //the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented. @@ -1461,127 +1424,120 @@ inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag) { -char t[2]; -t[0] = ch; -t[1] = 0; -if (flag) -{ - fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255); - drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255); -} -else -{ - drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255); - drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255); -} + char t[2]; + t[0] = ch; + t[1] = 0; + if (flag) + { + fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255); + } + else + { + drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255); + } } void draw_air(pixel *vid) { -int x, y, i, j; -pixel c; + int x, y, i, j; + pixel c; -if (cmode == CM_PERS)//this should never happen anyway - return; + if (cmode == CM_PERS)//this should never happen anyway + return; -for (y=0; y 0.0f) - c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! - else - c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! - } - else if (cmode == CM_VEL) - { - c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green - clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (cmode == CM_HEAT && aheat_enable) - { - float ttemp = hv[y][x]+(-MIN_TEMP); - int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); - c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); - //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green - // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue - } - else if (cmode == CM_CRACK) - { - int r; - int g; - int b; - // velocity adds grey - r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); - b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); - if (pv[y][x] > 0.0f) + if (cmode == CM_PRESS) { - r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); + if (pv[y][x] > 0.0f) + c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red! + else + c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue! } - else + else if (cmode == CM_VEL) { - b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! - if (r>255) - r=255; - if (g>255) - g=255; - if (b>255) - b=255; - c = PIXRGB(r, g, b); + c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green + clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue } + else if (cmode == CM_HEAT && aheat_enable) + { + float ttemp = hv[y][x]+(-MIN_TEMP); + int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); + //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green + // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (cmode == CM_CRACK) + { + int r; + int g; + int b; + // velocity adds grey + r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); + b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); + if (pv[y][x] > 0.0f) + { + r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + else + { + b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue! + if (r>255) + r=255; + if (g>255) + g=255; + if (b>255) + b=255; + c = PIXRGB(r, g, b); + } + } + for (j=0; jdx) -{ - dx = dx+dy; - dy = dx-dy; - dx = dx-dy; - check = 1; -} - -e = (dy<<2)-dx; -for (i=0; i<=dx; i++) -{ - if (x>=0 && y>=0 && x=0) + if (dy>dx) { - if (check==1) - x = x+sx; - else - y = y+sy; - e = e-(dx<<2); + dx = dx+dy; + dy = dx-dy; + dx = dx-dy; + check = 1; + } + + e = (dy<<2)-dx; + for (i=0; i<=dx; i++) + { + if (x>=0 && y>=0 && x=0) + { + if (check==1) + x = x+sx; + else + y = y+sy; + e = e-(dx<<2); + } + if (check==1) + y = y+sy; + else + x = x+sx; + e = e+(dy<<2); } - if (check==1) - y = y+sy; - else - x = x+sx; - e = e+(dy<<2); -} } //adds color to a pixel, does not overwrite. void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a) { -pixel t; -if (x<0 || y<0 || x>=XRES || y>=YRES) - return; -t = vid[y*(XRES+BARSIZE)+x]; -r = (a*r + 255*PIXR(t)) >> 8; -g = (a*g + 255*PIXG(t)) >> 8; -b = (a*b + 255*PIXB(t)) >> 8; -if (r>255) - r = 255; -if (g>255) - g = 255; -if (b>255) - b = 255; -vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); + pixel t; + if (x<0 || y<0 || x>=XRES || y>=YRES) + return; + t = vid[y*(XRES+BARSIZE)+x]; + r = (a*r + 255*PIXR(t)) >> 8; + g = (a*g + 255*PIXG(t)) >> 8; + b = (a*b + 255*PIXB(t)) >> 8; + if (r>255) + r = 255; + if (g>255) + g = 255; + if (b>255) + b = 255; + vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); } //draws one of two colors, so that it is always clearly visible void xor_pixel(int x, int y, pixel *vid) { -int c; -if (x<0 || y<0 || x>=XRES || y>=YRES) - return; -c = vid[y*(XRES+BARSIZE)+x]; -c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); -if (c<512) - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0); -else - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); + int c; + if (x<0 || y<0 || x>=XRES || y>=YRES) + return; + c = vid[y*(XRES+BARSIZE)+x]; + c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); + if (c<512) + vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0); + else + vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); } //same as xor_pixel, but draws a line of it void xor_line(int x1, int y1, int x2, int y2, pixel *vid) { -int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; -float e, de; -if (cp) -{ - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; -} -if (x1 > x2) -{ - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; -} -dx = x2 - x1; -dy = abs(y2 - y1); -e = 0.0f; -if (dx) - de = dy/(float)dx; -else - de = 0.0f; -y = y1; -sy = (y1abs(x2-x1), x, y, dx, dy, sy; + float e, de; if (cp) - xor_pixel(y, x, vid); - else - xor_pixel(x, y, vid); - e += de; - if (e >= 0.5f) { - y += sy; - e -= 1.0f; + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } } -} } //same as blend_pixel, but draws a line of it void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) { -int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; -float e, de; -if (cp) -{ - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; -} -if (x1 > x2) -{ - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; -} -dx = x2 - x1; -dy = abs(y2 - y1); -e = 0.0f; -if (dx) - de = dy/(float)dx; -else - de = 0.0f; -y = y1; -sy = (y1abs(x2-x1), x, y, dx, dy, sy; + float e, de; if (cp) - blendpixel(vid, y, x, r, g, b, a); - else - blendpixel(vid, x, y, r, g, b, a); - e += de; - if (e >= 0.5f) { - y += sy; - e -= 1.0f; + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } } -} } //same as xor_pixel, but draws a rectangle void xor_rect(pixel *vid, int x, int y, int w, int h) { -int i; -for (i=0; i(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head - { - sprintf(buff, "%3d", 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); - } - - if ((int)player.elem(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + if (t==PT_STKM) { - sprintf(buff, "%3d", 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); + char buff[20]; //Buffer for HP + pixel pc; + + if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", 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); + } + + if ((int)player.elem(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + else if (t==PT_STKM2) { - sprintf(buff, "%3d", 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); + char buff[20]; //Buffer for HP + pixel pc; + + if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", 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); + } + + if ((int)player2.elemelemelem].pcolors; - else pc = PIXPACK(0x8080FF); - s = XRES+BARSIZE; - //head - draw_line(vid , nx, ny+2, nx+2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); - draw_line(vid , nx+2, ny, nx, ny-2, PIXR(pc), PIXG(pc), PIXB(pc), s); - draw_line(vid , nx, ny-2, nx-2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); - draw_line(vid , nx-2, ny, nx, ny+2, PIXR(pc), PIXG(pc), PIXB(pc), s); - //legs - draw_line(vid , nx, ny+3, figh->legs[0], figh->legs[1], 255, 255, 255, s); - draw_line(vid , figh->legs[0], figh->legs[1], figh->legs[4], figh->legs[5], 255, 255, 255, s); - draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], 255, 255, 255, s); - draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], 255, 255, 255, s); - } - if (cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY && t!=PT_PUMP && t!=PT_GPMP && t!=PT_PBCN && t!=PT_FILT && t!=PT_HSWC && t!=PT_PCLN && t!=PT_DEUT && t!=PT_WIFI && t!=PT_LIFE)//nothing display but show needed color changes + else if (t==PT_FIGH) //Fighter should be visible in heat mode + { + char buff[10]; //Buffer for HP + pixel pc; + playerst *figh = &fighters[(unsigned char)parts[i].tmp]; + + if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head + { + sprintf(buff, "%3d", 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); + } + if ((int)figh->elemelem].pcolors; + else pc = PIXPACK(0x8080FF); + s = XRES+BARSIZE; + //head + draw_line(vid , nx, ny+2, nx+2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); + draw_line(vid , nx+2, ny, nx, ny-2, PIXR(pc), PIXG(pc), PIXB(pc), s); + draw_line(vid , nx, ny-2, nx-2, ny, PIXR(pc), PIXG(pc), PIXB(pc), s); + draw_line(vid , nx-2, ny, nx, ny+2, PIXR(pc), PIXG(pc), PIXB(pc), s); + //legs + draw_line(vid , nx, ny+3, figh->legs[0], figh->legs[1], 255, 255, 255, s); + draw_line(vid , figh->legs[0], figh->legs[1], figh->legs[4], figh->legs[5], 255, 255, 255, s); + draw_line(vid , nx, ny+3, figh->legs[8], figh->legs[9], 255, 255, 255, s); + draw_line(vid , figh->legs[8], figh->legs[9], figh->legs[12], figh->legs[13], 255, 255, 255, s); + } + if (cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY && t!=PT_PUMP && t!=PT_GPMP && t!=PT_PBCN && t!=PT_FILT && t!=PT_HSWC && t!=PT_PCLN && t!=PT_DEUT && t!=PT_WIFI && t!=PT_LIFE && t!=PT_PVOD)//nothing display but show needed color changes { if (t==PT_PHOT) {