From 627d814f487ac38d4f9b9b71da9bef46f33b3dad Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 11 Oct 2015 22:04:05 +0800 Subject: Implement the collision system and a simple effect. Fixed a problem that keeps the screen black on start up. Replace the build script in dtputil with makefile. Sync with the newest SMELT revision. --- src/blr3.dtp | Bin 459968 -> 459997 bytes src/core/bullet.cpp | 53 +++++++++++++++++++++++++++++++++++++++----- src/core/bullet.hpp | 11 +++++++-- src/core/gamescene.cpp | 4 ++++ src/core/player.cpp | 4 ++-- src/core/player.hpp | 2 +- src/master/intro.cpp | 2 +- src/plugin/pluginmgr_dl.cpp | 7 +++--- 8 files changed, 68 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/blr3.dtp b/src/blr3.dtp index bda99d9..58a5de6 100644 Binary files a/src/blr3.dtp and b/src/blr3.dtp differ diff --git a/src/core/bullet.cpp b/src/core/bullet.cpp index 7a5682b..ddbf964 100644 --- a/src/core/bullet.cpp +++ b/src/core/bullet.cpp @@ -6,7 +6,12 @@ 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(char fstarg,...){++fstarg;exist=true;renderscale=1;special=false;} +void bulletBase::init(char fstarg,...) +{ + ++fstarg;exist=true;renderscale=1; + special=invincible=false;scollrange=64;collrange=16; + scb=cb=8; +} void bulletBase::update() { if(!exist)return; @@ -14,7 +19,18 @@ void bulletBase::update() 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 + if((pos-player->pos).l()>scollrange)if(invincible)cscb=scb; + if((pos-player->pos).l()>collrange)if(invincible)ccb=cb; + if((pos-player->pos).l()<=scollrange&&(pos-player->pos).l()>collrange) + { + if(!invincible)scollrange=-1,++player->scoll,bmInstance->addFXBullet(grey); + else{if(++cscb>scb)cscb=0,++player->scoll,bmInstance->addFXBullet(grey);} + } + if((pos-player->pos).l()<=collrange) + { + if(!invincible)exist=false,++player->coll,bmInstance->addFXBullet(red); + else{if(++ccb>cb)ccb=0,++player->coll,bmInstance->addFXBullet(red);} + } } void bulletBase::render() { @@ -36,8 +52,11 @@ void bulletBonus::init(char fstarg,...) } void bulletBonus::update() { - bulletBase::update(); - if((pos-player->pos).l()<9) exist=false; + if(!exist)return; + vel=vel+acc; + if(vel.l()>velim&&velim>0)vel=velim*vel.getNormalized(); + pos=pos-vel; + if((pos-player->pos).l()<9)exist=false; if(vel.y<0&&!attrd[0])attrd[0]=1,acc=smvec2d(0,0); if(attrd[0]) @@ -48,6 +67,23 @@ void bulletBonus::update() vel=attrf[0]*vel; } } +void bulletFX::init(char fstarg,...) +{ + fstarg=0;va_list val;va_start(val,fstarg); + pos=player->pos; + basecolor=(TColors)va_arg(val,int); + rendercolor=0x33FFFFFF; + va_end(val);renderscale=0.4;collrange=scollrange=-1; + attrf[0]=0;attrd[0]=0;exist=special=invincible=true; + vel.x=rand()%1000-500;vel.y=rand()%1000-500; + vel=(2+rand()%3+rand()%10/10.)*vel.getNormalized(); +} +void bulletFX::update() +{ + pos=pos-vel; + rendercolor=SETA(rendercolor,GETA(rendercolor)-2); + if(GETA(rendercolor)<=2)exist=false; +} void bulletManager::init() { @@ -73,8 +109,7 @@ void bulletManager::updateBullet() { bullets[i]->exist=false; smvec2d p=bullets[i]->pos; - int ptr=allocBullet(); - bullets[ptr]->init(0,p.x,p.y); + bullets[allocBullet()]->init(0,p.x,p.y); } for(int i=0;iexist) @@ -88,6 +123,12 @@ void bulletManager::renderBullet() bullets[i]->render(); } } +void bulletManager::addFXBullet(TColors col) +{ + int c=rand()%5+5; + for(int i=0;i()]->init(0,col); +} smEntity2D* bulletManager::getBulEntity2D(TColors col){return bulent2d[col];} smEntity3D* bulletManager::getBulEntity3D(TColors col){return bulent3d[col];} bulletBase* bulletManager::getHandle(int id){if(idsmGetDelta(); extern sceneManager *sceneMgr;float lps=sceneMgr->getLPS(); if(udly>1){udly=0;utime=sceneMgr->getTHUpdateTime();} + ttfont.updateString(L"Coll: %d\n",player->coll); + ttfont.render(0,50,0xFFFFFFFF,ALIGN_LEFT); + ttfont.updateString(L"SColl: %d\n",player->scoll); + ttfont.render(0,65,0xFFFFFFFF,ALIGN_LEFT); ttfont.updateString(L"LPS: %.2f",lps); ttfont.render(0,680,0xFFFFFFFF,ALIGN_LEFT); ttfont.updateString(L"Update Time: %dns",utime); diff --git a/src/core/player.cpp b/src/core/player.cpp index 5cbc47e..d461b52 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -11,7 +11,7 @@ playerBase::playerBase(double _x,double _y) plyrctl[0]=SMK_UP;plyrctl[1]=SMK_DOWN; plyrctl[2]=SMK_LEFT;plyrctl[3]=SMK_RIGHT; plyrctl[4]=SMK_SHIFT; - rot=0; + rot=0;scoll=coll=0;vel=3.5;velp=1.5; } playerBase::~playerBase() { @@ -22,7 +22,7 @@ void playerBase::update() //player control... static double realspeed=0; if(sm->smGetKeyState(plyrctl[4])) - realspeed=0.85;else realspeed=3.5; + realspeed=velp;else realspeed=vel; if(sm->smGetKeyState(plyrctl[0])) {if(pos.y>15)pos.y-=realspeed;else pos.y=15;} if(sm->smGetKeyState(plyrctl[1])) diff --git a/src/core/player.hpp b/src/core/player.hpp index 51f4c79..2580e7a 100644 --- a/src/core/player.hpp +++ b/src/core/player.hpp @@ -10,7 +10,7 @@ private: public: smvec2d pos; double rot,vel,velp; - int plyrctl[6]; + int plyrctl[6],coll,scoll; playerBase(double _x=400,double _y=400); ~playerBase(); diff --git a/src/master/intro.cpp b/src/master/intro.cpp index f8cf46b..1e45ddb 100644 --- a/src/master/intro.cpp +++ b/src/master/intro.cpp @@ -182,7 +182,7 @@ introScene::introScene() sm=smGetInterface(SMELT_APILEVEL); pos=new smvec2d[1024];vel=new smvec2d[1024]; scale=new float[1024];acc=new smvec2d[1024]; - extern const char* bsnames[]; + extern const char* bsnames[];delay=0; smTexInfo *ti=ssanm.getTextureInfo(bsnames[rand()%8]); blt=new smEntity2D(ti->tex,ti->rect); blt->setCentre(12,12); diff --git a/src/plugin/pluginmgr_dl.cpp b/src/plugin/pluginmgr_dl.cpp index f3ab816..337fa99 100644 --- a/src/plugin/pluginmgr_dl.cpp +++ b/src/plugin/pluginmgr_dl.cpp @@ -1,17 +1,18 @@ #include #include +#include #include "pluginmgr.hpp" pluginManager::pluginManager() { - pluginFolder="./plugins"; + strcpy(pluginFolder,"./plugins"); } void pluginManager::scanPlugin() { DIR *dir; struct dirent *file; - if(dir=opendir(pluginFolder)) + if((dir=opendir(pluginFolder))) { - while(file=readdir(dir)) + while((file=readdir(dir))) //puts(file->d_name); if(strcmp(file->d_name+strlen(file->d_name)-3,".so")==0) strcpy(fn[fcnt++],file->d_name); -- cgit v1.2.3