- removed old unused files

- improved CWindow and CTextBox Classes


git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@206 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
gerstrong
2009-08-03 13:50:09 +00:00
parent 89dd1e260c
commit 53b822f703
9 changed files with 80 additions and 622 deletions

View File

@@ -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 ; i<m_Textline.size() ; i++ )
{
g_pGraphics->drawFont(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;
}
}

View File

@@ -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 <std::string> m_Textline;
float m_x, m_y, m_w, m_h;
float m_fontwidth, m_fontheight;
bool m_border_relative;
};
#endif /* CTEXTBOX_H_ */

View File

@@ -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 //
////////////////////////

View File

@@ -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<CTextBox*> m_TextBox;
private:
float m_x;
float m_y;
@@ -36,7 +46,6 @@ private:
float m_8x8tilewidth;
std::list<int> m_ID_List;
std::vector<CTextBox*> m_TextBox;
void drawWindow();
};

View File

@@ -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<numtiles ; i++)
if(canbePickedup(i) )
if(canbePickedup(i) || isaDoor(i) )
tile[i].chgtile = 143;
switch(m_episode)
@@ -201,8 +201,7 @@ void CTileLoader::assignChangeTileAttribute(stTile *tile)
}
// Only for Doors! Tile is always 182
if(TileProperty[i][BEHAVIOR] >= 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);
}

View File

@@ -45,6 +45,7 @@ private:
void assignChangeTileAttribute(stTile *tile);
bool setProperOffset();
bool canbePickedup(int tile);
bool isaDoor(int tile);
};
#endif /* CTILELOADER_H_ */

View File

@@ -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

View File

@@ -1,501 +0,0 @@
/*
* CPlayer.cpp
*
* Created on: 31.03.2009
* Author: gerstrong
*/
#include <SDL.h>
#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)<<CSF,(ty)<<CSF,0))
{
bisBlockedUp = true;
}
if(TileProperty[getmaptileat((tx+i),ty+PLAYERHEIGHT)][BUP] || checkobjsolid((tx+i)<<CSF,(ty+PLAYERHEIGHT)<<CSF,0))
{
// Standing on an solid object
bisBlockedDown = true;
}
}
for( i=1 ; i < PLAYERHEIGHT ; i++ )
{
if(TileProperty[getmaptileat(tx+PLAYERWIDTH,ty+i)][BRIGHT] || checkobjsolid((tx+PLAYERWIDTH)<<CSF,(ty+i)<<CSF,0))
{
bisBlockedRight = true;
}
if(TileProperty[getmaptileat(tx,ty+i)][BLEFT] || checkobjsolid((tx)<<CSF,(ty+i)<<CSF,0))
{
bisBlockedLeft = true;
}
}
}
void CPlayer::processGoodies(void)
{
}
void CPlayer::processInvincibility(void)
{
}
void CPlayer::processRaygun(void)
{
}
void CPlayer::processStunned(void)
{
}
// Process and decide if player is walking or standing
void CPlayer::processWalking(void)
{
m_vx = 0;
if(isStanding || isWalking)
{
if(g_pInput->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;
}
}
}

View File

@@ -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_ */