@ -3,6 +3,9 @@
# include "Crawler.h"
# include "Crawler.h"
# include "DEFINES.h"
# include "DEFINES.h"
# include "Menu.h"
# include "Menu.h"
# include "Unlock.h"
# include "ConnectionPoint.h"
# include "utils.h"
INCLUDE_MONSTER_LIST
INCLUDE_MONSTER_LIST
INCLUDE_game
INCLUDE_game
@ -14,7 +17,8 @@ State_OverworldMap::State_OverworldMap(){
}
}
void State_OverworldMap : : OnStateChange ( GameState * prevState ) {
void State_OverworldMap : : OnStateChange ( GameState * prevState ) {
Menu : : CloseAllMenus ( ) ;
Menu : : CloseAllMenus ( ) ;
game - > GetPlayer ( ) - > SetPos ( currentConnectionPoint - > rect . pos ) ;
game - > GetPlayer ( ) - > SetPos ( currentConnectionPoint - > rect . pos + currentConnectionPoint - > rect . size / 2 + vf2d { 0 , 16 } ) ;
playerTargetPos = currentConnectionPoint - > rect . pos + currentConnectionPoint - > rect . size / 2 + vf2d { 0 , 16 } ;
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( DOWN ) ;
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( DOWN ) ;
game - > GetPlayer ( ) - > SetState ( State : : FORCE_WALK ) ;
game - > GetPlayer ( ) - > SetState ( State : : FORCE_WALK ) ;
game - > GetPlayer ( ) - > SetSizeMult ( 1 ) ;
game - > GetPlayer ( ) - > SetSizeMult ( 1 ) ;
@ -23,6 +27,40 @@ void State_OverworldMap::OnUserUpdate(Crawler*game){
game - > camera . SetTarget ( currentConnectionPoint - > rect . middle ( ) ) ;
game - > camera . SetTarget ( currentConnectionPoint - > rect . middle ( ) ) ;
game - > UpdateCamera ( game - > GetElapsedTime ( ) ) ;
game - > UpdateCamera ( game - > GetElapsedTime ( ) ) ;
game - > GetPlayer ( ) - > Update ( game - > GetElapsedTime ( ) ) ;
game - > GetPlayer ( ) - > Update ( game - > GetElapsedTime ( ) ) ;
if ( game - > GetPlayer ( ) - > GetPos ( ) ! = playerTargetPos ) {
if ( geom2d : : line < float > ( game - > GetPlayer ( ) - > GetPos ( ) , playerTargetPos ) . length ( ) < 2 ) {
game - > GetPlayer ( ) - > SetPos ( playerTargetPos ) ;
} else {
game - > GetPlayer ( ) - > SetPos ( game - > GetPlayer ( ) - > GetPos ( ) + util : : pointTo ( game - > GetPlayer ( ) - > GetPos ( ) , playerTargetPos ) * playerMoveSpd * game - > GetElapsedTime ( ) ) ;
}
}
for ( ConnectionPoint & cp : connections ) {
if ( game - > GetMouse ( Mouse : : LEFT ) . bPressed & & geom2d : : overlaps ( game - > GetWorldMousePos ( ) , cp . rect ) ) {
for ( int neighborInd : currentConnectionPoint - > neighbors ) {
if ( neighborInd = = - 1 ) continue ;
ConnectionPoint & neighbor = ConnectionPointFromIndex ( neighborInd ) ;
if ( Unlock : : IsUnlocked ( neighbor . name ) & & & cp = = & neighbor ) {
currentConnectionPoint = & neighbor ;
playerTargetPos = currentConnectionPoint - > rect . pos + currentConnectionPoint - > rect . size / 2 + vf2d { 0 , 16 } ;
float angleTo = util : : angleTo ( game - > GetPlayer ( ) - > GetPos ( ) , playerTargetPos ) ;
if ( angleTo > = - 3 * PI / 4 & & angleTo < - PI / 4 ) {
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( UP ) ;
} else
if ( angleTo < PI / 4 & & angleTo > = - PI / 4 ) {
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( RIGHT ) ;
} else
if ( angleTo > = PI / 4 & & angleTo < 3 * PI / 4 ) {
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( DOWN ) ;
} else {
game - > GetPlayer ( ) - > UpdateWalkingAnimation ( LEFT ) ;
}
break ;
}
}
}
}
} ;
} ;
void State_OverworldMap : : Draw ( Crawler * game ) {
void State_OverworldMap : : Draw ( Crawler * game ) {
currentTime + = game - > GetElapsedTime ( ) ;
currentTime + = game - > GetElapsedTime ( ) ;
@ -73,3 +111,11 @@ void State_OverworldMap::SetStageMarker(std::string connectionName){
std : : cout < < " WARNING! Could not find a connection point with name " < < connectionName < < " ! " < < std : : endl ;
std : : cout < < " WARNING! Could not find a connection point with name " < < connectionName < < " ! " < < std : : endl ;
throw ;
throw ;
}
}
ConnectionPoint & State_OverworldMap : : ConnectionPointFromIndex ( int ind ) {
return connections . at ( ind ) ;
}
ConnectionPoint & State_OverworldMap : : GetCurrentConnectionPoint ( ) {
return * ( ( State_OverworldMap * ) ( GameState : : states . at ( States : : OVERWORLD_MAP ) ) ) - > currentConnectionPoint ;
}