Scenario 1 implemented.
This commit is contained in:
parent
7e63a0a875
commit
f840213233
@ -56,7 +56,7 @@ Stage 1:
|
||||
The yellow bar represent a unit's Health memory allocation. Make sure there's always at least 1 bit of it.
|
||||
|
||||
(Simulate dragging over unit and selection)
|
||||
Highlight over your target unit and then select a target location via right-click.
|
||||
Drag over your target unit and then select a target location via right-click.
|
||||
|
||||
That should be all you need for now. I'll be back after my coffee break.
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "Scenario.h"
|
||||
#include "TileManager.h"
|
||||
|
||||
Scenario::Scenario(VirusAttack*game)
|
||||
:game(game){
|
||||
@ -12,21 +13,109 @@ void Scenario::_Update(){
|
||||
Update();
|
||||
}
|
||||
void Scenario::_Draw(){
|
||||
if(game->objective.length()>0){
|
||||
game->DrawShadowStringDecal({4,24},"Objective:");
|
||||
game->DrawShadowStringDecal({6,36},game->objective);
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
void Scenario::DisplayDialog(std::string dialogText,bool spooky){
|
||||
dialog.Initialize(dialogText,{24,64},"",spooky?game->IMAGES[SPOOK_HOODED_FIGURE].get():game->IMAGES[HOODED_FIGURE].get(),{378,28},game->SOUNDS[Sound::VOICEOVER].get());
|
||||
}
|
||||
|
||||
void Scenario::SetObjective(std::string objective){
|
||||
game->objective=objective;
|
||||
}
|
||||
|
||||
void Scenario::SetupCameraTarget(vf2d pos){
|
||||
cameraTargetPos=pos;
|
||||
camera.SetTarget(cameraTargetPos);
|
||||
}
|
||||
|
||||
void Scenario::MoveCamera(){
|
||||
game->game.SetWorldOffset(camera.GetViewPosition());
|
||||
camera.Update(game->GetElapsedTime());
|
||||
}
|
||||
|
||||
Stage1::Stage1(VirusAttack*game)
|
||||
:Scenario(game){}
|
||||
|
||||
void Stage1::Start(){
|
||||
game->unitMetersGreyedOut=true;
|
||||
game->playerInControl=false;
|
||||
camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset());
|
||||
camera.SetLazyFollowRate(1);
|
||||
camera.SetMode(utils::Camera2D::Mode::LazyFollow);
|
||||
}
|
||||
|
||||
void Stage1::Update(){
|
||||
switch(state){
|
||||
case 0:{
|
||||
dialog.Initialize("Hello Hacker, thank you for taking on this request for me.",{24,64},"",game->IMAGES[HOODED_FIGURE].get(),{378,28},game->SOUNDS[Sound::VOICEOVER].get());
|
||||
DisplayDialog("Hello Hacker, thank you for taking on this request for me.");
|
||||
if(dialog.bPressed){
|
||||
dialog.SetVisible(false);
|
||||
state=1;
|
||||
}
|
||||
}break;
|
||||
case 1:{
|
||||
DisplayDialog("It appears we have no time to waste, most sectors are already infected and it will just keep getting worse over time.");
|
||||
if(dialog.bPressed){
|
||||
dialog.SetVisible(false);
|
||||
state=2;
|
||||
}
|
||||
}break;
|
||||
case 2:{
|
||||
game->SOUNDS[Sound::PING]->PlayCentered();
|
||||
SetupCameraTarget({320,320});
|
||||
state=3;
|
||||
}break;
|
||||
case 3:{
|
||||
for(int y=-1;y<=1;y++){
|
||||
for(int x=-1;x<=1;x++){
|
||||
vi2d basePos={320+x*96,320+y*96};
|
||||
TileManager::visibleTiles[{basePos.x/96,basePos.y/96}]=30;
|
||||
}
|
||||
}
|
||||
MoveCamera();
|
||||
if(camera.ReachedTarget()){
|
||||
state=4;
|
||||
}
|
||||
}break;
|
||||
case 4:{
|
||||
DisplayDialog("Your mission is to take out all the RAM banks from the system, this will stop any further creation and spread of viruses.");
|
||||
if(dialog.bPressed){
|
||||
dialog.SetVisible(false);
|
||||
SetupCameraTarget({128,128});
|
||||
state=5;
|
||||
}
|
||||
}break;
|
||||
case 5:{
|
||||
MoveCamera();
|
||||
if(camera.ReachedTarget()){
|
||||
state=6;
|
||||
}
|
||||
}break;
|
||||
case 6:{
|
||||
DisplayDialog("The yellow bars represent a unit's Health memory allocation. Make sure there's always at least 1 bit of it.");
|
||||
if(dialog.bPressed){
|
||||
state=7;
|
||||
}
|
||||
}break;
|
||||
case 7:{
|
||||
DisplayDialog("Drag over your target unit and then select a target location via right-click.");
|
||||
if(dialog.bPressed){
|
||||
state=8;
|
||||
}
|
||||
}break;
|
||||
case 8:{
|
||||
DisplayDialog("That should be all you need for now. I'll be back after my coffee break.");
|
||||
SetObjective("Defeat the RAM bank");
|
||||
if(dialog.bPressed){
|
||||
dialog.SetVisible(false);
|
||||
game->playerInControl=true;
|
||||
state=9;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "VirusAttack.h"
|
||||
#include "olcUTIL_Camera2D.h"
|
||||
|
||||
class Scenario{
|
||||
public:
|
||||
@ -9,11 +10,17 @@ public:
|
||||
virtual void Update()=0;
|
||||
void _Draw();
|
||||
virtual void Draw()=0;
|
||||
void DisplayDialog(std::string dialogText,bool spooky=false);
|
||||
void SetObjective(std::string objective);
|
||||
void SetupCameraTarget(vf2d pos);
|
||||
void MoveCamera();
|
||||
protected:
|
||||
VirusAttack*game;
|
||||
int state=0;
|
||||
Textbox dialog;
|
||||
float initialWaitTimer=3;
|
||||
utils::Camera2D camera;
|
||||
vf2d cameraTargetPos={};
|
||||
};
|
||||
|
||||
class Stage1:public Scenario{
|
||||
|
@ -7,4 +7,5 @@ enum class Sound{
|
||||
BOSS1,
|
||||
BOSS2,
|
||||
VOICEOVER,
|
||||
PING,
|
||||
};
|
@ -38,6 +38,7 @@ void Textbox::SetDefaults(){
|
||||
headerText="";
|
||||
audioVolume=0;
|
||||
continueWordTimer=0;
|
||||
bPressed=false;
|
||||
}
|
||||
|
||||
void Textbox::Update(PixelGameEngine*pge){
|
||||
@ -56,6 +57,10 @@ void Textbox::Update(PixelGameEngine*pge){
|
||||
tempText+=text[textboxMarker+1];
|
||||
|
||||
auto WrapText=[&](std::string&tempText,std::string&text,std::string&displayText,int&lastWordMarker,std::string&lastWord){
|
||||
vf2d maxSize=this->maxSize;
|
||||
if(boxImg!=nullptr){
|
||||
maxSize-={26,0};
|
||||
}
|
||||
if(pge->GetTextSizeProp(tempText).x>=maxSize.x){
|
||||
displayText=displayText.substr(0,lastWordMarker);
|
||||
displayText+='\n';
|
||||
@ -91,6 +96,7 @@ void Textbox::Update(PixelGameEngine*pge){
|
||||
dialogSound->SetVolume(soundHandle,audioVolume);
|
||||
}
|
||||
}
|
||||
bPressed=pge->GetMouse(0).bPressed||pge->GetMouse(1).bPressed;
|
||||
}
|
||||
maxSize.y=std::max(maxSize.y,float(pge->GetTextSizeProp(displayHeaderText).y+pge->GetTextSizeProp(displayText).y));
|
||||
lastLetterTime=letterDisplayDelay;
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
vf2d GetSize();
|
||||
void SetBackgroundColor(Pixel col);
|
||||
bool IsVisible();
|
||||
bool bPressed=false;
|
||||
private:
|
||||
void Update(PixelGameEngine*pge);
|
||||
void UpdatePosition(vf2d newPos);
|
||||
|
@ -75,8 +75,8 @@ void VirusAttack::InitializeLevelData(){
|
||||
levelData[stage].worldZoom={1,1};
|
||||
levelData[stage].scenario=scenarios[0];
|
||||
levelData[stage].levelColor=DARK_RED;
|
||||
levelData[stage].size={64,64};
|
||||
levelData[stage].bgm=Sound::BOSS2;
|
||||
levelData[stage].size={24,24};
|
||||
levelData[stage].bgm=Sound::GRAVITY;
|
||||
levelData[stage].player_starting_resources={500,500,500,500,500};
|
||||
levelData[stage].enemy_starting_resources={0,0,0,0,0};
|
||||
{
|
||||
@ -84,26 +84,8 @@ void VirusAttack::InitializeLevelData(){
|
||||
std::vector<CPData>&collectionPoints=levelData[stage].cpPlacement;
|
||||
|
||||
units.push_back({UnitType::LeftShifter,vf2d{128,128},true});
|
||||
units.push_back({UnitType::RightShifter,vf2d{129,129},true});
|
||||
units.push_back({UnitType::BitRestorer,vf2d{130,130},true});
|
||||
units.push_back({UnitType::BitRestorer,vf2d{130,140},true});
|
||||
units.push_back({UnitType::MemorySwapper,vf2d{131,131},true});
|
||||
units.push_back({UnitType::Corrupter,vf2d{132,132},true});
|
||||
units.push_back({UnitType::MemoryAllocator,vf2d{133,133},true});
|
||||
units.push_back({UnitType::RAMBank,vf2d{134,134},true});
|
||||
units.push_back({UnitType::MemoryGuard,vf2d{200,134},true});
|
||||
|
||||
|
||||
for(int i=0;i<5;i++){
|
||||
collectionPoints.push_back({vf2d{32.f+48*i,32.f},0,MemoryType(i)});
|
||||
collectionPoints.push_back({vf2d{32.f,32.f+48*i},-PI/2,MemoryType(i)});
|
||||
}
|
||||
|
||||
units.push_back({UnitType::RAMBank,vf2d{1200,1200},false});
|
||||
|
||||
units.push_back({UnitType::RightShifter,vf2d{1260,1200},false});
|
||||
units.push_back({UnitType::RightShifter,vf2d{360,300},false});
|
||||
units.push_back({UnitType::RightShifter,vf2d{361,300},false});
|
||||
units.push_back({UnitType::LeftShifter,vf2d{128,128},true});
|
||||
units.push_back({UnitType::RAMBank,vf2d{320,320},false});
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
@ -225,6 +207,8 @@ void VirusAttack::LoadLevel(LevelName level){
|
||||
}
|
||||
|
||||
randomBackgroundOffset={util::random(128),util::random(128)};
|
||||
|
||||
objective="";
|
||||
}
|
||||
|
||||
void VirusAttack::InitializeGUIs(){
|
||||
@ -271,6 +255,7 @@ void VirusAttack::InitializeSounds(){
|
||||
LoadSound(Sound::BOSS1,"boss1.mp3");
|
||||
LoadSound(Sound::BOSS2,"boss2.mp3");
|
||||
LoadSound(Sound::VOICEOVER,"voice.mp3");
|
||||
LoadSound(Sound::PING,"ping.mp3");
|
||||
}
|
||||
|
||||
bool VirusAttack::UnitCreationClickHandled(){
|
||||
|
@ -26,6 +26,7 @@ struct Letter{
|
||||
|
||||
class VirusAttack : public olc::PixelGameEngine
|
||||
{
|
||||
friend class Scenario;
|
||||
friend class Stage1;
|
||||
private:
|
||||
#ifdef SPLASH_ENABLED
|
||||
@ -87,6 +88,8 @@ private:
|
||||
bool unitMetersGreyedOut=false; //If true, all but health meters show up as dark grey.
|
||||
bool playerInControl=true;
|
||||
|
||||
std::string objective="";
|
||||
|
||||
vf2d randomBackgroundOffset;
|
||||
|
||||
vf2d startingDragPos=CONSTANT::UNSELECTED;
|
||||
|
@ -147,6 +147,12 @@ namespace olc::utils
|
||||
return m_bWorldBoundary;
|
||||
}
|
||||
|
||||
inline bool ReachedTarget() const
|
||||
{
|
||||
float dist=sqrt(pow(m_vPosition.x-GetTarget().x,2)+pow(m_vPosition.y-GetTarget().y,2));
|
||||
return dist<=4;
|
||||
}
|
||||
|
||||
// Get the world boundary rectangle position
|
||||
inline const olc::vf2d& GetWorldBoundaryPosition() const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user