- Mòdul del logo de 'JAILGAMES' fet

This commit is contained in:
2024-07-05 13:51:23 +02:00
parent c48ba26b64
commit 0cee2e3c36
8 changed files with 165 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ floor.gif
font.gif
font2.gif
gat.gif
jailgames.gif
objectes.gif
obrer.gif
roomaux.gif

BIN
data/jailgames.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

View File

@@ -262,6 +262,11 @@ namespace draw
free(buffer);
}
void setPaletteColor(const uint8_t index, const uint8_t r, const uint8_t g, const uint8_t b)
{
palette[index] = (r<<16) + (g<<8) + b;
}
// Esborra la superficie "destination" amb el color especificat
void cls(const uint8_t color)
{
@@ -269,7 +274,7 @@ namespace draw
const int size = destination->w * destination->h;
// Omplim la memòria dels pixels de la superficie de destinació amb "color"
memset(destination->pixels, color, size);
memset(destination->pixels, color_indices[color], size);
}
//Estableix el color especificat com a transparent
@@ -298,7 +303,7 @@ namespace draw
}
}
// Funció interna per a llegir un pixel d'una superficie eixir-se'n de la memòria i petar el mame
// Funció interna per a llegir un pixel d'una superficie sense eixir-se'n de la memòria i petar el mame
const uint8_t pget(surface *surface, const int x, const int y)
{
// Si està fora de la surface, directament passem
@@ -399,6 +404,11 @@ namespace draw
vline(x+w-1,y,h);
}
void pset(const int x, const int y, const uint8_t color)
{
pset(destination, x, y, color);
}
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)
{
surface* tmp = source;

View File

@@ -77,6 +77,8 @@ namespace draw
/// @param filename nom de l'arxiu GIF d'on carregar la paleta
void loadPalette(const std::string &filename);
void setPaletteColor(const uint8_t index, const uint8_t r, const uint8_t g, const uint8_t b);
/// @brief Esborra la superficie "destination" amb el color especificat
/// @param color color a usar per a borrar la superficie de destinació
void cls(const uint8_t color);
@@ -103,6 +105,8 @@ namespace draw
void fillrect(const int x, const int y, const int w, const int h);
void rect(const int x, const int y, const int w, const int h);
void pset(const int x, const int y, const uint8_t color);
void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
void print2(const char* text, const int x, const int y, const uint8_t color, const int zoom);
void print2(const int num, const int positions, const int x, const int y, const uint8_t color, const int zoom);

View File

@@ -3,6 +3,7 @@
#include "room.h"
#include "jui.h"
#include "jinput.h"
#include "jgame.h"
#include "console.h"
#include "editor.h"
@@ -17,6 +18,8 @@ namespace modules
void init()
{
::game::setUpdateTicks(64);
if (editor::isDevMode()) {
actor::templates::load();

120
source/m_logo.cpp Normal file
View File

@@ -0,0 +1,120 @@
#include "m_logo.h"
#include "jdraw.h"
#include "jinput.h"
#include <SDL2/SDL.h>
namespace modules
{
namespace logo
{
struct pixel_t
{
int x, y;
float distance;
float angle;
float di, dd, ai, ad;
};
pixel_t pixels[200];
int num_pixels = 0;
float d = 1;
float a = 0;
void get_dist_angle_from_xy(int pixel);
void calculate_coords_from_dist_angle(int pixel);
void init()
{
srand(SDL_GetTicks());
num_pixels = 0;
draw::surface *surf = draw::getSurface("jailgames.gif");
for (int y=0; y<surf->h; ++y)
for (int x=0; x<surf->w; ++x)
if (surf->pixels[x+y*surf->w]!=0)
{
pixels[num_pixels].x = x;
pixels[num_pixels].y = y;
get_dist_angle_from_xy(num_pixels);
pixels[num_pixels].dd = float((rand()%5)+1)/100.0f;
pixels[num_pixels].ad = float((rand()%10)+1);
pixels[num_pixels].di = 1;
pixels[num_pixels].ai = 0;
for (int i=0; i<40; ++i)
{
pixels[num_pixels].di += pixels[num_pixels].dd;
pixels[num_pixels].ai += pixels[num_pixels].ad;
}
num_pixels++;
}
}
int steps=0;
bool loop()
{
if (input::keyDown(SDL_SCANCODE_ESCAPE)) {
return false;
}
draw::cls(2);
draw::color(1);
if (steps < 40) {
for (int i=0; i<num_pixels; ++i)
{
calculate_coords_from_dist_angle(i);
draw::swapcol(1, 12+(steps/5));
draw::fillrect(60+pixels[i].x*4, 106+pixels[i].y*4, 4*pixels[i].di, 4*pixels[i].di);
pixels[i].di -= pixels[i].dd;
pixels[i].ai -= pixels[i].ad;
}
} else if (steps<56) {
draw::swapcol(1, 12+(steps-40)/2);
draw::swapcol(2, 19-(steps-40)/2);
for (int i=0; i<num_pixels; ++i)
{
pixels[i].di = 1;
pixels[i].ai = 0;
calculate_coords_from_dist_angle(i);
draw::fillrect(60+pixels[i].x*4, 106+pixels[i].y*4, 4*pixels[i].di, 4*pixels[i].di);
}
} else if (steps<200) {
draw::swapcol(1,WHITE+LIGHT);
draw::swapcol(2,BLACK);
for (int i=0; i<num_pixels; ++i)
{
draw::fillrect(60+pixels[i].x*4, 106+pixels[i].y*4, 4*pixels[i].di, 4*pixels[i].di);
}
} else if (steps<216) {
draw::swapcol(1, 19-(steps-200)/2);
for (int i=0; i<num_pixels; ++i)
{
draw::fillrect(60+pixels[i].x*4, 106+pixels[i].y*4, 4*pixels[i].di, 4*pixels[i].di);
}
} else {
return false;
}
draw::render();
steps++;
return true;
}
void get_dist_angle_from_xy(int pixel)
{
int x = pixels[pixel].x - 25;
int y = 3 - pixels[pixel].y;
pixels[pixel].distance = sqrtf(x*x + y*y);
pixels[pixel].angle = atan2f(y, x)/(M_PI/180.0f);
}
void calculate_coords_from_dist_angle(int pixel)
{
pixels[pixel].x = 25 + roundf(cosf((pixels[pixel].angle+pixels[pixel].ai)*(M_PI/180.0f)) * (pixels[pixel].distance*pixels[pixel].di));
pixels[pixel].y = 3 - roundf(sinf((pixels[pixel].angle+pixels[pixel].ai)*(M_PI/180.0f)) * (pixels[pixel].distance*pixels[pixel].di));
}
}
}

10
source/m_logo.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
namespace modules
{
namespace logo
{
void init();
bool loop();
}
}

View File

@@ -5,6 +5,11 @@
#include "string.h"
#include "m_game.h"
#include "m_logo.h"
#define M_LOGO 0
#define M_GAME 1
int current_module = M_LOGO;
void game::init()
{
@@ -18,12 +23,19 @@ void game::init()
}
draw::loadPalette("test.gif");
game::setUpdateTicks(64);
modules::game::init();
modules::logo::init();
}
bool game::loop()
{
switch(current_module)
{
case M_LOGO:
if (!modules::logo::loop()) { modules::game::init(); current_module = M_GAME; }
break;
case M_GAME:
return modules::game::loop();
};
return true;
}