generated from kdx/gint-project-template
Transférer les fichiers vers 'src'
This commit is contained in:
parent
48e2a7836e
commit
d4ae82e09d
|
@ -0,0 +1,251 @@
|
|||
#include <gint/display.h>
|
||||
#include <math.h>
|
||||
#include "primitives.h"
|
||||
|
||||
|
||||
/* return the sign of the number given in parameter*/
|
||||
/* -1 if x<0 0 if x=0 and +1 if x>0 */
|
||||
int _sgn( int x )
|
||||
{
|
||||
if(x>=0)
|
||||
return 1;
|
||||
else if(x<0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return the absolute value of the number given in parameter*/
|
||||
int _abs( int x )
|
||||
{
|
||||
if(x>=0)
|
||||
return x;
|
||||
else
|
||||
return -1*x;
|
||||
}
|
||||
|
||||
/* draw a pixel at coordinates (X,Y) of color (R,G,B) */
|
||||
/* all color values (R,G,B) to be in the range 0..255 */
|
||||
inline void _fastPixelRGB( unsigned int X, unsigned int Y, unsigned char R, unsigned char G, unsigned char B )
|
||||
{
|
||||
if ( X<DWIDTH && Y<DHEIGHT)
|
||||
{
|
||||
//dpixel( X, Y, C_RGB(R,G,B) );
|
||||
unsigned int color = (((R>>3) << 11) | ((G>>2) << 5 ) | (B>>3));
|
||||
gint_vram[ Y*DWIDTH + X ] = color;
|
||||
}
|
||||
}
|
||||
|
||||
inline void _fastGetPixelRGB( unsigned int X, unsigned int Y, unsigned char *R, unsigned char *G, unsigned char *B )
|
||||
{
|
||||
unsigned int color = gint_vram[ Y*DWIDTH + X ];
|
||||
*R = (((color >> 11 ) & 0b11111 ) << 3);
|
||||
*G = (((color >> 5) & 0b111111) << 2);
|
||||
*B = ((color & 0b11111) << 3);
|
||||
}
|
||||
|
||||
/* return the color of the pixel at coordinates (X,Y) */
|
||||
/* modifies R,G,B given as parameters */
|
||||
/* all returns R,G,B are in range 0..255 */
|
||||
void _getPixelRGB( unsigned int X, unsigned int Y, unsigned char *R, unsigned char *G, unsigned char *B )
|
||||
{
|
||||
if (X<DWIDTH && Y<DHEIGHT)
|
||||
{
|
||||
unsigned int color = gint_vram[ Y*DWIDTH + X ];
|
||||
*R = (((color >> 11 ) & 0b11111 ) << 3);
|
||||
*G = (((color >> 5) & 0b111111) << 2);
|
||||
*B = ((color & 0b11111) << 3);
|
||||
}
|
||||
}
|
||||
|
||||
inline void _calculateBlendRGBA( unsigned int X, unsigned int Y, unsigned char *R, unsigned char *G, unsigned char *B, unsigned char A )
|
||||
{
|
||||
unsigned char Ro, Go, Bo;
|
||||
_fastGetPixelRGB( X, Y, &Ro, &Go, &Bo );
|
||||
*R = Ro + (((*R-Ro)*A) >> 8);
|
||||
*G = Go + (((*G-Go)*A) >> 8);
|
||||
*B = Bo + (((*B-Bo)*A) >> 8);
|
||||
}
|
||||
|
||||
void _pixelRGBA( unsigned int X, unsigned int Y, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
if (X<DWIDTH && Y<DHEIGHT)
|
||||
{
|
||||
if (A==0) return;
|
||||
else if (A==255) _fastPixelRGB( X, Y, R, G, B );
|
||||
else
|
||||
{
|
||||
unsigned char Rf = R;
|
||||
unsigned char Gf = G;
|
||||
unsigned char Bf = B;
|
||||
_calculateBlendRGBA( X, Y, &Rf, &Gf, &Bf, A );
|
||||
_fastPixelRGB( X, Y, Rf, Gf, Bf );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _lineRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
int x,y,dx,dy,swp,temp,s1,s2,p,i;
|
||||
|
||||
x=X1;
|
||||
y=Y1;
|
||||
dx=_abs(X2-X1);
|
||||
dy=_abs(Y2-Y1);
|
||||
s1=_sgn(X2-X1);
|
||||
s2=_sgn(Y2-Y1);
|
||||
swp=0;
|
||||
|
||||
_pixelRGBA( X1, Y1, R, G, B, A );
|
||||
|
||||
if(dy>dx)
|
||||
{
|
||||
temp=dx;
|
||||
dx=dy;
|
||||
dy=temp;
|
||||
swp=1;
|
||||
}
|
||||
p=2*dy-dx;
|
||||
for(i=0; i<=dx; i++)
|
||||
{
|
||||
_pixelRGBA( x, y, R, G, B, A );
|
||||
|
||||
while(p>=0)
|
||||
{
|
||||
p=p-2*dx;
|
||||
if(swp)
|
||||
x+=s1;
|
||||
else
|
||||
y+=s2;
|
||||
}
|
||||
p=p+2*dy;
|
||||
if(swp)
|
||||
y+=s2;
|
||||
else
|
||||
x+=s1;
|
||||
}
|
||||
}
|
||||
|
||||
void _hLineRGBA( unsigned int X1, unsigned int X2, unsigned int Y, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
if( X1<=X2 )
|
||||
{
|
||||
for(int k=X1; k<=X2; k++)
|
||||
{
|
||||
_pixelRGBA(k,Y,R,G,B,A);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int k=X2; k<=X1; k++)
|
||||
{
|
||||
_pixelRGBA(k,Y,R,G,B,A);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void _rectangleRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
|
||||
_lineRGBA( X1, Y1, X1, Y2, R, G, B, A ) ;
|
||||
_lineRGBA( X1, Y2, X2, Y2, R, G, B, A ) ;
|
||||
_lineRGBA( X2, Y2, X2, Y1, R, G, B, A ) ;
|
||||
_lineRGBA( X2, Y1, X1, Y1, R, G, B, A ) ;
|
||||
|
||||
}
|
||||
|
||||
void _boxRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
if (Y1<=Y2)
|
||||
{
|
||||
for( unsigned int k=Y1; k<=Y2; k++)
|
||||
_lineRGBA( X1, k, X2, k, R, G, B, A ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( unsigned int k=Y2; k<=Y1; k++)
|
||||
_lineRGBA( X1, k, X2, k, R, G, B, A ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void _circleRGBA( unsigned int X1, unsigned int Y1, unsigned int Rad, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
|
||||
int x,y,p;
|
||||
|
||||
x=0;
|
||||
y=Rad;
|
||||
p=3-2*Rad;
|
||||
|
||||
_pixelRGBA(X1+x,Y1+y,R,G,B,A);
|
||||
_pixelRGBA(X1+x,Y1-y,R,G,B,A);
|
||||
_pixelRGBA(X1-x,Y1+y,R,G,B,A);
|
||||
_pixelRGBA(X1-x,Y1-y,R,G,B,A);
|
||||
_pixelRGBA(X1+y,Y1+x,R,G,B,A);
|
||||
_pixelRGBA(X1+y,Y1-x,R,G,B,A);
|
||||
_pixelRGBA(X1-y,Y1+x,R,G,B,A);
|
||||
_pixelRGBA(X1-y,Y1-x,R,G,B,A);
|
||||
|
||||
while(x<y)
|
||||
{
|
||||
if(p<0)
|
||||
{
|
||||
x++;
|
||||
p=p+4*x+6;
|
||||
}
|
||||
else
|
||||
{
|
||||
x++;
|
||||
y--;
|
||||
p=p+4*(x-y)+10;
|
||||
}
|
||||
_pixelRGBA(X1+x,Y1+y,R,G,B,A);
|
||||
_pixelRGBA(X1+x,Y1-y,R,G,B,A);
|
||||
_pixelRGBA(X1-x,Y1+y,R,G,B,A);
|
||||
_pixelRGBA(X1-x,Y1-y,R,G,B,A);
|
||||
_pixelRGBA(X1+y,Y1+x,R,G,B,A);
|
||||
_pixelRGBA(X1+y,Y1-x,R,G,B,A);
|
||||
_pixelRGBA(X1-y,Y1+x,R,G,B,A);
|
||||
_pixelRGBA(X1-y,Y1-x,R,G,B,A);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void _filledCircleRGBA( unsigned int X1, unsigned int Y1, unsigned int Rad, unsigned char R, unsigned char G, unsigned char B, unsigned char A )
|
||||
{
|
||||
|
||||
int x,y,p;
|
||||
|
||||
x=0;
|
||||
y=Rad;
|
||||
p=3-2*Rad;
|
||||
|
||||
_hLineRGBA(X1+x,X1-x,Y1+y,R,G,B,A);
|
||||
_hLineRGBA(X1+x,X1-x,Y1-y,R,G,B,A);
|
||||
_hLineRGBA(X1+y,X1-y,Y1+x,R,G,B,A);
|
||||
_hLineRGBA(X1+y,X1-y,Y1-x,R,G,B,A);
|
||||
|
||||
while(x<y)
|
||||
{
|
||||
if(p<0)
|
||||
{
|
||||
x++;
|
||||
p=p+4*x+6;
|
||||
}
|
||||
else
|
||||
{
|
||||
x++;
|
||||
y--;
|
||||
p=p+4*(x-y)+10;
|
||||
}
|
||||
|
||||
_hLineRGBA(X1+x,X1-x,Y1+y,R,G,B,A);
|
||||
_hLineRGBA(X1+x,X1-x,Y1-y,R,G,B,A);
|
||||
_hLineRGBA(X1+y,X1-y,Y1+x,R,G,B,A);
|
||||
_hLineRGBA(X1+y,X1-y,Y1-x,R,G,B,A);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <gint/display.h>
|
||||
|
||||
void _calculateBlendRGBA( unsigned int X, unsigned int Y, unsigned char* R, unsigned char* G, unsigned char* B, unsigned char A );
|
||||
void _fastPixelRGB( unsigned int X, unsigned int Y, unsigned char R, unsigned char G, unsigned char B );
|
||||
void _pixelRGBA( unsigned int X, unsigned int Y, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _fastGetPixelRGB( unsigned int X, unsigned int Y, unsigned char* R, unsigned char* G, unsigned char* B );
|
||||
void _getPixelRGB( unsigned int X, unsigned int Y, unsigned char* R, unsigned char* G, unsigned char* B );
|
||||
void _lineRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _hLineRGBA( unsigned int X1, unsigned int X2, unsigned int Y, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _rectangleRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _boxRGBA( unsigned int X1, unsigned int Y1, unsigned int X2, unsigned int Y2, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _circleRGBA( unsigned int X1, unsigned int Y1, unsigned int Rad, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
void _filledCircleRGBA( unsigned int X1, unsigned int Y1, unsigned int Rad, unsigned char R, unsigned char G, unsigned char B, unsigned char A );
|
||||
|
||||
int _sgn( int x );
|
||||
|
||||
int _abs( int x );
|
|
@ -0,0 +1,235 @@
|
|||
#define NB_RECEPTORS_PER_DOOR_MAX 3
|
||||
|
||||
enum orientations
|
||||
{
|
||||
GAUCHE = 0,
|
||||
DROITE = 1,
|
||||
HAUT = 2,
|
||||
BAS = 3,
|
||||
AUCUNE = 4,
|
||||
VERTICAL = 5,
|
||||
HORIZONTAL = 6
|
||||
};
|
||||
|
||||
struct Receptor
|
||||
{
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
orientations direction;
|
||||
unsigned char R, G, B;
|
||||
bool isvalide;
|
||||
};
|
||||
|
||||
enum selection
|
||||
{
|
||||
NONE = 0,
|
||||
JOUEUR = 1,
|
||||
LUMIERE = 2,
|
||||
ROUGE = 3,
|
||||
VERT = 4,
|
||||
BLEU = 5,
|
||||
NOIR = 6
|
||||
};
|
||||
|
||||
enum ID
|
||||
{
|
||||
VIDE = 0,
|
||||
MUR = 1,
|
||||
PORTE = 2
|
||||
};
|
||||
|
||||
enum kind
|
||||
{
|
||||
OPAQUE = 0,
|
||||
TRANSPARENT = 1
|
||||
};
|
||||
|
||||
struct Blocks
|
||||
{
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
unsigned char R,G,B,A;
|
||||
kind type;
|
||||
};
|
||||
|
||||
struct Player
|
||||
{
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
orientations direction;
|
||||
};
|
||||
|
||||
struct MapItem
|
||||
{
|
||||
unsigned char ID;
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
orientations direction;
|
||||
};
|
||||
|
||||
struct Light
|
||||
{
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
unsigned char R,G,B,A;
|
||||
bool movable;
|
||||
};
|
||||
|
||||
struct Wall
|
||||
{
|
||||
orientations direction;
|
||||
unsigned int mini;
|
||||
unsigned int maxi;
|
||||
unsigned int fixe;
|
||||
};
|
||||
|
||||
struct Door
|
||||
{
|
||||
unsigned char x, y;
|
||||
orientations direction;
|
||||
bool isopen;
|
||||
bool isdoor;
|
||||
unsigned char nbreceptor;
|
||||
char receptors[NB_RECEPTORS_PER_DOOR_MAX];
|
||||
char nextLevelNumber;
|
||||
};
|
||||
|
||||
enum content
|
||||
{
|
||||
RIEN = 0,
|
||||
PIERRE_NOIRE,
|
||||
PIERRE_VERTE,
|
||||
PIERRE_BLEUE,
|
||||
PIERRE_ROUGE,
|
||||
PIERRE_BLANCHE,
|
||||
LINGOT_FER,
|
||||
LINGOT_BRONZE,
|
||||
LINGOT_ARGENT,
|
||||
LINGOT_OR,
|
||||
LINGOT_PLATINE,
|
||||
WHITE_FRAGMENT,
|
||||
BLACK_FRAGMENT ,
|
||||
RED_FRAGMENT,
|
||||
GREEN_FRAGMENT,
|
||||
BLUE_FRAGMENT,
|
||||
HEART_SINGLE, // to restore one single point of Life (1 heart)
|
||||
HEART_FULL // to restore all points of Life (up to LifeMax, function of difficulty)
|
||||
};
|
||||
|
||||
enum chest
|
||||
{
|
||||
T_RED = 0,
|
||||
T_YELLOW,
|
||||
T_GREEN,
|
||||
T_BLUE
|
||||
};
|
||||
|
||||
enum nonmovable
|
||||
{
|
||||
BLOCK_STONE = 0,
|
||||
BLOCK_MOON,
|
||||
BLOCK_WOOD,
|
||||
BLOCK_SUN,
|
||||
BLOCK_WATER
|
||||
};
|
||||
|
||||
struct Obstacle
|
||||
{
|
||||
unsigned char x, y;
|
||||
nonmovable type;
|
||||
};
|
||||
|
||||
struct Treasure
|
||||
{
|
||||
unsigned char x, y;
|
||||
chest type;
|
||||
bool isopen;
|
||||
content inside;
|
||||
unsigned int scoreboost;
|
||||
bool isvisible;
|
||||
};
|
||||
|
||||
struct Minimap
|
||||
{
|
||||
char x, y;
|
||||
unsigned char R,G,B,A;
|
||||
bool visited;
|
||||
bool doorNorth;
|
||||
bool doorSouth;
|
||||
bool doorWest;
|
||||
bool doorEast;
|
||||
};
|
||||
|
||||
struct LevelSaveStatus
|
||||
{
|
||||
unsigned char chestStatusSave[8]={0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA}; // max 8 chest per level : status = 0 if chest not touched yet / 1 if open (and then empty) (activated one time) / 2 if not visible (activated 2 times)
|
||||
unsigned char doorStatusSave[4]={0xBB,0xBB,0xBB,0xBB}; // status of the door (0 = closed; 1 = open )
|
||||
unsigned char bossStatusSave[8]={0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC}; // max 8 bosses per level (0 = normal; 1 = defeated )
|
||||
unsigned char monsterStatusSave[8]={0xDD,0xDD,0xDD,0xDD,0xDD,0xDD,0xDD,0xDD}; // max 8 monsters per level (0 = normal; 1 = defeated )
|
||||
unsigned char redBlockSave[2]={0xEE,0xEE}; // X and Y coordinates
|
||||
unsigned char greenBlockSave[2]={0xEE,0xEE}; // X and Y coordinates
|
||||
unsigned char blueBlockSave[2]={0xEE,0xEE}; // X and Y coordinates
|
||||
unsigned char blackBlockSave[2]={0xEE,0xEE}; // X and Y coordinates
|
||||
unsigned char lightSave[2]={0xFF,0xFF}; // X and Y coordinates
|
||||
}; // TOTAL 38 bytes per level saved
|
||||
|
||||
struct GameSaveStatus
|
||||
{
|
||||
unsigned char currentScore[2]; // Score between 0 and 65535 [byte 1 : score / 256] and [byte 2 : score % 256 ]
|
||||
unsigned char currentLevel;
|
||||
unsigned char visitedLevels[33]; // Levels 1 to 32 save status as level 0 is always visited (0 = not visited, 1 = visited)
|
||||
unsigned char currentDifficulty;
|
||||
unsigned char currentLife;
|
||||
unsigned char redFrag; // 0 = bot collected yet - 1 = collected
|
||||
unsigned char greenFrag; // 0 = bot collected yet - 1 = collected
|
||||
unsigned char blueFrag; // 0 = bot collected yet - 1 = collected
|
||||
unsigned char blackFrag; // 0 = bot collected yet - 1 = collected
|
||||
unsigned char whiteFrag; // 0 = bot collected yet - 1 = collected
|
||||
unsigned char terminator = 0x99;
|
||||
}; // TOTAL 44 bytes
|
||||
|
||||
enum monstertype
|
||||
{
|
||||
BLOB = 0,
|
||||
BAT,
|
||||
GHOST,
|
||||
SPIDER,
|
||||
SKELETON
|
||||
};
|
||||
|
||||
struct Monster
|
||||
{
|
||||
unsigned char xcur, ycur;
|
||||
unsigned char mini, maxi;
|
||||
orientations direction;
|
||||
orientations sens;
|
||||
monstertype kind;
|
||||
};
|
||||
|
||||
enum bosscolor
|
||||
{
|
||||
B_RED = 0,
|
||||
B_GREEN,
|
||||
B_BLUE,
|
||||
B_BLACK,
|
||||
BIGBOSS
|
||||
};
|
||||
|
||||
|
||||
struct Boss
|
||||
{
|
||||
unsigned char xcur, ycur;
|
||||
unsigned char mini, maxi;
|
||||
orientations direction;
|
||||
orientations sens;
|
||||
bosscolor color;
|
||||
};
|
||||
|
||||
|
||||
struct Bullet
|
||||
{
|
||||
unsigned int xpart;
|
||||
unsigned int ypart;
|
||||
unsigned int color;
|
||||
bool visible;
|
||||
};
|
Loading…
Reference in New Issue