diff --git a/CMakeLists.txt b/CMakeLists.txt index 6355093..c336120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ find_package(LibProf 2.4 REQUIRED) set(SOURCES src/main.cpp + src/player.cpp src/utilities.cpp src/particles.cpp src/bullet.cpp @@ -24,16 +25,18 @@ set(SOURCES set(ASSETS_cg assets-cg/font.png - assets-cg/Sprites/firstboom.png - assets-cg/Sprites/emp_circ.png - assets-cg/Sprites/fill_circ.png + assets-cg/Sprites/Explosions/firstboom.png + assets-cg/Sprites/Explosions/emp_circ.png + assets-cg/Sprites/Explosions/fill_circ.png - assets-cg/Sprites/bullet_normal.png - assets-cg/Sprites/bullet_blue.png + assets-cg/Sprites/Bullets/bullet_normal.png + assets-cg/Sprites/Bullets/bullet_blue.png - assets-cg/Sprites/mainship1.png - assets-cg/Sprites/mainship2.png - + assets-cg/Sprites/Players/mainship1.png + assets-cg/Sprites/Players/Satellite_Lvl1.png + + assets-cg/Sprites/Ennemies/mainship2.png + assets-cg/Sprites/Ennemies/Ennemy_Blue_Lvl1.png # ... diff --git a/assets-cg/Sprites/bullet_blue.png b/assets-cg/Sprites/Bullets/bullet_blue.png similarity index 100% rename from assets-cg/Sprites/bullet_blue.png rename to assets-cg/Sprites/Bullets/bullet_blue.png diff --git a/assets-cg/Sprites/bullet_normal.png b/assets-cg/Sprites/Bullets/bullet_normal.png similarity index 100% rename from assets-cg/Sprites/bullet_normal.png rename to assets-cg/Sprites/Bullets/bullet_normal.png diff --git a/assets-cg/Sprites/Bullets/fxconv-metadata.txt b/assets-cg/Sprites/Bullets/fxconv-metadata.txt new file mode 100644 index 0000000..99767a5 --- /dev/null +++ b/assets-cg/Sprites/Bullets/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + section: .data + profile: p8_rgb565a diff --git a/assets-cg/Sprites/Ennemies/Ennemy_Blue_Lvl1.png b/assets-cg/Sprites/Ennemies/Ennemy_Blue_Lvl1.png new file mode 100644 index 0000000..2b15093 Binary files /dev/null and b/assets-cg/Sprites/Ennemies/Ennemy_Blue_Lvl1.png differ diff --git a/assets-cg/Sprites/Ennemies/fxconv-metadata.txt b/assets-cg/Sprites/Ennemies/fxconv-metadata.txt new file mode 100644 index 0000000..99767a5 --- /dev/null +++ b/assets-cg/Sprites/Ennemies/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + section: .data + profile: p8_rgb565a diff --git a/assets-cg/Sprites/mainship2.png b/assets-cg/Sprites/Ennemies/mainship2.png similarity index 100% rename from assets-cg/Sprites/mainship2.png rename to assets-cg/Sprites/Ennemies/mainship2.png diff --git a/assets-cg/Sprites/emp_circ.png b/assets-cg/Sprites/Explosions/emp_circ.png similarity index 100% rename from assets-cg/Sprites/emp_circ.png rename to assets-cg/Sprites/Explosions/emp_circ.png diff --git a/assets-cg/Sprites/fill_circ.png b/assets-cg/Sprites/Explosions/fill_circ.png similarity index 100% rename from assets-cg/Sprites/fill_circ.png rename to assets-cg/Sprites/Explosions/fill_circ.png diff --git a/assets-cg/Sprites/firstboom.png b/assets-cg/Sprites/Explosions/firstboom.png similarity index 100% rename from assets-cg/Sprites/firstboom.png rename to assets-cg/Sprites/Explosions/firstboom.png diff --git a/assets-cg/Sprites/Explosions/fxconv-metadata.txt b/assets-cg/Sprites/Explosions/fxconv-metadata.txt new file mode 100644 index 0000000..99767a5 --- /dev/null +++ b/assets-cg/Sprites/Explosions/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + section: .data + profile: p8_rgb565a diff --git a/assets-cg/Sprites/Players/Satellite_Lvl1.png b/assets-cg/Sprites/Players/Satellite_Lvl1.png new file mode 100644 index 0000000..eb63de0 Binary files /dev/null and b/assets-cg/Sprites/Players/Satellite_Lvl1.png differ diff --git a/assets-cg/Sprites/Players/fxconv-metadata.txt b/assets-cg/Sprites/Players/fxconv-metadata.txt new file mode 100644 index 0000000..99767a5 --- /dev/null +++ b/assets-cg/Sprites/Players/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + section: .data + profile: p8_rgb565a diff --git a/assets-cg/Sprites/mainship1.png b/assets-cg/Sprites/Players/mainship1.png similarity index 100% rename from assets-cg/Sprites/mainship1.png rename to assets-cg/Sprites/Players/mainship1.png diff --git a/assets-cg/Sprites/empty_circle_explode_1_to_7pix.ase b/assets-cg/Sprites/empty_circle_explode_1_to_7pix.ase deleted file mode 100644 index 5ec57ac..0000000 Binary files a/assets-cg/Sprites/empty_circle_explode_1_to_7pix.ase and /dev/null differ diff --git a/assets-cg/Sprites/filled_circle_explode_1_to_7pix.ase b/assets-cg/Sprites/filled_circle_explode_1_to_7pix.ase deleted file mode 100644 index c695841..0000000 Binary files a/assets-cg/Sprites/filled_circle_explode_1_to_7pix.ase and /dev/null differ diff --git a/src/ennemy.cpp b/src/ennemy.cpp index ca35511..46fb982 100644 --- a/src/ennemy.cpp +++ b/src/ennemy.cpp @@ -4,6 +4,7 @@ extern bopti_image_t img_mainship2; +extern bopti_image_t img_Ennemy_Blue_Lvl1; Ennemy::Ennemy( int16_t _x, int16_t _y, uint8_t _id ) { @@ -21,6 +22,13 @@ Ennemy::Ennemy( int16_t _x, int16_t _y, uint8_t _id ) height = img_mainship2.height/2; speed = 1; } + else if (ID==1) + { + width = img_Ennemy_Blue_Lvl1.width/2; + height = img_Ennemy_Blue_Lvl1.height/2; + speed = 2; + } + xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; @@ -28,7 +36,8 @@ Ennemy::Ennemy( int16_t _x, int16_t _y, uint8_t _id ) toberemoved = false; - if (ID==0) life = 100; + if (ID==0) life = 400; + else if (ID==1) life = 200; } Ennemy::~Ennemy() @@ -57,6 +66,7 @@ void Ennemy::Update( float dt ) void Ennemy::Render( void ) { if (ID==0) azrp_image_p8_effect(xmin, ymin, &img_mainship2, IMAGE_VFLIP); + if (ID==1) azrp_image_p8_effect(xmin, ymin, &img_Ennemy_Blue_Lvl1, DIMAGE_NONE); } diff --git a/src/main.cpp b/src/main.cpp index 1d37924..f13b1cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,7 @@ #include +#include "player.h" #include "utilities.h" #include "particles.h" #include "bullet.h" @@ -54,8 +55,7 @@ uint8_t texttodraw=1; extern bopti_image_t img_mainship1; -uint16_t playerX = 0; -uint16_t playerY = 0; +Player *MyPlayer; @@ -102,15 +102,15 @@ void Create_Player_Shoot( uint8_t id ) if (id==0) { - Bullet *b = new Bullet( playerX, playerY-21, id ); + Bullet *b = new Bullet( MyPlayer->x, MyPlayer->y-21, id ); MyPlayerBullets.push_back( b ); } else if (id==1) { - Bullet *b1 = new Bullet( playerX-17, playerY, id ); + Bullet *b1 = new Bullet( MyPlayer->x-17, MyPlayer->y, id ); MyPlayerBullets.push_back( b1 ); - Bullet *b2 = new Bullet( playerX+17, playerY, id ); + Bullet *b2 = new Bullet( MyPlayer->x+17, MyPlayer->y, id ); MyPlayerBullets.push_back( b2 ); } @@ -126,11 +126,11 @@ void Create_Ennemies( void ) e2->Set_Speed_Vector( 1, 6, 1 ); MyEnnemies.push_back( e2 ); - Ennemy* e3 = new Ennemy( 198, 50, 0); + Ennemy* e3 = new Ennemy( 198, 50, 1); e3->Set_Speed_Vector( 1, -3, 3 ); MyEnnemies.push_back( e3 ); - Ennemy* e4 = new Ennemy( 198, 50, 0); + Ennemy* e4 = new Ennemy( 198, 50, 1); e4->Set_Speed_Vector( 1, 3, 3 ); MyEnnemies.push_back( e4 ); } @@ -147,10 +147,37 @@ void Create_Explosion( uint16_t xexplosion, uint16_t yexplosion ) } +void Clean_Everything( void ) +{ + for(unsigned int i=0; iUpdate( dt ); + for(auto& e : MyEnnemies) e->Update( dt ); @@ -201,15 +228,14 @@ static void update( float dt ) //TODO : we can create a list of impacts here, to be rendered later on } } - } - //MyStarField->Update( dt ); - + } } static void get_inputs( void ) { uint8_t speed = 4; + uint32_t tempshoot = rtc_ticks(); key_event_t ev; while((ev = pollevent()).type != KEYEV_NONE) @@ -218,8 +244,22 @@ static void get_inputs( void ) } //if(keydown(KEY_F3)) {Create_Explosion();} - if(keydown(KEY_F1)) {Create_Player_Shoot(0);} - if(keydown(KEY_F2)) {Create_Player_Shoot(1);} + if(keydown(KEY_F1)) + { + if(tempshoot-MyPlayer->lastshoot1>8) + { + Create_Player_Shoot(0); + MyPlayer->lastshoot1=tempshoot; + } + } + if(keydown(KEY_F2)) + { + if(tempshoot-MyPlayer->lastshoot2>15) + { + Create_Player_Shoot(1); + MyPlayer->lastshoot2=tempshoot; + } + } if(keydown(KEY_EXIT)) {exitToOS = true; }; @@ -237,23 +277,19 @@ static void get_inputs( void ) if(keydown(KEY_LEFT)) { - if(playerX>img_mainship1.width/2+speed) - playerX-=speed; + MyPlayer->Go_Left(); } if(keydown(KEY_RIGHT)) { - if(playerXGo_Right(); } if(keydown(KEY_UP)) { - if(playerY>img_mainship1.height/2+speed) - playerY-=speed; + MyPlayer->Go_Up(); } if(keydown(KEY_DOWN)) { - if(playerYGo_Down(); } @@ -354,8 +390,8 @@ int main(void) Create_Ennemies( ); - playerX = azrp_width/2; - playerY = azrp_height-img_mainship1.height/2; + MyPlayer = new Player( azrp_width/2, azrp_height/2, 0); + usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL }; usb_open(interfaces, GINT_CALL_NULL); @@ -396,7 +432,7 @@ int main(void) #if(BIAS) if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000000.0f / elapsedTime) ); if (texttodraw>=1) Azur_draw_text(1,11, "Part.= %d - Bull.= %d", MyParticles.size(), MyPlayerBullets.size() ); - if (texttodraw>=1 && !MyEnnemies.empty()) Azur_draw_text(1,21, "Ennrmy Life= %d", MyEnnemies[0]->life ); + if (texttodraw>=1 && !MyEnnemies.empty()) Azur_draw_text(1,21, "Ennmy Life= %d", MyEnnemies[0]->life ); if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update ); if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.0f mc secs", (float) time_render ); if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f ); @@ -423,8 +459,7 @@ int main(void) for(auto& p : MyParticles) p->Render(); - azrp_image_p8(playerX-img_mainship1.width/2, playerY-img_mainship1.height/2, &img_mainship1, DIMAGE_NONE); - + MyPlayer->Render(); azrp_update(); } @@ -455,9 +490,7 @@ int main(void) while (exitToOS==false); - for(auto& p : MyParticles) delete(p); - MyParticles.clear(); - + Clean_Everything(); azrp_starfield_close( ); diff --git a/src/player.cpp b/src/player.cpp new file mode 100644 index 0000000..40445d9 --- /dev/null +++ b/src/player.cpp @@ -0,0 +1,155 @@ +#include "player.h" +#include "bullet.h" +#include "ennemy.h" +#include +#include +#include + + +extern bopti_image_t img_mainship1; +extern bopti_image_t img_Satellite_Lvl1; + +static int16_t cosTable[360], sinTable[360]; +#define PI 3.141592 + +Player::Player( int16_t _x, int16_t _y, uint8_t _id ) +{ + x = _x; + y = _y; + + ID = _id; + + width = img_mainship1.width/2; + height = img_mainship1.height/2; + speed = 2; + + xmin = (int) x - width; + xmax = (int) x + width; + ymin = (int) y - height; + ymax = (int) y + height; + + if (ID==0) life = 1000; + + lastshoot1 = rtc_ticks(); + lastshoot2 = rtc_ticks(); + + satellites = true; + satLevel = 1; + satNumber = 6; + satAngle = 0; + satRadius = 50; + satSpeed = 2; + + for(int u=0; u<360; u++) + { + cosTable[u] = (int16_t) (satRadius*cos( u * PI / 180 )); + sinTable[u] = (int16_t) (satRadius*sin( u * PI / 180 )); + } +} + +Player::~Player() +{ + + +} + +void Player::Update( float dt ) +{ + xmin = (int) x - width; + xmax = (int) x + width; + ymin = (int) y - height; + ymax = (int) y + height; + + if(satellites) + { + satAngle += satSpeed * dt / 25000.0f; + if (satAngle>360.0f) satAngle-=360.0f; + } +} + +void Player::Render( void ) +{ + if (ID==0) azrp_image_p8_effect(xmin, ymin, &img_mainship1, DIMAGE_NONE); + + int w = img_Satellite_Lvl1.width/2; + int h = img_Satellite_Lvl1.height/2; + + if(satellites) + { + int incangle = 360/satNumber; + + for(int u=0; ux >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax ) + { + life -= projectile->strength; + projectile->toberemoved = true; + return true; + } + else return false; +} + +bool Player::Test_Impact( Ennemy *adverseship ) +{ + if (adverseship->xmax >= xmin && adverseship->xmin <= xmax && adverseship->ymax >= ymin && adverseship->ymin <= ymax ) + { + life -= 50; + adverseship->life -= 25; + return true; + } + else return false; +} + +void Player::Set_Speed( uint8_t _sp ) +{ + speed = _sp; +} + + +void Player::Go_Left( void ) +{ + if( x > width/2+speed ) + { + x -= speed; + this->Update( 0.0f ); + } +} + +void Player::Go_Right( void ) +{ + if(x < azrp_width-width/2-speed) + { + x += speed; + this->Update( 0.0f ); + } +} + +void Player::Go_Up( void ) +{ + if(y > height/2+speed) + { + y -= speed; + this->Update( 0.0f ); + } +} + +void Player::Go_Down( void ) +{ + if(y < azrp_height -height/2 -speed) + { + y += speed; + this->Update( 0.0f ); + } +} \ No newline at end of file diff --git a/src/player.h b/src/player.h new file mode 100644 index 0000000..ec70952 --- /dev/null +++ b/src/player.h @@ -0,0 +1,55 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include +#include + +#include +#include + +#include +#include "bullet.h" +#include "ennemy.h" + + +class Player +{ + public: + Player( int16_t _x, int16_t _y, uint8_t _id ); + ~Player(); + + void Update( float dt ); + void Render( void ); + + bool Test_Impact( Bullet *projectile ); + bool Test_Impact( Ennemy *adverseship ); + void Set_Speed( uint8_t _sp ); + + void Go_Left( void ); + void Go_Right( void ); + void Go_Up( void ); + void Go_Down( void ); + + uint16_t x, y; // center position of the player + 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 the player + uint32_t lastshoot1 = 0; + uint32_t lastshoot2 = 0; + + bool satellites; + uint8_t satLevel; + uint8_t satNumber; + uint8_t satSpeed; + + private: + float satAngle; + uint8_t satRadius; +}; + + + + +#endif \ No newline at end of file