diff options
| author | Jonas Ask | 2009-11-12 01:21:36 +0000 |
|---|---|---|
| committer | Jonas Ask | 2009-11-12 01:21:36 +0000 |
| commit | b04bb54ef68a1e10b4126caece7b522d39a4ed05 (patch) | |
| tree | 0c9d91412cc9f9bdc54330dbdbd27474602f0faa /WorldSegment.cpp | |
| parent | 017d462239242224553e4bbb95b6352c7ab639ec (diff) | |
| download | stonesense-b04bb54ef68a1e10b4126caece7b522d39a4ed05.tar.gz stonesense-b04bb54ef68a1e10b4126caece7b522d39a4ed05.tar.bz2 stonesense-b04bb54ef68a1e10b4126caece7b522d39a4ed05.tar.xz | |
Added 7c's Tower Cap. very nice.
ROTATIONS! Finally I think I got them working right (knock on wood). Redid a boat-load of stuff, not gonna list it all.
Diffstat (limited to 'WorldSegment.cpp')
| -rw-r--r-- | WorldSegment.cpp | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/WorldSegment.cpp b/WorldSegment.cpp index e44caee..baf67d0 100644 --- a/WorldSegment.cpp +++ b/WorldSegment.cpp @@ -21,10 +21,54 @@ Block* WorldSegment::getBlock(uint32_t x, uint32_t y, uint32_t z){ lx -= this->x;
ly -= this->y;
lz -= this->z;
+
+ correctBlockForRotation( (int32_t&)lx,(int32_t&)ly,(int32_t&)lz );
uint32_t index = lx + (ly * this->sizex) + ((lz) * this->sizex * this->sizey);
return blocksAsPointerVolume[index];
}
+
+Block* WorldSegment::getBlockRelativeTo(uint32_t x, uint32_t y, uint32_t z, dirRelative direction){
+ int32_t lx = x;
+ int32_t ly = y;
+ int32_t lz = z;
+ //make local
+ lx -= this->x;
+ ly -= this->y;
+ lz -= this->z;
+
+ correctBlockForRotation( (int32_t&)lx,(int32_t&)ly,(int32_t&)lz );
+ switch (direction){
+ case eUp:
+ ly--; break;
+ case eDown:
+ ly++; break;
+ case eLeft:
+ lx--; break;
+ case eRight:
+ lx++; break;
+ case eAbove:
+ lz++; break;
+ case eBelow:
+ lz--; break;
+ case eUpLeft:
+ ly--; lx--; break;
+ case eUpRight:
+ ly--; lx++; break;
+ case eDownLeft:
+ ly++; lx--; break;
+ case eDownRight:
+ ly++; lx++; break;
+ }
+
+ if((int)lx < 0 || lx >= this->sizex) return 0;
+ if((int)ly < 0 || ly >= this->sizey) return 0;
+ if((int)lz < 0 || lz >= this->sizez) return 0;
+
+ uint32_t index = lx + (ly * this->sizex) + ((lz) * this->sizex * this->sizey);
+ return blocksAsPointerVolume[index];
+}
+
Block* WorldSegment::getBlockLocal(uint32_t x, uint32_t y, uint32_t z){
if((int)x < 0 || x >= (uint32_t)this->sizex) return 0;
if((int)y < 0 || y >= (uint32_t)this->sizey) return 0;
@@ -40,6 +84,26 @@ Block* WorldSegment::getBlock(uint32_t index){ return blocks[index];
}
+void correctBlockForRotation(int32_t& x, int32_t& y, int32_t& z){
+ int32_t oldx = x;
+ int32_t oldy = y;
+ int w = config.segmentSize.x;
+ int h = config.segmentSize.y;
+
+ if(DisplayedRotation == 1){
+ x = h - oldy -1;
+ y = oldx;
+ }
+ if(DisplayedRotation == 2){
+ x = w - oldx -1;
+ y = h - oldy -1;
+ }
+ if(DisplayedRotation == 3){
+ x = oldy;
+ y = w - oldx -1;
+ }
+}
+
void WorldSegment::addBlock(Block* b){
this->blocks.push_back(b);
//b = &(this->blocks[ blocks.size() - 1]);
@@ -52,6 +116,9 @@ void WorldSegment::addBlock(Block* b){ y -= this->y;
z -= this->z;
+ //rotate
+ correctBlockForRotation( (int32_t&)x, (int32_t&)y, (int32_t&)z );
+
uint32_t index = x + (y * this->sizex) + ((z) * this->sizex * this->sizey);
//assert( x < sizex && x >=0);
//assert( y < sizey && y >=0);
@@ -75,20 +142,43 @@ void WorldSegment::drawAllBlocks(BITMAP* target){ viewedSegment->blocks[i]->Draw(target);
}
}*/
+
+void WorldSegment::drawAllBlocks(BITMAP* target){
+ // x,y,z print pricess
+ int32_t vsxmax = viewedSegment->sizex;
+ int32_t vsymax = viewedSegment->sizey;
+ int32_t vszmax = viewedSegment->sizez;
+ for(int32_t vsz=0; vsz < vszmax; vsz++){
+ for(int32_t vsx=0; vsx < vsxmax; vsx++){
+ for(int32_t vsy=0; vsy < vsymax; vsy++){
+ Block *b = getBlockLocal(vsx,vsy,vsz);
+ if (b)
+ {
+ b->Draw(target);
+ //while(!key[KEY_SPACE]) ;
+ //rest(100);
+ }
+ }
+ }
+ }
+}
+/*
void WorldSegment::drawAllBlocks(BITMAP* target){
// x,y,z print pricess
int32_t vsxmax = viewedSegment->x + viewedSegment->sizex;
int32_t vsymax = viewedSegment->y + viewedSegment->sizey;
int32_t vszmax = viewedSegment->z + viewedSegment->sizez;
for(int32_t vsz=viewedSegment->z; vsz < vszmax; vsz++){
- switch (DisplayedRotation){
+ switch (DisplayedRotation * 0){
case 0:
for(int32_t vsx=viewedSegment->x; vsx < vsxmax; vsx++){
for(int32_t vsy=viewedSegment->y; vsy < vsymax; vsy++){
Block *b = getBlock(vsx,vsy,vsz);
if (b)
{
- b->Draw(target);
+ b->Draw(screen);
+ //while(!key[KEY_SPACE]);
+ //while(key[KEY_SPACE]);
}
}
}
@@ -100,6 +190,7 @@ void WorldSegment::drawAllBlocks(BITMAP* target){ if (b)
{
b->Draw(target);
+
}
}
}
@@ -129,6 +220,7 @@ void WorldSegment::drawAllBlocks(BITMAP* target){ }
}
}
+*/
/*void WorldSegment::drawAllBlocks(BITMAP* target){
// x,y,z print pricess
int32_t vsxmax = viewedSegment->x + viewedSegment->sizex;
|
