Compare commits

...

3 Commits

32 changed files with 491 additions and 153 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# Build files
/build-fx
/build-cg
/build-cg-push
/*.g1a
/*.g3a

View File

@ -43,14 +43,15 @@ set(SOURCES
src/starfieldshader.cpp
src/background.cpp
src/bonus.cpp
src/boss.cpp
src/point2D.cpp
src/trajectory.cpp
# ...
)
set(ASSETS_cg
assets-cg/font.png
#assets-cg/font.png
assets-cg/milifont.png
assets-cg/Sprites/Explosions/firstboom.png
assets-cg/Sprites/Explosions/emp_circ.png
@ -71,6 +72,8 @@ set(ASSETS_cg
assets-cg/Sprites/Enemies/mainship2.png
assets-cg/Sprites/Enemies/Enemy_Blue_Lvl1.png
assets-cg/Sprites/Enemies/Enemy_Red_Lvl1.png
assets-cg/Sprites/Boss/Boss1.png
assets-cg/Levels/tileset.png
assets-cg/Levels/Level2.json

View File

@ -27,7 +27,7 @@ The SHMUP Todo list :
# Bosses
- Créer des bosses avec différentes zones, mobiles les unes par rapport aux autres
- Créer des hitboxes pour chacune des zones du boss avec différentes sensibilités (par exemple le coeur/générateur = zone critique, mais mieux défendues)
- Créer des protections des certaines zones qui peuvent "sauter" (boucliers qui s'usent)
- Créer des protections pour certaines zones qui peuvent "sauter" (boucliers qui s'usent)
# Autres :
- plein de trucs dont boss "multi-morceaux et multi-hitboxes"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,14 +0,0 @@
{ "columns":32,
"image":"tileset.png",
"imageheight":1024,
"imagewidth":512,
"margin":0,
"name":"Tileset_Space",
"spacing":0,
"tilecount":2048,
"tiledversion":"1.8.0",
"tileheight":16,
"tilewidth":16,
"type":"tileset",
"version":"1.8"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,5 @@
*.png:
type: bopti-image
name_regex: (.*)\.png img_\1
section: .data
profile: p8_rgb565a

View File

@ -1,4 +1,8 @@
*.png:
type: bopti-image
name_regex: (.*)\.png img_\1
profile: p8_rgb565a
milifont.png:
name: milifont_prop
type: font
charset: print
width: 3
grid.size: 3x5
grid.padding: 1
proportional: true

BIN
assets-cg/milifont.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -10,7 +10,6 @@
void azrp_starfield( void );
void azrp_starfield_init( uint8_t nbstars );
void azrp_starfield_close( void );
void azrp_starfield_USBDEBUG( uint8_t info );
void azrp_tilesmap( int shifttile, int *tilemap, bopti_image_t *image, int tileset_size );

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "background.h"
#include <azur/azur.h>
#include <azur/gint/render.h>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "bonus.h"
#include <num/num.h>
#include <gint/rtc.h>

285
src/boss.cpp Normal file
View File

@ -0,0 +1,285 @@
#include "config.h"
#include "boss.h"
#include "bullet.h"
#include <cstdint>
#include <num/num.h>
#include <gint/rtc.h>
#include <sys/types.h>
#include "fast_trig.h"
#include <gint/gint.h>
#include "collections.h"
extern bopti_image_t img_Lifebar;
extern bopti_image_t img_Boss1;
extern font_t milifont_prop;
#define NB_PIECES_BOSS 12
libnum::num XdataBossInternal[NB_PIECES_BOSS];
libnum::num YdataBossInternal[NB_PIECES_BOSS];
libnum::num XdataBossExternal[NB_PIECES_BOSS];
libnum::num YdataBossExternal[NB_PIECES_BOSS];
BossPart Pieces[NB_PIECES_BOSS*2];
#include <stdio.h>
void savedata( void )
{
FILE* exportfp = fopen("databosPtxt", "w" );
if(exportfp)
{
fprintf(exportfp, "Points : \n" );
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
fprintf(exportfp, "Ext[ %d ] : X= %d - Y= %d \n", i, (int) XdataBossExternal[i], (int) YdataBossExternal[i] );
}
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
fprintf(exportfp, "Int[ %d ] : X= %d - Y= %d \n", i, (int) XdataBossInternal[i], (int) YdataBossInternal[i] );
}
fprintf(exportfp, "Triangles : \n" );
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
fprintf(exportfp, "Tri ext[ %d ] : P1= %d - P2= %d - P3= %d \n", i, Pieces[2*i].P1, Pieces[2*i].P2, Pieces[2*i].P3 );
}
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
fprintf(exportfp, "Tri int[ %d ] : P1= %d - P2= %d - P3= %d \n", i, Pieces[2*i+1].P1, Pieces[2*i+1].P2, Pieces[2*i+1].P3 );
}
fclose( exportfp );
}
}
bool Is_Point_Inside_Triangle( int Px, int Py, int P1x, int P1y, int P2x, int P2y, int P3x, int P3y )
{
int as_x = Px - P1x;
int as_y = Py - P1y;
bool s_ab = (P2x - P1x) * as_y - (P2y - P1y) * as_x > 0;
if (((P3x - P1x) * as_y - (P3y - P1y) * as_x > 0) == s_ab)
return false;
if (((P3x - P2x) * (Py - P2y) - (P3y - P2y)*(Px - P2x) > 0) != s_ab)
return false;
return true;
}
Boss::Boss( int16_t _x, int16_t _y, uint8_t _id )
{
x = libnum::num(_x);
y = libnum::num(_y);
ID = _id;
speed = 10;
toberemoved = false;
width = img_Boss1.width/2;
height = img_Boss1.height/2;
xmin = (int) x - width;
xmax = (int) x + width;
ymin = (int) y - height;
ymax = (int) y + height;
if (ID==0)
{
life = 1000;
life0 = 1000;
}
lastshoot0 = rtc_ticks();
lastshoot1 = rtc_ticks();
lastshoot2 = rtc_ticks();
radiusInt = libnum::num( 75 );
radiusExt = libnum::num( 100 );
rotAngle = 0.0f;
rotSpeed = 2;
this->Update(0.0f);
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
Pieces[i*2].P1 = i%NB_PIECES_BOSS; //exterior circle
Pieces[i*2].P2 = (i+1)%NB_PIECES_BOSS; //exterior circle
Pieces[i*2].P3 = (i+1)%NB_PIECES_BOSS; //interior circle
Pieces[i*2].life = 100;
Pieces[i*2].toberemoved = false;
Pieces[i*2].color = 0xbdf7; //light gray
Pieces[i*2+1].P1 = i%NB_PIECES_BOSS; //interior circle
Pieces[i*2+1].P2 = (i+1)%NB_PIECES_BOSS; //interior circle
Pieces[i*2+1].P3 = i%NB_PIECES_BOSS; //exterior circle
Pieces[i*2+1].life = 100;
Pieces[i*2+1].toberemoved = false;
Pieces[i*2+1].color = 0x528a; //darker gray
}
/* FOR DEBUGGING */
// gint_world_switch( GINT_CALL( savedata ) );
}
Boss::~Boss()
{
}
void Boss::Update( float dt )
{
xmin = (int) x - width;
xmax = (int) x + width;
ymin = (int) y - height;
ymax = (int) y + height;
rotAngle += rotSpeed * dt / 25000.0f;
if (rotAngle>360.0f) rotAngle-=360.0f;
uint16_t angleint = (uint16_t) rotAngle;
uint16_t angledelta = (uint16_t) (360/NB_PIECES_BOSS);
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
XdataBossInternal[ i ] = this->x + this->radiusInt * FastCosInt( angleint );
YdataBossInternal[ i ] = this->y + this->radiusInt * FastSinInt( angleint );
angleint += angledelta;
if (angleint>=360) angleint -= 360;
}
// Pour le cercle Exterieur on se décale d'un demi-incrément d'angle pour le sommet du triangle
angleint = (uint16_t) rotAngle + angledelta/2;
if (angleint>=360) angleint -= 360;
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
XdataBossExternal[ i ] = this->x + this->radiusExt * FastCosInt( angleint );
YdataBossExternal[ i ] = this->y + this->radiusExt * FastSinInt( angleint );
angleint += angledelta;
if (angleint>=360) angleint -= 360;
}
}
void Boss::Render( void )
{
if (ID==0 && toberemoved==false)
{
for( int i=0; i<NB_PIECES_BOSS; i++ )
{
if (Pieces[i*2].toberemoved == false)
{
azrp_triangle( (int) XdataBossExternal[ Pieces[i*2].P1 ], (int) YdataBossExternal[ Pieces[i*2].P1 ],
(int) XdataBossExternal[ Pieces[i*2].P2 ], (int) YdataBossExternal[ Pieces[i*2].P2 ],
(int) XdataBossInternal[ Pieces[i*2].P3 ], (int) YdataBossInternal[ Pieces[i*2].P3 ],
Pieces[i*2].color );
#if(DEBUG_MODE)
dfont( &milifont_prop );
int X = (int) ((XdataBossExternal[ Pieces[i*2].P1 ] + XdataBossExternal[ Pieces[i*2].P2 ] + XdataBossInternal[ Pieces[i*2].P3 ]) / 3);
int Y = (int) ((YdataBossExternal[ Pieces[i*2].P1 ] + YdataBossExternal[ Pieces[i*2].P2 ] + YdataBossInternal[ Pieces[i*2].P3 ]) / 3);
azrp_print( X, Y, C_WHITE, "%d", Pieces[i*2].life );
#endif
}
if (Pieces[i*2+1].toberemoved == false)
{
azrp_triangle( (int) XdataBossInternal[ Pieces[i*2+1].P1 ], (int) YdataBossInternal[ Pieces[i*2+1].P1 ],
(int) XdataBossInternal[ Pieces[i*2+1].P2 ], (int) YdataBossInternal[ Pieces[i*2+1].P2 ],
(int) XdataBossExternal[ Pieces[i*2+1].P3 ], (int) YdataBossExternal[ Pieces[i*2+1].P3 ],
Pieces[i*2+1].color );
#if(DEBUG_MODE)
dfont( &milifont_prop );;
int X = (int) ((XdataBossInternal[ Pieces[i*2+1].P1 ] + XdataBossInternal[ Pieces[i*2+1].P2 ] + XdataBossExternal[ Pieces[i*2+1].P3 ]) / 3);
int Y = (int) ((YdataBossInternal[ Pieces[i*2+1].P1 ] + YdataBossInternal[ Pieces[i*2+1].P2 ] + YdataBossExternal[ Pieces[i*2+1].P3 ]) / 3);
azrp_print( X, Y, C_WHITE, "%d", Pieces[i*2+1].life );
#endif
}
}
azrp_image_p8_effect(xmin, ymin, &img_Boss1, DIMAGE_NONE);
if (life>life0*2/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 7, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
else if (life>life0/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 12, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
else azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 17, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE );
};
}
bool Boss::Test_Impact( Bullet *projectile )
{
for( int i=0; i< NB_PIECES_BOSS; i++ )
{
if (Pieces[i*2].toberemoved == false)
{
if (Is_Point_Inside_Triangle( (int) projectile->x, (int) projectile->y,
(int) XdataBossExternal[ Pieces[i*2].P1 ], (int) YdataBossExternal[ Pieces[i*2].P1 ],
(int) XdataBossExternal[ Pieces[i*2].P2 ], (int) YdataBossExternal[ Pieces[i*2].P2 ],
(int) XdataBossInternal[ Pieces[i*2].P3 ], (int) YdataBossInternal[ Pieces[i*2].P3 ] ))
{
Pieces[i*2].life -= projectile->strength;
if (Pieces[i*2].life<=0)
{
Pieces[i*2].toberemoved = true;
Create_Explosion( (int) projectile->x, (int) projectile->y );
}
projectile->toberemoved = true;
return true;
}
}
if (Pieces[i*2+1].toberemoved == false)
{
if (Is_Point_Inside_Triangle( (int) projectile->x, (int) projectile->y,
(int) XdataBossInternal[ Pieces[i*2+1].P1 ], (int) YdataBossInternal[ Pieces[i*2+1].P1 ],
(int) XdataBossInternal[ Pieces[i*2+1].P2 ], (int) YdataBossInternal[ Pieces[i*2+1].P2 ],
(int) XdataBossExternal[ Pieces[i*2+1].P3 ], (int) YdataBossExternal[ Pieces[i*2+1].P3 ] ))
{
Pieces[i*2+1].life -= projectile->strength;
if (Pieces[i*2+1].life<=0)
{
Pieces[i*2+1].toberemoved = true;
Create_Explosion( (int) projectile->x, (int) projectile->y );
}
projectile->toberemoved = true;
return true;
}
}
}
if (projectile->x >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax )
{
life -= projectile->strength;
if (life<0) this->toberemoved = true;
projectile->toberemoved = true;
return true;
}
else return false;
}

55
src/boss.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef BOSS_H
#define BOSS_H
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <cstdint>
#include <stdlib.h>
#include <num/num.h>
#include <sys/types.h>
#include "bullet.h"
typedef struct
{
uint8_t P1, P2, P3;
int16_t life;
bool toberemoved;
int color;
} BossPart;
class Boss
{
public:
Boss( int16_t _x, int16_t _y, uint8_t _id );
~Boss();
void Update( float dt );
void Render( void );
bool Test_Impact( Bullet *projectile );
libnum::num x, y; // center position of the boss
uint8_t width, height; // width and height -for the hitbox
int16_t xmin, xmax, ymin, ymax; // square hitbox (to speed up the bullet impact calculations)
uint8_t ID;
int16_t life, life0;
uint8_t speed; // speed of the boss
uint32_t lastshoot0 = 0;
uint32_t lastshoot1 = 0;
uint32_t lastshoot2 = 0;
uint8_t rotSpeed;
bool toberemoved;
private:
float rotAngle;
libnum::num radiusInt, radiusExt;
};
#endif

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "bullet.h"
#include <azur/azur.h>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "collections.h"
#include <vector>

12
src/config.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef CONFIG_H
#define CONFIG_H
#define DEBUG_MODE 0
#define USB 1
#define MORE_RAM 0
#define CALCEMU 0
#endif

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "enemy.h"
#include "bullet.h"
#include <num/num.h>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "extrakeyboard.h"
#include <gint/keyboard.h>
#include <gint/rtc.h>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "impact.h"

View File

@ -1,6 +1,4 @@
#define DEBUG_MODE 0
#define USB 1
#define MORE_RAM 1
#include "config.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
@ -43,7 +41,7 @@
#include "bonus.h"
#include "impact.h"
#include "background.h"
#include "boss.h"
#include "trajectory.h"
#include <vector>
@ -89,46 +87,47 @@ std::vector<Bonus*> MyBonuses;
Background MyBackground;
Player *MyPlayer;
Boss *MyBoss;
KeyboardExtra MyKeyboard;
static void hook_prefrag(int id, void *fragment, int size)
{
if(!screenshot && !record)
return;
/* Screenshot takes precedence */
char const *type = screenshot ? "image" : "video";
#if(USB)
int pipe = usb_ff_bulk_output();
static void hook_prefrag(int id, void *fragment, int size)
{
if(!screenshot && !record)
return;
if(id == 0) {
usb_fxlink_header_t h;
usb_fxlink_image_t sh;
int size = azrp_width * azrp_height * 2;
usb_fxlink_fill_header(&h, "fxlink", type, size + sizeof sh);
sh.width = htole32(azrp_width);
sh.height = htole32(azrp_height);
sh.pixel_format = htole32(USB_FXLINK_IMAGE_RGB565);
/* Screenshot takes precedence */
char const *type = screenshot ? "image" : "video";
usb_write_sync(pipe, &h, sizeof h, false);
usb_write_sync(pipe, &sh, sizeof sh, false);
}
int pipe = usb_ff_bulk_output();
usb_write_sync(pipe, fragment, size, false);
if(id == 0) {
usb_fxlink_header_t h;
usb_fxlink_image_t sh;
int size = azrp_width * azrp_height * 2;
if(id == azrp_frag_count - 1) {
usb_commit_sync(pipe);
screenshot = false;
usb_fxlink_fill_header(&h, "fxlink", type, size + sizeof sh);
sh.width = htole32(azrp_width);
sh.height = htole32(azrp_height);
sh.pixel_format = htole32(USB_FXLINK_IMAGE_RGB565);
usb_write_sync(pipe, &h, sizeof h, false);
usb_write_sync(pipe, &sh, sizeof sh, false);
}
usb_write_sync(pipe, fragment, size, false);
if(id == azrp_frag_count - 1) {
usb_commit_sync(pipe);
screenshot = false;
}
}
#endif
}
static void update( float dt )
{
// all update stuff depending on time will be done here
@ -164,6 +163,23 @@ static void update( float dt )
delete( MyEnemies[i] );
MyEnemies.erase( MyEnemies.begin() + i );
}
}
if (MyBoss!=nullptr)
{
MyBoss->Update( dt );
if (MyBoss->toberemoved == true)
{
Bonus *b = new Bonus( (int) MyBoss->x, (int) MyBoss->y, rand() % 2 );
MyBonuses.push_back( b );
Create_Explosion( (int) MyBoss->x, (int) MyBoss->y );
delete( MyBoss );
MyBoss=nullptr;
}
}
for(unsigned int i=0; i<MyParticles.size(); i++)
@ -191,6 +207,14 @@ static void update( float dt )
}
}
if (MyBoss)
if(MyBoss->Test_Impact(MyPlayerBullets[i])==true)
{
//TODO : we can create a list of impacts here, to be rendered later on
Create_Impact( (int) MyPlayerBullets[i]->x, (int) MyPlayerBullets[i]->y );
}
// Check if the property toberemoved has been set to "true" for particle deletion
if (MyPlayerBullets[i]->toberemoved == true)
{
@ -259,6 +283,9 @@ static void render( void )
for(auto& e : MyEnemies)
e->Render();
if (MyBoss!=nullptr)
MyBoss->Render();
for( auto& i : MyImpacts)
i->Render();
@ -292,7 +319,6 @@ static void render( void )
static void get_inputs( float dt )
{
uint8_t speed = 4;
uint32_t tempshoot = rtc_ticks();
if(MyKeyboard.IsKeyPressed(MYKEY_F1))
@ -340,7 +366,7 @@ static void get_inputs( float dt )
bool AddMoreRAM( void )
{
#if(MORE_RAM)
#if(MORE_RAM && !CALCEMU)
/* allow more RAM */
char const *osv = (char*) 0x80020020;
@ -386,11 +412,24 @@ bool AddMoreRAM( void )
kmalloc_add_arena(&extended_ram );
return true;
}
#elif (MORE_RAM && CALCEMU)
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = (void *)0x8c200000;
extended_ram.end = (void *)0x8c4e0000 ;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return true;
#else
return false;
#endif
return false;
}
void FreeMoreRAM( void )
@ -429,7 +468,7 @@ int main(void)
_uram = kmalloc_get_arena("_uram");
#endif
bool canWeAllocate3Mb = AddMoreRAM();
bool canWeAllocateMoreRam = AddMoreRAM();
__printf_enable_fp();
__printf_enable_fixed();
@ -439,7 +478,9 @@ int main(void)
//azrp_shader_image_rgb16_configure();
//azrp_shader_image_p8_configure();
//azrp_shader_image_p4_configure();
azrp_hook_set_prefrag(hook_prefrag);
#if(USB)
azrp_hook_set_prefrag(hook_prefrag);
#endif
azrp_starfield_init( 250 );
@ -447,6 +488,8 @@ int main(void)
MyPlayer = new Player( azrp_width/4, azrp_height/2, 0);
MyBoss = new Boss( 3*azrp_width/4, azrp_height/2, 0);
/*
#if(DBGCRSH)
debug_crash( 1 );
@ -494,7 +537,7 @@ int main(void)
render();
azrp_update();
azrp_update();
}
@ -533,7 +576,7 @@ int main(void)
usb_close();
#endif
FreeMoreRAM( );
if (canWeAllocateMoreRam) FreeMoreRAM( );
return 1;
}

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "particles.h"
#include <azur/azur.h>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "player.h"
#include "bullet.h"
#include "enemy.h"

View File

@ -1,3 +1,5 @@
#include "config.h"
#include <azur/gint/render.h>
#include "MyAzurShaders.h"
#include <cstdlib>
@ -64,12 +66,6 @@ static void register_shader(void)
}
void azrp_starfield_USBDEBUG( uint8_t info )
{
}
void azrp_starfield_init( uint8_t nbstars )
{

View File

@ -1,3 +1,5 @@
#include "config.h"
#include <azur/gint/render.h>
#include "MyAzurShaders.h"
#include <cstdlib>

View File

@ -1,3 +1,5 @@
#include "config.h"
#include "trajectory.h"
Trajectory::Trajectory( )

View File

@ -1,3 +1,5 @@
#include "config.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
@ -6,10 +8,13 @@
#include <stdlib.h>
#include <fxlibc/printf.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];
/* char str[128];
va_list args;
va_start(args, fmt);
vsnprintf(str, 128, fmt, args);
@ -24,4 +29,14 @@ void Azur_draw_text(int x, int y, char const *fmt, ...)
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);
vsnprintf(str, 128, fmt, args);
va_end(args);
dfont( &milifont_prop );
azrp_text( x, y, C_WHITE, str );
}