Player (#167) · ModusCreateOrg/creative-engine@b45ad22 · GitHub
Skip to content

Commit b45ad22

Browse files
mschwartzjaygarcia
authored andcommitted
Player (#167)
* DrawRect method that takes TRect arg * wip
1 parent cb272e9 commit b45ad22

11 files changed

Lines changed: 127 additions & 27 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions

‎src/BAnimSprite.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void BAnimSprite::Animate() {
9696
case ADELTAI:
9797
mDx = mAnimPtr[mAnimIndex++];
9898
mDy = mAnimPtr[mAnimIndex++];
99-
return;
99+
continue;
100100
}
101101
}
102102
}
@@ -116,5 +116,9 @@ TBool BAnimSprite::Render(BViewPort *aViewPort) {
116116
const TBool ret = BSprite::Render(aViewPort);
117117
x -= mDx;
118118
y -= mDy;
119+
mRect.x1 -= TInt32(mDx);
120+
mRect.x2 -= TInt32(mDx);
121+
mRect.y1 -= TInt32(mDy);
122+
mRect.y2 -= TInt32(mDy);
119123
return ret;
120124
}

‎src/BBitmap.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class BBitmap : public BBase {
166166
void DrawLine(BViewPort *aViewPort, TInt aX1, TInt aY1, TInt aX2, TInt aY2, TUint8 aColor);
167167

168168
void DrawRect(BViewPort *aViewPort, TInt aX1, TInt aY1, TInt aX2, TInt aY2, TUint8 aColor);
169+
void DrawRect(BViewPort *aViewPort, TRect &aRect, TUint8 aColor) {
170+
DrawRect(aViewPort, aRect.x1, aRect.y1, aRect.x2, aRect.y2, aColor);
171+
}
169172

170173
void FillRect(BViewPort *aViewPort, TInt aX1, TInt aY1, TInt aX2, TInt aY2, TUint8 aColor);
171174

‎src/BMapPlayfield.cpp‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
class BMapTileset : public BBitmap {
44
public:
55
TUint8 *TilePtr(TUint32 aTileNumber) {
6-
const TInt tw = Width() / 16,
6+
const TInt tw = Width() / TILESIZE,
77
row = aTileNumber / tw,
88
col = aTileNumber % tw;
99

10-
const TInt offset = row * 16 * Width() + col*16;
10+
const TInt offset = row * TILESIZE * Width() + col*TILESIZE;
1111
return &mPixels[offset];
1212
};
13+
14+
/**
15+
* Return number of tiles in the bmp
16+
* @return count
17+
*/
18+
TUint32 TileCount() {
19+
return (Width() / TILESIZE) * (Height() / TILESIZE);
20+
21+
}
1322
};
1423

1524
struct MAP {
@@ -25,6 +34,7 @@ BMapPlayfield::BMapPlayfield(BViewPort *aViewPort, TUint16 aTilesetSlot, TUint16
2534
mMapSlot = aMapSlot;
2635
mCodesSlot = aCodesSlot;
2736
mTileset = (BMapTileset *)gResourceManager.GetBitmap(mTilesetSlot);
37+
printf("TILESET BMP is %d tiles\n", mTileset->TileCount());
2838
gDisplay.SetPalette(mTileset);
2939

3040
BRaw *rawMap = gResourceManager.GetRaw(aMapSlot);
@@ -50,20 +60,28 @@ void BMapPlayfield::Render() {
5060

5161

5262
for (TInt row=0; row<tilesHigh; row++) {
63+
64+
5365
const TInt offset = (row +offRow) * mMapWidth + offCol;
5466
TUint32 *map = &mMapData[offset];
5567
for (TInt col=0; col<tilesWide; col++) {
68+
// printf("%04x ", map[col]);
5669
const TUint8 *tile = mTileset->TilePtr(TUint32(map[col]) & TUint32(0xffff));
57-
const TInt offset = (rect.y1 + row*16) * SCREEN_WIDTH + rect.x1 + col*16;
70+
const TInt offset = (rect.y1 + row*TILESIZE) * SCREEN_WIDTH + rect.x1 + col*TILESIZE;
5871
TUint8 *bm = &gDisplay.renderBitmap->mPixels[offset];
59-
for (TInt y=0; y<16; y++) {
60-
for (TInt x=0; x<16; x++) {
72+
for (TInt y=0; y<TILESIZE; y++) {
73+
for (TInt x=0; x<TILESIZE; x++) {
74+
// printf("%02x ", tile[x]);
6175
bm[x] = tile[x];
6276
}
77+
// printf("\n");
6378
bm += SCREEN_WIDTH;
6479
tile += mTileset->Width();
6580
}
81+
// printf("\n\n\n");
6682
}
83+
// printf("\n");
84+
// fflush(stdout);
6785
}
6886
}
6987

‎src/BMapPlayfield.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
class BMapTileset;
77

8-
// Playfield is a map of width,height 16x16 tiles
9-
// TODO: 32x32 tiles, 64x64 tiles, etc.
8+
// 32x32 tiles, 64x64 tiles, etc.
9+
const TInt TILESIZE = 32;
1010
class BMapPlayfield : public BPlayfield {
1111
public:
1212
BMapPlayfield(BViewPort *aViewPort, TUint16 aTilesetSlot, TUint16 aMapSlot, TUint16 aCodesSlot);
@@ -15,11 +15,11 @@ class BMapPlayfield : public BPlayfield {
1515

1616
public:
1717
// in pixels
18-
inline TUint16 TileSize() { return 16; }
19-
TUint16 MapWidth() { return mMapWidth * 16; }
20-
TUint16 MapHeight() { return mMapHeight * 16; }
21-
TUint16 MapMaxX() { return mMapWidth * 16 - SCREEN_WIDTH; }
22-
TUint16 MapMaxY() { return mMapHeight * 16 - SCREEN_HEIGHT; }
18+
inline TUint16 TileSize() { return TILESIZE; }
19+
TUint16 MapWidth() { return mMapWidth * TILESIZE; }
20+
TUint16 MapHeight() { return mMapHeight * TILESIZE; }
21+
TUint16 MapMaxX() { return mMapWidth * TILESIZE - SCREEN_WIDTH; }
22+
TUint16 MapMaxY() { return mMapHeight * TILESIZE - SCREEN_HEIGHT; }
2323

2424
// in tiles
2525
TUint16 MapWidthTiles() { return mMapWidth; }

‎src/BResourceManager.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ BBitmap *BResourceManager::GetBitmap(TInt16 aSlotId) {
193193

194194
TInt BResourceManager::BitmapWidth(TInt aSlotId) {
195195
static const TUint16 widthTable[] = {
196-
0, 8, 16, 32, 48, 64, 128, 256,
196+
0, 8, 16, 32, 64, 128, 256,
197197
8, 16, 8, 32, 8, 64, 8, 128, 8, 256,
198198
16, 32, 16, 64, 16, 128, 16, 256,
199199
32, 64, 32, 128, 32, 256,
@@ -210,7 +210,7 @@ TInt BResourceManager::BitmapWidth(TInt aSlotId) {
210210

211211
TInt BResourceManager::BitmapHeight(TInt aSlotId) {
212212
static const TUint16 heightTable[] = {
213-
0, 8, 16, 32, 48, 64, 128, 256,
213+
0, 8, 16, 32, 64, 128, 256,
214214
16, 8, 32, 8, 64, 8, 128, 8, 256, 8,
215215
32, 16, 64, 16, 128, 16, 256, 16,
216216
64, 32, 128, 32, 256, 32,

‎src/BSprite.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TBool BSprite::Render(BViewPort *aViewPort) {
5656
TFloat screenX = x - aViewPort->mWorldX;
5757
TFloat screenY = y - aViewPort->mWorldY;
5858
if (flags & SFLAG_ANCHOR) {
59-
TInt dy = gResourceManager.BitmapHeight(mBitmapSlot) / 2;
59+
TInt dy = gResourceManager.BitmapHeight(mBitmapSlot);
6060
if (flags & SFLAG_FLOP) {
6161
screenY += dy;
6262
} else {
@@ -70,15 +70,21 @@ TBool BSprite::Render(BViewPort *aViewPort) {
7070
bh = gResourceManager.BitmapHeight(mBitmapSlot),
7171
pitch = mBitmap->Width() / bw;
7272

73-
mRect.x1 = (mImageNumber % pitch) * bw;
74-
mRect.x2 = mRect.x1 + bw - 1;
75-
mRect.y1 = (mImageNumber / pitch) * bh;
76-
mRect.y2 = mRect.y1 + bh - 1;
73+
mRect.x1 = TInt32(screenX);
74+
mRect.y1 = TInt32(screenY);
75+
mRect.x2 = TInt32(screenX) + gResourceManager.BitmapWidth(mBitmapSlot) -1;
76+
mRect.y2 = TInt32(screenY) + gResourceManager.BitmapHeight(mBitmapSlot) -1;
77+
78+
TRect srcRect;
79+
srcRect.x1 = (mImageNumber % pitch) * bw;
80+
srcRect.x2 = srcRect.x1 + bw - 1;
81+
srcRect.y1 = (mImageNumber / pitch) * bh;
82+
srcRect.y2 = srcRect.y1 + bh - 1;
7783

7884
return (mBitmap->TransparentColor() != -1)
79-
? gDisplay.renderBitmap->DrawBitmapTransparent(aViewPort, mBitmap, mRect, round(screenX), round(screenY),
85+
? gDisplay.renderBitmap->DrawBitmapTransparent(aViewPort, mBitmap, srcRect, round(screenX), round(screenY),
8086
(flags >> 6) & 0x0f)
81-
: gDisplay.renderBitmap->DrawBitmap(aViewPort, mBitmap, mRect, round(screenX), round(screenY),
87+
: gDisplay.renderBitmap->DrawBitmap(aViewPort, mBitmap, srcRect, round(screenX), round(screenY),
8288
(flags >> 6) & 0x0f);
8389
}
8490

‎src/Display/DesktopDisplay/DesktopDisplay.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ DesktopDisplay::DesktopDisplay() : DisplayBase() {
2626
windowTitle,
2727
SDL_WINDOWPOS_UNDEFINED, // initial resources position
2828
SDL_WINDOWPOS_UNDEFINED, // initial y position
29-
SCREEN_WIDTH * 2, // Width in pixels
30-
SCREEN_HEIGHT * 2, // Height in pixels
29+
SCREEN_WIDTH * 4, // Width in pixels
30+
SCREEN_HEIGHT * 4, // Height in pixels
3131
flags // flags - see above
3232
);
3333

‎src/Types/TRect.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ struct TRect {
105105

106106
void Height(TInt32 aHeight) { y2 = y1 + aHeight - 1; }
107107

108+
void Dump() {
109+
printf("TRect %f,%f %f,%f\n", x1, y1, x2, y2);
110+
}
111+
108112
public:
109113
// offset (move) by detla in resources and y
110114
void Offset(TInt aDX, TInt aDY) {

‎tools/Makefile‎

Lines changed: 9 additions & 3 deletions

0 commit comments

Comments
 (0)