Skip to content

Commit

Permalink
more game features
Browse files Browse the repository at this point in the history
  • Loading branch information
spidamoo committed Jun 15, 2014
1 parent 81d2e10 commit 1f5be53
Show file tree
Hide file tree
Showing 194 changed files with 5,294 additions and 534 deletions.
635 changes: 635 additions & 0 deletions SoDlib/SoDLib.depend

Large diffs are not rendered by default.

284 changes: 155 additions & 129 deletions SoDlib/SoDlib.layout

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions SoDlib/include/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ class Character
bool loadFromXml(TiXmlElement* xml, b2Vec2 origin);

void draw(bool schematicMode);
virtual void control(float dt)=0;
void update(float dt);
virtual void update(float dt);
void updateParams(Condition* condition); void updateStatus();

void turn();
void run(float speed);
void jump(b2Vec2 speed);
void move(float dx, float dy);

void setMove(int anim);
virtual void setMove(int anim);

b2Vec2 getPosition();
void setPosition(b2Vec2 newPos);
Expand All @@ -39,7 +38,7 @@ class Character
int getDirection();
float getAngle();

float getHotSpotX(int index), getHotSpotY(int index); int getHotSpotIndex(char* name);
float getHotSpotX(int index), getHotSpotY(int index), getHotSpotAngle(int index); int getHotSpotIndex(char* name);

float getAnimTime();

Expand Down
2 changes: 1 addition & 1 deletion SoDlib/include/CharacterAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CharacterAction
void save(TiXmlElement* elem);

bool take(Game* game, Character* character); void perform(Game* game, Character* character);
void prepareStatus(Character* character), prepareResource(Character* character);
void prepare(Character* character); void prepareStatus(Character* character), prepareResource(Character* character);

int getEffectsCount();
CharacterActionEffect* getEffect(int index);
Expand Down
11 changes: 7 additions & 4 deletions SoDlib/include/CharacterActionCause.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const int ACTIONCAUSE_TYPE_ONGROUND = 201;
const int ACTIONCAUSE_TYPE_ANGLE_MORE = 202;
const int ACTIONCAUSE_TYPE_ANGLE_LESS = 203;

const int ACTIONCAUSE_TYPE_ANIM_TIME_PASSED = 301;
const int ACTIONCAUSE_TYPE_ANIM_TIME_IS = 302;
const int ACTIONCAUSE_TYPE_ANIM_TIME_PASSED = 301;
const int ACTIONCAUSE_TYPE_ANIM_TIME_LESS = 302;
const int ACTIONCAUSE_TYPE_ANIM_TIME_IS = 303;

const int ACTIONCAUSE_TYPE_HAVE_STATUS = 401;

Expand All @@ -39,10 +40,12 @@ class CharacterActionCause
int getType();
void setType(int type);
float getParam(), getParam(int index);
void setParam(float param), setParam(int index, float param);
void setParam(float param), setParam(int index, float param);
void setUsed(bool used);
protected:
int type;
float param; float param2;
float param; float param2;
bool used;
private:
};

Expand Down
2 changes: 1 addition & 1 deletion SoDlib/include/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Effect
void update(float dt), draw(bool schematicMode);

float getTime();
void setPosition(b2Vec2 position); b2Vec2 getPosition();
void setPosition(b2Vec2 position); void setPosition(b2Vec2 position, float angle); b2Vec2 getPosition();
void setHotSpotIndex(int index);

void setAnimation(hgeAnimation* animation, int blendMode);
Expand Down
7 changes: 5 additions & 2 deletions SoDlib/include/EffectPrototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class EffectPrototype
int getAnimationsCount();
void addAnimation(const char* filename), removeAnimation(int index);

int getBlendMode(); void setBlendMode(int mode);
int getBlendMode(); void setBlendMode(int mode);

int getList(); void setList(int list);
protected:
Game* game;

Expand All @@ -114,7 +116,8 @@ class EffectPrototype
char* hotSpotName;

EffectAction** actions; int actionsCount;
char** animations; int animationsCount; int blendMode;
char** animations; int animationsCount; int blendMode;
int effectsList;
private:
};
#endif // EFFECTPROTOTYPE_H
9 changes: 6 additions & 3 deletions SoDlib/include/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const int COUNTER_DRAW_END = 13;

const int COUNTERS_COUNT = 14;

const int EFFECT_LIST_NORMAL = 0;
const int EFFECT_LIST_BACKGROUND = 1;

static const char* COUNTER_NAMES[COUNTERS_COUNT] = {
"total",
" update",
Expand Down Expand Up @@ -101,7 +104,7 @@ class Game
void loadMap(char* fn);
void addGroundLine(GroundLine* newGL); void addMapAnimation(MapAnimation* newMA); void addPlatform(Platform* newPlatform);

void removeEffect(int index);
void removeEffect(int index, int listIndex);


bool loadEffectPrototypes(char* fn); int getEffectPrototypesCount(); EffectPrototype* getEffectPrototype(int index);
Expand All @@ -122,7 +125,7 @@ class Game
bool loadCharacterMoveTypes(char* fn); int getCharacterMoveTypesCount(); CharacterMoveType* getCharacterMoveType(int index);
void addCharacterMoveType(), removeCharacterMoveType(int index);

void addEffect(Effect* newEffect);
void addEffect(Effect* newEffect, int listIndex);

int getCharactersCount();
Character* getCharacter(int index);
Expand Down Expand Up @@ -184,7 +187,7 @@ class Game

Platform** platforms; int platformsCount;
Character** characters; int charactersCount;
Effect** effects; int effectsCount;
Effect*** effects; int* effectsCount;
EffectPrototype** effectPrototypes; int effectPrototypesCount;
ConditionPrototype** conditionPrototypes; int conditionPrototypesCount;
CharacterParamPrototype** characterParamPrototypes; int characterParamPrototypesCount;
Expand Down
14 changes: 9 additions & 5 deletions SoDlib/include/PlayerCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const int CHARACTER_KEY_BACK = 1;
const int CHARACTER_KEY_FORTH = 2;
const int CHARACTER_KEY_JUMP = 3;
const int CHARACTER_KEY_ATTACK = 4;
const int CHARACTER_KEY_SATTACK = 5;
const int CHARACTER_KEY_SATTACK = 5;
const int CHARACTER_KEY_SIT = 6;

class PlayerCharacter : public Character
{
Expand All @@ -16,12 +17,15 @@ class PlayerCharacter : public Character
virtual ~PlayerCharacter();

inline int getType() {return CHARACTER_TYPE_PLAYER;};

void control(float dt);

void update(float dt);
void setMove(int move);

bool isKeyHit(int key);
bool isKeyDown(int key);
protected:
bool isKeyDown(int key);
bool wasKeyHit(int key);
protected:
bool* keyWasHit;
private:
};

Expand Down
Binary file modified SoDlib/libSoDlib.a
Binary file not shown.
10 changes: 7 additions & 3 deletions SoDlib/src/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ void Character::update(float dt) {
resources[i]->regen(dt);
}

control(dt);
}

void Character::updateParams(Condition* condition) {
Expand Down Expand Up @@ -669,8 +668,7 @@ void Character::setMove(int move) {
// printf("move set to #%d\n", move);

for (int i = 0; i< actionsCounts[currentMove]; i++) {
actions[currentMove][i]->prepareStatus(this);
actions[currentMove][i]->prepareResource(this);
actions[currentMove][i]->prepare(this);
}
}

Expand Down Expand Up @@ -730,6 +728,12 @@ float Character::getHotSpotY(int index) {
}
return position.y + animatedValue( frameHotSpotY[currentMove][currentFrame][index], frameHotSpotY[currentMove][nextFrame][index] );
}
float Character::getHotSpotAngle(int index) {
if (index < 0 || index > hotSpotsCount) {
return position.y;
}
return turnedRight ? -animatedValue( frameHotSpotAngle[currentMove][currentFrame][index], frameHotSpotAngle[currentMove][nextFrame][index] ) : animatedValue( frameHotSpotAngle[currentMove][currentFrame][index], frameHotSpotAngle[currentMove][nextFrame][index] );
}
int Character::getHotSpotIndex(char* name) {
for (int i = 0; i < hotSpotsCount; i++) {
if ( compareStrings( name, hotSpots[i]->getName() ) ) {
Expand Down
8 changes: 8 additions & 0 deletions SoDlib/src/CharacterAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ void CharacterAction::perform(Game* game, Character* character) {
effects[i]->perform(game, character);
}
}

void CharacterAction::prepare(Character* character) {
prepareResource(character);
prepareStatus(character);
for (int i = 0; i < causesCount; i++) {
causes[i]->setUsed(false);
}
}
void CharacterAction::prepareStatus(Character* character) {
for (int i = 0; i < causesCount; i++) {
if (causes[i]->getType() == ACTIONCAUSE_TYPE_HAVE_STATUS) {
Expand Down
15 changes: 13 additions & 2 deletions SoDlib/src/CharacterActionCause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CharacterActionCause::save(TiXmlElement* elem)
bool CharacterActionCause::test(Game* game, Character* character) {
switch (type) {
case ACTIONCAUSE_TYPE_KEYHIT:
return ((PlayerCharacter*)character)->isKeyHit(param);
return ((PlayerCharacter*)character)->wasKeyHit(param);
break;
case ACTIONCAUSE_TYPE_KEYRELEASED:
return !((PlayerCharacter*)character)->isKeyDown(param);
Expand All @@ -57,8 +57,15 @@ bool CharacterActionCause::test(Game* game, Character* character) {
case ACTIONCAUSE_TYPE_ANIM_TIME_PASSED:
return ( character->getAnimTime() >= param );
break;
case ACTIONCAUSE_TYPE_ANIM_TIME_LESS:
return ( character->getAnimTime() <= param );
break;
case ACTIONCAUSE_TYPE_ANIM_TIME_IS:
return ( character->getAnimTime() == param );
if (!used && character->getAnimTime() >= param) {
used = true;
return true;
}
return false;
break;
case ACTIONCAUSE_TYPE_ANGLE_MORE:
return ( character->getAngle() > param );
Expand Down Expand Up @@ -100,3 +107,7 @@ void CharacterActionCause::setParam(int index, float _param) {
break;
}
}

void CharacterActionCause::setUsed(bool _used) {
used = _used;
}
4 changes: 2 additions & 2 deletions SoDlib/src/CharacterActionEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void CharacterActionEffect::perform(Game* game, Character* character) {
character->turn();
break;
case ACTIONEFFECT_TYPE_CHANGEMOVE:
character->setMove(param);
character->setMove((int)param);
break;
case ACTIONEFFECT_TYPE_RUN:
character->run(param);
Expand All @@ -41,7 +41,7 @@ void CharacterActionEffect::perform(Game* game, Character* character) {
character->jump(b2Vec2(param2, -param));
break;
case ACTIONEFFECT_TYPE_SPAWN_EFFECT:
game->addEffect( game->getEffectPrototype(param)->spawnEffect(character) );
game->addEffect( game->getEffectPrototype(param)->spawnEffect(character), game->getEffectPrototype(param)->getList() );
//printf("effect spawn\n");
break;
case ACTIONEFFECT_TYPE_ADD_CONDITION:
Expand Down
38 changes: 30 additions & 8 deletions SoDlib/src/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,24 @@ Effect::Effect(Game* game, EffectPrototype* prototype) {

owner = NULL;

width = 1.0f;
width = 1.0f;

position = b2Vec2_zero;
angle = 0;
}

Effect::~Effect() {
delete animation;
delete actionTimes;
delete actionTimes;

for ( int i = 0; i < prototype->getActionsCount(); i++ ) {
switch ( prototype->getAction(i)->getType() ) {
case EFFECTACTION_TYPE_INFLICT_CONDITION:
delete actionInteractions[i];
break;
}
}
delete actionInteractions;
}

void Effect::setOwner(Character* owner) {
Expand All @@ -61,21 +73,27 @@ void Effect::initialize() {

time = prototype->evalStartExpression(EFFECT_FUNCTION_TIME);
prototype->setParam(EFFECT_PARAM_TIME, time);
angle = prototype->evalStartExpression(EFFECT_FUNCTION_ANGLE);
angle += prototype->evalStartExpression(EFFECT_FUNCTION_ANGLE);
prototype->setParam(EFFECT_PARAM_ANGLE, angle);

componentSpeed.x = prototype->evalStartExpression(EFFECT_FUNCTION_XSPEED);
componentSpeed.y = prototype->evalStartExpression(EFFECT_FUNCTION_YSPEED);

r = prototype->evalStartExpression(EFFECT_FUNCTION_R);
g = prototype->evalStartExpression(EFFECT_FUNCTION_G);
b = prototype->evalStartExpression(EFFECT_FUNCTION_B);
a = prototype->evalStartExpression(EFFECT_FUNCTION_A);
if (animation) {
r = prototype->evalStartExpression(EFFECT_FUNCTION_R);
g = prototype->evalStartExpression(EFFECT_FUNCTION_G);
b = prototype->evalStartExpression(EFFECT_FUNCTION_B);
a = prototype->evalStartExpression(EFFECT_FUNCTION_A);
animation->SetColor( (a << 24) + (r << 16) + (g << 8) + b );
}

scale = prototype->evalStartExpression(EFFECT_FUNCTION_SCALE);

width = prototype->evalStartExpression(EFFECT_FUNCTION_WIDTH);
height = prototype->evalStartExpression(EFFECT_FUNCTION_HEIGHT);

position.x += prototype->evalStartExpression(EFFECT_FUNCTION_X);
position.y += prototype->evalStartExpression(EFFECT_FUNCTION_Y);
}

void Effect::draw(bool schematicMode) {
Expand Down Expand Up @@ -267,7 +285,7 @@ void Effect::update(float dt) {
break;
case EFFECTACTION_TYPE_SPAWN_EFFECT:
//printf("effect spawns effect\n");
game->addEffect( game->getEffectPrototype( action->getParam() )->spawnEffect(this) );
game->addEffect( game->getEffectPrototype( action->getParam() )->spawnEffect(this), game->getEffectPrototype( action->getParam() )->getList() );
break;
case EFFECTACTION_TYPE_INFLICT_CONDITION:
//printf("trying to apply condition\n");
Expand Down Expand Up @@ -311,6 +329,10 @@ float Effect::getTime() {
void Effect::setPosition(b2Vec2 position) {
this->position = position;
}
void Effect::setPosition(b2Vec2 _position, float _angle) {
position = _position;
angle = _angle;
}
b2Vec2 Effect::getPosition() {
return position;
}
Expand Down
Loading

0 comments on commit 1f5be53

Please sign in to comment.