Improved level and implemented switchable tiles (though they're buggy if switched while inside them')

This commit is contained in:
Adam Blažek 2020-06-27 23:05:40 +02:00
parent 3ff1b98f81
commit c745c924a9
4 changed files with 29 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 B

After

Width:  |  Height:  |  Size: 120 B

View File

@ -1,9 +1,11 @@
1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,1
1,0,0,0,0,0,0,1
1,0,0,0,0,0,0,1
1,2,0,0,0,0,0,1
1,1,0,1,1,0,1,1
1,1,0,0,0,0,1,1
1,1,0,0,0,0,1,1
1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
1,1,1,1,3,3,1,1,1,1,1,3,3,1,1,1,1
1,1,1,1,3,3,3,3,3,3,3,3,3,1,1,1,1
1,1,1,1,3,3,3,3,3,3,3,3,3,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1
3 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1
4 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1
5 1 2 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1
6 1 1 0 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1
7 1 1 2 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1
8 1 1 0 1 0 1 0 3 0 3 1 1 1 1 1 3 3 1 1 1 1
9 1 1 1 1 1 3 1 3 1 3 1 3 3 3 3 3 3 1 1 1 1
10 1 1 1 1 3 3 3 3 3 3 3 3 3 1 1 1 1
11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

View File

@ -14,6 +14,8 @@ const
AirTile* = 0
WallTile* = 1
PlayerTile* = 2
SecretTileClosed* = 3
SecretTileOpen* = 4
type
Level* = ref object of TileMap
@ -24,7 +26,7 @@ proc init*(level: Level, number: Positive) =
level.graphic = gfxData["tiles"]
level.initSprite(TileDim)
level.map = loadCSV[int](&"data/levels/{number}.csv", parseInt)
level.passable.add @[AirTile, PlayerTile]
level.passable.add @[AirTile, PlayerTile, SecretTileOpen]
level.onlyReachableColliders = true
level.initCollider()

View File

@ -1,6 +1,7 @@
import
sequtils,
sugar,
nimgame2 / [
assets,
entity,
input,
nimgame,
@ -53,9 +54,20 @@ method event*(scene: MainScene, event: Event) =
method update*(scene: MainScene, elapsed: float) =
scene.updateScene(elapsed)
if ScancodeUp.pressed or ScancodeW.pressed or ScancodeSpace.pressed:
scene.player.jump()
if ScancodeUp.pressed or ScancodeW.pressed:
scene.player.jump
if ScancodeRight.down or ScancodeD.down:
scene.player.right(elapsed)
if ScancodeLeft.down or ScancodeA.down:
scene.player.left(elapsed)
if ScanCodeSpace.pressed:
scene.level.map = scene.level.map.map(row => row.map(tile => (
case tile
of SecretTileClosed:
SecretTileOpen
of SecretTileOpen:
SecretTileClosed
else:
tile
)))
scene.level.initCollider