From b9d4b60486e224261990c0732852513e86dd94ff Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 2 Oct 2015 23:48:34 +0800 Subject: Add BLR3 files. Modify Readme. Currently BLR3 is VERY primitive!! --- src/core/bullet.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/core/bullet.cpp (limited to 'src/core/bullet.cpp') diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp new file mode 100644 index 0000000..175bae4 --- /dev/null +++ b/src/core/bullet.cpp @@ -0,0 +1,101 @@ +#include "bullet.hpp" +#include "../master/resources.hpp" +#include +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::update() +{ + if(!exist)return; + vel=vel+acc; + if(vel.l()>velim&&velim>0)vel=velim*vel.getNormalized(); + pos=pos-vel; + if(!extborder&&(pos.x<-10||pos.y<-10||pos.x>810||pos.y>610))exist=false; + //check clr & collision +} +void bulletBase::render() +{ + //test view mode + bmInstance->getBulEntity2D(basecolor)->setColor(0xC0FFFFFF); + bmInstance->getBulEntity2D(basecolor)->render(pos.x,pos.y,0,renderscale*0.6); +} +bulletBase::~bulletBase(){} + +void bulletBonus::update() +{ + //the player is not implemented yet... +} + +void bulletManager::init() +{ + alloced=used=0; + for(int i=0;i<(int)COLOR_COUNT;++i) + { + bulent2d[i]=new smEntity2D(ssanm.getTextureInfo(bsnames[i])->tex,ssanm.getTextureInfo(bsnames[i])->rect); + bulent3d[i]=new smEntity3D(ssanm.getTextureInfo(bsnames[i])->tex,ssanm.getTextureInfo(bsnames[i])->rect); + } +} +void bulletManager::deinit() +{ + if(alloced){for(int i=0;i +int bulletManager::allocBullet() +{ + if(!alloced) + { + alloced=1; + bullets[0]=new T; + return 0; + } + else + { + int i; + for(i=0;iexist)break; + if(i==alloced) + bullets[alloced++]=new T; + return i; + } + return -1; +} +template +int bulletManager::createBullet() +{ + //stub... + int ptr=allocBullet(); + bullets[ptr]->init(); + return ptr; +} +void bulletManager::updateBullet() +{ + static int b=0; + ++b; + if(b>15) + { + int a=createBullet(); + bulletBase* x=getHandle(a); + x->pos=smvec2d(400,300); + x->vel=smvec2d(rand()%100-50,rand()%100-50); + x->vel.normalize(); + b=0; + } + for(int i=0;iexist) + bullets[i]->update(); +} +void bulletManager::renderBullet() +{ + for(int i=0;iexist) + { + bullets[i]->render(); + } +} +smEntity2D* bulletManager::getBulEntity2D(TColors col){return bulent2d[col];} +smEntity3D* bulletManager::getBulEntity3D(TColors col){return bulent3d[col];} +bulletBase* bulletManager::getHandle(int id){if(id