SBSPSS/source/jellfish/jellfish.cpp

190 lines
3.6 KiB
C++
Raw Normal View History

2001-05-10 16:00:29 +02:00
/*=========================================================================
jellfish.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __JELLFISH_JELLFISH_H__
#include "jellfish\jellfish.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __ENEMY_NSJBACK_H__
#include "enemy\nsjback.h"
#endif
2001-05-10 23:30:17 +02:00
#ifndef __ENEMY_NSJ2BACK_H__
#include "enemy\nsj2back.h"
#endif
2001-05-11 00:19:55 +02:00
#ifndef __ENEMY_NBUTTFLY_H__
#include "enemy\nbuttfly.h"
#endif
2001-05-10 16:00:29 +02:00
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
u8 CJellyfishGenerator::m_jellyfishCount;
s32 CJellyfishGenerator::m_timer;
2001-05-10 18:47:35 +02:00
u8 CJellyfishGenerator::m_on;
2001-05-10 23:30:17 +02:00
u8 CJellyfishGenerator::m_level;
2001-05-10 16:00:29 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::init()
{
m_timer = 1 * GameState::getOneSecondInFrames();
m_jellyfishCount = 0;
2001-05-10 18:47:35 +02:00
m_on = true;
2001-05-10 23:30:17 +02:00
m_level = 1;
2001-05-10 18:47:35 +02:00
switch( CLevel::getCurrentChapter() )
{
case 1:
{
switch( CLevel::getCurrentChapterLevel() )
{
case 2:
{
2001-05-11 00:19:55 +02:00
m_level = 3;
2001-05-10 23:30:17 +02:00
break;
}
case 4:
{
m_level = 2;
break;
2001-05-10 18:47:35 +02:00
}
}
break;
}
}
2001-05-10 16:00:29 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::think( int _frames, CLevel *level )
{
2001-05-10 18:47:35 +02:00
if ( m_on )
2001-05-10 16:00:29 +02:00
{
2001-05-10 18:47:35 +02:00
if ( m_timer <= 0 )
2001-05-10 16:00:29 +02:00
{
2001-05-10 18:47:35 +02:00
if ( m_jellyfishCount < 10 )
2001-05-10 16:00:29 +02:00
{
2001-05-10 18:47:35 +02:00
// add jellyfish
m_timer = 1 * GameState::getOneSecondInFrames();
m_jellyfishCount++;
2001-05-11 00:19:55 +02:00
CNpcEnemy *enemy = NULL;
2001-05-10 23:30:17 +02:00
2001-05-11 00:19:55 +02:00
switch( m_level )
2001-05-10 23:30:17 +02:00
{
2001-05-11 00:19:55 +02:00
case 1:
{
enemy = new( "jellyfish" ) CNpcSmallJellyfishBackgroundEnemy;
2001-05-21 20:36:26 +02:00
ASSERT(enemy);
2001-05-11 00:19:55 +02:00
enemy->setType( CNpcEnemy::NPC_SMALL_JELLYFISH_BACKGROUND );
break;
}
case 2:
{
2001-05-21 20:36:26 +02:00
if ( getRnd() % 4 == 0 )
{
enemy = new( "jellyfish" ) CNpcSmallJellyfish2BackgroundEnemy;
ASSERT(enemy);
enemy->setType( CNpcEnemy::NPC_SMALL_JELLYFISH_2_BACKGROUND );
}
else
{
enemy = new( "jellyfish" ) CNpcSmallJellyfishBackgroundEnemy;
ASSERT(enemy);
enemy->setType( CNpcEnemy::NPC_SMALL_JELLYFISH_BACKGROUND );
}
2001-05-11 00:19:55 +02:00
break;
}
case 3:
{
2001-05-21 20:36:26 +02:00
enemy = new( "butterfly" ) CNpcButterflyBackgroundEnemy;
ASSERT(enemy);
2001-05-11 00:19:55 +02:00
enemy->setType( CNpcEnemy::NPC_BUTTERFLY_BACKGROUND );
break;
}
2001-05-10 23:30:17 +02:00
}
2001-05-10 18:47:35 +02:00
enemy->init();
enemy->setLayerCollision( level->getCollisionLayer() );
DVECTOR offset = CLevel::getCameraPos();
DVECTOR startPos;
2001-05-10 23:30:17 +02:00
2001-05-21 20:36:26 +02:00
CNpcSmallJellyfishBackgroundEnemy *jfish = ( CNpcSmallJellyfishBackgroundEnemy * ) enemy;
2001-05-11 00:19:55 +02:00
2001-05-21 20:36:26 +02:00
if ( ( getRnd() % 10 ) > 4 )
{
jfish->setTargetHeading( 0 );
startPos.vx = offset.vx - 20;
}
else
{
jfish->setTargetHeading( 2048 );
startPos.vx = offset.vx + VidGetScrW() + 20;
2001-05-10 18:47:35 +02:00
}
startPos.vy = offset.vy + ( getRnd() % VidGetScrH() );
enemy->setStartPos( startPos.vx >> 4, startPos.vy >> 4 );
enemy->postInit();
2001-05-11 00:39:23 +02:00
enemy->updateCollisionArea();
2001-05-10 16:00:29 +02:00
}
}
2001-05-10 18:47:35 +02:00
else
{
m_timer -= _frames;
}
2001-05-10 16:00:29 +02:00
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CJellyfishGenerator::decCounter()
{
if ( m_jellyfishCount > 0 )
{
m_jellyfishCount--;
}
}