added lasers [WIP]

This commit is contained in:
Sylvain PILLOT 2023-01-22 11:07:36 +01:00
parent 34fa959d5e
commit cc38291736
6 changed files with 79 additions and 18 deletions

View File

@ -31,6 +31,7 @@ set(ASSETS_cg
assets-cg/Sprites/Bullets/bullet_normal.png
assets-cg/Sprites/Bullets/bullet_blue.png
assets-cg/Sprites/Bullets/bullet_laser.png
assets-cg/Sprites/Players/mainship1.png
assets-cg/Sprites/Players/Satellite_Lvl1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

View File

@ -11,7 +11,7 @@
extern bopti_image_t img_bullet_normal;
extern bopti_image_t img_bullet_blue;
extern bopti_image_t img_bullet_laser;
Bullet::Bullet( uint16_t lx, uint16_t ly, uint8_t id )
{
@ -32,7 +32,12 @@ Bullet::Bullet( uint16_t lx, uint16_t ly, uint8_t id )
sy = libnum::num( -3 );
strength = 2;
}
else if (ID==2)
{
sx = 0;
sy = libnum::num( -6 );
strength = 1;
}
toberemoved = false;
}
@ -66,5 +71,10 @@ void Bullet::Render( )
azrp_image_p8( px-4, py-11, &img_bullet_blue, DIMAGE_NONE );
return;
}
else if (ID==2)
{
azrp_image_p8( px-4, py-11, &img_bullet_laser, DIMAGE_NONE );
return;
}
}

View File

@ -1,3 +1,5 @@
#define DEBUG_MODE 1
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <gint/drivers/r61524.h>
@ -113,7 +115,17 @@ void Create_Player_Shoot( uint8_t id )
Bullet *b2 = new Bullet( MyPlayer->x+17, MyPlayer->y, id );
MyPlayerBullets.push_back( b2 );
}
else if (id==2)
{
Bullet *b1 = new Bullet( MyPlayer->x, MyPlayer->y-21, id );
MyPlayerBullets.push_back( b1 );
Bullet *b2 = new Bullet( MyPlayer->x+17, MyPlayer->y, id );
MyPlayerBullets.push_back( b2 );
Bullet *b3 = new Bullet( MyPlayer->x-17, MyPlayer->y, id );
MyPlayerBullets.push_back( b3 );
}
}
void Create_Ennemies( void )
@ -135,6 +147,7 @@ void Create_Ennemies( void )
MyEnnemies.push_back( e4 );
}
void Create_Explosion( uint16_t xexplosion, uint16_t yexplosion )
{
srand(rtc_ticks());
@ -246,33 +259,32 @@ static void get_inputs( void )
//if(keydown(KEY_F3)) {Create_Explosion();}
if(keydown(KEY_F1))
{
if(tempshoot-MyPlayer->lastshoot1>8)
{
Create_Player_Shoot(0);
MyPlayer->lastshoot1=tempshoot;
}
if (MyPlayer->Shoot_OK(tempshoot, 0)) Create_Player_Shoot(0);
}
if(keydown(KEY_F2))
{
if(tempshoot-MyPlayer->lastshoot2>15)
{
Create_Player_Shoot(1);
MyPlayer->lastshoot2=tempshoot;
}
if (MyPlayer->Shoot_OK(tempshoot, 1)) Create_Player_Shoot(1);
}
if(keydown(KEY_F3))
{
if (MyPlayer->Shoot_OK(tempshoot, 2)) Create_Player_Shoot(2);
}
if(keydown(KEY_EXIT)) {exitToOS = true; };
if(keydown(KEY_7)) {screenshot = true;};
if(keydown(KEY_8)) {record = true; };
if(keydown(KEY_9)) {record = false; };
if(keydown(KEY_DEL)) {textoutput = true;};
#if(DEBUG_MODE)
if(keydown(KEY_7) && usb_is_open() ) {screenshot = true;};
if(keydown(KEY_8) && usb_is_open()) {record = true; };
if(keydown(KEY_9) && usb_is_open()) {record = false; };
if(keydown(KEY_DEL) && usb_is_open()) {textoutput = true;};
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;}
#endif
if(keydown(KEY_LEFT))
@ -480,12 +492,15 @@ int main(void)
elapsedTime = ((float) (time_update+time_render));
#if(DEBUG_MODE)
if (textoutput && usb_is_open())
{
azrp_starfield_USBDEBUG( SHOW_PIXELS );
azrp_starfield_USBDEBUG( SHOW_STARS );
textoutput = false;
}
#endif
}
while (exitToOS==false);

View File

@ -30,6 +30,7 @@ Player::Player( int16_t _x, int16_t _y, uint8_t _id )
if (ID==0) life = 1000;
lastshoot0 = rtc_ticks();
lastshoot1 = rtc_ticks();
lastshoot2 = rtc_ticks();
@ -117,6 +118,37 @@ void Player::Set_Speed( uint8_t _sp )
speed = _sp;
}
bool Player::Shoot_OK( uint32_t tempshoot, uint8_t shootID )
{
if (shootID==0)
{
if(tempshoot-lastshoot0>8)
{
lastshoot0=tempshoot;
return true;
}
else return false;
}
else if (shootID==1)
{
if(tempshoot-lastshoot1>15)
{
lastshoot1=tempshoot;
return true;
}
else return false;
}
else if (shootID==2)
{
if(tempshoot-lastshoot2>2)
{
lastshoot2=tempshoot;
return true;
}
else return false;
}
else return false;
}
void Player::Go_Left( void )
{

View File

@ -25,6 +25,8 @@ class Player
bool Test_Impact( Ennemy *adverseship );
void Set_Speed( uint8_t _sp );
bool Shoot_OK( uint32_t tempshoot, uint8_t shootID );
void Go_Left( void );
void Go_Right( void );
void Go_Up( void );
@ -36,6 +38,7 @@ class Player
uint8_t ID;
int16_t life;
uint8_t speed; // speed of the player
uint32_t lastshoot0 = 0;
uint32_t lastshoot1 = 0;
uint32_t lastshoot2 = 0;