Skip to content

Commit

Permalink
двигающиеся платформы в игре
Browse files Browse the repository at this point in the history
крыса
  • Loading branch information
spidamoo committed Sep 27, 2013
1 parent 9d439d8 commit b652013
Show file tree
Hide file tree
Showing 51 changed files with 295 additions and 947 deletions.
757 changes: 0 additions & 757 deletions SoDlib/SoDLib.depend

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SoDlib/include/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Character
void turn();
void run(float speed);
void jump(b2Vec2 speed);
void move(float dx, float dy);

void setAnim(int anim);

Expand Down
5 changes: 4 additions & 1 deletion SoDlib/include/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class Game
Character* getCharacter(int index);

int getGroundLinesCount();
GroundLine* getGroundLine(int index);
GroundLine* getGroundLine(int index);

int getMapAnimationsCount();
MapAnimation* getMapAnimation(int index);

HGE* getHge();
b2World* getWorld();
Expand Down
1 change: 1 addition & 0 deletions SoDlib/include/GroundLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GroundLine
float horizontalDistanceTo(float x);
float distanceTo(float x, float y);
void debugDraw(), debugDraw(DWORD color);
void move(float dx, float dy);
protected:
b2Vec2 startPoint, endPoint;
float k, inversedK;
Expand Down
1 change: 1 addition & 0 deletions SoDlib/include/MapAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MapAnimation
virtual ~MapAnimation();

void draw(bool schematicMode);
void move(float dx, float dy);
protected:
float x, y, angle;
hgeAnimation* animation;
Expand Down
9 changes: 8 additions & 1 deletion SoDlib/include/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ class Platform
public:
Platform(Game* game, TiXmlElement* elem);
virtual ~Platform();

void update(float dt);

bool characterOn(int charIndex);
protected:
Game* game;
int groundLinesCount, animationsCount;
int* groundLines; int *animations;
int spotsCount;
float* spotX; float* spotY; float*spotAngle; float*spotTime;
float* spotX; float* spotY; float* spotAngle; float* spotTime;

float currentTime; float currentSpotStart; int currentSpot;
float currentX, currentY;
private:
};

Expand Down
Binary file modified SoDlib/libSoDlib.a
Binary file not shown.
5 changes: 5 additions & 0 deletions SoDlib/src/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ void Character::jump(b2Vec2 speed)
//speed.y = 6 * speed.y;
//position.y -= 2;

}

void Character::move(float dx, float dy)
{
position.x += dx; position.y += dy;
}

void Character::setAnim(int anim)
Expand Down
25 changes: 19 additions & 6 deletions SoDlib/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,15 @@ void Game::updateWorld(float dt)
//world->Step(timeStep, velocityIterations, positionIterations);
for (int i = 0; i < charactersCount; i++) {
characters[i]->update(dt);
}
for (int i = 0; i < platformsCount; i++) {
platforms[i]->update(dt);
}
cameraPos = characters[0]->getPosition() - b2Vec2(0.5 * screenWidth / pixelsPerMeter, 0.5 * screenHeight / pixelsPerMeter);
}
bool Game::updateControls()
{
// Process keys
/// Process keys
if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
if (hge->Input_KeyDown(HGEK_TAB)) schematicDrawMode = !schematicDrawMode;
//if (hge->Input_KeyDown(HGEK_SPACE)) loadConstruction("box.xml", b2Vec2(10 + hge->Random_Float(-1, 1), 0));
Expand All @@ -202,12 +205,9 @@ bool Game::updateControls()

void Game::startDraw()
{
// Begin rendering quads.
// This function must be called
// before any actual rendering.
hge->Gfx_BeginScene();

// Clear screen with skyblue color
/// Clear screen with skyblue color
DWORD color = 0x7fc7ff;
if (schematicDrawMode) {
color = 0;
Expand All @@ -219,7 +219,7 @@ void Game::endDraw()
{

gui->Render();
// End rendering and update the screen
/// End rendering and update the screen
hge->Gfx_EndScene();
}

Expand Down Expand Up @@ -619,6 +619,19 @@ GroundLine* Game::getGroundLine(int index)
} else {
return NULL;
}
}

int Game::getMapAnimationsCount()
{
return mapAnimationsCount;
}
MapAnimation* Game::getMapAnimation(int index)
{
if (index < mapAnimationsCount) {
return mapAnimations[index];
} else {
return NULL;
}
}

float Game::worldX(float screenX)
Expand Down
6 changes: 6 additions & 0 deletions SoDlib/src/GroundLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ float GroundLine::distanceTo(float x, float y)
{
return distanceToSegment(startPoint.x, startPoint.y, endPoint.x, endPoint.y, x, y);
}

void GroundLine::move(float dx, float dy)
{
startPoint.x += dx; startPoint.y += dy;
endPoint.x += dx; endPoint.y += dy;
}
5 changes: 5 additions & 0 deletions SoDlib/src/MapAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ void MapAnimation::draw(bool schematicMode)
game->getScaleFactor()
);
}

void MapAnimation::move(float dx, float dy)
{
x += dx; y += dy;
}
54 changes: 54 additions & 0 deletions SoDlib/src/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,63 @@ Platform::Platform(Game* game, TiXmlElement* element)
j++;
child = child->NextSiblingElement("spot");
}

currentSpot = 0;
currentTime = 0.0f;
currentSpotStart = 0.0f;
currentX = 0;
currentY = 0;
}

Platform::~Platform()
{
//dtor
}

void Platform::update(float dt)
{
currentTime += dt;
if (currentTime > currentSpotStart + spotTime[currentSpot]) {
///Ïåðåõîäèì ê ñëåäóþùåìó ïîëîæåíèþ
if (currentSpot == spotsCount - 1) {
currentTime -= (currentSpotStart + spotTime[currentSpot]);
currentSpotStart = 0;
currentSpot = 0;
} else {
currentSpotStart += spotTime[currentSpot];
currentSpot++;
}
}
float prevX = 0; float prevY = 0;
if (currentSpot > 0) {
prevX = spotX[currentSpot - 1];
prevY = spotY[currentSpot - 1];
}
float progress = (currentTime - currentSpotStart) / spotTime[currentSpot];
float x = prevX + (spotX[currentSpot] - prevX) * progress;
float y = prevY + (spotY[currentSpot] - prevY) * progress;
float dx = x - currentX; float dy = y - currentY;

for (int i = 0; i < game->getCharactersCount(); i++) {
if (characterOn(i)) {
game->getCharacter(i)->move(dx, dy);
}
}
for (int i = 0; i < groundLinesCount; i++) {
game->getGroundLine(groundLines[i])->move(dx, dy);
}
for (int i = 0; i < animationsCount; i++) {
game->getMapAnimation(animations[i])->move(dx, dy);
}
currentX = x; currentY = y;
}

bool Platform::characterOn(int charIndex)
{
Character* character = game->getCharacter(charIndex);
for (int i = 0; i < groundLinesCount; i++) {
if (character->getOnGround() == groundLines[i])
return true;
}
return false;
}
13 changes: 7 additions & 6 deletions characterEditor/bin/Debug/animations.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" ?>
<animation file="mage/staff.png.xml"/>
<animation file="mage/body.png.xml"/>
<animation file="mage/head.png.xml"/>
<animation file="mage/open_hand.png.xml"/>
<animation file="mage/fist.png.xml"/>
<animation file="mage/foot.png.xml"/>
<animation file="rat/tail2.png.xml"/>
<animation file="rat/body.png.xml"/>
<animation file="rat/tail.png.xml"/>
<animation file="rat/leg.png.xml"/>
<animation file="rat/head2.png.xml"/>
<animation file="rat/head.png.xml"/>
<animation file="rat/arm.png.xml"/>
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/disabled_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="icons.png" x="0" y="0" w="16" h="16" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions characterEditor/bin/Debug/rat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<animation file="rat/tail2.png.xml"/>
<animation file="rat/body.png.xml"/>
<animation file="rat/tail.png.xml"/>
<animation file="rat/leg.png.xml"/>
<animation file="rat/head2.png.xml"/>
<animation file="rat/head.png.xml"/>
<animation file="rat/arm.png.xml"/>
Binary file added characterEditor/bin/Debug/rat/arm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/arm.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="57" w="9" h="7" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/body.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/body.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="8" w="33" h="14" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/head.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="16" y="46" w="12" h="8" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/head2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/head2.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="46" w="15" h="10" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/leg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/leg.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="37" w="16" h="8" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/rat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added characterEditor/bin/Debug/rat/tail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/tail.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="23" w="21" h="13" nframes="1" fps="0" />
Binary file added characterEditor/bin/Debug/rat/tail2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/rat/tail2.png.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="rat/rat.png" x="0" y="0" w="38" h="7" nframes="1" fps="0" />
2 changes: 2 additions & 0 deletions characterEditor/bin/Debug/resize_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<animation texture="icons.png" x="16" y="0" w="16" h="16" nframes="1" fps="0" />
Loading

0 comments on commit b652013

Please sign in to comment.