Added bullets
This commit is contained in:
parent
61ef31bc16
commit
cdce9ab3c5
|
@ -15,18 +15,25 @@ set(SOURCES
|
|||
src/main.cpp
|
||||
src/utilities.cpp
|
||||
src/particles.cpp
|
||||
src/bullet.cpp
|
||||
src/starfieldshader.cpp
|
||||
# ...
|
||||
)
|
||||
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/fill_circ.png
|
||||
|
||||
assets-cg/Sprites/bullet_normal.png
|
||||
assets-cg/Sprites/bullet_blue.png
|
||||
|
||||
assets-cg/Sprites/mainship1.png
|
||||
assets-cg/Sprites/mainship2.png
|
||||
|
||||
|
||||
|
||||
# ...
|
||||
)
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 808 B |
Binary file not shown.
After Width: | Height: | Size: 704 B |
|
@ -0,0 +1,68 @@
|
|||
#include "bullet.h"
|
||||
|
||||
#include <azur/azur.h>
|
||||
#include <azur/gint/render.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <num/num.h>
|
||||
|
||||
|
||||
extern bopti_image_t img_bullet_normal;
|
||||
extern bopti_image_t img_bullet_blue;
|
||||
|
||||
|
||||
Bullet::Bullet( uint16_t lx, uint16_t ly, uint8_t id )
|
||||
{
|
||||
x = libnum::num( lx );
|
||||
y = libnum::num( ly );
|
||||
|
||||
ID=id;
|
||||
|
||||
if (ID==0)
|
||||
{
|
||||
sx = 0;
|
||||
sy = libnum::num( -6 );
|
||||
}
|
||||
else if (ID==1)
|
||||
{
|
||||
sx = 0;
|
||||
sy = libnum::num( -3 );
|
||||
}
|
||||
|
||||
toberemoved = false;
|
||||
}
|
||||
|
||||
Bullet::~Bullet()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Bullet::Update( float dt )
|
||||
{
|
||||
libnum::num a = libnum::num( dt / 12000.0f );
|
||||
x += sx * a;
|
||||
y += sy * a;
|
||||
|
||||
if (y<-10) toberemoved=true;
|
||||
}
|
||||
|
||||
void Bullet::Render( )
|
||||
{
|
||||
uint16_t px = (int) x;
|
||||
uint16_t py = (int) y;
|
||||
|
||||
if (ID==0)
|
||||
{
|
||||
azrp_image_p8( px-4, py-11, &img_bullet_normal, DIMAGE_NONE );
|
||||
return;
|
||||
}
|
||||
else if (ID==1)
|
||||
{
|
||||
azrp_image_p8( px-4, py-11, &img_bullet_blue, DIMAGE_NONE );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef BULLET_H
|
||||
#define BULLET_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <num/num.h>
|
||||
|
||||
class Bullet
|
||||
{
|
||||
public:
|
||||
Bullet( uint16_t lx, uint16_t ly, uint8_t id );
|
||||
~Bullet();
|
||||
void Update( float dt );
|
||||
void Render();
|
||||
|
||||
uint8_t ID;
|
||||
|
||||
libnum::num x, y;
|
||||
libnum::num sx, sy;
|
||||
|
||||
bool toberemoved;
|
||||
};
|
||||
|
||||
#endif //PARTICLES_H
|
91
src/main.cpp
91
src/main.cpp
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "utilities.h"
|
||||
#include "particles.h"
|
||||
|
||||
#include "bullet.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -43,6 +43,8 @@ bool exitToOS = false;
|
|||
#define NOBIAS (1-BIAS)
|
||||
|
||||
std::vector<Particle*> MyParticles;
|
||||
std::vector<Bullet*> MyPlayerBullets;
|
||||
|
||||
Starfield *MyStarField;
|
||||
uint8_t texttodraw=1;
|
||||
|
||||
|
@ -94,6 +96,28 @@ static void hook_prefrag(int id, void *fragment, int size)
|
|||
MyStarField = new Starfield();
|
||||
}*/
|
||||
|
||||
|
||||
void Create_Player_Shoot( uint8_t id )
|
||||
{
|
||||
|
||||
if (id==0)
|
||||
{
|
||||
Bullet *b = new Bullet( playerX, playerY-21, id );
|
||||
MyPlayerBullets.push_back( b );
|
||||
}
|
||||
else if (id==1)
|
||||
{
|
||||
Bullet *b1 = new Bullet( playerX-17, playerY, id );
|
||||
MyPlayerBullets.push_back( b1 );
|
||||
|
||||
Bullet *b2 = new Bullet( playerX+17, playerY, id );
|
||||
MyPlayerBullets.push_back( b2 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Create_Explosion( void )
|
||||
{
|
||||
if(MyParticles.size()>=1) return;
|
||||
|
@ -114,7 +138,8 @@ void Create_Explosion( void )
|
|||
static void update( float dt )
|
||||
{
|
||||
// all update stuff depending on time will be done here
|
||||
|
||||
|
||||
|
||||
for(unsigned int i=0; i<MyParticles.size(); i++)
|
||||
{
|
||||
MyParticles[i]->Update( dt );
|
||||
|
@ -127,6 +152,19 @@ static void update( float dt )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0; i<MyPlayerBullets.size(); i++)
|
||||
{
|
||||
MyPlayerBullets[i]->Update( dt );
|
||||
|
||||
// Check if the property toberemoved has been set to "true" for particle deletion
|
||||
if (MyPlayerBullets[i]->toberemoved == true)
|
||||
{
|
||||
delete( MyPlayerBullets[i] );
|
||||
MyPlayerBullets.erase( MyPlayerBullets.begin() + i );
|
||||
}
|
||||
}
|
||||
|
||||
//MyStarField->Update( dt );
|
||||
|
||||
}
|
||||
|
@ -144,7 +182,9 @@ static void get_inputs( void )
|
|||
|
||||
movement = 0;
|
||||
|
||||
if(keydown(KEY_SHIFT)) {Create_Explosion();}
|
||||
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_EXIT)) {exitToOS = true; };
|
||||
|
||||
|
@ -153,31 +193,31 @@ static void get_inputs( void )
|
|||
if(keydown(KEY_9)) {record = false; };
|
||||
if(keydown(KEY_DEL)) {textoutput = true;};
|
||||
|
||||
if(keydown(KEY_F1)) {texttodraw=0;}
|
||||
if(keydown(KEY_F2)) {texttodraw=1;}
|
||||
if(keydown(KEY_F3)) {texttodraw=2;}
|
||||
if(keydown(KEY_F4)) {texttodraw=3;}
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F1)) {texttodraw=0;}
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F2)) {texttodraw=1;}
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F3)) {texttodraw=2;}
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F4)) {texttodraw=3;}
|
||||
|
||||
|
||||
|
||||
if(keydown(KEY_LEFT))
|
||||
{
|
||||
if(playerX>speed)
|
||||
if(playerX>img_mainship1.width/2+speed)
|
||||
playerX-=speed;
|
||||
}
|
||||
if(keydown(KEY_RIGHT))
|
||||
{
|
||||
if(playerX<azrp_width-img_mainship1.width-speed)
|
||||
if(playerX<azrp_width-img_mainship1.width/2-speed)
|
||||
playerX+=speed;
|
||||
}
|
||||
if(keydown(KEY_UP))
|
||||
{
|
||||
if(playerY>speed)
|
||||
if(playerY>img_mainship1.height/2+speed)
|
||||
playerY-=speed;
|
||||
}
|
||||
if(keydown(KEY_DOWN))
|
||||
{
|
||||
if(playerY<azrp_height-img_mainship1.height-speed)
|
||||
if(playerY<azrp_height-img_mainship1.height/2-speed)
|
||||
playerY+=speed;
|
||||
}
|
||||
|
||||
|
@ -276,11 +316,11 @@ int main(void)
|
|||
|
||||
azrp_starfield_init( 100 );
|
||||
|
||||
playerX = (azrp_width - img_mainship1.width)/2;
|
||||
playerY = azrp_height - img_mainship1.height;
|
||||
playerX = azrp_width/2;
|
||||
playerY = azrp_height-img_mainship1.height/2;
|
||||
|
||||
bossX = (azrp_width - img_mainship2.width)/2;
|
||||
bossY = 0;
|
||||
bossX = azrp_width/2 ;
|
||||
bossY = img_mainship2.height/2;
|
||||
|
||||
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
|
||||
usb_open(interfaces, GINT_CALL_NULL);
|
||||
|
@ -319,8 +359,8 @@ int main(void)
|
|||
azrp_clear( C_BLACK );
|
||||
|
||||
#if(BIAS)
|
||||
if (texttodraw>=1) Azur_draw_text(1,01, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
||||
if (texttodraw>=1) Azur_draw_text(1,11, "Parts = %d", MyParticles.size() );
|
||||
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>=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 );
|
||||
|
@ -332,19 +372,22 @@ int main(void)
|
|||
if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
|
||||
|
||||
if (texttodraw>=3) Azur_draw_text(1,121, "Size of Particles : %d bytes", sizeof(Particle) );
|
||||
|
||||
if (texttodraw>=3) Azur_draw_text(1,131, "Size of Bullets : %d bytes", sizeof(Bullet) );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
azrp_starfield();
|
||||
|
||||
for(auto& b : MyPlayerBullets)
|
||||
b->Render();
|
||||
|
||||
azrp_image_p8_effect(bossX-img_mainship2.width/2, bossY-img_mainship2.height/2, &img_mainship2, IMAGE_VFLIP);
|
||||
|
||||
for(auto& p : MyParticles)
|
||||
p->Render();
|
||||
|
||||
|
||||
azrp_starfield();
|
||||
|
||||
azrp_image_p8_effect(bossX, bossY, &img_mainship2, IMAGE_VFLIP);
|
||||
|
||||
azrp_image_p8(playerX, playerY, &img_mainship1, DIMAGE_NONE);
|
||||
azrp_image_p8(playerX-img_mainship1.width/2, playerY-img_mainship1.height/2, &img_mainship1, DIMAGE_NONE);
|
||||
|
||||
|
||||
azrp_update();
|
||||
|
|
Loading…
Reference in New Issue