1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#lang rhombus/static
import "world.rhm"
fun test(test_result :: Boolean, test_str :: String):
if test_result
| println("Passed " +& test_str)
| println("Failed " +& test_str)
fun
| reset_entity(entity :: world.Entity): reset_entity(entity, 0, 0)
| reset_entity(entity :: world.Entity, x :: Int, y :: Int):
entity.x := x
entity.y := y
let wrld = world.World()
let chunk = world.Chunk(64, 64, 0, 0)
wrld.chunks.add(chunk)
let entity = world.Entity(0, 0, 0, chunk)
wrld.entities.add(entity)
reset_entity(entity)
test(entity.move(1, 0), "move horizontal")
reset_entity(entity, 1, 1)
test(entity.move(0, 1), "move vertical")
reset_entity(entity)
test(entity.move(1, 1), "move diagonal")
reset_entity(entity)
test(!entity.move(2, 0), "move diagonal")
reset_entity(entity)
test(!entity.move(0, 0), "starting pos")
let new_chunk = world.Chunk(64, 64, 1, 0)
chunk.add_neighbour(new_chunk, #'east)
reset_entity(entity, 63, 0)
test(entity.move(64, 0), "cross chunk")
test(entity.current_chunk == new_chunk, "changed chunk")
entity.current_chunk := chunk
reset_entity(entity, 0, 1)
entity.current_chunk.set_tile(0, 1, world.Tile(#'wall_north))
test(!entity.move(0, 0), "Blocked by wall")
test(entity.move(1,1), "Move by wall")
//world.entities
//println(@str{Entity is @(entity.x) @(entity.y)})
|