new class Player with satellites + different ennemies + lower speed shoot
|
@ -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
|
||||
|
||||
|
||||
# ...
|
||||
|
|
Before Width: | Height: | Size: 808 B After Width: | Height: | Size: 808 B |
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 704 B |
|
@ -0,0 +1,5 @@
|
|||
*.png:
|
||||
type: bopti-image
|
||||
name_regex: (.*)\.png img_\1
|
||||
section: .data
|
||||
profile: p8_rgb565a
|
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,5 @@
|
|||
*.png:
|
||||
type: bopti-image
|
||||
name_regex: (.*)\.png img_\1
|
||||
section: .data
|
||||
profile: p8_rgb565a
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 261 B After Width: | Height: | Size: 261 B |
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 231 B |
|
@ -0,0 +1,5 @@
|
|||
*.png:
|
||||
type: bopti-image
|
||||
name_regex: (.*)\.png img_\1
|
||||
section: .data
|
||||
profile: p8_rgb565a
|
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,5 @@
|
|||
*.png:
|
||||
type: bopti-image
|
||||
name_regex: (.*)\.png img_\1
|
||||
section: .data
|
||||
profile: p8_rgb565a
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
89
src/main.cpp
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <num/num.h>
|
||||
|
||||
#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; i<MyEnnemies.size(); i++)
|
||||
{
|
||||
delete( MyEnnemies[i] );
|
||||
MyEnnemies.erase( MyEnnemies.begin() + i );
|
||||
}
|
||||
MyEnnemies.clear();
|
||||
|
||||
for(unsigned int i=0; i<MyParticles.size(); i++)
|
||||
{
|
||||
delete( MyParticles[i] );
|
||||
MyParticles.erase( MyParticles.begin() + i );
|
||||
}
|
||||
MyParticles.clear();
|
||||
|
||||
for(unsigned int i=0; i<MyPlayerBullets.size(); i++)
|
||||
{
|
||||
delete( MyPlayerBullets[i] );
|
||||
MyPlayerBullets.erase( MyPlayerBullets.begin() + i );
|
||||
}
|
||||
MyPlayerBullets.clear();
|
||||
}
|
||||
|
||||
|
||||
static void update( float dt )
|
||||
{
|
||||
// all update stuff depending on time will be done here
|
||||
|
||||
MyPlayer->Update( 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(playerX<azrp_width-img_mainship1.width/2-speed)
|
||||
playerX+=speed;
|
||||
MyPlayer->Go_Right();
|
||||
}
|
||||
if(keydown(KEY_UP))
|
||||
{
|
||||
if(playerY>img_mainship1.height/2+speed)
|
||||
playerY-=speed;
|
||||
MyPlayer->Go_Up();
|
||||
}
|
||||
if(keydown(KEY_DOWN))
|
||||
{
|
||||
if(playerY<azrp_height-img_mainship1.height/2-speed)
|
||||
playerY+=speed;
|
||||
MyPlayer->Go_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( );
|
||||
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
#include "player.h"
|
||||
#include "bullet.h"
|
||||
#include "ennemy.h"
|
||||
#include <num/num.h>
|
||||
#include <gint/rtc.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
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; u<satNumber; u++)
|
||||
{
|
||||
int angle = (int) satAngle + u*incangle;
|
||||
angle = angle % 360;
|
||||
int xsat = x + cosTable[angle];
|
||||
int ysat = y + sinTable[angle];
|
||||
azrp_image_p8_effect(xsat-w, ysat-h, &img_Satellite_Lvl1, DIMAGE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Player::Test_Impact( Bullet *projectile )
|
||||
{
|
||||
if (projectile->x >= 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 );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <azur/azur.h>
|
||||
#include <azur/gint/render.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <num/num.h>
|
||||
#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
|