From c108631ffb580cfed1e92b1a0713e11d8dcbdddd Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 9 Oct 2015 23:49:43 +0800 Subject: Suffering from object slicing (?)... However a test program doesn't... I am really puzzled. --- src/core/bullet.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/core/bullet.cpp') 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 +#include +#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;iexist&&!bullets[i]->special) + { + bullets[i]->exist=false; + int ptr=allocBullet(); + bullets[ptr]->init(0,bullets[i]->vel.x,bullets[i]->vel.y); + } for(int i=0;iexist) bullets[i]->update(); -- cgit v1.2.3