major refactoring of code and project classes phase 2
This commit is contained in:
parent
df5fcd900d
commit
137cf2f6a9
|
@ -15,12 +15,14 @@ find_package(LibProf 2.4 REQUIRED)
|
|||
fxconv_declare_converters(assets-cg/converters.py)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/Level2.json"
|
||||
OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/Level1.json"
|
||||
OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/Level2.json"
|
||||
COMMENT "Convert Tiled TMX map to usable JSON file"
|
||||
COMMAND tiled --export-tileset json Tileset_Space.tsx Tileset_Space.json
|
||||
COMMAND find | grep .*.tmx | sed 's/.tmx//g' | xargs -l bash -c 'tiled --export-map json $$0.tmx $$0.json'
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/
|
||||
DEPENDS assets-cg/Levels/Level2.tmx
|
||||
DEPENDS assets-cg/Levels/Level1.tmx
|
||||
assets-cg/Levels/Level2.tmx
|
||||
assets-cg/converters.py
|
||||
assets-cg/Levels/tileset.png
|
||||
assets-cg/Levels/Tileset_Space.tsx)
|
||||
|
@ -43,6 +45,7 @@ set(SOURCES
|
|||
src/shaders/line.cpp
|
||||
src/shaders/starfieldshader.cpp
|
||||
|
||||
src/shmup/entity.cpp
|
||||
src/shmup/collections.cpp
|
||||
src/shmup/impact.cpp
|
||||
src/shmup/player.cpp
|
||||
|
@ -55,6 +58,7 @@ set(SOURCES
|
|||
src/shmup/trajectory.cpp
|
||||
# ...
|
||||
)
|
||||
|
||||
set(ASSETS_cg
|
||||
#assets-cg/font.png
|
||||
assets-cg/milifont.png
|
||||
|
|
5
TODO.txt
5
TODO.txt
|
@ -5,6 +5,11 @@
|
|||
- [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 !!!"
|
||||
- refactoriser les classes des entités "mobiles"
|
||||
o class Entity (position, box, ID, trajectory)
|
||||
~~> class Enemy : public Entity (+shoot, +life)
|
||||
~~> class Boss : public Enemy (+multiple shoots, +multiple life)
|
||||
~~> class Bonus : public Entity (currentframe)
|
||||
|
||||
|
||||
## Partie décors :
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "../config.h"
|
||||
|
||||
#include "bonus.h"
|
||||
#include "entity.h"
|
||||
#include <num/num.h>
|
||||
#include <gint/rtc.h>
|
||||
|
||||
|
@ -8,13 +9,8 @@ extern bopti_image_t img_emp_circ;
|
|||
extern bopti_image_t img_life_bonus;
|
||||
extern bopti_image_t img_sat_bonus;
|
||||
|
||||
Bonus::Bonus( int16_t _x, int16_t _y, uint8_t _id )
|
||||
Bonus::Bonus( int16_t _x, int16_t _y, uint8_t _id ) : Entity( _x, _y, _id )
|
||||
{
|
||||
x = libnum::num( _x );
|
||||
y = libnum::num( _y );
|
||||
|
||||
ID = _id;
|
||||
|
||||
if (ID==0)
|
||||
{
|
||||
width = img_life_bonus.width/2;
|
||||
|
@ -33,11 +29,7 @@ Bonus::Bonus( int16_t _x, int16_t _y, uint8_t _id )
|
|||
ymin = (int) y - height;
|
||||
ymax = (int) y + height;
|
||||
|
||||
toberemoved = false;
|
||||
|
||||
currentframe = libnum::num(0);
|
||||
|
||||
accumulatedTime = 0.0f;
|
||||
}
|
||||
|
||||
Bonus::~Bonus()
|
||||
|
|
|
@ -10,31 +10,22 @@
|
|||
#include <num/num.h>
|
||||
#include "trajectory.h"
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class Bonus
|
||||
|
||||
class Bonus : public Entity
|
||||
{
|
||||
public:
|
||||
Bonus( int16_t _x, int16_t _y, uint8_t _id );
|
||||
~Bonus();
|
||||
|
||||
void Update( float dt );
|
||||
void Render( void );
|
||||
|
||||
libnum::num x, y; // center position of the ennemy
|
||||
uint8_t width, height; // width and height -for the hitbox
|
||||
int16_t xmin, xmax, ymin, ymax; // square hitbox (to speed up the collision calculations)
|
||||
uint8_t ID;
|
||||
uint8_t speed;
|
||||
bool toberemoved;
|
||||
|
||||
bool hasTrajectory = false;
|
||||
Trajectory *pathToFollow;
|
||||
virtual void Update( float dt ) override;
|
||||
virtual void Render( void ) override;
|
||||
|
||||
private:
|
||||
int8_t dirx, diry;
|
||||
libnum::num currentframe;
|
||||
|
||||
float accumulatedTime;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -93,17 +93,10 @@ bool Is_Point_Inside_Triangle( int Px, int Py, int P1x, int P1y, int P2x, int P2
|
|||
|
||||
|
||||
|
||||
Boss::Boss( int16_t _x, int16_t _y, uint8_t _id )
|
||||
Boss::Boss( int16_t _x, int16_t _y, uint8_t _id ) : Enemy( _x, _y, _id )
|
||||
{
|
||||
x = libnum::num(_x);
|
||||
y = libnum::num(_y);
|
||||
|
||||
ID = _id;
|
||||
|
||||
speed = 1;
|
||||
|
||||
toberemoved = false;
|
||||
|
||||
width = img_Boss1.width/2;
|
||||
height = img_Boss1.height/2;
|
||||
|
||||
|
@ -154,22 +147,15 @@ Boss::Boss( int16_t _x, int16_t _y, uint8_t _id )
|
|||
Guns[i].toberemoved = false;
|
||||
}
|
||||
|
||||
accumulatedTime = 0.0f;
|
||||
/* FOR DEBUGGING */
|
||||
// gint_world_switch( GINT_CALL( savedata ) );
|
||||
|
||||
}
|
||||
|
||||
Boss::~Boss()
|
||||
{
|
||||
if (hasTrajectory)
|
||||
pathToFollow->DeleteRegistry();
|
||||
}
|
||||
|
||||
|
||||
void Boss::Update( float dt )
|
||||
{
|
||||
|
||||
if (hasTrajectory)
|
||||
{
|
||||
pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, true, &x, &y );
|
||||
|
@ -179,6 +165,7 @@ void Boss::Update( float dt )
|
|||
xmax = (int) x + width;
|
||||
ymin = (int) y - height;
|
||||
ymax = (int) y + height;
|
||||
|
||||
|
||||
rotAngle += rotSpeed * dt / 25000.0f;
|
||||
if (rotAngle>360.0f) rotAngle-=360.0f;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <num/num.h>
|
||||
#include <sys/types.h>
|
||||
#include "bullet.h"
|
||||
#include "enemy.h"
|
||||
#include "trajectory.h"
|
||||
|
||||
|
||||
|
@ -29,29 +30,18 @@ typedef struct
|
|||
} BossGun;
|
||||
|
||||
|
||||
class Boss
|
||||
class Boss : public Enemy
|
||||
{
|
||||
public:
|
||||
Boss( int16_t _x, int16_t _y, uint8_t _id );
|
||||
~Boss();
|
||||
|
||||
void Update( float dt );
|
||||
void Render( void );
|
||||
virtual void Update( float dt ) override;
|
||||
virtual void Render( void ) override;
|
||||
virtual bool Test_Impact( Bullet *projectile ) override;
|
||||
|
||||
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 lastshoot = 0;
|
||||
uint8_t rotSpeed;
|
||||
bool toberemoved;
|
||||
|
||||
bool hasTrajectory = false;
|
||||
Trajectory *pathToFollow;
|
||||
|
||||
private:
|
||||
float rotAngle;
|
||||
|
@ -60,9 +50,7 @@ class Boss
|
|||
uint32_t lastshoot0 = 0;
|
||||
uint32_t lastshoot1 = 0;
|
||||
|
||||
float accumulatedTime;
|
||||
|
||||
bool Shoot_OK( uint32_t tempshoot, uint8_t shootID );
|
||||
virtual bool Shoot_OK( uint32_t tempshoot, uint8_t shootID ) override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -15,16 +15,11 @@ extern std::vector<Bullet*> MyEnemiesBullets;
|
|||
|
||||
|
||||
|
||||
Enemy::Enemy( int16_t _x, int16_t _y, uint8_t _id )
|
||||
Enemy::Enemy( int16_t _x, int16_t _y, uint8_t _id ) : Entity( _x, _y, _id )
|
||||
{
|
||||
x = libnum::num( _x );
|
||||
y = libnum::num( _y );
|
||||
|
||||
dirx = 1;
|
||||
diry = -6;
|
||||
|
||||
ID = _id;
|
||||
|
||||
if (ID==0)
|
||||
{
|
||||
width = img_mainship2.width/2;
|
||||
|
@ -52,17 +47,12 @@ Enemy::Enemy( int16_t _x, int16_t _y, uint8_t _id )
|
|||
ymin = (int) y - height;
|
||||
ymax = (int) y + height;
|
||||
|
||||
toberemoved = false;
|
||||
|
||||
lastshottime = 0;
|
||||
|
||||
accumulatedTime = 0.0f;
|
||||
}
|
||||
|
||||
Enemy::~Enemy()
|
||||
{
|
||||
if (hasTrajectory)
|
||||
pathToFollow->DeleteRegistry();
|
||||
|
||||
}
|
||||
|
||||
void Enemy::Update( float dt )
|
||||
|
|
|
@ -9,41 +9,29 @@
|
|||
|
||||
#include <num/num.h>
|
||||
#include "bullet.h"
|
||||
#include "entity.h"
|
||||
#include "trajectory.h"
|
||||
|
||||
|
||||
class Enemy
|
||||
class Enemy : public Entity
|
||||
{
|
||||
public:
|
||||
Enemy( int16_t _x, int16_t _y, uint8_t _id );
|
||||
~Enemy();
|
||||
|
||||
void Update( float dt );
|
||||
void Render( void );
|
||||
virtual void Update( float dt ) override;
|
||||
virtual void Render( void ) override;
|
||||
|
||||
bool Test_Impact( Bullet *projectile );
|
||||
virtual bool Test_Impact( Bullet *projectile ) override;
|
||||
void Set_Speed_Vector( uint8_t _sp, uint8_t _xd, uint8_t _yd);
|
||||
|
||||
void Set_Accumulated_Time( float value );
|
||||
|
||||
libnum::num x, y; // center position of the ennemy
|
||||
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;
|
||||
uint8_t speed; // speed of this ennemy
|
||||
bool toberemoved;
|
||||
|
||||
bool hasTrajectory = false;
|
||||
Trajectory *pathToFollow;
|
||||
virtual void Set_Accumulated_Time( float value );
|
||||
|
||||
private:
|
||||
int8_t dirx, diry; // vector of the current direction of the ennemy (TODO : to implement more complex displacement pattern)
|
||||
|
||||
uint32_t lastshottime;
|
||||
float accumulatedTime;
|
||||
|
||||
bool Shoot_OK( uint32_t tempshoot, uint8_t shootID );
|
||||
virtual bool Shoot_OK( uint32_t tempshoot, uint8_t shootID );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include "entity.h"
|
||||
#include <num/num.h>
|
||||
|
||||
Entity::Entity( int16_t _x, int16_t _y, uint8_t _id )
|
||||
{
|
||||
x = libnum::num(_x);
|
||||
y = libnum::num(_y);
|
||||
ID = _id;
|
||||
toberemoved = false;
|
||||
hasTrajectory = false;
|
||||
accumulatedTime = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
Entity::~Entity( void )
|
||||
{
|
||||
if (hasTrajectory)
|
||||
pathToFollow->DeleteRegistry();
|
||||
}
|
||||
|
||||
void Entity::Update( float dt )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Entity::Render( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Entity::Test_Impact( Bullet *projectile )
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <num/num.h>
|
||||
#include <sys/types.h>
|
||||
#include "bullet.h"
|
||||
#include "trajectory.h"
|
||||
|
||||
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
Entity( int16_t _x, int16_t _y, uint8_t _id );
|
||||
virtual ~Entity();
|
||||
|
||||
virtual void Update( float dt );
|
||||
virtual void Render( void );
|
||||
virtual 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;
|
||||
uint8_t speed; // speed of the boss
|
||||
int16_t life;
|
||||
bool toberemoved;
|
||||
|
||||
bool hasTrajectory = false;
|
||||
Trajectory *pathToFollow;
|
||||
float accumulatedTime;
|
||||
int16_t life0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue