00001 #include "nncmath.h"
00002 #include "objmgr.h"
00003 #include "bearspawn.h"
00004
00005 #define SPAWN_TIME 4000
00006
00007 BearSpawnPoint::BearSpawnPoint(ObjectManager &om, pointtype pt) :
00008 GameObject(om, "Spawn Point")
00009 {
00010 c_pointtype = pt;
00011 spawn_delay = SPAWN_TIME;
00012 lastspawntime = Util_GetTime();
00013 }
00014
00015 BearSpawnPoint::BearSpawnPoint(ObjectManager &om, double xp, double yp, pointtype pt) : GameObject(om)
00016 {
00017 c_pointtype = pt;
00018 spawn_delay = SPAWN_TIME;
00019 SetPosition(xp, yp);
00020 lastspawntime = Util_GetTime();
00021 }
00022
00023
00024 void BearSpawnPoint::SetPointType(pointtype pt)
00025 {
00026 c_pointtype = pt;
00027 }
00028
00029 void BearSpawnPoint::think()
00030 {
00031 int count;
00032 if((count = Util_TimePassed(&lastspawntime, spawn_delay)) != 0) {
00033 for(int i = 0; i < count; i++) {
00034 GameObject *obj = OM.AddObject(OT_BEAR);
00035
00036
00037 switch(c_pointtype) {
00038 case PT_POINT:
00039 obj->SetPosition(Xpos, Ypos);
00040 break;
00041 case PT_VLINE:
00042 obj->SetPosition(Xpos, Ypos+Util_Random(100)-50);
00043 break;
00044 case PT_HLINE:
00045 obj->SetPosition(Xpos+Util_Random(100)-50, Ypos);
00046 break;
00047 case PT_SQUARE:
00048 obj->SetPosition(Xpos+Util_Random(100)-50,
00049 Ypos+Util_Random(100)-50);
00050 break;
00051 case PT_CIRCLE:
00052 {
00053 radian r;
00054 r.value = Util_Random((int)(2*NNCMath::PI*1000))/1000.0;
00055 obj->SetPosition(Xpos+NNCMath::Cos(r)*50,
00056 Ypos+NNCMath::Sin(r)*50);
00057 break;
00058 }
00059 default:
00060 break;
00061 }
00062 }
00063 }
00064 }
00065