Prepare stuff for mode of Shmup

This commit is contained in:
Sylvain PILLOT 2023-08-25 10:33:52 +02:00
parent 51536e6dcd
commit 5b83f8f2a8
13 changed files with 219 additions and 130 deletions

View File

@ -4,6 +4,7 @@
## Engine
- [DONE] better keyboard management engine for keypressed() and keyreleased() events
- Mettre une système d'ajustement de FPS mini avec switch des niveaux d'overclock à la volée de manière dynamique
- [DONE] Mettre en place un système de collision en "pixel perfect" pour mode jeu "Asteroids Alert !!!"
## Partie décors :
@ -26,7 +27,7 @@
- implémenter les collisions de bullets avec les satellites pour que ceux-ci perdent de la vie aussi
- implémenter le tir des satellites
- [DONE] implémenter un système de bonus (points, upgrade tir/satellites/... )
- implémenter un système d'amélioration de compétence de tirs (bullet -> mega bullet -> laser -> )
- implémenter un système d'amélioration de compétence de tirs (bullet -> mega bullet -> laser -> mega laser -> bomb -> etc.)
- implémenter un système d'animation du vaisseau (réacteurs par exemple)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,112 +0,0 @@
{ "frames": {
"asteroide1_12frames 0.ase": {
"frame": { "x": 0, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 1.ase": {
"frame": { "x": 32, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 2.ase": {
"frame": { "x": 64, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 3.ase": {
"frame": { "x": 96, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 4.ase": {
"frame": { "x": 128, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 5.ase": {
"frame": { "x": 160, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 6.ase": {
"frame": { "x": 192, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 7.ase": {
"frame": { "x": 224, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 8.ase": {
"frame": { "x": 256, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 9.ase": {
"frame": { "x": 288, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 10.ase": {
"frame": { "x": 320, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
},
"asteroide1_12frames 11.ase": {
"frame": { "x": 352, "y": 0, "w": 32, "h": 32 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 32, "h": 32 },
"sourceSize": { "w": 32, "h": 32 },
"duration": 100
}
},
"meta": {
"app": "https://github.com/LibreSprite/LibreSprite/",
"version": "1.0",
"image": "/home/sylvain/Programmes/Casio/shmup/assets-cg/Sprites/Rocks/asteroide1_12frames.png",
"format": "RGBA8888",
"size": { "w": 384, "h": 32 },
"scale": "1",
"frameTags": [
],
"layers": [
{ "name": "Layer 1", "opacity": 255, "blendMode": "normal" }
]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

View File

@ -3,33 +3,19 @@
#include <azur/azur.h>
#include <azur/gint/render.h>
#include "utilities.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fxlibc/printf.h>
#include <sys/types.h>
extern font_t milifont_prop;
/* Render text with Azur images - quite bad, but I don't have time lol. */
void Azur_draw_text(int x, int y, char const *fmt, ...)
{
/* char str[128];
va_list args;
va_start(args, fmt);
vsnprintf(str, 128, fmt, args);
va_end(args);
extern bopti_image_t img_font;
for(int i = 0; str[i]; i++) {
if(str[i] < 32 || str[i] >= 0x7f) continue;
int row = (str[i] - 32) >> 4;
int col = (str[i] - 32) & 15;
azrp_subimage(x + 5 * i, y, &img_font, 7 * col + 1, 9 * row + 1, 6, 8, DIMAGE_NONE);
}
*/
char str[128];
va_list args;
va_start(args, fmt);
@ -40,3 +26,189 @@ void Azur_draw_text(int x, int y, char const *fmt, ...)
azrp_text( x, y, C_WHITE, str );
}
bool AABB_Collision( SpriteLocator image1, SpriteLocator image2 )
{
if( (image2.x >= image1.x + image1.image->width)
|| (image2.x + image2.image->width <= image1.x)
|| (image2.y >= image1.y + image1.image->height)
|| (image2.y + image2.image->height <= image1.y) )
return false;
// no need to do pixel perfect detection
return true;
}
bool Pixel_Perfect_Collision( SpriteLocator image1, SpriteLocator image2 )
{
if( !AABB_Collision( image1, image2 ) )
return false; // bounding boxes not overlapping, impossible to have collision
/* if we reach that point, this means that we need to perform pixel perfect collsion detection */
/* First we will calculate the corners of the zone to be tested for collision */
/* as it is not usefull to check for all the surface of the image, only the */
/* overlapping area will be verified */
/* WARNING !! */
/* P4 format is not supported yet has it is currently focused on use with Azur */
/* that is mostly P8/RGB565 oriented for ultra fast performances */
if ( IMAGE_IS_P4(image1.image->format) || IMAGE_IS_P4(image2.image->format) )
return false;
int astartx, aendx;
int astarty, aendy;
int adeltax, adeltay;
int bstartx, bendx;
int bstarty, bendy;
int bdeltax, bdeltay;
int rows, columns;
if (image1.x <= image2.x)
{
adeltax = image2.x - image1.x;
columns = MIN(image1.image->width - adeltax, image2.image->width);
bdeltax = 0;
}
else
{
bdeltax = image1.x - image2.x;
columns = MIN(image2.image->width - bdeltax, image1.image->width);
adeltax = 0;
}
if (image1.y <= image2.y)
{
adeltay = image2.y - image1.y;
rows = MIN(image1.image->height - adeltay, image2.image->height);
bdeltay = 0;
}
else
{
bdeltay = image1.y - image2.y;
rows = MIN(image2.image->height - bdeltay, image1.image->height);
adeltay = 0;
}
/* if BOTH images are in a 16bits color format, we will not use masks and will quicken the process */
if ( IMAGE_IS_RGB16(image1.image->format) && IMAGE_IS_RGB16(image2.image->format) )
{
void *data1 = image1.image->data + adeltay * image1.image->stride;
void *data2 = image2.image->data + bdeltay * image2.image->stride;
uint16_t *data_u16_1 = (uint16_t *) data1;
uint16_t *data_u16_2 = (uint16_t *) data2;
int transp1 = image_alpha(image1.image->format);
int transp2 = image_alpha(image2.image->format);
for( int j=0; j<rows; j++)
{
for (int i=0; i<columns; i++)
{
if( (data_u16_1[ adeltax + i ] != transp1 )
&& (data_u16_2[ bdeltax + i ] != transp2 ) )
return true;
}
data1 += image1.image->stride;
data_u16_1 = (uint16_t *) data1;
data2 += image2.image->stride;
data_u16_2 = (uint16_t *) data2;
}
return false;
}
/* if BOTH images are in a 8bits color format, we will not use masks and will quicken the process */
if ( IMAGE_IS_P8(image1.image->format) && IMAGE_IS_P8(image2.image->format) )
{
void *data1 = image1.image->data + adeltay * image1.image->stride;
void *data2 = image2.image->data + bdeltay * image2.image->stride;
int8_t *data_u8_1 = (int8_t *) data1;
int8_t *data_u8_2 = (int8_t *) data2;
int transp1 = image_alpha(image1.image->format);
int transp2 = image_alpha(image2.image->format);
for( int j=0; j<rows; j++)
{
for (int i=0; i<columns; i++)
{
if( (data_u8_1[ adeltax + i ] != transp1 )
&& (data_u8_2[ bdeltax + i ] != transp2 ) )
return true;
}
data1 += image1.image->stride;
data_u8_1 = (int8_t *) data1;
data2 += image2.image->stride;
data_u8_2 = (int8_t *) data2;
}
return false;
}
/* if we reach that point, this means that images have differnt format and we need to manage this */
uint8_t d1;
uint8_t d2;
void *data1 = image1.image->data + adeltay * image1.image->stride;
void *data2 = image2.image->data + bdeltay * image2.image->stride;
int8_t *data_u8_1 = (int8_t *) data1;
uint16_t *data_u16_1 = (uint16_t *) data1;
int8_t *data_u8_2 = (int8_t *) data2;
uint16_t *data_u16_2 = (uint16_t *) data2;
int transp1 = image_alpha(image1.image->format);
int transp2 = image_alpha(image2.image->format);
bool im1_P16 = IMAGE_IS_RGB16(image1.image->format);
bool im1_P8 = IMAGE_IS_P8(image1.image->format);
bool im2_P16 = IMAGE_IS_RGB16(image2.image->format);
bool im2_P8 = IMAGE_IS_P8(image2.image->format);
for( int j=0; j<rows; j++)
{
for (int i=0; i<columns; i++)
{
/* d1 is set to 1 if pixel of image1 is not transparent and to 0 if transparent */
/* need to be format dependant here so quite time consumming test at each loop :( )*/
if (im1_P16)
d1 = data_u16_1[ adeltax + i ] == transp1 ? 0 : 1;
else if (im1_P8)
d1 = data_u8_1[ adeltax + i ] == transp1 ? 0 : 1;
/* d2 is set to 1 if pixel of image2 is not transparent and to 0 if transparent */
/* need to be format dependant here so quite time consumming test at each loop :( )*/
if (im2_P16)
d2 = data_u16_2[ bdeltax + i ] == transp2 ? 0 : 1;
else if (im2_P8)
d2 = data_u8_2[ bdeltax + i ] == transp2 ? 0 : 1;
/* if d1 + d2 = 2 means that both coincident pixels are not transparent and then we have collision*/
if (d1 + d2 == 2) return true;
}
/* we move the pointer to the next line of both images */
data1 += image1.image->stride;
data2 += image2.image->stride;
data_u8_1 = (int8_t *) data1;
data_u8_2 = (int8_t *) data2;
data_u16_1 = (uint16_t *) data1;
data_u16_2 = (uint16_t *) data2;
}
return false;
}

View File

@ -1,6 +1,34 @@
#ifndef UTILITIES_H
#define UTILITIES_H
#include <cstdint>
#include "gint/image.h"
typedef struct
{
/* position of the picture */
int16_t x, y;
/* pointer to the image structure */
image_t *image;
} SpriteLocator;
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define FLOOR(a) ((a) < 0 ? (int)((a)-1.0) : (int)(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
bool AABB_Collision( SpriteLocator image1, SpriteLocator image2 );
bool Pixel_Perfect_Collision( SpriteLocator image1, SpriteLocator image2 );
void Azur_draw_text(int x, int y, char const *fmt, ...);
#endif