diff --git a/src/dialog/CTextBox.cpp b/src/dialog/CTextBox.cpp index 3bbe9929f..bce512861 100644 --- a/src/dialog/CTextBox.cpp +++ b/src/dialog/CTextBox.cpp @@ -9,14 +9,28 @@ #include "../CGraphics.h" #include "../StringUtils.h" -CTextBox::CTextBox(float x, float y, float w, float h, float font_w, float font_h, const std::string& text) { - m_fontwidth = font_w; - m_fontheight = font_h; +CTextBox::CTextBox(float x, float y, float w, float h, const std::string& text, bool border_rel) { + m_fontwidth = 0; + m_fontheight = 0; m_x = x; m_y = y; m_w = w; m_h = h; m_String = text; + m_border_relative = border_rel; +} + +void CTextBox::setFontDimensions(float width, float height) +{ + m_fontwidth = width; + m_fontheight = (height>0.0f) ? height : width; // 0 it is square + if(m_border_relative) + { + m_x += m_fontwidth; + m_y += m_fontheight; + m_w -= 2*m_fontwidth; + m_h -= 2*m_fontheight; + } } void CTextBox::format() @@ -33,7 +47,7 @@ void CTextBox::format() { word = GetNextWord(it, m_String); - if((oneline.length() + word.length()) > m_w/m_fontwidth) + if((oneline.length() + word.length()) > m_w/m_fontwidth) // if the line is full { if(*(oneline.end()-1) == ' ') oneline.erase(oneline.end()-1); m_Textline.push_back(oneline); @@ -49,13 +63,18 @@ void CTextBox::format() } +int CTextBox::getNumberOfTextlines() +{ + return m_Textline.size(); +} + void CTextBox::draw() { // Draw Routine for the Textbox for(unsigned int i=0 ; idrawFont(m_Textline[i], m_x, m_y+i*m_fontheight, 0); // 0 is blank colour - if( i*m_fontheight>m_h ) + if( i*m_fontheight > m_h ) break; } } diff --git a/src/dialog/CTextBox.h b/src/dialog/CTextBox.h index f9d1892fd..12fcb0723 100644 --- a/src/dialog/CTextBox.h +++ b/src/dialog/CTextBox.h @@ -13,17 +13,22 @@ class CTextBox { public: - CTextBox(float x, float y, float w, float h, float font_w, float font_h, const std::string& text); + CTextBox(float x, float y, float w, float h, + const std::string& text, bool border_rel = true); + void setFontDimensions(float width, float height = 0.0f); void format(); void draw(); + int getNumberOfTextlines(); + private: std::string m_String; std::vector m_Textline; float m_x, m_y, m_w, m_h; float m_fontwidth, m_fontheight; + bool m_border_relative; }; #endif /* CTEXTBOX_H_ */ diff --git a/src/dialog/CWindow.cpp b/src/dialog/CWindow.cpp index b091f862f..63d3a8a8a 100644 --- a/src/dialog/CWindow.cpp +++ b/src/dialog/CWindow.cpp @@ -38,30 +38,34 @@ CWindow::~CWindow() { /////////////////////// // Creation Routines // /////////////////////// -void CWindow::addTextBox(float x, float y, float w, float h, const std::string& text, bool border_rel) +void CWindow::addObject(CTextBox* newTextBox) { + //float x, float y, float w, float h, const std::string& text, bool border_rel; // Element coordinates are all relative and must go inside the borders if desired! // if false it will be relative to the window itself and can be used as title border - if(border_rel) - { - x *= m_w; - x += (m_8x8tilewidth); - y *= m_h; - y += (m_8x8tileheight); - w -= 2*m_8x8tilewidth/(m_w); - h -= 2*m_8x8tileheight/(m_h); - } - CTextBox* ptr = new CTextBox(x + m_x, - y + m_y, - w*(m_w), - h*(m_h), - m_8x8tilewidth, m_8x8tileheight, text); - m_TextBox.push_back(ptr); + m_TextBox.push_back(newTextBox); m_TextBox.back()->format(); m_ID_List.push_back(OBJ_TYPE_TEXT); } +/////////////////////////// +// Property Set Routines // +/////////////////////////// +void CWindow::Resize(float width, float height) +{ + m_w = width; + m_h = height; +} + +/////////////////////////// +// Property Get Routines // +/////////////////////////// +float CWindow::getWidth() +{ + return m_w; +} + //////////////////////// // Rendering Routines // //////////////////////// diff --git a/src/dialog/CWindow.h b/src/dialog/CWindow.h index cea29688a..24b814137 100644 --- a/src/dialog/CWindow.h +++ b/src/dialog/CWindow.h @@ -22,10 +22,20 @@ public: CWindow(float x, float y, float w, float h); virtual ~CWindow(); - void addTextBox(float x, float y, float w, float h, const std::string& text, bool border_rel); + // Creation routines + void addObject(CTextBox* newTextBox); + // Property set methods + void Resize(float width, float height); + + // Property retrieval methods + float getWidth(); + + // Drawing routines void render(); + std::vector m_TextBox; + private: float m_x; float m_y; @@ -36,7 +46,6 @@ private: float m_8x8tilewidth; std::list m_ID_List; - std::vector m_TextBox; void drawWindow(); }; diff --git a/src/fileio/CTileLoader.cpp b/src/fileio/CTileLoader.cpp index f47019e14..f41656ca1 100644 --- a/src/fileio/CTileLoader.cpp +++ b/src/fileio/CTileLoader.cpp @@ -165,7 +165,7 @@ void CTileLoader::assignChangeTileAttribute(stTile *tile) // At any other case, than the special ones, the tile is always 143 for pickuppable items // 17 is tile for an exit. Until row 19, this seems to be valid for(int i=0 ; i= 2 && - TileProperty[i][BEHAVIOR] <= 5) + if(isaDoor(i)) tile[i].chgtile = 182; } @@ -219,3 +218,8 @@ bool CTileLoader::canbePickedup(int tile) TileProperty[tile][BEHAVIOR] == 27 || TileProperty[tile][BEHAVIOR] == 28); } + +bool CTileLoader::isaDoor(int tile) +{ + return (TileProperty[tile][BEHAVIOR] >= 2 && TileProperty[tile][BEHAVIOR] <= 5); +} diff --git a/src/fileio/CTileLoader.h b/src/fileio/CTileLoader.h index 1d4e99c63..180bdeb89 100644 --- a/src/fileio/CTileLoader.h +++ b/src/fileio/CTileLoader.h @@ -45,6 +45,7 @@ private: void assignChangeTileAttribute(stTile *tile); bool setProperOffset(); bool canbePickedup(int tile); + bool isaDoor(int tile); }; #endif /* CTILELOADER_H_ */ diff --git a/src/misc.cpp b/src/misc.cpp index b6d2a2e85..87c2a9ebb 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -186,9 +186,17 @@ void showGameHint(int mpx, int mpy, int episode, int level) } } - CWindow *InfoTextWindow = new CWindow(0.2, 0.2, 0.6, 0.6); - InfoTextWindow->addTextBox(0.0f, 0.0f, 1.0f, 0.8f, getstring(strname), true); - InfoTextWindow->addTextBox(0.2f, 0.8f, 1.0f, 0.2f, "Okay!", true); + CTextBox* TextBox; + CWindow *InfoTextWindow = new CWindow(0.2f, 0.2f, 0.6f, 0.6f); + + TextBox = new CTextBox(0.2f, 0.2f, 0.6f, 0.6f, getstring(strname), true); + TextBox->setFontDimensions(8.0f/320.0f, 8.0f/200.0f); + InfoTextWindow->addObject(TextBox); + + // The Text will be too big, so resize in knowing the height of the first text. + InfoTextWindow->Resize(InfoTextWindow->getWidth(), + ( (float)(InfoTextWindow->m_TextBox[0]->getNumberOfTextlines()+2)*8.0f ) / 200.0f ); + g_pInput->flushAll(); do diff --git a/src/vorticon/CPlayer.cpp b/src/vorticon/CPlayer.cpp deleted file mode 100644 index 4de3fd4e7..000000000 --- a/src/vorticon/CPlayer.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* - * CPlayer.cpp - * - * Created on: 31.03.2009 - * Author: gerstrong - */ - -#include -#include "CPlayer.h" -#include "../sdl/CInput.h" - -#include "../keen.h" -#include "../funcdefs.h" - -extern int **TileProperty; - -//////////////////////// -// section of defines // -//////////////////////// - -#define CSF 5 - -// the walking defines -#define STANDING_LEFT 0 -#define STANDING_RIGHT 4 - -#define WALK_SPEED 16 - -// rate at which player walking animation is shown -#define WALKANIMRATE 40+WALK_SPEED - -// friction - -// the various jump states -enum jumpstates{ -NOJUMP, PREPAREJUMP, JUMPUP, JUMPED, PREPAREPOGO,POGOING}; - -// Now the frictions we have in the game -enum frictiontable -{ - FRIC_GROUND = 10, - FRIC_SLIPPERY = 10, - FRIC_ICE = 10, - FRIC_AIR = 10, -}; - -enum direction{ LEFT, RIGHT}; - -#define MAX_FRICTIONTIME 1000 - -#define PFIREFRAME 20 // raygun frame index - -// pogo frames -#define PFRAME_POGO 24 -#define PFRAME_POGOBOUNCE 25 - -// frame and animation speed for frozen keen (ep1) and stunned keen (ep2&3) -#define PFRAME_FROZEN 28 -#define PFROZENANIMTIME 100 -// how long keen should stay frozen when hit by an ice chunk -#define PFROZEN_TIME 1000 -#define PFROZEN_THAW 100 - -// when falling keen's Y inertia increases at INCREASERATE up to MAXSPEED -#define PFALL_INCREASERATE 3 -#define PFALL_MAXSPEED 19 - -// friction when player is pushed by yorp's, ball's, etc. -#define PLAYPUSH_DECREASERATE 1 - -#define PDIEFRAME 22 - -#define PLAYERHEIGHT 24 -#define PLAYERWIDTH 12 - -///////////////////////////////////////// -// Section of functions implementation // -///////////////////////////////////////// - - -CPlayer::CPlayer() { - object = 1; // it is only 1 for the first player - - episode=0; // while no episode is selected. Indeed the program must select one manually - - mp_scrx = NULL; - mp_scry = NULL; - - active = false; - isGameover = false; - isFalling = false; - isDying = false; - isWalking = false; - isPushed = false; - cannotWalk = false; - cannotfall = false; - usePogostick = false; - isStanding = true; - - bisBlockedUp = false; - bisBlockedDown = false; - bisBlockedLeft = false; - bisBlockedRight = false; - - walktimer = 0; - frictiontimer = 0; - - Jumpmode = 0; -} - -CPlayer::~CPlayer() { -} - -unsigned long CPlayer::getCoordX(void) -{ - return m_x; -} - -unsigned long CPlayer::getCoordY(void) -{ - return m_y; -} - -void CPlayer::setpScrCoord(int *px, int *py) -{ - mp_scrx = px; - mp_scry = py; -} - -void CPlayer::setCoord(unsigned long in_x, unsigned long in_y) -{ - m_x = in_x; - m_y = in_y; -} - -unsigned short CPlayer::getObject(void) -{ - return object; -} - -void CPlayer::useObject(unsigned short value) -{ - object = value; -} - -bool CPlayer::isPlaying(void) -{ - return active; -} - -void CPlayer::enablePlayer(bool value) -{ - active = value; -} - -void CPlayer::handlePlayer(void) -{ -/* char doFall; - - if (player[cp].pdie) - { - gamepdo_dieanim(cp, pCKP); - if (!pCKP->Control.levelcontrol.gameovermode) - { - gamepdo_StatusBox(cp, pCKP); - } - } - else - { - if (!pCKP->Control.levelcontrol.gameovermode) - { - player[cp].inhibitwalking = 0; - player[cp].inhibitfall = 0; - - gamepdo_StatusBox(cp, pCKP); - - gamepdo_ProcessInput(cp, pCKP); - - gamepdo_setdir(cp, pCKP); - - gamepdo_setblockedlru(cp, pCKP); - gamepdo_getgoodies(cp, pCKP); - - if (pCKP->Control.levelcontrol.episode==3) gamepdo_ankh(cp); - - gamepdo_raygun(cp, pCKP); - - gamepdo_keencicle(cp, pCKP); - - - if(!player[cp].pjumping && !player[cp].pfalling) - { - gamepdo_walking(cp, pCKP); - gamepdo_walkinganim(cp, pCKP); - } - - - if (fade.mode==NO_FADE || fade.dir==FADE_IN || demomode) - { - gamepdo_playpushed(cp, pCKP); - gamepdo_InertiaAndFriction_X(cp, pCKP); - } - - gamepdo_JumpAndPogo(cp, pCKP); - - // decide if player should fall - doFall = 1; - if (player[cp].inhibitfall) doFall = 0; - //else if (pCKP->Option[OPT_CHEATS].value) doFall = 0; - - if (doFall) - { - gamepdo_falling(cp, pCKP); - } - else - { - if(player[cp].pjumping == PJUMPED) - player[cp].pfalling = 0; - player[cp].psupportingtile = 145; - player[cp].psupportingobject = 0; - } - - } - else - { // we're in game-over mode - - } - } -*/ - applyFrame(); -} - -void CPlayer::performDieAnimation(void) -{ - -} - -void CPlayer::processInput(void) -{ - -} - -void CPlayer::processDirection(void) -{ - -} - -void CPlayer::checkCollisions(void) -{ - unsigned int tx,ty; - short i; - - tx = (m_x>>CSF)+2; - ty = (m_y>>CSF); - - bisBlockedDown = false; - bisBlockedUp = false; - bisBlockedLeft = false; - bisBlockedRight = false; - - for( i=1 ; i < PLAYERWIDTH ; i++ ) - { - if(TileProperty[getmaptileat((tx+i),ty)][BDOWN] || checkobjsolid((tx+i)<getHoldedCommand(IC_RIGHT)) - { - isStanding = false; - isWalking = true; - m_vx = WALK_SPEED; - headingDirection = RIGHT; - } - else if(g_pInput->getHoldedCommand(IC_LEFT)) - { - isStanding = false; - isWalking = true; - m_vx = -WALK_SPEED; - headingDirection = LEFT; - } - else - { - isStanding = true; - isWalking = false; - } - - if(g_pInput->getHoldedCommand(IC_UP)) - { - isStanding = false; - isWalking = true; - m_vy = -WALK_SPEED; - } - else if(g_pInput->getHoldedCommand(IC_DOWN)) - { - isStanding = false; - isWalking = true; - m_vy = WALK_SPEED; - } - } - -} - -void CPlayer::processMovements(void) -{ - // Acceleration formula - if(m_vx != 0) - m_vx += m_ax; - if(m_vy != 0) - m_vy += m_ay; - - if(bisBlockedDown) - { - if(headingDirection == RIGHT && (isWalking || walkframe > 0)) - { - if(walktimer < WALKANIMRATE) - { - //m_vx = 0; - walktimer++; - } - else - { - walktimer = 0; - if(walkframe < 3) - walkframe++; - else - walkframe = 0; - } - - if(walkframe != 0 && !isWalking) - m_vx = 1; - } - } - - // Check, if player is blocked - // If it is not the add Players velocity - if((!bisBlockedRight && m_vx > 0) || - (!bisBlockedLeft && m_vx < 0)) - m_x += m_vx; - - if((!bisBlockedUp && m_vy < 0) || - (!bisBlockedDown && m_vy > 0)) - m_y += m_vy; -} - -void CPlayer::processInertia(void) -{ - -} - -void CPlayer::processFriction(void) -{ - frictiontimer++; - if(frictiontimer > MAX_FRICTIONTIME) - frictiontimer = 0; - - // We have two sections: friction in the air and on ground - - // friction in the air - - // friction on the ground: Division again in three section. Normal, slippery and ice - // on the Ground - if(bisBlockedDown) - { - // He is standing on something solid - if(frictiontimer % 1 == 0) - { - if(m_vx > 0) - { - m_vx-=3; - if(m_vx < 0) - m_vx = 0; - } - if(m_vx < 0) - { - m_vx+=3; - if(m_vx > 0) - m_vx = 0; - } - } - } - -} - -void CPlayer::processSwitches(void) -{ - -} - -void CPlayer::processPogo(void) -{ - -} - -void CPlayer::processJump(void) -{ - -} - -void CPlayer::processFalling(void) -{ - -} - -void CPlayer::showStatusBox(void) -{ - -} - -unsigned short CPlayer::getPlayerframe(void) -{ - return playframe; -} - -// select the appropriate player frame based on what he's doing -void CPlayer::applyFrame(void) -{ - playframe = 0; // basic standing - - // select the frame assuming he's pointing right. ep1 does not select - // a walk frame while fading--this is for the bonus teleporter in L13. - if (isDying) playframe = PDIEFRAME + dieframe; - else - { - if (frozentime) playframe = PFRAME_FROZEN + frozenframe; - else if (isFiring) playframe = PFIREFRAME; - else if (usePogostick) playframe = PFRAME_POGO + (Jumpmode==PREPAREPOGO); - else if (Jumpmode) playframe += jumpframe; - else if (isFalling) playframe += 13; - else if (isWalking || isPushed) playframe += walkframe; - } - - // if he's going left switch the frame selected above to the - // appropriate one for the left direction - if (headingDirection==LEFT && !isDying && !frozentime) - { - if (isFiring) - { - playframe++; - } - else if (usePogostick) - { - playframe+=2; - } - else if (Jumpmode || isFalling) - { - playframe+=6; - } - else - { - playframe+=4; - } - } -} diff --git a/src/vorticon/CPlayer.h b/src/vorticon/CPlayer.h deleted file mode 100644 index 5a3e90ed8..000000000 --- a/src/vorticon/CPlayer.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * CPlayer.h - * - * Created on: 31.03.2009 - * Author: gerstrong - */ - -#ifndef CPLAYER_H_ -#define CPLAYER_H_ - -class CPlayer { -public: - CPlayer(); - virtual ~CPlayer(); - - void handlePlayer(void); - void showStatusBox(void); - unsigned short getPlayerframe(void); - bool isPlaying(void); - void enablePlayer(bool value); - void useObject(unsigned short value); - unsigned short getObject(void); - unsigned long getCoordX(void); - unsigned long getCoordY(void); - void setCoord(unsigned long in_x, unsigned long in_y); - void setpScrCoord(int *px, int *py); - -private: - short episode; - - bool active; - bool isGameover; - bool isFalling; - bool isDying; - bool isFiring; - bool isWalking; - bool isPushed; - bool isStanding; - bool cannotWalk; - bool cannotfall; - bool usePogostick; - - unsigned long m_x; - unsigned long m_y; - int *mp_scrx; - int *mp_scry; - - - unsigned short playframe; - unsigned short Jumpmode; - unsigned short dieframe; - unsigned short frozenframe; - unsigned short jumpframe; - unsigned short headingDirection; - unsigned short frozentime; - unsigned short walkframe; - unsigned short object; - unsigned short walktimer; - unsigned short frictiontimer; - short m_vx; - short m_vy; - short m_ax; - short m_ay; - - bool bisBlockedUp; - bool bisBlockedDown; - bool bisBlockedLeft; - bool bisBlockedRight; - - void performDieAnimation(void); - void processInput(void); - void processDirection(void); - void checkCollisions(void); - void processGoodies(void); - void processInvincibility(void); - void processRaygun(void); - void processStunned(void); - void processWalking(void); - void processInertia(void); - void processFriction(void); - void processSwitches(void); - void processPogo(void); - void processJump(void); - void processFalling(void); - void processMovements(void); - - void applyFrame(void); - -}; - -#endif /* CPLAYER_H_ */