├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── example.gif ├── player_0.png ├── player_1.png ├── player_2.png ├── player_3.png ├── roboto_regular.ttf ├── thumbnail.png └── tilesource.png ├── dgrid └── dgrid.lua ├── example ├── atlas.atlas ├── collection.collection ├── font_regular.font ├── gui.gui ├── gui_script.gui_script ├── map.go ├── player.go ├── player.script ├── tilemap.tilemap └── tilesource.tilesource ├── game.project └── input └── game.input_binding /.gitattributes: -------------------------------------------------------------------------------- 1 | # Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091) 2 | *.animationset linguist-language=JSON5 3 | *.atlas linguist-language=JSON5 4 | *.camera linguist-language=JSON5 5 | *.collection linguist-language=JSON5 6 | *.collectionfactory linguist-language=JSON5 7 | *.collectionproxy linguist-language=JSON5 8 | *.collisionobject linguist-language=JSON5 9 | *.cubemap linguist-language=JSON5 10 | *.display_profiles linguist-language=JSON5 11 | *.factory linguist-language=JSON5 12 | *.font linguist-language=JSON5 13 | *.gamepads linguist-language=JSON5 14 | *.go linguist-language=JSON5 15 | *.gui linguist-language=JSON5 16 | *.input_binding linguist-language=JSON5 17 | *.label linguist-language=JSON5 18 | *.material linguist-language=JSON5 19 | *.mesh linguist-language=JSON5 20 | *.model linguist-language=JSON5 21 | *.particlefx linguist-language=JSON5 22 | *.render linguist-language=JSON5 23 | *.sound linguist-language=JSON5 24 | *.sprite linguist-language=JSON5 25 | *.spinemodel linguist-language=JSON5 26 | *.spinescene linguist-language=JSON5 27 | *.texture_profiles linguist-language=JSON5 28 | *.tilemap linguist-language=JSON5 29 | *.tilesource linguist-language=JSON5 30 | 31 | # Defold JSON Files 32 | *.buffer linguist-language=JSON 33 | 34 | # Defold GLSL Shaders 35 | *.fp linguist-language=GLSL 36 | *.vp linguist-language=GLSL 37 | 38 | # Defold Lua Files 39 | *.editor_script linguist-language=Lua 40 | *.render_script linguist-language=Lua 41 | *.script linguist-language=Lua 42 | *.gui_script linguist-language=Lua 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.internal 2 | /build 3 | .externalToolBuilders 4 | .DS_Store 5 | Thumbs.db 6 | .lock-wscript 7 | *.pyc 8 | .project 9 | .cproject 10 | builtins -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024 White Box Dev 2 | 3 | This software is provided 'as-is', without any express or implied warranty. 4 | In no event will the authors be held liable for any damages arising from the use of this software. 5 | 6 | Permission is granted to anyone to use this software for any purpose, 7 | including commercial applications, and to alter it and redistribute it freely, 8 | subject to the following restrictions: 9 | 10 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 11 | If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 12 | 13 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 14 | 15 | 3. This notice may not be removed or altered from any source distribution. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Defold Grid Engine 2 | 3 | Defold Grid Engine provides grid-based movement, interactions, and utility features to a Defold game engine project. 4 | 5 | Please click the ☆ button on GitHub if this repository is useful or interesting. Thank you! 6 | 7 | ![alt text](https://github.com/whiteboxdev/library-defold-grid-engine/blob/master/assets/thumbnail.png?raw=true) 8 | 9 | ## Installation 10 | 11 | Add the latest version to your project's dependencies: 12 | https://github.com/whiteboxdev/library-defold-grid-engine/archive/master.zip 13 | 14 | ## Configuration 15 | 16 | Import the dgrid Lua module into your character's script: 17 | `local dgrid = require "dgrid.dgrid"` 18 | 19 | The grid system itself must be initialized before registering any characters: 20 | 21 | ``` 22 | local grid_box_size = 16 23 | 24 | local collision_map = { 25 | { 2, 2, 2, 2, 2 }, 26 | { 2, 1, 1, 1, 2 }, 27 | { 2, 1, 1, 1, 2 }, 28 | { 2, 1, 1, 1, 2 }, 29 | { 2, 2, 2, 2, 2 } 30 | } 31 | 32 | local property_map = { 33 | ["31"] = { bonus_points = 1000 }, 34 | ["55"] = { bonus_points = 2000 } 35 | } 36 | 37 | function init(self) 38 | dgrid.set_stride(grid_box_size) 39 | dgrid.set_collision_map(collision_map) 40 | dgrid.set_property_map(property_map) 41 | end 42 | ``` 43 | 44 | The `dgrid.set_stride()` function sets the size of each grid box. In the example above, each grid box is set to 16 pixels. 45 | 46 | The `dgrid.set_collision_map()` function assigns a collision map to the grid. Collision maps consist of a two-dimensional array of integers, each of which corresponds to a collision tag. All tags can be found in the `dgrid.tag` [table](#dgridtag). Custom tags may be inserted into the `dgrid.tag` table if you wish to detect additional collision cases. dgrid will post a `dgrid.msg.collide_passable` or `dgrid.msg.collide_impassable` message to your character's `on_message()` function when your character collides with any grid box. If you did not specify a collision map, then `dgrid.msg.collide_none` will be posted instead. 47 | 48 | The `dgrid.set_property_map()` function assigns a property map to the grid. Property maps consist of a table of custom data. The purpose of this map is to assign semantics to your grid boxes. Keys correspond to the x and y coordinates of the targetted grid box, while values correspond to the custom data. When a character collides with a grid box that contains custom data, the data is attached to the `dgrid.msg.collide` messages as the `message.property` field. In the example above, colliding with the grid box at coordinates <3, 1> will send a `message.property` value of `{ bonus_points = 1000 }`. 49 | 50 | If the bottom-left of your tilemap is not located at the origin of the game world, you should call the `dgrid.set_map_offset()` function, which allows you to shift your collision and property maps to match up with the world position of your tilemap. 51 | 52 | Configuration is complete. Next step is to register your characters: 53 | 54 | ``` 55 | local config = { 56 | size = vmath.vector3(16, 32, 0), 57 | direction = dgrid.direction.down, 58 | speed = 3 59 | } 60 | 61 | function init(self) 62 | self.dgrid = dgrid.register(config) 63 | end 64 | ``` 65 | 66 | 1. `size`: Size of your character in pixels. 67 | 2. `direction`: Initial direction in which your character is looking. 68 | 3. `speed`: Movement speed in grid boxes per second. If `speed = 0`, then movement is instant. 69 | 70 | dgrid snaps your character into a grid box on registration. To do this, the bottom-center `stride x stride` square region of your character is used to properly position it onto the grid. 71 | 72 | Finally, make sure to call `self.dgrid.update()` and `self.dgrid.unregister()` in your character's script: 73 | 74 | ``` 75 | function update(self, dt) 76 | self.dgrid.update(dt) 77 | end 78 | 79 | function final(self) 80 | self.dgrid.unregister() 81 | end 82 | ``` 83 | 84 | ## API: Properties 85 | 86 | ### dgrid.direction 87 | 88 | Table for referencing character orientation: 89 | 90 | ``` 91 | dgrid.direction = { 92 | up = { value = 1, string = "up", offset = vmath.vector3(0, 1, 0) }, 93 | left = { value = 2, string = "left", offset = vmath.vector3(-1, 0, 0) }, 94 | down = { value = 3, string = "down", offset = vmath.vector3(0, -1, 0) }, 95 | right = { value = 4, string = "right", offset = vmath.vector3(1, 0, 0) } 96 | } 97 | ``` 98 | 99 | 1. `value`: Identification value of this direction. 100 | 2. `string`: Name of this direction. 101 | 3. `offset`: Coordinate offset of this direction. 102 | 103 | ### dgrid.msg 104 | 105 | Table for referencing messages posted to your character's `on_message()` function: 106 | 107 | ``` 108 | dgrid.msg = { 109 | move_start = hash("move_start"), 110 | move_end = hash("move_end"), 111 | move_repeat = hash("move_repeat"), 112 | collide_none = hash("collide_none"), 113 | collide_passable = hash("collide_passable"), 114 | collide_impassable = hash("collide_impassable") 115 | } 116 | ``` 117 | 118 | 1. `move_start`: Posted when your character starts moving from rest. 119 | 2. `move_end`: Posted when your character stops moving. 120 | 3. `move_repeat`: Posted when your character continues moving between grid boxes without stopping. 121 | 4. `collide_none`: Posted when your character collides with any grid box which lies outside of the supplied collision map. The `message.property` field contains the user-defined data at this grid position. 122 | 5. `collide_passable`: Posted when your character collides with any passable grid box. The `message.name` field contains the tag's hashed `name` string. The `message.property` field contains the user-defined data at this grid position. 123 | 6. `collide_impassable`: Posted when your character collides with any impassable grid box. The `message.name` field contains the tag's hashed `name` string. The `message.property` field contains the user-defined data at this grid position. 124 | 125 | ### dgrid.tag 126 | 127 | Table for referencing collision tags. Each key (index of tag) corresponds to an integer used in your collision map. Custom tags may be inserted if you wish to detect additional collision cases. 128 | 129 | ``` 130 | dgrid.tag = { 131 | { name = hash("passable"), passable = true }, 132 | { name = hash("impassable"), passable = false } 133 | } 134 | ``` 135 | 136 | 1. `name`: Hashed name of this tag. 137 | 2. `passable`: `bool` indicating whether characters may pass through grid boxes assigned to this tag. 138 | 139 | ## API: Functions 140 | 141 | ### dgrid.get_stride() 142 | 143 | Gets the size of each grid box in pixels. 144 | 145 | #### Returns 146 | 147 | Returns a number. 148 | 149 | --- 150 | 151 | ### dgrid.get_collision_map() 152 | 153 | Gets the collision map. 154 | 155 | #### Returns 156 | 157 | Returns a table of lists of integers in the following format: 158 | 159 | ``` 160 | { 161 | { , ... }, 162 | ... 163 | } 164 | ``` 165 | 166 | --- 167 | 168 | ### dgrid.get_property_map() 169 | 170 | Gets the property map. 171 | 172 | #### Returns 173 | 174 | Returns a table of custom data. Keys correspond to the x and y coordinates of the targetted grid box, while values correspond to the custom data: 175 | 176 | ``` 177 | { 178 | ["xy"] = { ... }, 179 | ... 180 | } 181 | ``` 182 | 183 | --- 184 | 185 | ### dgrid.get_map_offset() 186 | 187 | Gets the collision and property map offset. 188 | 189 | #### Returns 190 | 191 | Returns a `vector3`. 192 | 193 | --- 194 | 195 | ### dgrid.get_tag(name) 196 | 197 | Gets tag information. 198 | 199 | #### Parameters 200 | 1. `name`: Hashed name of a tag. 201 | 202 | #### Returns 203 | 204 | Returns a table in the following format: 205 | 206 | ``` 207 | { 208 | key = , 209 | value = { name = hash(""), passable = } 210 | } 211 | ``` 212 | 213 | --- 214 | 215 | ### dgrid.to_pixel_position(grid_position) 216 | 217 | Converts grid coordinates to pixel coordinates. The returned pixel coordinates point to the center of the grid box. 218 | 219 | #### Parameters 220 | 1. `grid_position`: `vector3` denoting the grid box to convert. The `z` component remains unchanged. 221 | 222 | #### Returns 223 | 224 | Returns a `vector3`. 225 | 226 | --- 227 | 228 | ### dgrid.to_grid_position(pixel_position) 229 | 230 | Converts pixel coordinates to grid coordinates. 231 | 232 | #### Parameters 233 | 1. `pixel_position`: `vector3` denoting the pixel to convert. The `z` component remains unchanged. 234 | 235 | #### Returns 236 | 237 | Returns a `vector3`. 238 | 239 | --- 240 | 241 | ### dgrid.to_map_position(grid_position) 242 | 243 | Converts grid coordinates to map coordinates. Map coordinates take into account the `map_offset`. 244 | 245 | #### Parameters 246 | 1. `grid_position`: `vector3` denoting the grid box to convert. The `z` component remains unchanged. 247 | 248 | #### Returns 249 | 250 | Returns a `vector3`. 251 | 252 | --- 253 | 254 | ### dgrid.set_stride(stride) 255 | 256 | Sets the size of each grid box in pixels. 257 | 258 | #### Parameters 259 | 1. `stride`: Size of each grid box in pixels. 260 | 261 | --- 262 | 263 | ### dgrid.set_collision_map(collision_map) 264 | 265 | Sets the collision map. 266 | 267 | #### Parameters 268 | 1. `collision_map`: Table of lists of integers in the following format: 269 | 270 | ``` 271 | { 272 | { , ... }, 273 | ... 274 | } 275 | ``` 276 | 277 | --- 278 | 279 | ### dgrid.set_property_map(property_map) 280 | 281 | Sets the property map. 282 | 283 | #### Parameters 284 | 1. `property_map`: Table of custom data. Keys correspond to the x and y coordinates of the targetted grid box, while values correspond to the custom data: 285 | 286 | ``` 287 | { 288 | ["xy"] = { ... }, 289 | ... 290 | } 291 | ``` 292 | 293 | --- 294 | 295 | ### dgrid.set_map_offset(offset) 296 | 297 | Sets the collision and property map offset. If the bottom-left of your tilemap is not loaded at the origin of the game world, then this function will allow you to shift your collision property maps to match up with the world position of your tilemap. 298 | 299 | #### Parameters 300 | 1. `offset`: `vector3` denoting number of grid boxes to shift. 301 | 302 | --- 303 | 304 | ### dgrid.set_tag(name, passable) 305 | 306 | Sets an existing tag's `passable` flag. 307 | 308 | #### Parameters 309 | 1. `name`: Hashed name of tag. 310 | 2. `passable`: `bool` indicating whether characters may pass through grid boxes assigned to this tag. 311 | 312 | --- 313 | 314 | ### dgrid.add_tag(name, passable) 315 | 316 | Adds a tag to the `dgrid.tag` table. 317 | 318 | #### Parameters 319 | 1. `name`: Hashed name of tag. 320 | 2. `passable`: `bool` indicating whether characters may pass through grid boxes assigned to this tag. 321 | 322 | #### Returns 323 | 324 | Returns the tag's integer value which may be used when constructing your collision map. 325 | 326 | --- 327 | 328 | ### dgrid.register(config) 329 | 330 | Registers the current game object in the grid system. 331 | 332 | #### Parameters 333 | 1. `config`: Table for setting up this character's properties. 334 | 1. `size`: `vector3` of integers specifying this character's dimensions in pixels. 335 | 2. `direction`: Initial `dgrid.direction` in which your character is looking. 336 | 3. `speed`: Movement speed in grid boxes per second. If `speed = 0`, then movement is instant. 337 | 338 | #### Returns 339 | 340 | Returns an instance of dgrid. 341 | 342 | --- 343 | 344 | ### self.dgrid.get_size() 345 | 346 | Gets the size of this character in pixels. 347 | 348 | #### Returns 349 | 350 | Returns a number. 351 | 352 | --- 353 | 354 | ### self.dgrid.get_direction() 355 | 356 | Gets the `dgrid.direction` in which this character is looking. 357 | 358 | #### Returns 359 | 360 | Returns an entry of the `dgrid.direction` [table](#dgriddirection). 361 | 362 | --- 363 | 364 | ### self.dgrid.get_speed() 365 | 366 | Gets the speed of this character in grid boxes per second. 367 | 368 | #### Returns 369 | 370 | Returns a number. 371 | 372 | --- 373 | 374 | ### self.dgrid.is_moving() 375 | 376 | Checks if this character is moving. 377 | 378 | #### Returns 379 | 380 | Returns a `bool`. 381 | 382 | --- 383 | 384 | ### self.dgrid.is_forcing_movement() 385 | 386 | Checks if this character is able to move through impassable grid boxes specified by the collision map. 387 | 388 | #### Returns 389 | 390 | Returns a `bool`. 391 | 392 | --- 393 | 394 | ### self.dgrid.get_grid_position() 395 | 396 | Gets the grid coordinates of this character. 397 | 398 | #### Returns 399 | 400 | Returns a `vector3`. 401 | 402 | --- 403 | 404 | ### self.dgrid.get_map_position() 405 | 406 | Gets the map coordinates of this character. Map coordinates take into account the `map_offset`. 407 | 408 | #### Returns 409 | 410 | Returns a `vector3`. 411 | 412 | --- 413 | 414 | ### self.dgrid.reach() 415 | 416 | Gets the position of the grid box directly in front of this character in grid coordinates. 417 | 418 | #### Returns 419 | 420 | Returns a `vector3`. 421 | 422 | --- 423 | 424 | ### self.dgrid.set_direction(direction) 425 | 426 | Sets the `dgrid.direction` in which this character is looking. This affects the return value of funtions such as `self.dgrid.reach()`. This is also useful for simply turning a character in some direction without actually moving. 427 | 428 | #### Parameters 429 | 1. `direction`: Entry in the `dgrid.direction` [table](#dgriddirection). 430 | 431 | --- 432 | 433 | ### self.dgrid.set_speed(speed) 434 | 435 | Sets the speed of this character in grid boxes per second. 436 | 437 | #### Parameters 438 | 1. `speed`: Speed of this character in grid boxes per second. If `speed = 0`, then movement is instant. 439 | 440 | --- 441 | 442 | ### self.dgrid.force_movement(flag) 443 | 444 | Allows this character to move through impassable grid boxes as specified by the collision map. 445 | 446 | #### Parameters 447 | 1. `flag`: `bool` indicating whether to force movement. 448 | 449 | --- 450 | 451 | ### self.dgrid.add_lerp_callback(callback, volatile) 452 | 453 | Adds a lerp callback, which triggers upon each complete character movement. 454 | 455 | #### Parameters 456 | 1. `callback`: Callback function. 457 | 2. `volatile`: `bool` indicating whether to remove this callback after being triggered once. 458 | 459 | --- 460 | 461 | ### self.dgrid.remove_lerp_callback(callback, volatile) 462 | 463 | Removes a lerp callback, which triggers upon each complete character movement. Does nothing if the specified callback does not exist. 464 | 465 | #### Parameters 466 | 1. `callback`: Callback function. 467 | 2. `volatile`: `bool` indicating whether to remove this callback after being triggered once. 468 | 469 | --- 470 | 471 | ### self.dgrid.set_grid_position(grid_position) 472 | 473 | Sets the position of this character in grid coordinates. 474 | 475 | #### Parameters 476 | 1. `grid_position`: `vector3` denoting the grid box to warp to. 477 | 478 | --- 479 | 480 | ### self.dgrid.move(direction) 481 | 482 | Begin moving in some direction. Movement will continue until `self.dgrid.stop()` is called. 483 | 484 | #### Parameters 485 | 1. `direction`: Entry in the `dgrid.direction` [table](#dgriddirection). 486 | 487 | --- 488 | 489 | ### self.dgrid.stop(direction) 490 | 491 | Stop moving in some direction. 492 | 493 | #### Parameters 494 | 1. `direction`: Entry in the `dgrid.direction` [table](#dgriddirection). Omit this argument if you wish to stop movement in all directions instead of just one. 495 | 496 | --- 497 | 498 | ### self.dgrid.update(dt) 499 | 500 | Updates all relevant properties. Must be called in this character's `update()` function. 501 | 502 | #### Properties 503 | 1. `dt`: Change in time since last frame. 504 | 505 | --- 506 | 507 | ### self.dgrid.unregister() 508 | 509 | Unregisters this character from dgrid. Must be called in this character's `final()` function. 510 | -------------------------------------------------------------------------------- /assets/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/example.gif -------------------------------------------------------------------------------- /assets/player_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/player_0.png -------------------------------------------------------------------------------- /assets/player_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/player_1.png -------------------------------------------------------------------------------- /assets/player_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/player_2.png -------------------------------------------------------------------------------- /assets/player_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/player_3.png -------------------------------------------------------------------------------- /assets/roboto_regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/roboto_regular.ttf -------------------------------------------------------------------------------- /assets/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/thumbnail.png -------------------------------------------------------------------------------- /assets/tilesource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whiteboxdev/library-defold-grid-engine/c4de5250bcc8eb4b39396253f7b60cfe1439a9e7/assets/tilesource.png -------------------------------------------------------------------------------- /dgrid/dgrid.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- 2 | -- LICENSE 3 | -------------------------------------------------------------------------------- 4 | 5 | -- Copyright (c) 2024 White Box Dev 6 | 7 | -- This software is provided 'as-is', without any express or implied warranty. 8 | -- In no event will the authors be held liable for any damages arising from the use of this software. 9 | 10 | -- Permission is granted to anyone to use this software for any purpose, 11 | -- including commercial applications, and to alter it and redistribute it freely, 12 | -- subject to the following restrictions: 13 | 14 | -- 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 15 | -- If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 16 | 17 | -- 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 18 | 19 | -- 3. This notice may not be removed or altered from any source distribution. 20 | 21 | -------------------------------------------------------------------------------- 22 | -- INFORMATION 23 | -------------------------------------------------------------------------------- 24 | 25 | -- https://github.com/whiteboxdev/library-defold-grid-engine 26 | 27 | ---------------------------------------------------------------------- 28 | -- PROPERTIES 29 | ---------------------------------------------------------------------- 30 | 31 | local dgrid = {} 32 | 33 | local tile_width 34 | local tile_height 35 | 36 | local entities = {} 37 | 38 | local map = {} 39 | local map_width 40 | local map_height 41 | local map_offset_x = 0 42 | local map_offset_y = 0 43 | 44 | local tags = 45 | { 46 | [1] = { id = hash("passable"), passable = true }, 47 | [2] = { id = hash("impassable"), passable = false } 48 | } 49 | 50 | ---------------------------------------------------------------------- 51 | -- CONSTANTS 52 | ---------------------------------------------------------------------- 53 | 54 | dgrid.messages = 55 | { 56 | turn = hash("turn"), 57 | move_start = hash("move_start"), 58 | move_complete = hash("move_complete"), 59 | collide_passable = hash("collide_passable"), 60 | collide_impassable = hash("collide_impassable"), 61 | collide_entity = hash("collide_entity") 62 | } 63 | 64 | ---------------------------------------------------------------------- 65 | -- LOCAL FUNCTIONS 66 | ---------------------------------------------------------------------- 67 | 68 | local function to_tile_position(pixel_x, pixel_y) 69 | return math.floor(pixel_x / tile_width) + 1, math.floor(pixel_y / tile_height) + 1 70 | end 71 | 72 | local function to_pixel_position(tile_x, tile_y) 73 | return tile_x * tile_width - tile_width * 0.5, tile_y * tile_height - tile_height * 0.5 74 | end 75 | 76 | local function to_map_position(tile_x, tile_y) 77 | return tile_x - map_offset_x, tile_y - map_offset_y 78 | end 79 | 80 | local function get_forward_tile_position(tile_x, tile_y, direction) 81 | if direction == 1 then 82 | return tile_x, tile_y + 1 83 | end 84 | if direction == 2 then 85 | return tile_x - 1, tile_y 86 | end 87 | if direction == 3 then 88 | return tile_x, tile_y - 1 89 | end 90 | if direction == 4 then 91 | return tile_x + 1, tile_y 92 | end 93 | end 94 | 95 | local function get_tile(tile_x, tile_y) 96 | local forward_map_x, forward_map_y = to_map_position(tile_x, tile_y) 97 | return map[forward_map_y][forward_map_x] 98 | end 99 | 100 | local function get_entity(tile_x, tile_y) 101 | for _, entity in pairs(entities) do 102 | if entity.tile_x == tile_x and entity.tile_y == tile_y then 103 | return entity 104 | end 105 | end 106 | end 107 | 108 | local function check_collision(entity, direction) 109 | local forward_tile_x, forward_tile_y = get_forward_tile_position(entity.tile_x, entity.tile_y, direction) 110 | local tile = get_tile(forward_tile_x, forward_tile_y) 111 | if tile.tag.passable then 112 | msg.post(entity.url, dgrid.messages.collide_passable, { tag = tile.tag, data = tile.data }) 113 | else 114 | msg.post(entity.url, dgrid.messages.collide_impassable, { tag = tile.tag, data = tile.data }) 115 | return true 116 | end 117 | local other_entity = get_entity(forward_tile_x, forward_tile_y) 118 | if other_entity then 119 | msg.post(entity.url, dgrid.messages.collide_entity, { data = other_entity.data }) 120 | return true 121 | end 122 | end 123 | 124 | local function move(entity, dt) 125 | local position = go.get_position(entity.id) 126 | entity.dt = entity.dt + dt * entity.speed 127 | if entity.direction == 1 then 128 | local current_y = vmath.lerp(entity.dt, entity.start_pixel_y, entity.target_pixel_y) 129 | if current_y > entity.target_pixel_y then 130 | current_y = entity.target_pixel_y 131 | end 132 | go.set_position(vmath.vector3(position.x, current_y, position.z), entity.id) 133 | elseif entity.direction == 2 then 134 | local current_x = vmath.lerp(entity.dt, entity.start_pixel_x, entity.target_pixel_x) 135 | if current_x < entity.target_pixel_x then 136 | current_x = entity.target_pixel_x 137 | end 138 | go.set_position(vmath.vector3(current_x, position.y, position.z), entity.id) 139 | elseif entity.direction == 3 then 140 | local current_y = vmath.lerp(entity.dt, entity.start_pixel_y, entity.target_pixel_y) 141 | if current_y < entity.target_pixel_y then 142 | current_y = entity.target_pixel_y 143 | end 144 | go.set_position(vmath.vector3(position.x, current_y, position.z), entity.id) 145 | elseif entity.direction == 4 then 146 | local current_x = vmath.lerp(entity.dt, entity.start_pixel_x, entity.target_pixel_x) 147 | if current_x > entity.target_pixel_x then 148 | current_x = entity.target_pixel_x 149 | end 150 | go.set_position(vmath.vector3(current_x, position.y, position.z), entity.id) 151 | end 152 | end 153 | 154 | local function is_move_complete(entity) 155 | local position = go.get_position(entity.id) 156 | if entity.direction == 1 then 157 | return position.y == entity.target_pixel_y 158 | elseif entity.direction == 2 then 159 | return position.x == entity.target_pixel_x 160 | elseif entity.direction == 3 then 161 | return position.y == entity.target_pixel_y 162 | elseif entity.direction == 4 then 163 | return position.x == entity.target_pixel_x 164 | end 165 | end 166 | 167 | local function complete_move(entity) 168 | entity.moving = false 169 | entity.speed = 0 170 | entity.dt = nil 171 | entity.start_pixel_x = nil 172 | entity.start_pixel_y = nil 173 | entity.target_pixel_x = nil 174 | entity.target_pixel_y = nil 175 | msg.post(entity.url, dgrid.messages.move_complete, { tile_x = entity.tile_x, tile_y = entity.tile_y }) 176 | end 177 | 178 | local function snap_to_tile(entity) 179 | local position = go.get_position(entity.id) 180 | local tile_x, tile_y = to_tile_position(position.x, position.y) 181 | local pixel_x, pixel_y = to_pixel_position(tile_x, tile_y) 182 | go.set_position(vmath.vector3(pixel_x, pixel_y, position.z)) 183 | end 184 | 185 | ---------------------------------------------------------------------- 186 | -- MODULE FUNCTIONS 187 | ---------------------------------------------------------------------- 188 | 189 | function dgrid.set_map_dimensions(width, height) 190 | map = {} 191 | map_width = width 192 | map_height = height 193 | for y = 1, height do 194 | table.insert(map, {}) 195 | for x = 1, width do 196 | table.insert(map[y], { tag = tags[1], data = {} }) 197 | end 198 | end 199 | end 200 | 201 | function dgrid.set_map_offset(x, y) 202 | map_offset_x = x 203 | map_offset_y = y 204 | end 205 | 206 | function dgrid.set_map_tags(keys) 207 | for y = 1, #keys do 208 | for x = 1, #keys[y] do 209 | map[y][x].tag = tags[keys[#keys - y + 1][x]] 210 | end 211 | end 212 | end 213 | 214 | function dgrid.add_map_tag(id, passable) 215 | table.insert(tags, { id = id, passable = passable }) 216 | return #tags 217 | end 218 | 219 | function dgrid.modify_map_tag(key, passable) 220 | tags[key].passable = passable 221 | end 222 | 223 | function dgrid.set_tile_dimensions(width, height) 224 | tile_width = width 225 | tile_height = height 226 | end 227 | 228 | function dgrid.get_tile_data(x, y) 229 | return map[y][x].data 230 | end 231 | 232 | function dgrid.add_entity(id, url, center, direction, data) 233 | if not entities[id] then 234 | local position = go.get_position(id) 235 | local tile_x, tile_y = to_tile_position(position.x, position.y) 236 | entities[id] = 237 | { 238 | id = id, 239 | url = url, 240 | center = center, 241 | direction = direction, 242 | data = data or {}, 243 | moving = false, 244 | speed = 0, 245 | dt = nil, 246 | start_x = nil, 247 | start_y = nil, 248 | target_x = nil, 249 | target_y = nil, 250 | tile_x = tile_x, 251 | tile_y = tile_y, 252 | input = true 253 | } 254 | snap_to_tile(entities[id]) 255 | end 256 | end 257 | 258 | function dgrid.remove_entity(id) 259 | entities[id] = nil 260 | end 261 | 262 | function dgrid.clear_entities() 263 | entities = {} 264 | end 265 | 266 | function dgrid.set_entity_url(id, url) 267 | if entities[id] then 268 | entities[id].url = url 269 | end 270 | end 271 | 272 | function dgrid.get_entity_direction(id) 273 | return entities[id] and entities[id].direction 274 | end 275 | 276 | function dgrid.set_entity_data(id, data) 277 | if entities[id] then 278 | entities[id].data = data 279 | end 280 | end 281 | 282 | function dgrid.get_entity_data(id) 283 | return entities[id] and entities[id].data 284 | end 285 | 286 | function dgrid.is_entity_moving(id) 287 | return entities[id] and entities[id].moving 288 | end 289 | 290 | function dgrid.get_entity_speed(id) 291 | return entities[id] and entities[id].speed 292 | end 293 | 294 | function dgrid.get_entity_position(id) 295 | if entities[id] then 296 | return entities[id].tile_x, entities[id].tile_y 297 | end 298 | end 299 | 300 | function dgrid.toggle_entity_input(id, flag) 301 | if entities[id] then 302 | entities[id].input = flag 303 | end 304 | end 305 | 306 | function dgrid.toggle_all_entity_input(flag) 307 | for _, entity in entities do 308 | entity.input = flag 309 | end 310 | end 311 | 312 | function dgrid.interact(id) 313 | local entity = entities[id] 314 | if entity and not entity.moving and entity.input then 315 | local forward_tile_x, forward_tile_y = get_forward_tile_position(entity.tile_x, entity.tile_y, entity.direction) 316 | local tile = get_tile(forward_tile_x, forward_tile_y) 317 | local entity = get_entity(forward_tile_x, forward_tile_y) 318 | return { tag = tile.tag, tile_data = tile and tile.data, entity_data = entity and entity.data } 319 | end 320 | end 321 | 322 | function dgrid.turn_up(id) 323 | local entity = entities[id] 324 | if entity and not entity.moving and entity.input then 325 | entity.direction = 1 326 | msg.post(entity.url, dgrid.messages.turn, { direction = entity.direction }) 327 | end 328 | end 329 | 330 | function dgrid.turn_left(id) 331 | local entity = entities[id] 332 | if entity and not entity.moving and entity.input then 333 | entity.direction = 2 334 | msg.post(entity.url, dgrid.messages.turn, { direction = entity.direction }) 335 | end 336 | end 337 | 338 | function dgrid.turn_down(id) 339 | local entity = entities[id] 340 | if entity and not entity.moving and entity.input then 341 | entity.direction = 3 342 | msg.post(entity.url, dgrid.messages.turn, { direction = entity.direction }) 343 | end 344 | end 345 | 346 | function dgrid.turn_right(id) 347 | local entity = entities[id] 348 | if entity and not entity.moving and entity.input then 349 | entity.direction = 4 350 | msg.post(entity.url, dgrid.messages.turn, { direction = entity.direction }) 351 | end 352 | end 353 | 354 | function dgrid.turn(id, direction) 355 | if direction == 1 then 356 | dgrid.turn_up(id) 357 | elseif direction == 2 then 358 | dgrid.turn_left(id) 359 | elseif direction == 3 then 360 | dgrid.turn_down(id) 361 | elseif direction == 4 then 362 | dgrid.turn_right(id) 363 | end 364 | end 365 | 366 | function dgrid.move_up(id, speed) 367 | local entity = entities[id] 368 | if entity then 369 | if not entity.moving and entity.input then 370 | dgrid.turn_up(entity.id) 371 | if not check_collision(entity, 1) then 372 | entity.moving = true 373 | entity.speed = speed 374 | entity.dt = 0 375 | local position = go.get_position(id) 376 | entity.start_pixel_x = position.x 377 | entity.start_pixel_y = position.y 378 | entity.target_pixel_x = position.x 379 | entity.target_pixel_y = position.y + tile_height 380 | local start_tile_x, start_tile_y = to_tile_position(entity.start_pixel_x, entity.start_pixel_y) 381 | entity.tile_x, entity.tile_y = to_tile_position(entity.target_pixel_x, entity.target_pixel_y) 382 | msg.post(entity.url, dgrid.messages.move_start, { direction = entity.direction, speed = entity.speed, start_x = start_tile_x, start_y = start_tile_y, target_x = entity.tile_x, target_y = entity.tile_y }) 383 | end 384 | end 385 | end 386 | end 387 | 388 | function dgrid.move_left(id, speed) 389 | local entity = entities[id] 390 | if entity then 391 | if not entity.moving and entity.input then 392 | dgrid.turn_left(entity.id) 393 | if not check_collision(entity, 2) then 394 | entity.moving = true 395 | entity.speed = speed 396 | entity.direction = 2 397 | entity.dt = 0 398 | local position = go.get_position(id) 399 | entity.start_pixel_x = position.x 400 | entity.start_pixel_y = position.y 401 | entity.target_pixel_x = position.x - tile_width 402 | entity.target_pixel_y = position.y 403 | local start_tile_x, start_tile_y = to_tile_position(entity.start_pixel_x, entity.start_pixel_y) 404 | entity.tile_x, entity.tile_y = to_tile_position(entity.target_pixel_x, entity.target_pixel_y) 405 | msg.post(entity.url, dgrid.messages.move_start, { direction = entity.direction, speed = entity.speed, start_x = start_tile_x, start_y = start_tile_y, target_x = entity.tile_x, target_y = entity.tile_y }) 406 | end 407 | end 408 | end 409 | end 410 | 411 | function dgrid.move_down(id, speed) 412 | local entity = entities[id] 413 | if entity then 414 | if not entity.moving and entity.input then 415 | dgrid.turn_down(entity.id) 416 | if not check_collision(entity, 3) then 417 | entity.moving = true 418 | entity.speed = speed 419 | entity.direction = 3 420 | entity.dt = 0 421 | local position = go.get_position(id) 422 | entity.start_pixel_x = position.x 423 | entity.start_pixel_y = position.y 424 | entity.target_pixel_x = position.x 425 | entity.target_pixel_y = position.y - tile_height 426 | local start_tile_x, start_tile_y = to_tile_position(entity.start_pixel_x, entity.start_pixel_y) 427 | entity.tile_x, entity.tile_y = to_tile_position(entity.target_pixel_x, entity.target_pixel_y) 428 | msg.post(entity.url, dgrid.messages.move_start, { direction = entity.direction, speed = entity.speed, start_x = start_tile_x, start_y = start_tile_y, target_x = entity.tile_x, target_y = entity.tile_y }) 429 | end 430 | end 431 | end 432 | end 433 | 434 | function dgrid.move_right(id, speed) 435 | local entity = entities[id] 436 | if entity then 437 | if not entity.moving and entity.input then 438 | dgrid.turn_right(entity.id) 439 | if not check_collision(entity, 4) then 440 | entity.moving = true 441 | entity.speed = speed 442 | entity.direction = 4 443 | entity.dt = 0 444 | local position = go.get_position(id) 445 | entity.start_pixel_x = position.x 446 | entity.start_pixel_y = position.y 447 | entity.target_pixel_x = position.x + tile_width 448 | entity.target_pixel_y = position.y 449 | local start_tile_x, start_tile_y = to_tile_position(entity.start_pixel_x, entity.start_pixel_y) 450 | entity.tile_x, entity.tile_y = to_tile_position(entity.target_pixel_x, entity.target_pixel_y) 451 | msg.post(entity.url, dgrid.messages.move_start, { direction = entity.direction, speed = entity.speed, start_x = start_tile_x, start_y = start_tile_y, target_x = entity.tile_x, target_y = entity.tile_y }) 452 | end 453 | end 454 | end 455 | end 456 | 457 | function dgrid.move(id, speed, direction) 458 | if direction == 1 then 459 | dgrid.move_up(id, speed) 460 | elseif direction == 2 then 461 | dgrid.move_left(id, speed) 462 | elseif direction == 3 then 463 | dgrid.move_down(id, speed) 464 | elseif direction == 4 then 465 | dgrid.move_right(id, speed) 466 | end 467 | end 468 | 469 | function dgrid.update(dt) 470 | for _, entity in pairs(entities) do 471 | if entity.moving then 472 | move(entity, dt) 473 | if is_move_complete(entity) then 474 | complete_move(entity) 475 | end 476 | end 477 | end 478 | end 479 | 480 | return dgrid -------------------------------------------------------------------------------- /example/atlas.atlas: -------------------------------------------------------------------------------- 1 | animations { 2 | id: "player_idle" 3 | images { 4 | image: "/assets/player_0.png" 5 | sprite_trim_mode: SPRITE_TRIM_MODE_OFF 6 | } 7 | images { 8 | image: "/assets/player_1.png" 9 | sprite_trim_mode: SPRITE_TRIM_MODE_OFF 10 | } 11 | images { 12 | image: "/assets/player_2.png" 13 | sprite_trim_mode: SPRITE_TRIM_MODE_OFF 14 | } 15 | images { 16 | image: "/assets/player_3.png" 17 | sprite_trim_mode: SPRITE_TRIM_MODE_OFF 18 | } 19 | playback: PLAYBACK_LOOP_FORWARD 20 | fps: 4 21 | flip_horizontal: 0 22 | flip_vertical: 0 23 | } 24 | margin: 0 25 | extrude_borders: 2 26 | inner_padding: 0 27 | -------------------------------------------------------------------------------- /example/collection.collection: -------------------------------------------------------------------------------- 1 | name: "collection" 2 | instances { 3 | id: "map" 4 | prototype: "/example/map.go" 5 | position { 6 | x: 0.0 7 | y: 0.0 8 | z: 0.0 9 | } 10 | rotation { 11 | x: 0.0 12 | y: 0.0 13 | z: 0.0 14 | w: 1.0 15 | } 16 | scale3 { 17 | x: 5.0 18 | y: 5.0 19 | z: 1.0 20 | } 21 | } 22 | instances { 23 | id: "camera" 24 | prototype: "/rendercam/camera.go" 25 | position { 26 | x: 120.0 27 | y: 120.0 28 | z: 1.0 29 | } 30 | rotation { 31 | x: 0.0 32 | y: 0.0 33 | z: 0.0 34 | w: 1.0 35 | } 36 | component_properties { 37 | id: "script" 38 | properties { 39 | id: "fixedAspectRatio" 40 | value: "true" 41 | type: PROPERTY_TYPE_BOOLEAN 42 | } 43 | properties { 44 | id: "viewArea" 45 | value: "1280.0, 720.0, 0.0" 46 | type: PROPERTY_TYPE_VECTOR3 47 | } 48 | properties { 49 | id: "expandView" 50 | value: "true" 51 | type: PROPERTY_TYPE_BOOLEAN 52 | } 53 | } 54 | scale3 { 55 | x: 1.0 56 | y: 1.0 57 | z: 1.0 58 | } 59 | } 60 | instances { 61 | id: "player" 62 | prototype: "/example/player.go" 63 | position { 64 | x: 117.0 65 | y: 112.0 66 | z: 0.5 67 | } 68 | rotation { 69 | x: 0.0 70 | y: 0.0 71 | z: 0.0 72 | w: 1.0 73 | } 74 | scale3 { 75 | x: 5.0 76 | y: 5.0 77 | z: 1.0 78 | } 79 | } 80 | scale_along_z: 0 81 | -------------------------------------------------------------------------------- /example/font_regular.font: -------------------------------------------------------------------------------- 1 | font: "/assets/roboto_regular.ttf" 2 | material: "/builtins/fonts/font.material" 3 | size: 32 4 | antialias: 1 5 | alpha: 1.0 6 | outline_alpha: 1.0 7 | outline_width: 2.0 8 | shadow_alpha: 0.0 9 | shadow_blur: 0 10 | shadow_x: 0.0 11 | shadow_y: 0.0 12 | extra_characters: "" 13 | output_format: TYPE_BITMAP 14 | all_chars: false 15 | cache_width: 0 16 | cache_height: 0 17 | render_mode: MODE_SINGLE_LAYER 18 | -------------------------------------------------------------------------------- /example/gui.gui: -------------------------------------------------------------------------------- 1 | script: "/example/gui_script.gui_script" 2 | fonts { 3 | name: "font_regular" 4 | font: "/example/font_regular.font" 5 | } 6 | background_color { 7 | x: 0.0 8 | y: 0.0 9 | z: 0.0 10 | w: 0.0 11 | } 12 | nodes { 13 | position { 14 | x: 640.0 15 | y: 680.0 16 | z: 0.0 17 | w: 1.0 18 | } 19 | rotation { 20 | x: 0.0 21 | y: 0.0 22 | z: 0.0 23 | w: 1.0 24 | } 25 | scale { 26 | x: 1.0 27 | y: 1.0 28 | z: 1.0 29 | w: 1.0 30 | } 31 | size { 32 | x: 200.0 33 | y: 100.0 34 | z: 0.0 35 | w: 1.0 36 | } 37 | color { 38 | x: 1.0 39 | y: 1.0 40 | z: 1.0 41 | w: 1.0 42 | } 43 | type: TYPE_TEXT 44 | blend_mode: BLEND_MODE_ALPHA 45 | text: "Defold Grid Engine - Example" 46 | font: "font_regular" 47 | id: "title" 48 | xanchor: XANCHOR_NONE 49 | yanchor: YANCHOR_NONE 50 | pivot: PIVOT_CENTER 51 | outline { 52 | x: 0.0 53 | y: 0.0 54 | z: 0.0 55 | w: 1.0 56 | } 57 | shadow { 58 | x: 1.0 59 | y: 1.0 60 | z: 1.0 61 | w: 1.0 62 | } 63 | adjust_mode: ADJUST_MODE_FIT 64 | line_break: false 65 | layer: "" 66 | inherit_alpha: true 67 | alpha: 1.0 68 | outline_alpha: 1.0 69 | shadow_alpha: 1.0 70 | template_node_child: false 71 | text_leading: 1.0 72 | text_tracking: 0.0 73 | custom_type: 0 74 | enabled: true 75 | visible: true 76 | material: "" 77 | } 78 | nodes { 79 | position { 80 | x: 640.0 81 | y: 590.0 82 | z: 0.0 83 | w: 1.0 84 | } 85 | rotation { 86 | x: 0.0 87 | y: 0.0 88 | z: 0.0 89 | w: 1.0 90 | } 91 | scale { 92 | x: 1.0 93 | y: 1.0 94 | z: 1.0 95 | w: 1.0 96 | } 97 | size { 98 | x: 200.0 99 | y: 100.0 100 | z: 0.0 101 | w: 1.0 102 | } 103 | color { 104 | x: 1.0 105 | y: 1.0 106 | z: 1.0 107 | w: 1.0 108 | } 109 | type: TYPE_TEXT 110 | blend_mode: BLEND_MODE_ALPHA 111 | text: "W, A, S, D --> Move\n" 112 | "LShift --> Move Fast\n" 113 | "R --> Reach" 114 | font: "font_regular" 115 | id: "controls" 116 | xanchor: XANCHOR_NONE 117 | yanchor: YANCHOR_NONE 118 | pivot: PIVOT_CENTER 119 | outline { 120 | x: 0.0 121 | y: 0.0 122 | z: 0.0 123 | w: 1.0 124 | } 125 | shadow { 126 | x: 1.0 127 | y: 1.0 128 | z: 1.0 129 | w: 1.0 130 | } 131 | adjust_mode: ADJUST_MODE_FIT 132 | line_break: false 133 | layer: "" 134 | inherit_alpha: true 135 | alpha: 1.0 136 | outline_alpha: 1.0 137 | shadow_alpha: 1.0 138 | template_node_child: false 139 | text_leading: 1.0 140 | text_tracking: 0.0 141 | custom_type: 0 142 | enabled: true 143 | visible: true 144 | material: "" 145 | } 146 | nodes { 147 | position { 148 | x: 640.0 149 | y: 40.0 150 | z: 0.0 151 | w: 1.0 152 | } 153 | rotation { 154 | x: 0.0 155 | y: 0.0 156 | z: 0.0 157 | w: 1.0 158 | } 159 | scale { 160 | x: 1.0 161 | y: 1.0 162 | z: 1.0 163 | w: 1.0 164 | } 165 | size { 166 | x: 200.0 167 | y: 100.0 168 | z: 0.0 169 | w: 1.0 170 | } 171 | color { 172 | x: 0.0 173 | y: 1.0 174 | z: 1.0 175 | w: 1.0 176 | } 177 | type: TYPE_TEXT 178 | blend_mode: BLEND_MODE_ALPHA 179 | text: "" 180 | font: "font_regular" 181 | id: "display" 182 | xanchor: XANCHOR_NONE 183 | yanchor: YANCHOR_NONE 184 | pivot: PIVOT_CENTER 185 | outline { 186 | x: 0.0 187 | y: 0.0 188 | z: 0.0 189 | w: 1.0 190 | } 191 | shadow { 192 | x: 1.0 193 | y: 1.0 194 | z: 1.0 195 | w: 1.0 196 | } 197 | adjust_mode: ADJUST_MODE_FIT 198 | line_break: false 199 | layer: "" 200 | inherit_alpha: true 201 | alpha: 1.0 202 | outline_alpha: 1.0 203 | shadow_alpha: 1.0 204 | template_node_child: false 205 | text_leading: 1.0 206 | text_tracking: 0.0 207 | custom_type: 0 208 | enabled: true 209 | visible: true 210 | material: "" 211 | } 212 | material: "/builtins/materials/gui.material" 213 | adjust_reference: ADJUST_REFERENCE_PARENT 214 | max_nodes: 512 215 | -------------------------------------------------------------------------------- /example/gui_script.gui_script: -------------------------------------------------------------------------------- 1 | local h_str = { 2 | display = hash("display"), 3 | clear = hash("clear") 4 | } 5 | 6 | local names = { 7 | [1] = "Dark Tile", 8 | [2] = "Light Tile", 9 | [3] = "Treasure Chest", 10 | [4] = "Up-Down Red Carpet", 11 | [5] = "Up-Right Red Carpet", 12 | [6] = "Up-Left Red Carpet", 13 | [7] = "Left-Right Red Carpet", 14 | [8] = "Down-Right Red Carpet", 15 | [9] = "Down-Left Red Carpet", 16 | [10] = "Down-Left-Right Red Carpet" 17 | } 18 | 19 | function on_message(self, message_id, message, sender) 20 | if message_id == h_str.display then 21 | gui.set_text(gui.get_node(h_str.display), names[message.id]) 22 | elseif message_id == h_str.clear then 23 | gui.set_text(gui.get_node(h_str.display), "") 24 | end 25 | end -------------------------------------------------------------------------------- /example/map.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "tilemap" 3 | component: "/example/tilemap.tilemap" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | } 16 | components { 17 | id: "gui" 18 | component: "/example/gui.gui" 19 | position { 20 | x: 0.0 21 | y: 0.0 22 | z: 0.0 23 | } 24 | rotation { 25 | x: 0.0 26 | y: 0.0 27 | z: 0.0 28 | w: 1.0 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/player.go: -------------------------------------------------------------------------------- 1 | components { 2 | id: "script" 3 | component: "/example/player.script" 4 | position { 5 | x: 0.0 6 | y: 0.0 7 | z: 0.0 8 | } 9 | rotation { 10 | x: 0.0 11 | y: 0.0 12 | z: 0.0 13 | w: 1.0 14 | } 15 | } 16 | embedded_components { 17 | id: "sprite" 18 | type: "sprite" 19 | data: "tile_set: \"/example/atlas.atlas\"\n" 20 | "default_animation: \"player_idle\"\n" 21 | "material: \"/builtins/materials/sprite.material\"\n" 22 | "blend_mode: BLEND_MODE_ALPHA\n" 23 | "" 24 | position { 25 | x: 0.0 26 | y: 0.0 27 | z: 0.0 28 | } 29 | rotation { 30 | x: 0.0 31 | y: 0.0 32 | z: 0.0 33 | w: 1.0 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /example/player.script: -------------------------------------------------------------------------------- 1 | local dgrid = require "dgrid.dgrid" 2 | local rendercam = require "rendercam.rendercam" 3 | 4 | local stride = 80 5 | local walk_speed = 3 6 | local dash_speed = 6 7 | 8 | local member_config = { 9 | size = vmath.vector3(stride, stride, 0), 10 | direction = dgrid.direction.down, 11 | speed = walk_speed 12 | } 13 | 14 | local h_str = { 15 | acquire_input_focus = hash("acquire_input_focus"), 16 | release_input_focus = hash("release_input_focus"), 17 | up = hash("up"), 18 | left = hash("left"), 19 | down = hash("down"), 20 | right = hash("right"), 21 | reach = hash("reach"), 22 | fast = hash("fast"), 23 | display = hash("display"), 24 | clear = hash("clear"), 25 | custom_tag_1 = hash("custom_tag_1"), 26 | custom_tag_2 = hash("custom_tag_2"), 27 | object = hash("object"), 28 | terrain = hash("terrain") 29 | } 30 | 31 | function init(self) 32 | msg.post("#", h_str.acquire_input_focus) 33 | rendercam.follow_lerp_speed = 8 34 | rendercam.follow("/player") 35 | dgrid.add_tag(h_str.custom_tag_1, true) 36 | dgrid.add_tag(h_str.custom_tag_2, false) 37 | dgrid.set_stride(stride) 38 | dgrid.set_collision_map({ 39 | { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, 40 | { 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 }, 41 | { 2, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 2 }, 42 | { 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2 }, 43 | { 2, 2, 2, 2, 2, 1, 3, 1, 2, 2, 2, 2, 2 }, 44 | { 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2 }, 45 | { 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2 }, 46 | { 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 }, 47 | { 2, 1, 3, 1, 2, 2, 2, 2, 2, 1, 3, 1, 2 }, 48 | { 2, 1, 3, 1, 2, 2, 2, 2, 2, 1, 3, 1, 2 }, 49 | { 2, 1, 3, 1, 2, 2, 2, 2, 2, 1, 3, 1, 2 }, 50 | { 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 }, 51 | { 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2 }, 52 | { 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 }, 53 | { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 } 54 | }) 55 | dgrid.set_property_map({ 56 | ["73"] = { gold = 9001 } 57 | }) 58 | self.dgrid = dgrid.register(member_config) 59 | end 60 | 61 | function final(self) 62 | self.dgrid.unregister() 63 | end 64 | 65 | function update(self, dt) 66 | self.dgrid.update(dt) 67 | end 68 | 69 | function on_input(self, action_id, action) 70 | if action.pressed then 71 | if action_id == h_str.up then 72 | self.dgrid.move(dgrid.direction.up) 73 | msg.post("/map#gui", h_str.clear) 74 | elseif action_id == h_str.left then 75 | self.dgrid.move(dgrid.direction.left) 76 | msg.post("/map#gui", h_str.clear) 77 | elseif action_id == h_str.down then 78 | self.dgrid.move(dgrid.direction.down) 79 | msg.post("/map#gui", h_str.clear) 80 | elseif action_id == h_str.right then 81 | self.dgrid.move(dgrid.direction.right) 82 | msg.post("/map#gui", h_str.clear) 83 | elseif action_id == h_str.reach and not self.dgrid.is_moving() then 84 | local tile_position = self.dgrid.reach() 85 | local tile_id_object = tilemap.get_tile("/map#tilemap", h_str.object, tile_position.x, tile_position.y) 86 | local tile_id_terrain = tilemap.get_tile("/map#tilemap", h_str.terrain, tile_position.x, tile_position.y) 87 | if tile_id_object ~= 0 then 88 | msg.post("/map#gui", h_str.display, { id = tile_id_object }) 89 | elseif tile_id_terrain ~= 0 then 90 | msg.post("/map#gui", h_str.display, { id = tile_id_terrain }) 91 | end 92 | elseif action_id == h_str.fast then 93 | self.dgrid.set_speed(dash_speed) 94 | end 95 | elseif action.released then 96 | if action_id == h_str.up then 97 | self.dgrid.stop(dgrid.direction.up) 98 | elseif action_id == h_str.left then 99 | self.dgrid.stop(dgrid.direction.left) 100 | elseif action_id == h_str.down then 101 | self.dgrid.stop(dgrid.direction.down) 102 | elseif action_id == h_str.right then 103 | self.dgrid.stop(dgrid.direction.right) 104 | elseif action_id == h_str.fast then 105 | self.dgrid.set_speed(walk_speed) 106 | end 107 | end 108 | end 109 | 110 | function on_message(self, message_id, message, sender) 111 | if message_id == dgrid.msg.move_start then 112 | print("Caught dgrid.msg.move_start.") 113 | elseif message_id == dgrid.msg.move_end then 114 | print("Caught dgrid.msg.move_end.") 115 | elseif message_id == dgrid.msg.move_repeat then 116 | print("Caught dgrid.msg.move_repeat.") 117 | elseif message_id == dgrid.msg.collide_none then 118 | print("Caught dgrid.msg.collide_none") 119 | elseif message_id == dgrid.msg.collide_passable then 120 | print("Caught dgrid.msg.collide_passable. Tag name:", message.name, "Property:", message.property and message.property.gold or nil) 121 | elseif message_id == dgrid.msg.collide_impassable then 122 | print("Caught dgrid.msg.collide_passable. Tag name:", message.name, "Property:", message.property and message.property.gold or nil) 123 | end 124 | end -------------------------------------------------------------------------------- /example/tilemap.tilemap: -------------------------------------------------------------------------------- 1 | tile_set: "/example/tilesource.tilesource" 2 | layers { 3 | id: "terrain" 4 | z: 0.0 5 | is_visible: 1 6 | cell { 7 | x: 0 8 | y: 0 9 | tile: 0 10 | h_flip: 0 11 | v_flip: 0 12 | } 13 | cell { 14 | x: 1 15 | y: 0 16 | tile: 0 17 | h_flip: 0 18 | v_flip: 0 19 | } 20 | cell { 21 | x: 2 22 | y: 0 23 | tile: 0 24 | h_flip: 0 25 | v_flip: 0 26 | } 27 | cell { 28 | x: 3 29 | y: 0 30 | tile: 0 31 | h_flip: 0 32 | v_flip: 0 33 | } 34 | cell { 35 | x: 4 36 | y: 0 37 | tile: 0 38 | h_flip: 0 39 | v_flip: 0 40 | } 41 | cell { 42 | x: 5 43 | y: 0 44 | tile: 0 45 | h_flip: 0 46 | v_flip: 0 47 | } 48 | cell { 49 | x: 6 50 | y: 0 51 | tile: 0 52 | h_flip: 0 53 | v_flip: 0 54 | } 55 | cell { 56 | x: 7 57 | y: 0 58 | tile: 0 59 | h_flip: 0 60 | v_flip: 0 61 | } 62 | cell { 63 | x: 8 64 | y: 0 65 | tile: 0 66 | h_flip: 0 67 | v_flip: 0 68 | } 69 | cell { 70 | x: 9 71 | y: 0 72 | tile: 0 73 | h_flip: 0 74 | v_flip: 0 75 | } 76 | cell { 77 | x: 10 78 | y: 0 79 | tile: 0 80 | h_flip: 0 81 | v_flip: 0 82 | } 83 | cell { 84 | x: 11 85 | y: 0 86 | tile: 0 87 | h_flip: 0 88 | v_flip: 0 89 | } 90 | cell { 91 | x: 12 92 | y: 0 93 | tile: 0 94 | h_flip: 0 95 | v_flip: 0 96 | } 97 | cell { 98 | x: 0 99 | y: 1 100 | tile: 0 101 | h_flip: 0 102 | v_flip: 0 103 | } 104 | cell { 105 | x: 1 106 | y: 1 107 | tile: 1 108 | h_flip: 0 109 | v_flip: 0 110 | } 111 | cell { 112 | x: 2 113 | y: 1 114 | tile: 1 115 | h_flip: 0 116 | v_flip: 0 117 | } 118 | cell { 119 | x: 3 120 | y: 1 121 | tile: 1 122 | h_flip: 0 123 | v_flip: 0 124 | } 125 | cell { 126 | x: 4 127 | y: 1 128 | tile: 1 129 | h_flip: 0 130 | v_flip: 0 131 | } 132 | cell { 133 | x: 5 134 | y: 1 135 | tile: 1 136 | h_flip: 0 137 | v_flip: 0 138 | } 139 | cell { 140 | x: 6 141 | y: 1 142 | tile: 1 143 | h_flip: 0 144 | v_flip: 0 145 | } 146 | cell { 147 | x: 7 148 | y: 1 149 | tile: 1 150 | h_flip: 0 151 | v_flip: 0 152 | } 153 | cell { 154 | x: 8 155 | y: 1 156 | tile: 1 157 | h_flip: 0 158 | v_flip: 0 159 | } 160 | cell { 161 | x: 9 162 | y: 1 163 | tile: 1 164 | h_flip: 0 165 | v_flip: 0 166 | } 167 | cell { 168 | x: 10 169 | y: 1 170 | tile: 1 171 | h_flip: 0 172 | v_flip: 0 173 | } 174 | cell { 175 | x: 11 176 | y: 1 177 | tile: 1 178 | h_flip: 0 179 | v_flip: 0 180 | } 181 | cell { 182 | x: 12 183 | y: 1 184 | tile: 0 185 | h_flip: 0 186 | v_flip: 0 187 | } 188 | cell { 189 | x: 0 190 | y: 2 191 | tile: 0 192 | h_flip: 0 193 | v_flip: 0 194 | } 195 | cell { 196 | x: 1 197 | y: 2 198 | tile: 1 199 | h_flip: 0 200 | v_flip: 0 201 | } 202 | cell { 203 | x: 2 204 | y: 2 205 | tile: 1 206 | h_flip: 0 207 | v_flip: 0 208 | } 209 | cell { 210 | x: 3 211 | y: 2 212 | tile: 1 213 | h_flip: 0 214 | v_flip: 0 215 | } 216 | cell { 217 | x: 4 218 | y: 2 219 | tile: 1 220 | h_flip: 0 221 | v_flip: 0 222 | } 223 | cell { 224 | x: 5 225 | y: 2 226 | tile: 1 227 | h_flip: 0 228 | v_flip: 0 229 | } 230 | cell { 231 | x: 6 232 | y: 2 233 | tile: 1 234 | h_flip: 0 235 | v_flip: 0 236 | } 237 | cell { 238 | x: 7 239 | y: 2 240 | tile: 1 241 | h_flip: 0 242 | v_flip: 0 243 | } 244 | cell { 245 | x: 8 246 | y: 2 247 | tile: 1 248 | h_flip: 0 249 | v_flip: 0 250 | } 251 | cell { 252 | x: 9 253 | y: 2 254 | tile: 1 255 | h_flip: 0 256 | v_flip: 0 257 | } 258 | cell { 259 | x: 10 260 | y: 2 261 | tile: 1 262 | h_flip: 0 263 | v_flip: 0 264 | } 265 | cell { 266 | x: 11 267 | y: 2 268 | tile: 1 269 | h_flip: 0 270 | v_flip: 0 271 | } 272 | cell { 273 | x: 12 274 | y: 2 275 | tile: 0 276 | h_flip: 0 277 | v_flip: 0 278 | } 279 | cell { 280 | x: 0 281 | y: 3 282 | tile: 0 283 | h_flip: 0 284 | v_flip: 0 285 | } 286 | cell { 287 | x: 1 288 | y: 3 289 | tile: 1 290 | h_flip: 0 291 | v_flip: 0 292 | } 293 | cell { 294 | x: 2 295 | y: 3 296 | tile: 1 297 | h_flip: 0 298 | v_flip: 0 299 | } 300 | cell { 301 | x: 3 302 | y: 3 303 | tile: 1 304 | h_flip: 0 305 | v_flip: 0 306 | } 307 | cell { 308 | x: 4 309 | y: 3 310 | tile: 1 311 | h_flip: 0 312 | v_flip: 0 313 | } 314 | cell { 315 | x: 5 316 | y: 3 317 | tile: 1 318 | h_flip: 0 319 | v_flip: 0 320 | } 321 | cell { 322 | x: 6 323 | y: 3 324 | tile: 1 325 | h_flip: 0 326 | v_flip: 0 327 | } 328 | cell { 329 | x: 7 330 | y: 3 331 | tile: 1 332 | h_flip: 0 333 | v_flip: 0 334 | } 335 | cell { 336 | x: 8 337 | y: 3 338 | tile: 1 339 | h_flip: 0 340 | v_flip: 0 341 | } 342 | cell { 343 | x: 9 344 | y: 3 345 | tile: 1 346 | h_flip: 0 347 | v_flip: 0 348 | } 349 | cell { 350 | x: 10 351 | y: 3 352 | tile: 1 353 | h_flip: 0 354 | v_flip: 0 355 | } 356 | cell { 357 | x: 11 358 | y: 3 359 | tile: 1 360 | h_flip: 0 361 | v_flip: 0 362 | } 363 | cell { 364 | x: 12 365 | y: 3 366 | tile: 0 367 | h_flip: 0 368 | v_flip: 0 369 | } 370 | cell { 371 | x: 0 372 | y: 4 373 | tile: 0 374 | h_flip: 0 375 | v_flip: 0 376 | } 377 | cell { 378 | x: 1 379 | y: 4 380 | tile: 1 381 | h_flip: 0 382 | v_flip: 0 383 | } 384 | cell { 385 | x: 2 386 | y: 4 387 | tile: 1 388 | h_flip: 0 389 | v_flip: 0 390 | } 391 | cell { 392 | x: 3 393 | y: 4 394 | tile: 1 395 | h_flip: 0 396 | v_flip: 0 397 | } 398 | cell { 399 | x: 4 400 | y: 4 401 | tile: 1 402 | h_flip: 0 403 | v_flip: 0 404 | } 405 | cell { 406 | x: 5 407 | y: 4 408 | tile: 1 409 | h_flip: 0 410 | v_flip: 0 411 | } 412 | cell { 413 | x: 6 414 | y: 4 415 | tile: 1 416 | h_flip: 0 417 | v_flip: 0 418 | } 419 | cell { 420 | x: 7 421 | y: 4 422 | tile: 1 423 | h_flip: 0 424 | v_flip: 0 425 | } 426 | cell { 427 | x: 8 428 | y: 4 429 | tile: 1 430 | h_flip: 0 431 | v_flip: 0 432 | } 433 | cell { 434 | x: 9 435 | y: 4 436 | tile: 1 437 | h_flip: 0 438 | v_flip: 0 439 | } 440 | cell { 441 | x: 10 442 | y: 4 443 | tile: 1 444 | h_flip: 0 445 | v_flip: 0 446 | } 447 | cell { 448 | x: 11 449 | y: 4 450 | tile: 1 451 | h_flip: 0 452 | v_flip: 0 453 | } 454 | cell { 455 | x: 12 456 | y: 4 457 | tile: 0 458 | h_flip: 0 459 | v_flip: 0 460 | } 461 | cell { 462 | x: 0 463 | y: 5 464 | tile: 0 465 | h_flip: 0 466 | v_flip: 0 467 | } 468 | cell { 469 | x: 1 470 | y: 5 471 | tile: 1 472 | h_flip: 0 473 | v_flip: 0 474 | } 475 | cell { 476 | x: 2 477 | y: 5 478 | tile: 1 479 | h_flip: 0 480 | v_flip: 0 481 | } 482 | cell { 483 | x: 3 484 | y: 5 485 | tile: 1 486 | h_flip: 0 487 | v_flip: 0 488 | } 489 | cell { 490 | x: 4 491 | y: 5 492 | tile: 1 493 | h_flip: 0 494 | v_flip: 0 495 | } 496 | cell { 497 | x: 5 498 | y: 5 499 | tile: 1 500 | h_flip: 0 501 | v_flip: 0 502 | } 503 | cell { 504 | x: 6 505 | y: 5 506 | tile: 1 507 | h_flip: 0 508 | v_flip: 0 509 | } 510 | cell { 511 | x: 7 512 | y: 5 513 | tile: 1 514 | h_flip: 0 515 | v_flip: 0 516 | } 517 | cell { 518 | x: 8 519 | y: 5 520 | tile: 1 521 | h_flip: 0 522 | v_flip: 0 523 | } 524 | cell { 525 | x: 9 526 | y: 5 527 | tile: 1 528 | h_flip: 0 529 | v_flip: 0 530 | } 531 | cell { 532 | x: 10 533 | y: 5 534 | tile: 1 535 | h_flip: 0 536 | v_flip: 0 537 | } 538 | cell { 539 | x: 11 540 | y: 5 541 | tile: 1 542 | h_flip: 0 543 | v_flip: 0 544 | } 545 | cell { 546 | x: 12 547 | y: 5 548 | tile: 0 549 | h_flip: 0 550 | v_flip: 0 551 | } 552 | cell { 553 | x: 0 554 | y: 6 555 | tile: 0 556 | h_flip: 0 557 | v_flip: 0 558 | } 559 | cell { 560 | x: 1 561 | y: 6 562 | tile: 1 563 | h_flip: 0 564 | v_flip: 0 565 | } 566 | cell { 567 | x: 2 568 | y: 6 569 | tile: 1 570 | h_flip: 0 571 | v_flip: 0 572 | } 573 | cell { 574 | x: 3 575 | y: 6 576 | tile: 1 577 | h_flip: 0 578 | v_flip: 0 579 | } 580 | cell { 581 | x: 4 582 | y: 6 583 | tile: 1 584 | h_flip: 0 585 | v_flip: 0 586 | } 587 | cell { 588 | x: 5 589 | y: 6 590 | tile: 1 591 | h_flip: 0 592 | v_flip: 0 593 | } 594 | cell { 595 | x: 6 596 | y: 6 597 | tile: 1 598 | h_flip: 0 599 | v_flip: 0 600 | } 601 | cell { 602 | x: 7 603 | y: 6 604 | tile: 1 605 | h_flip: 0 606 | v_flip: 0 607 | } 608 | cell { 609 | x: 8 610 | y: 6 611 | tile: 1 612 | h_flip: 0 613 | v_flip: 0 614 | } 615 | cell { 616 | x: 9 617 | y: 6 618 | tile: 1 619 | h_flip: 0 620 | v_flip: 0 621 | } 622 | cell { 623 | x: 10 624 | y: 6 625 | tile: 1 626 | h_flip: 0 627 | v_flip: 0 628 | } 629 | cell { 630 | x: 11 631 | y: 6 632 | tile: 1 633 | h_flip: 0 634 | v_flip: 0 635 | } 636 | cell { 637 | x: 12 638 | y: 6 639 | tile: 0 640 | h_flip: 0 641 | v_flip: 0 642 | } 643 | cell { 644 | x: 0 645 | y: 7 646 | tile: 0 647 | h_flip: 0 648 | v_flip: 0 649 | } 650 | cell { 651 | x: 1 652 | y: 7 653 | tile: 1 654 | h_flip: 0 655 | v_flip: 0 656 | } 657 | cell { 658 | x: 2 659 | y: 7 660 | tile: 1 661 | h_flip: 0 662 | v_flip: 0 663 | } 664 | cell { 665 | x: 3 666 | y: 7 667 | tile: 1 668 | h_flip: 0 669 | v_flip: 0 670 | } 671 | cell { 672 | x: 4 673 | y: 7 674 | tile: 1 675 | h_flip: 0 676 | v_flip: 0 677 | } 678 | cell { 679 | x: 5 680 | y: 7 681 | tile: 1 682 | h_flip: 0 683 | v_flip: 0 684 | } 685 | cell { 686 | x: 6 687 | y: 7 688 | tile: 1 689 | h_flip: 0 690 | v_flip: 0 691 | } 692 | cell { 693 | x: 7 694 | y: 7 695 | tile: 1 696 | h_flip: 0 697 | v_flip: 0 698 | } 699 | cell { 700 | x: 8 701 | y: 7 702 | tile: 1 703 | h_flip: 0 704 | v_flip: 0 705 | } 706 | cell { 707 | x: 9 708 | y: 7 709 | tile: 1 710 | h_flip: 0 711 | v_flip: 0 712 | } 713 | cell { 714 | x: 10 715 | y: 7 716 | tile: 1 717 | h_flip: 0 718 | v_flip: 0 719 | } 720 | cell { 721 | x: 11 722 | y: 7 723 | tile: 1 724 | h_flip: 0 725 | v_flip: 0 726 | } 727 | cell { 728 | x: 12 729 | y: 7 730 | tile: 0 731 | h_flip: 0 732 | v_flip: 0 733 | } 734 | cell { 735 | x: 0 736 | y: 8 737 | tile: 0 738 | h_flip: 0 739 | v_flip: 0 740 | } 741 | cell { 742 | x: 1 743 | y: 8 744 | tile: 1 745 | h_flip: 0 746 | v_flip: 0 747 | } 748 | cell { 749 | x: 2 750 | y: 8 751 | tile: 1 752 | h_flip: 0 753 | v_flip: 0 754 | } 755 | cell { 756 | x: 3 757 | y: 8 758 | tile: 1 759 | h_flip: 0 760 | v_flip: 0 761 | } 762 | cell { 763 | x: 4 764 | y: 8 765 | tile: 1 766 | h_flip: 0 767 | v_flip: 0 768 | } 769 | cell { 770 | x: 5 771 | y: 8 772 | tile: 1 773 | h_flip: 0 774 | v_flip: 0 775 | } 776 | cell { 777 | x: 6 778 | y: 8 779 | tile: 1 780 | h_flip: 0 781 | v_flip: 0 782 | } 783 | cell { 784 | x: 7 785 | y: 8 786 | tile: 1 787 | h_flip: 0 788 | v_flip: 0 789 | } 790 | cell { 791 | x: 8 792 | y: 8 793 | tile: 1 794 | h_flip: 0 795 | v_flip: 0 796 | } 797 | cell { 798 | x: 9 799 | y: 8 800 | tile: 1 801 | h_flip: 0 802 | v_flip: 0 803 | } 804 | cell { 805 | x: 10 806 | y: 8 807 | tile: 1 808 | h_flip: 0 809 | v_flip: 0 810 | } 811 | cell { 812 | x: 11 813 | y: 8 814 | tile: 1 815 | h_flip: 0 816 | v_flip: 0 817 | } 818 | cell { 819 | x: 12 820 | y: 8 821 | tile: 0 822 | h_flip: 0 823 | v_flip: 0 824 | } 825 | cell { 826 | x: 0 827 | y: 9 828 | tile: 0 829 | h_flip: 0 830 | v_flip: 0 831 | } 832 | cell { 833 | x: 1 834 | y: 9 835 | tile: 1 836 | h_flip: 0 837 | v_flip: 0 838 | } 839 | cell { 840 | x: 2 841 | y: 9 842 | tile: 1 843 | h_flip: 0 844 | v_flip: 0 845 | } 846 | cell { 847 | x: 3 848 | y: 9 849 | tile: 1 850 | h_flip: 0 851 | v_flip: 0 852 | } 853 | cell { 854 | x: 4 855 | y: 9 856 | tile: 1 857 | h_flip: 0 858 | v_flip: 0 859 | } 860 | cell { 861 | x: 5 862 | y: 9 863 | tile: 1 864 | h_flip: 0 865 | v_flip: 0 866 | } 867 | cell { 868 | x: 6 869 | y: 9 870 | tile: 1 871 | h_flip: 0 872 | v_flip: 0 873 | } 874 | cell { 875 | x: 7 876 | y: 9 877 | tile: 1 878 | h_flip: 0 879 | v_flip: 0 880 | } 881 | cell { 882 | x: 8 883 | y: 9 884 | tile: 1 885 | h_flip: 0 886 | v_flip: 0 887 | } 888 | cell { 889 | x: 9 890 | y: 9 891 | tile: 1 892 | h_flip: 0 893 | v_flip: 0 894 | } 895 | cell { 896 | x: 10 897 | y: 9 898 | tile: 1 899 | h_flip: 0 900 | v_flip: 0 901 | } 902 | cell { 903 | x: 11 904 | y: 9 905 | tile: 1 906 | h_flip: 0 907 | v_flip: 0 908 | } 909 | cell { 910 | x: 12 911 | y: 9 912 | tile: 0 913 | h_flip: 0 914 | v_flip: 0 915 | } 916 | cell { 917 | x: 0 918 | y: 10 919 | tile: 0 920 | h_flip: 0 921 | v_flip: 0 922 | } 923 | cell { 924 | x: 1 925 | y: 10 926 | tile: 0 927 | h_flip: 0 928 | v_flip: 0 929 | } 930 | cell { 931 | x: 2 932 | y: 10 933 | tile: 0 934 | h_flip: 0 935 | v_flip: 0 936 | } 937 | cell { 938 | x: 3 939 | y: 10 940 | tile: 0 941 | h_flip: 0 942 | v_flip: 0 943 | } 944 | cell { 945 | x: 4 946 | y: 10 947 | tile: 0 948 | h_flip: 0 949 | v_flip: 0 950 | } 951 | cell { 952 | x: 5 953 | y: 10 954 | tile: 1 955 | h_flip: 0 956 | v_flip: 0 957 | } 958 | cell { 959 | x: 6 960 | y: 10 961 | tile: 1 962 | h_flip: 0 963 | v_flip: 0 964 | } 965 | cell { 966 | x: 7 967 | y: 10 968 | tile: 1 969 | h_flip: 0 970 | v_flip: 0 971 | } 972 | cell { 973 | x: 8 974 | y: 10 975 | tile: 0 976 | h_flip: 0 977 | v_flip: 0 978 | } 979 | cell { 980 | x: 9 981 | y: 10 982 | tile: 0 983 | h_flip: 0 984 | v_flip: 0 985 | } 986 | cell { 987 | x: 10 988 | y: 10 989 | tile: 0 990 | h_flip: 0 991 | v_flip: 0 992 | } 993 | cell { 994 | x: 11 995 | y: 10 996 | tile: 0 997 | h_flip: 0 998 | v_flip: 0 999 | } 1000 | cell { 1001 | x: 12 1002 | y: 10 1003 | tile: 0 1004 | h_flip: 0 1005 | v_flip: 0 1006 | } 1007 | cell { 1008 | x: 0 1009 | y: 11 1010 | tile: 0 1011 | h_flip: 0 1012 | v_flip: 0 1013 | } 1014 | cell { 1015 | x: 1 1016 | y: 11 1017 | tile: 1 1018 | h_flip: 0 1019 | v_flip: 0 1020 | } 1021 | cell { 1022 | x: 2 1023 | y: 11 1024 | tile: 1 1025 | h_flip: 0 1026 | v_flip: 0 1027 | } 1028 | cell { 1029 | x: 3 1030 | y: 11 1031 | tile: 1 1032 | h_flip: 0 1033 | v_flip: 0 1034 | } 1035 | cell { 1036 | x: 4 1037 | y: 11 1038 | tile: 1 1039 | h_flip: 0 1040 | v_flip: 0 1041 | } 1042 | cell { 1043 | x: 5 1044 | y: 11 1045 | tile: 1 1046 | h_flip: 0 1047 | v_flip: 0 1048 | } 1049 | cell { 1050 | x: 6 1051 | y: 11 1052 | tile: 1 1053 | h_flip: 0 1054 | v_flip: 0 1055 | } 1056 | cell { 1057 | x: 7 1058 | y: 11 1059 | tile: 1 1060 | h_flip: 0 1061 | v_flip: 0 1062 | } 1063 | cell { 1064 | x: 8 1065 | y: 11 1066 | tile: 1 1067 | h_flip: 0 1068 | v_flip: 0 1069 | } 1070 | cell { 1071 | x: 9 1072 | y: 11 1073 | tile: 1 1074 | h_flip: 0 1075 | v_flip: 0 1076 | } 1077 | cell { 1078 | x: 10 1079 | y: 11 1080 | tile: 1 1081 | h_flip: 0 1082 | v_flip: 0 1083 | } 1084 | cell { 1085 | x: 11 1086 | y: 11 1087 | tile: 1 1088 | h_flip: 0 1089 | v_flip: 0 1090 | } 1091 | cell { 1092 | x: 12 1093 | y: 11 1094 | tile: 0 1095 | h_flip: 0 1096 | v_flip: 0 1097 | } 1098 | cell { 1099 | x: 0 1100 | y: 12 1101 | tile: 0 1102 | h_flip: 0 1103 | v_flip: 0 1104 | } 1105 | cell { 1106 | x: 1 1107 | y: 12 1108 | tile: 1 1109 | h_flip: 0 1110 | v_flip: 0 1111 | } 1112 | cell { 1113 | x: 2 1114 | y: 12 1115 | tile: 1 1116 | h_flip: 0 1117 | v_flip: 0 1118 | } 1119 | cell { 1120 | x: 3 1121 | y: 12 1122 | tile: 1 1123 | h_flip: 0 1124 | v_flip: 0 1125 | } 1126 | cell { 1127 | x: 4 1128 | y: 12 1129 | tile: 1 1130 | h_flip: 0 1131 | v_flip: 0 1132 | } 1133 | cell { 1134 | x: 5 1135 | y: 12 1136 | tile: 1 1137 | h_flip: 0 1138 | v_flip: 0 1139 | } 1140 | cell { 1141 | x: 6 1142 | y: 12 1143 | tile: 1 1144 | h_flip: 0 1145 | v_flip: 0 1146 | } 1147 | cell { 1148 | x: 7 1149 | y: 12 1150 | tile: 1 1151 | h_flip: 0 1152 | v_flip: 0 1153 | } 1154 | cell { 1155 | x: 8 1156 | y: 12 1157 | tile: 1 1158 | h_flip: 0 1159 | v_flip: 0 1160 | } 1161 | cell { 1162 | x: 9 1163 | y: 12 1164 | tile: 1 1165 | h_flip: 0 1166 | v_flip: 0 1167 | } 1168 | cell { 1169 | x: 10 1170 | y: 12 1171 | tile: 1 1172 | h_flip: 0 1173 | v_flip: 0 1174 | } 1175 | cell { 1176 | x: 11 1177 | y: 12 1178 | tile: 1 1179 | h_flip: 0 1180 | v_flip: 0 1181 | } 1182 | cell { 1183 | x: 12 1184 | y: 12 1185 | tile: 0 1186 | h_flip: 0 1187 | v_flip: 0 1188 | } 1189 | cell { 1190 | x: 0 1191 | y: 13 1192 | tile: 0 1193 | h_flip: 0 1194 | v_flip: 0 1195 | } 1196 | cell { 1197 | x: 1 1198 | y: 13 1199 | tile: 1 1200 | h_flip: 0 1201 | v_flip: 0 1202 | } 1203 | cell { 1204 | x: 2 1205 | y: 13 1206 | tile: 1 1207 | h_flip: 0 1208 | v_flip: 0 1209 | } 1210 | cell { 1211 | x: 3 1212 | y: 13 1213 | tile: 1 1214 | h_flip: 0 1215 | v_flip: 0 1216 | } 1217 | cell { 1218 | x: 4 1219 | y: 13 1220 | tile: 1 1221 | h_flip: 0 1222 | v_flip: 0 1223 | } 1224 | cell { 1225 | x: 5 1226 | y: 13 1227 | tile: 1 1228 | h_flip: 0 1229 | v_flip: 0 1230 | } 1231 | cell { 1232 | x: 6 1233 | y: 13 1234 | tile: 1 1235 | h_flip: 0 1236 | v_flip: 0 1237 | } 1238 | cell { 1239 | x: 7 1240 | y: 13 1241 | tile: 1 1242 | h_flip: 0 1243 | v_flip: 0 1244 | } 1245 | cell { 1246 | x: 8 1247 | y: 13 1248 | tile: 1 1249 | h_flip: 0 1250 | v_flip: 0 1251 | } 1252 | cell { 1253 | x: 9 1254 | y: 13 1255 | tile: 1 1256 | h_flip: 0 1257 | v_flip: 0 1258 | } 1259 | cell { 1260 | x: 10 1261 | y: 13 1262 | tile: 1 1263 | h_flip: 0 1264 | v_flip: 0 1265 | } 1266 | cell { 1267 | x: 11 1268 | y: 13 1269 | tile: 1 1270 | h_flip: 0 1271 | v_flip: 0 1272 | } 1273 | cell { 1274 | x: 12 1275 | y: 13 1276 | tile: 0 1277 | h_flip: 0 1278 | v_flip: 0 1279 | } 1280 | cell { 1281 | x: 0 1282 | y: 14 1283 | tile: 0 1284 | h_flip: 0 1285 | v_flip: 0 1286 | } 1287 | cell { 1288 | x: 1 1289 | y: 14 1290 | tile: 0 1291 | h_flip: 0 1292 | v_flip: 0 1293 | } 1294 | cell { 1295 | x: 2 1296 | y: 14 1297 | tile: 0 1298 | h_flip: 0 1299 | v_flip: 0 1300 | } 1301 | cell { 1302 | x: 3 1303 | y: 14 1304 | tile: 0 1305 | h_flip: 0 1306 | v_flip: 0 1307 | } 1308 | cell { 1309 | x: 4 1310 | y: 14 1311 | tile: 0 1312 | h_flip: 0 1313 | v_flip: 0 1314 | } 1315 | cell { 1316 | x: 5 1317 | y: 14 1318 | tile: 0 1319 | h_flip: 0 1320 | v_flip: 0 1321 | } 1322 | cell { 1323 | x: 6 1324 | y: 14 1325 | tile: 0 1326 | h_flip: 0 1327 | v_flip: 0 1328 | } 1329 | cell { 1330 | x: 7 1331 | y: 14 1332 | tile: 0 1333 | h_flip: 0 1334 | v_flip: 0 1335 | } 1336 | cell { 1337 | x: 8 1338 | y: 14 1339 | tile: 0 1340 | h_flip: 0 1341 | v_flip: 0 1342 | } 1343 | cell { 1344 | x: 9 1345 | y: 14 1346 | tile: 0 1347 | h_flip: 0 1348 | v_flip: 0 1349 | } 1350 | cell { 1351 | x: 10 1352 | y: 14 1353 | tile: 0 1354 | h_flip: 0 1355 | v_flip: 0 1356 | } 1357 | cell { 1358 | x: 11 1359 | y: 14 1360 | tile: 0 1361 | h_flip: 0 1362 | v_flip: 0 1363 | } 1364 | cell { 1365 | x: 12 1366 | y: 14 1367 | tile: 0 1368 | h_flip: 0 1369 | v_flip: 0 1370 | } 1371 | } 1372 | layers { 1373 | id: "object" 1374 | z: 0.1 1375 | is_visible: 1 1376 | cell { 1377 | x: 2 1378 | y: 2 1379 | tile: 7 1380 | h_flip: 0 1381 | v_flip: 0 1382 | } 1383 | cell { 1384 | x: 3 1385 | y: 2 1386 | tile: 6 1387 | h_flip: 0 1388 | v_flip: 0 1389 | } 1390 | cell { 1391 | x: 4 1392 | y: 2 1393 | tile: 6 1394 | h_flip: 0 1395 | v_flip: 0 1396 | } 1397 | cell { 1398 | x: 5 1399 | y: 2 1400 | tile: 6 1401 | h_flip: 0 1402 | v_flip: 0 1403 | } 1404 | cell { 1405 | x: 6 1406 | y: 2 1407 | tile: 6 1408 | h_flip: 0 1409 | v_flip: 0 1410 | } 1411 | cell { 1412 | x: 7 1413 | y: 2 1414 | tile: 6 1415 | h_flip: 0 1416 | v_flip: 0 1417 | } 1418 | cell { 1419 | x: 8 1420 | y: 2 1421 | tile: 6 1422 | h_flip: 0 1423 | v_flip: 0 1424 | } 1425 | cell { 1426 | x: 9 1427 | y: 2 1428 | tile: 6 1429 | h_flip: 0 1430 | v_flip: 0 1431 | } 1432 | cell { 1433 | x: 10 1434 | y: 2 1435 | tile: 8 1436 | h_flip: 0 1437 | v_flip: 0 1438 | } 1439 | cell { 1440 | x: 2 1441 | y: 3 1442 | tile: 3 1443 | h_flip: 0 1444 | v_flip: 0 1445 | } 1446 | cell { 1447 | x: 10 1448 | y: 3 1449 | tile: 3 1450 | h_flip: 0 1451 | v_flip: 0 1452 | } 1453 | cell { 1454 | x: 2 1455 | y: 4 1456 | tile: 3 1457 | h_flip: 0 1458 | v_flip: 0 1459 | } 1460 | cell { 1461 | x: 4 1462 | y: 4 1463 | tile: 0 1464 | h_flip: 0 1465 | v_flip: 0 1466 | } 1467 | cell { 1468 | x: 5 1469 | y: 4 1470 | tile: 0 1471 | h_flip: 0 1472 | v_flip: 0 1473 | } 1474 | cell { 1475 | x: 6 1476 | y: 4 1477 | tile: 0 1478 | h_flip: 0 1479 | v_flip: 0 1480 | } 1481 | cell { 1482 | x: 7 1483 | y: 4 1484 | tile: 0 1485 | h_flip: 0 1486 | v_flip: 0 1487 | } 1488 | cell { 1489 | x: 8 1490 | y: 4 1491 | tile: 0 1492 | h_flip: 0 1493 | v_flip: 0 1494 | } 1495 | cell { 1496 | x: 10 1497 | y: 4 1498 | tile: 3 1499 | h_flip: 0 1500 | v_flip: 0 1501 | } 1502 | cell { 1503 | x: 2 1504 | y: 5 1505 | tile: 3 1506 | h_flip: 0 1507 | v_flip: 0 1508 | } 1509 | cell { 1510 | x: 4 1511 | y: 5 1512 | tile: 0 1513 | h_flip: 0 1514 | v_flip: 0 1515 | } 1516 | cell { 1517 | x: 5 1518 | y: 5 1519 | tile: 0 1520 | h_flip: 0 1521 | v_flip: 0 1522 | } 1523 | cell { 1524 | x: 6 1525 | y: 5 1526 | tile: 0 1527 | h_flip: 0 1528 | v_flip: 0 1529 | } 1530 | cell { 1531 | x: 7 1532 | y: 5 1533 | tile: 0 1534 | h_flip: 0 1535 | v_flip: 0 1536 | } 1537 | cell { 1538 | x: 8 1539 | y: 5 1540 | tile: 0 1541 | h_flip: 0 1542 | v_flip: 0 1543 | } 1544 | cell { 1545 | x: 10 1546 | y: 5 1547 | tile: 3 1548 | h_flip: 0 1549 | v_flip: 0 1550 | } 1551 | cell { 1552 | x: 2 1553 | y: 6 1554 | tile: 3 1555 | h_flip: 0 1556 | v_flip: 0 1557 | } 1558 | cell { 1559 | x: 4 1560 | y: 6 1561 | tile: 0 1562 | h_flip: 0 1563 | v_flip: 0 1564 | } 1565 | cell { 1566 | x: 5 1567 | y: 6 1568 | tile: 0 1569 | h_flip: 0 1570 | v_flip: 0 1571 | } 1572 | cell { 1573 | x: 6 1574 | y: 6 1575 | tile: 0 1576 | h_flip: 0 1577 | v_flip: 0 1578 | } 1579 | cell { 1580 | x: 7 1581 | y: 6 1582 | tile: 0 1583 | h_flip: 0 1584 | v_flip: 0 1585 | } 1586 | cell { 1587 | x: 8 1588 | y: 6 1589 | tile: 0 1590 | h_flip: 0 1591 | v_flip: 0 1592 | } 1593 | cell { 1594 | x: 10 1595 | y: 6 1596 | tile: 3 1597 | h_flip: 0 1598 | v_flip: 0 1599 | } 1600 | cell { 1601 | x: 2 1602 | y: 7 1603 | tile: 3 1604 | h_flip: 0 1605 | v_flip: 0 1606 | } 1607 | cell { 1608 | x: 10 1609 | y: 7 1610 | tile: 3 1611 | h_flip: 0 1612 | v_flip: 0 1613 | } 1614 | cell { 1615 | x: 2 1616 | y: 8 1617 | tile: 4 1618 | h_flip: 0 1619 | v_flip: 0 1620 | } 1621 | cell { 1622 | x: 3 1623 | y: 8 1624 | tile: 6 1625 | h_flip: 0 1626 | v_flip: 0 1627 | } 1628 | cell { 1629 | x: 4 1630 | y: 8 1631 | tile: 6 1632 | h_flip: 0 1633 | v_flip: 0 1634 | } 1635 | cell { 1636 | x: 5 1637 | y: 8 1638 | tile: 6 1639 | h_flip: 0 1640 | v_flip: 0 1641 | } 1642 | cell { 1643 | x: 6 1644 | y: 8 1645 | tile: 9 1646 | h_flip: 0 1647 | v_flip: 0 1648 | } 1649 | cell { 1650 | x: 7 1651 | y: 8 1652 | tile: 6 1653 | h_flip: 0 1654 | v_flip: 0 1655 | } 1656 | cell { 1657 | x: 8 1658 | y: 8 1659 | tile: 6 1660 | h_flip: 0 1661 | v_flip: 0 1662 | } 1663 | cell { 1664 | x: 9 1665 | y: 8 1666 | tile: 6 1667 | h_flip: 0 1668 | v_flip: 0 1669 | } 1670 | cell { 1671 | x: 10 1672 | y: 8 1673 | tile: 5 1674 | h_flip: 0 1675 | v_flip: 0 1676 | } 1677 | cell { 1678 | x: 6 1679 | y: 9 1680 | tile: 3 1681 | h_flip: 0 1682 | v_flip: 0 1683 | } 1684 | cell { 1685 | x: 6 1686 | y: 10 1687 | tile: 3 1688 | h_flip: 0 1689 | v_flip: 0 1690 | } 1691 | cell { 1692 | x: 6 1693 | y: 11 1694 | tile: 3 1695 | h_flip: 0 1696 | v_flip: 0 1697 | } 1698 | cell { 1699 | x: 1 1700 | y: 12 1701 | tile: 0 1702 | h_flip: 0 1703 | v_flip: 0 1704 | } 1705 | cell { 1706 | x: 6 1707 | y: 12 1708 | tile: 2 1709 | h_flip: 0 1710 | v_flip: 0 1711 | } 1712 | cell { 1713 | x: 11 1714 | y: 12 1715 | tile: 0 1716 | h_flip: 0 1717 | v_flip: 0 1718 | } 1719 | cell { 1720 | x: 1 1721 | y: 13 1722 | tile: 0 1723 | h_flip: 0 1724 | v_flip: 0 1725 | } 1726 | cell { 1727 | x: 2 1728 | y: 13 1729 | tile: 0 1730 | h_flip: 0 1731 | v_flip: 0 1732 | } 1733 | cell { 1734 | x: 10 1735 | y: 13 1736 | tile: 0 1737 | h_flip: 0 1738 | v_flip: 0 1739 | } 1740 | cell { 1741 | x: 11 1742 | y: 13 1743 | tile: 0 1744 | h_flip: 0 1745 | v_flip: 0 1746 | } 1747 | } 1748 | material: "/builtins/materials/tile_map.material" 1749 | blend_mode: BLEND_MODE_ALPHA 1750 | -------------------------------------------------------------------------------- /example/tilesource.tilesource: -------------------------------------------------------------------------------- 1 | image: "/assets/tilesource.png" 2 | tile_width: 16 3 | tile_height: 16 4 | tile_margin: 0 5 | tile_spacing: 0 6 | collision: "/assets/tilesource.png" 7 | material_tag: "tile" 8 | convex_hulls { 9 | index: 0 10 | count: 4 11 | collision_group: "" 12 | } 13 | convex_hulls { 14 | index: 4 15 | count: 4 16 | collision_group: "" 17 | } 18 | convex_hulls { 19 | index: 8 20 | count: 10 21 | collision_group: "" 22 | } 23 | convex_hulls { 24 | index: 18 25 | count: 4 26 | collision_group: "" 27 | } 28 | convex_hulls { 29 | index: 22 30 | count: 5 31 | collision_group: "" 32 | } 33 | convex_hulls { 34 | index: 27 35 | count: 5 36 | collision_group: "" 37 | } 38 | convex_hulls { 39 | index: 32 40 | count: 4 41 | collision_group: "" 42 | } 43 | convex_hulls { 44 | index: 36 45 | count: 5 46 | collision_group: "" 47 | } 48 | convex_hulls { 49 | index: 41 50 | count: 5 51 | collision_group: "" 52 | } 53 | convex_hulls { 54 | index: 46 55 | count: 6 56 | collision_group: "" 57 | } 58 | extrude_borders: 2 59 | inner_padding: 0 60 | sprite_trim_mode: SPRITE_TRIM_MODE_OFF 61 | -------------------------------------------------------------------------------- /game.project: -------------------------------------------------------------------------------- 1 | [bootstrap] 2 | main_collection = /example/collection.collectionc 3 | render = /rendercam/rendercam.renderc 4 | 5 | [script] 6 | shared_state = 1 7 | 8 | [display] 9 | width = 1280 10 | height = 720 11 | 12 | [android] 13 | input_method = HiddenInputField 14 | 15 | [project] 16 | title = Defold Grid Engine 17 | version = 1.0.0 18 | publisher = White Box Dev 19 | developer = White Box Dev 20 | dependencies#0 = https://github.com/rgrams/rendercam/archive/master.zip 21 | 22 | [library] 23 | include_dirs = dgrid 24 | default_texture_min_filter = nearest 25 | default_texture_mag_filter = nearest 26 | 27 | [physics] 28 | debug = 0 29 | 30 | [graphics] 31 | default_texture_min_filter = nearest 32 | default_texture_mag_filter = nearest 33 | 34 | -------------------------------------------------------------------------------- /input/game.input_binding: -------------------------------------------------------------------------------- 1 | key_trigger { 2 | input: KEY_W 3 | action: "up" 4 | } 5 | key_trigger { 6 | input: KEY_A 7 | action: "left" 8 | } 9 | key_trigger { 10 | input: KEY_S 11 | action: "down" 12 | } 13 | key_trigger { 14 | input: KEY_D 15 | action: "right" 16 | } 17 | key_trigger { 18 | input: KEY_R 19 | action: "reach" 20 | } 21 | key_trigger { 22 | input: KEY_LSHIFT 23 | action: "fast" 24 | } 25 | --------------------------------------------------------------------------------