From 185ee3797d14dec3062505caf8b8d7febf31a704 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sun, 22 Oct 2023 10:48:21 +0200 Subject: [PATCH] =?UTF-8?q?-=20Creat=20m=C3=B2dul=20proc=5Fexplosio=20per?= =?UTF-8?q?=20a=20vore=20pixels=20volant=20quan=20se=20trenca=20algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/proc_arounders.cpp | 7 ++++ source/proc_explosio.cpp | 74 +++++++++++++++++++++++++++++++++++++++ source/proc_explosio.h | 8 +++++ 3 files changed, 89 insertions(+) create mode 100644 source/proc_explosio.cpp create mode 100644 source/proc_explosio.h diff --git a/source/proc_arounders.cpp b/source/proc_arounders.cpp index c2a7faf..125644d 100644 --- a/source/proc_arounders.cpp +++ b/source/proc_arounders.cpp @@ -1,6 +1,7 @@ #include "proc_arounders.h" #include "jgame.h" #include "proc_mapa.h" +#include "proc_explosio.h" namespace arounders { @@ -108,6 +109,7 @@ namespace arounders draw::setSource(marca); draw::draw(arounders::seleccionat->x-3, arounders::seleccionat->y-3); } + explosio::pintar(); } const bool seleccionar() @@ -213,6 +215,7 @@ namespace arounders draw::draw(a->x-9, a->y-12); draw::setTrans(0); draw::setDestination(nullptr); + explosio::crear(a->x+4, a->y+3, 20, 200, 20, 0); mapa::arounders::morts++; } @@ -862,6 +865,7 @@ namespace arounders void doCavar(arounder *a) { if (a->orientacio == arounders::orientacions::dreta) { + explosio::crear(a->x+8, a->y, 10, 200, 10, 3); put_pixel(a->x+8, a->y, 0); put_pixel(a->x+8, a->y+1, 0); put_pixel(a->x+8, a->y+2, 0); @@ -871,6 +875,7 @@ namespace arounders put_pixel(a->x+8, a->y+6, 0); put_pixel(a->x+8, a->y+7, 0); } else { + explosio::crear(a->x-1, a->y, 10, 200, 10, 3); put_pixel(a->x-1, a->y, 0); put_pixel(a->x-1, a->y+1, 0); put_pixel(a->x-1, a->y+2, 0); @@ -880,10 +885,12 @@ namespace arounders put_pixel(a->x-1, a->y+6, 0); put_pixel(a->x-1, a->y+7, 0); } + } void doPerforar(arounder *a) { + explosio::crear(a->x+4, a->y+8, 10, 200, 10, 3); put_pixel(a->x , a->y+8, 0); put_pixel(a->x+1, a->y+8, 0); put_pixel(a->x+2, a->y+8, 0); diff --git a/source/proc_explosio.cpp b/source/proc_explosio.cpp new file mode 100644 index 0000000..c1e49f5 --- /dev/null +++ b/source/proc_explosio.cpp @@ -0,0 +1,74 @@ +#include "proc_explosio.h" +#include +#include "jgame.h" + +namespace explosio +{ + struct tipo_pix // Cada pixel de la explosió + { + float x, y; + float xa, ya; + float g; + uint8_t c; + }; + + struct tipo_exp // Tipo per a les explosions + { + int numpix; + tipo_pix pix[50]; + int count; + }; + + static tipo_exp exp[10]; + static int numexp {0}; + + void crear(const int x, const int y, const int num, const int c1, const int c2, const int c3) + { + if ( numexp >= 9 || numexp < 0 ) return; + + exp[numexp].count = 0; + exp[numexp].numpix = num*2; + const int expansio = c2*100; + for (int i=0; i<=exp[numexp].numpix; ++i) + { + exp[numexp].pix[i].x = x; + exp[numexp].pix[i].y = y; + exp[numexp].pix[i].xa = float((rand()%expansio) - (expansio >> 1))/1000.0f; + exp[numexp].pix[i].ya = float((rand()%expansio) - (expansio >> 1))/1000.0f; + exp[numexp].pix[i].g = 0.05; + exp[numexp].pix[i].c = rand()%60; + } + numexp++; + } + + void pintar() + { + int c1 = 0; + + while (c1 != numexp) + { + for (int c2=0; c2<=exp[c1].numpix; ++c2) + { + exp[c1].pix[c2].x = exp[c1].pix[c2].x + exp[c1].pix[c2].xa; + exp[c1].pix[c2].ya = exp[c1].pix[c2].ya + exp[c1].pix[c2].g; + exp[c1].pix[c2].y = exp[c1].pix[c2].y + exp[c1].pix[c2].ya; + //if ((exp[c1].pix[c2].x > 0) && (exp[c1].pix[c2].x < 319) && (exp[c1].pix[c2].y > 0) && (exp[c1].pix[c2].y < 199)) + draw::putPixel(exp[c1].pix[c2].x, exp[c1].pix[c2].y, exp[c1].pix[c2].c); + } + exp[c1].count++; + + c1++; + + if (exp[c1-1].count == 80) + { + numexp--; + c1--; + if (c1 != numexp) + { + exp[c1] = exp[numexp]; + } + } + } + } + +} \ No newline at end of file diff --git a/source/proc_explosio.h b/source/proc_explosio.h new file mode 100644 index 0000000..b6f168d --- /dev/null +++ b/source/proc_explosio.h @@ -0,0 +1,8 @@ +#pragma once + +namespace explosio +{ + void crear(const int x, const int y, const int num, const int c1, const int c2, const int c3); + + void pintar(); +} \ No newline at end of file