Skip to content

Commit

Permalink
Merge pull request #27 from Rushwind13/develop
Browse files Browse the repository at this point in the history
Dungeon Generation
  • Loading branch information
Rushwind13 committed Dec 21, 2017
2 parents f282796 + d78c83e commit 922596a
Show file tree
Hide file tree
Showing 29 changed files with 1,134 additions and 546 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
*.png
*.txt
*.psd
#*.png
#*.txt
Scores.txt

# XCode
*.xcodeproj
Expand Down
12 changes: 8 additions & 4 deletions AIMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ bool CAIBrain::UpdateSeek( float fCurTime )
}
break;
case MON_AI_DONTMOVE:
{
{
SetRandomDest( fCurTime );
}
break;
}
Expand Down Expand Up @@ -113,9 +114,12 @@ bool CAIBrain::UpdateGoToDest( float fCurTime )
switch(dwCollideType)
{
case DUNG_COLL_NO_COLLISION:
g_pGame->GetDungeon()->GetTile(m_vPos)->m_pCurMonster = NULL;
m_vPos += m_vVel;
g_pGame->GetDungeon()->GetTile(m_vPos)->m_pCurMonster = m_pParent;
if( m_dwMoveType != MON_AI_DONTMOVE )
{
g_pGame->GetDungeon()->GetTile(m_vPos)->m_pCurMonster = NULL;
m_vPos += m_vVel;
g_pGame->GetDungeon()->GetTile(m_vPos)->m_pCurMonster = m_pParent;
}
break;
case DUNG_COLL_PLAYER:
char szStatus[16];
Expand Down
115 changes: 115 additions & 0 deletions ClockStepState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// ClockStepState.cpp
// JMoria
//
// Created by Jimbo S. Harris on 12/16/17.
// Copyright © 2017 Jimbo S. Harris. All rights reserved.
//

#include "ClockStepState.h"

#include "DungeonTile.h"
#include "DisplayText.h"
#include "Game.h"

#include "FileParse.h"

extern CGame *g_pGame;

CClockStepState::CClockStepState()
: m_dwClock(0),
m_dwStep(1)
{
m_pKeyHandlers[CLOCKSTEP_INIT] = &CClockStepState::OnHandleInit;
m_pKeyHandlers[CLOCKSTEP_TICK] = &CClockStepState::OnHandleTick;

m_eCurModifier = CLOCKSTEP_INIT;
m_pCurKeyHandler = m_pKeyHandlers[m_eCurModifier];
}

CClockStepState::~CClockStepState()
{
}

int CClockStepState::OnHandleKey(SDL_Keysym *keysym)
{
int retval;
retval = ((*this).*(m_pCurKeyHandler))(keysym);
return retval;
}

int CClockStepState::OnHandleTick( SDL_Keysym *keysym )
{
int retval;
printf( "Handling TICK modifier\n" );
retval = OnBaseHandleKey( keysym );

if( retval == JRESETSTATE )
{
return 0;
}

if( retval == JCOMPLETESTATE )
{
printf( "TICK modifier complete, CLOCKSTEP state to next TICK\n");
DoTick();
m_eCurModifier = CLOCKSTEP_TICK;
m_pCurKeyHandler = m_pKeyHandlers[m_eCurModifier];
}

if( retval != JSUCCESS )
{
printf( "CLOCK still waiting for a valid key.\n" );
return 0;
}

// We got a valid key
printf( "TICK modifier got a valid key\n" );
g_pGame->GetEnd()->Clear();
DoTick();

return 0;
}

int CClockStepState::OnHandleInit( SDL_Keysym *keysym )
{
printf( "Initializing CLOCKSTEP state...\n" );

g_pGame->GetStats()->Clear();
DoTick();
m_eCurModifier = CLOCKSTEP_TICK;
m_pCurKeyHandler = m_pKeyHandlers[m_eCurModifier];
return 0;
}

int CClockStepState::OnBaseHandleKey( SDL_Keysym *keysym )
{
if( keysym->sym == SDLK_RETURN || keysym->sym == SDLK_SPACE )
{
return JCOMPLETESTATE;
}

return -1;
}

void CClockStepState::ResetToState( int newstate )
{
g_pGame->SetState(newstate);
m_cCommand = NULL;
m_eCurModifier = CLOCKSTEP_INIT;
m_pCurKeyHandler = m_pKeyHandlers[m_eCurModifier];
}


//////////////////////////////////////
/// command-specific fcns go below

//// Tick commands
bool CClockStepState::DoTick()
{
m_dwClock += m_dwStep;
g_pGame->GetStats()->Printf("Tick! %d\n", m_dwClock);
g_pGame->SetReadyForUpdate(true);
g_pGame->GetDungeon()->Tick(m_dwClock);
return true;
}
56 changes: 56 additions & 0 deletions ClockStepState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ClockStepState.h
// JMoria
//
// Created by Jimbo S. Harris on 12/16/17.
// Copyright © 2017 Jimbo S. Harris. All rights reserved.
//

#ifndef ClockStepState_h
#define ClockStepState_h
#include "JMDefs.h"
#include "StateBase.h"

#include "Dungeon.h"

class CClockStepState;
typedef int (CClockStepState::*ClockStepKeyHandler)(SDL_Keysym *keysym);
enum eClockStepModifier
{
CLOCKSTEP_INVALID=-1,
CLOCKSTEP_INIT=0,
CLOCKSTEP_TICK=1,
CLOCKSTEP_MAX
};
class CClockStepState : public CStateBase
{
// Member Variables
public:
protected:
char m_cCommand;
ClockStepKeyHandler m_pKeyHandlers[CLOCKSTEP_MAX];
ClockStepKeyHandler m_pCurKeyHandler;

eClockStepModifier m_eCurModifier;
private:
int m_dwClock;
int m_dwStep;

// Member Functions
public:
CClockStepState();
~CClockStepState();

virtual void OnUpdate() {};
virtual int OnBaseHandleKey( SDL_Keysym *keysym );
virtual int OnHandleKey( SDL_Keysym *keysym );
protected:
private:
int OnHandleTick( SDL_Keysym *keysym );
int OnHandleInit( SDL_Keysym *keysym );

void ResetToState( int newstate );

bool DoTick();
};
#endif /* ClockStepState_h */
9 changes: 5 additions & 4 deletions Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define __CONSTANTS_H__
#include <stdio.h>

#define VERSION "0.06"
#define VERSION "0.20"

// all the states which the game can run in
// this modifies the event handling
Expand All @@ -20,7 +20,8 @@
#define STATE_USE 3
#define STATE_STRINGINPUT 4
#define STATE_ENDGAME 5
#define STATE_MAX 6
#define STATE_CLOCKSTEP 6
#define STATE_MAX 7

// Various statuses that someone could have
#define STATUS_INVALID -1
Expand Down Expand Up @@ -55,8 +56,8 @@
#define DUNG_FLAG_LIT 0x00000001

// Dungeon Flags
#define DUNG_CFG_MONSTERS_PER_LEVEL 0.05f
#define DUNG_CFG_ITEMS_PER_LEVEL 0.05f
#define DUNG_CFG_MONSTERS_PER_LEVEL 0.005f
#define DUNG_CFG_ITEMS_PER_LEVEL 0.01f
#define DUNG_CFG_START_LEVEL 1
#define DUNG_CFG_MAX_SPAWN_TRIES 10

Expand Down
6 changes: 3 additions & 3 deletions DisplayText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class CGame;

#define FONT_DRAW_W 8
#define FONT_DRAW_H 10
#define FONT_DRAW_W 6
#define FONT_DRAW_H 8

#define TEXT_MAXCHARS 2048
// Constructor
Expand All @@ -37,7 +37,7 @@ m_rcViewport( 0, 480, 640, 0 )
memset( m_szText, 0, sizeof( *m_szText ) );
m_szDrawPtr = m_szText;

m_TileSet = new CTileset("Resources/Courier.png", 32, 32);
m_TileSet = new CTileset("Resources/SmallText6X8.png", 6,8);

m_Color.SetColor( 0, 0, 0, 255 );
}
Expand Down
Loading

0 comments on commit 922596a

Please sign in to comment.