aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/bullet.cpp31
-rw-r--r--src/core/bullet.hpp8
2 files changed, 35 insertions, 4 deletions
diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp
index e016300..8fdaa99 100644
--- a/src/core/bullet.cpp
+++ b/src/core/bullet.cpp
@@ -1,10 +1,12 @@
#include "bullet.hpp"
#include "../master/resources.hpp"
#include <cstdlib>
+#include <cstdarg>
+#include "player.hpp"
const char* bsnames[]={"green_bullet","cyan_bullet","yellow_bullet","purple_bullet",
"red_bullet","white_bullet","blue_bullet","orange_bullet",
"grey_bullet","circle_bullet"};
-void bulletBase::init(...){exist=true;renderscale=1;}
+void bulletBase::init(char fstarg,...){++fstarg;exist=true;renderscale=1;special=false;}
void bulletBase::update()
{
if(!exist)return;
@@ -22,9 +24,27 @@ void bulletBase::render()
}
bulletBase::~bulletBase(){}
+void bulletBonus::init(char fstarg,...)
+{
+ fstarg=0;va_list val;va_start(val,fstarg);
+ pos.x=va_arg(val,double);
+ pos.y=va_arg(val,double);
+ basecolor=grey;rendercolor=0x33FFFFFF;
+ va_end(val);renderscale=0.5;
+ attrf[0]=0;attrd[0]=0;exist=special=true;
+ vel.x=0;vel.y=-2;acc.x=0;acc.y=0.1;
+}
void bulletBonus::update()
{
//the player is not implemented yet...
+ if(vel.y>0)attrd[0]=1,acc=smvec2d(0,0);
+ if(attrd[0])
+ {
+ if(attrf[0]<10)attrf[0]+=.5;else attrf[0]=10.1;
+ vel=vel-player->pos;
+ vel.normalize();
+ vel=attrf[0]*vel;
+ }
}
void bulletManager::init()
@@ -44,6 +64,15 @@ void bulletManager::deinit()
}
void bulletManager::updateBullet()
{
+ extern SMELT *sm;
+ if(sm->smGetKeyState(SMK_SPACE)==SMKST_HIT)
+ for(int i=0;i<alloced;++i)
+ if(bullets[i]->exist&&!bullets[i]->special)
+ {
+ bullets[i]->exist=false;
+ int ptr=allocBullet<bulletBonus>();
+ bullets[ptr]->init(0,bullets[i]->vel.x,bullets[i]->vel.y);
+ }
for(int i=0;i<alloced;++i)
if(bullets[i]->exist)
bullets[i]->update();
diff --git a/src/core/bullet.hpp b/src/core/bullet.hpp
index f3dd9f2..d8f275e 100644
--- a/src/core/bullet.hpp
+++ b/src/core/bullet.hpp
@@ -15,18 +15,20 @@ public:
bool extborder,invincible;
//extborder: true=not removed if out of screen.
//invincible: true=not removed if collided with player or in range of CLR.
- bool exist,addblend;
+ bool exist,addblend,special;
int attrd[8];
double attrf[8];
TColors basecolor;
DWORD rendercolor;
- virtual void init(...);
+ virtual void init(char fstarg,...);
virtual void update();
virtual void render();
virtual ~bulletBase();
};
class bulletBonus:public bulletBase
{
+public:
+ void init(char fstarg,...)override;
void update()override;
};
class bulletManager
@@ -62,7 +64,7 @@ public:
{
//stub...
int ptr=allocBullet<T>();
- bullets[ptr]->init();
+ bullets[ptr]->init(0);
return ptr;
}
void updateBullet();