Skip to content

Commit 9c50adc

Browse files
committed
Tilemap
1 parent deb0dba commit 9c50adc

9 files changed

Lines changed: 801 additions & 122 deletions

File tree

Source/images/tile.pgm

16 KB
Binary file not shown.

Source/images/tile1.pgm

16 KB
Binary file not shown.

Source/main.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ function newWorld()
2222

2323
world:setPlaneFillColor(mode7.color.grayscale.new(60, 255))
2424

25+
--[[
26+
local tilemap = world:newTilemap(64, 64)
27+
28+
local tileBitmap = mode7.bitmap.loadPGM("images/tile.pgm")
29+
tilemap:setBitmapAtRange(tileBitmap, 0, 0, -1, -1)
30+
31+
local tileBitmap1 = mode7.bitmap.loadPGM("images/tile1.pgm")
32+
tilemap:setBitmapAtPosition(tileBitmap1, 16, 3)
33+
tilemap:setBitmapAtPosition(tileBitmap1, 16, 4)
34+
35+
tilemap:setFillBitmap(tileBitmap)
36+
37+
world:setPlaneTilemap(tilemap)
38+
--]]
39+
2540
local imageTable = mode7.imagetable.new("images/full-car")
2641

2742
addCar(world, imageTable, 246, 1106, 1.5)

Source/mode7.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ function mode7.world:setCeilingFillColor(color)
8989
self:_setCeilingFillColor(color.gray, color.alpha)
9090
end
9191

92+
--- Gets the color of the plane at the specified point.
93+
---
94+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-planeColorAt
95+
---@param x number
96+
---@param y number
97+
---@return mode7.color
98+
function mode7.world:planeColorAt(x, y)
99+
local gray, alpha = self:_planeColorAt(x, y)
100+
return mode7.color.grayscale.new(gray, alpha)
101+
end
102+
103+
--- Gets the color of the ceiling at the specified point.
104+
---
105+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-ceilingColorAt
106+
---@param x number
107+
---@param y number
108+
---@return mode7.color
109+
function mode7.world:ceilingColorAt(x, y)
110+
local gray, alpha = self:_ceilingColorAt(x, y)
111+
return mode7.color.grayscale.new(gray, alpha)
112+
end
113+
92114
-- Display
93115

94116
mode7.display.kScale1x1 = 0

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.5.0

lua/stub.lua

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ mode7.image = {}
6565
---@class mode7.imagetable
6666
mode7.imagetable = {}
6767

68+
---@class mode7.tilemap
69+
mode7.tilemap = {}
70+
6871
---@class mode7.array
6972
mode7.array = {}
7073

@@ -96,6 +99,18 @@ function mode7.world:_setCeilingFillColor(gray, alpha) end
9699
---@return integer alpha
97100
function mode7.world:_getCeilingFillColor() return 0, 0 end
98101

102+
---@param x integer
103+
---@param y integer
104+
---@return integer gray
105+
---@return integer alpha
106+
function mode7.world:_planeColorAt(x, y) return 0, 0 end
107+
108+
---@param x integer
109+
---@param y integer
110+
---@return integer gray
111+
---@return integer alpha
112+
function mode7.world:_ceilingColorAt(x, y) return 0, 0 end
113+
99114
---@param width integer
100115
---@param height integer
101116
---@param gray integer
@@ -172,6 +187,30 @@ function mode7.world:setCeilingBitmap(bitmap) end
172187
---@return mode7.bitmap
173188
function mode7.world:getCeilingBitmap() return {} end
174189

190+
--- Sets a tilemap for the plane.
191+
---
192+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-setPlaneTilemap
193+
---@param tilemap mode7.tilemap
194+
function mode7.world:setPlaneTilemap(tilemap) end
195+
196+
--- Gets the plane tilemap.
197+
---
198+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-getPlaneTilemap
199+
---@return mode7.tilemap
200+
function mode7.world:getPlaneTilemap() return {} end
201+
202+
--- Sets a tilemap for the ceiling.
203+
---
204+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-setCeilingTilemap
205+
---@param tilemap mode7.tilemap
206+
function mode7.world:setCeilingTilemap(tilemap) end
207+
208+
--- Gets the ceiling tilemap.
209+
---
210+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-getCeilingTilemap
211+
---@return mode7.tilemap
212+
function mode7.world:getCeilingTilemap() return {} end
213+
175214
--- Converts a world point to a display point. The z component of the returned value is 1 if the point is in front of the camera or -1 if the point is behind the camera.
176215
---
177216
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-worldToDisplayPoint
@@ -484,6 +523,13 @@ function mode7.background:getCenter() return 0, 0 end
484523
---@return mode7.bitmap
485524
function mode7.bitmap.loadPGM(path) return {} end
486525

526+
--- Returns a copy of the bitmap. The mask, if it exists, is copied too.
527+
---
528+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-bitmap-copy
529+
---@param bitmap mode7.bitmap
530+
---@return mode7.bitmap
531+
function mode7.bitmap:copy(bitmap) return {} end
532+
487533
--- Gets the bitmap size.
488534
---
489535
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-bitmap-getSize
@@ -683,6 +729,52 @@ function mode7.shader.radial:setInverted(inverted) end
683729
---@return boolean
684730
function mode7.shader.radial:getInverted() return false end
685731

732+
--- Creates new tilemap from world. tileWidth and tileHeight values must be a power of 2.
733+
---
734+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-world-newTilemap
735+
---@param tileWidth number
736+
---@param tileHeight number
737+
---@return mode7.tilemap
738+
function mode7.world:newTilemap(tileWidth, tileHeight) return {} end
739+
740+
--- Sets a bitmap at the specified position. Row and column start at 0.
741+
---
742+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-tilemap-setBitmapAtPosition
743+
---@param bitmap mode7.bitmap
744+
---@param row number
745+
---@param column number
746+
function mode7.tilemap:setBitmapAtPosition(bitmap, row, column) end
747+
748+
--- Sets a bitmap at the specified range (from start position to end position). Row and column start at 0, pass -1 as endRow or endColumn to express the highest row or column in the grid. For example, (0, 0, -1, -1) will set the bitmap to the entire grid.
749+
---
750+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-tilemap-setBitmapAtRange
751+
---@param bitmap mode7.bitmap
752+
---@param startRow number
753+
---@param startColumn number
754+
---@param endRow number
755+
---@param endColumn number
756+
function mode7.tilemap:setBitmapAtRange(bitmap, startRow, startColumn, endRow, endColumn) end
757+
758+
--- Gets the bitmap at the specified position.
759+
---
760+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-tilemap-getBitmapAtPosition
761+
---@param row number
762+
---@param column number
763+
---@return mode7.bitmap
764+
function mode7.tilemap:getBitmapAtPosition(row, column) return {} end
765+
766+
--- Sets a bitmap to be used for the out-of-bounds space.
767+
---
768+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-tilemap-setFillBitmap
769+
---@param bitmap mode7.bitmap
770+
function mode7.tilemap:setFillBitmap(bitmap) end
771+
772+
--- Gets a bitmap to be used for the out-of-bounds space.
773+
---
774+
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-tilemap-setFillBitmap
775+
---@return mode7.bitmap
776+
function mode7.tilemap:getFillBitmap() return {} end
777+
686778
--- Resize the pool to the given size in bytes. We recommend to call this function only once.
687779
---
688780
--- https://risolvipro.github.io/playdate-mode7/Lua-API.html#def-pool-realloc

src/c_example/main.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static LCDBitmapTable *carTable;
2727
static PDMode7_Bitmap *bitmap;
2828
static PDMode7_Sprite *sprite;
2929
static LCDBitmap *backgroundImage;
30+
static PDMode7_Tilemap *tilemap;
31+
static PDMode7_Bitmap *tileBitmap;
3032

3133
#ifdef _WINDLL
3234
__declspec(dllexport)
@@ -69,6 +71,21 @@ PDMode7_World *newWorld(void)
6971

7072
world = mode7->world->newWorld(configuration);
7173

74+
/*
75+
tilemap = mode7->world->newTilemap(world, 64, 64);
76+
mode7->world->setPlaneTilemap(world, tilemap);
77+
78+
tileBitmap = mode7->bitmap->loadPGM("images/tile.pgm");
79+
mode7->tilemap->setBitmapAtRange(tilemap, tileBitmap, 0, 0, -1, -1);
80+
81+
int *indexes = (int[2]){
82+
16 * 32 + 3, 16 * 32 + 4
83+
};
84+
85+
PDMode7_Bitmap *tileBitmap1 = mode7->bitmap->loadPGM("images/tile1.pgm");
86+
mode7->tilemap->setBitmapAtIndexes(tilemap, tileBitmap1, indexes, 2);
87+
*/
88+
7289
bitmap = mode7->bitmap->loadPGM("images/track-0.pgm");
7390
mode7->world->setPlaneBitmap(world, bitmap);
7491
mode7->world->setPlaneFillColor(world, mode7->color->newGrayscaleColor(60, 255));
@@ -130,7 +147,7 @@ static int update(void *userdata)
130147
PDMode7_Vec3 position = mode7->camera->getPosition(camera);
131148

132149
float angleDelta = 1 * dt;
133-
150+
134151
if(pressed & kButtonLeft)
135152
{
136153
angle -= angleDelta;
@@ -189,6 +206,14 @@ void restartWorld(void)
189206
{
190207
mode7->sprite->freeSprite(sprite);
191208
}
209+
if(tilemap)
210+
{
211+
mode7->tilemap->freeTilemap(tilemap);
212+
}
213+
if(tileBitmap)
214+
{
215+
mode7->bitmap->freeBitmap(tileBitmap);
216+
}
192217

193218
playdate->graphics->freeBitmap(backgroundImage);
194219
mode7->bitmap->freeBitmap(bitmap);

0 commit comments

Comments
 (0)