summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-04-03 03:47:46 +0200
committerTreeki <treeki@gmail.com>2012-04-03 03:47:46 +0200
commit3f6db4f669fe659af25169cc22b1d8e6b288d2b6 (patch)
treeed2fc22efed7a703fedbb0f66e11d2ec5cffe622 /src
parent92d2a8b8c2baa96d610a256944aa65a7f2af53e9 (diff)
downloadkamek-3f6db4f669fe659af25169cc22b1d8e6b288d2b6.tar.gz
kamek-3f6db4f669fe659af25169cc22b1d8e6b288d2b6.zip
magic platform fixes and updates
Diffstat (limited to 'src')
-rw-r--r--src/magicplatform.cpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/magicplatform.cpp b/src/magicplatform.cpp
index e9fa940..ae6631d 100644
--- a/src/magicplatform.cpp
+++ b/src/magicplatform.cpp
@@ -33,6 +33,11 @@ class daEnMagicPlatform_c : public dEn_c {
void deleteTiles();
void updateTilePositions();
+ void checkVisibility();
+ void setVisible(bool shown);
+
+ bool isVisible;
+
int srcX, srcY;
int width, height;
};
@@ -79,8 +84,8 @@ static void PhysCB3(daEnMagicPlatform_c *one, dStageActor_c *two, bool unkMaybeN
if (two->stageActorType != 1)
return;
- // if left/right
- if (one->moveDirection <= 1)
+ // if up/down
+ if (one->moveDirection > 1)
return;
if (unkMaybeNotBool) {
@@ -157,6 +162,8 @@ int daEnMagicPlatform_c::onDelete() {
int daEnMagicPlatform_c::onExecute() {
handleMovement();
+ checkVisibility();
+
updateTilePositions();
physics.update();
@@ -308,8 +315,6 @@ void daEnMagicPlatform_c::findSourceArea() {
void daEnMagicPlatform_c::createTiles() {
- TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
-
rendererCount = width * height;
renderers = new TileRenderer[rendererCount];
@@ -326,7 +331,6 @@ void daEnMagicPlatform_c::createTiles() {
TileRenderer *r = &renderers[rendererID];
r->tileNumber = *pExistingTile;
r->z = pos.z;
- list->add(r);
}
worldX += 16;
@@ -340,12 +344,7 @@ void daEnMagicPlatform_c::createTiles() {
void daEnMagicPlatform_c::deleteTiles() {
if (renderers != 0) {
- TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
-
- for (int i = 0; i < rendererCount; i++) {
- if (renderers[i].isInList())
- list->remove(&renderers[i]);
- }
+ setVisible(false);
delete[] renderers;
renderers = 0;
@@ -377,3 +376,38 @@ void daEnMagicPlatform_c::updateTilePositions() {
+void daEnMagicPlatform_c::checkVisibility() {
+ float effectiveLeft = pos.x, effectiveRight = pos.x + (width * 16.0f);
+ float effectiveBottom = pos.y - (height * 16.0f), effectiveTop = pos.y;
+
+ ClassWithCameraInfo *cwci = ClassWithCameraInfo::instance;
+
+ float screenRight = cwci->screenLeft + cwci->screenWidth;
+ float screenBottom = cwci->screenTop - cwci->screenHeight;
+
+ bool isOut = (effectiveLeft > screenRight) ||
+ (effectiveRight < cwci->screenLeft) ||
+ (effectiveTop < screenBottom) ||
+ (effectiveBottom > cwci->screenTop);
+
+ setVisible(!isOut);
+}
+
+void daEnMagicPlatform_c::setVisible(bool shown) {
+ if (isVisible == shown)
+ return;
+ isVisible = shown;
+
+ TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
+
+ for (int i = 0; i < rendererCount; i++) {
+ if (shown) {
+ if (!renderers[i].isInList() && renderers[i].tileNumber > 0)
+ list->add(&renderers[i]);
+ } else {
+ if (renderers[i].isInList())
+ list->remove(&renderers[i]);
+ }
+ }
+}
+