def test_floor(self): vb = dungeon.VertexBuilder() v, t, c = vb.floor(4, 5, 6, 3.0, 2.0) self.assertEqual(len(v), 4) # square floor in xz-plane self.assertEqual(v[0], (12.0, 12.0, 15.0)) self.assertEqual(v[1], (15.0, 12.0, 15.0)) self.assertEqual(v[2], (15.0, 12.0, 18.0)) self.assertEqual(v[3], (12.0, 12.0, 18.0)) # texCoord for floor rect self.assertEqual(t[0], (0.0, 0.0)) self.assertEqual(t[1], (1.0, 0.0)) self.assertEqual(t[2], (1.0, 0.5)) self.assertEqual(t[3], (0.0, 0.5)) # white color for all vertices for i in range(4): self.assertEqual(c[i], (1.0, 1.0, 1.0))
def test_eastWall(self): vb = dungeon.VertexBuilder() v, t, c = vb.eastWall(4, 5, -1, 3.0, 2.0) self.assertEqual(len(v), 4) # rect wall in left-hand yz-plane self.assertEqual(v[0], (15.0, 0.0, 15.0)) self.assertEqual(v[1], (15.0, 0.0, 18.0)) self.assertEqual(v[2], (15.0, -2.0, 18.0)) self.assertEqual(v[3], (15.0, -2.0, 15.0)) # texCoord for wall rect self.assertEqual(t[0], (0.0, 0.5)) self.assertEqual(t[1], (1.0, 0.5)) self.assertEqual(t[2], (1.0, 1.0)) self.assertEqual(t[3], (0.0, 1.0)) # white color for all vertices for i in range(4): self.assertEqual(c[i], (1.0, 1.0, 1.0))
def test_build(self): # load test dungeon raw = '''3x3 # # .# #.#''' d = dungeon.Dungeon() self.assertTrue(d.loadFromMemory(raw)) # monkeypatch for easier unittesting vb = dungeon.VertexBuilder() vb.floor = lambda x, y, z, w, h: ((x, y, z), ('F', w, h), (None, None, None, None)) vb.northWall = lambda x, y, z, w, h: ((x, y, z), ('N', w, h), (None, None, None, None)) vb.southWall = lambda x, y, z, w, h: ((x, y, z), ('S', w, h), (None, None, None, None)) vb.westWall = lambda x, y, z, w, h: ((x, y, z), ('W', w, h), (None, None, None, None)) vb.eastWall = lambda x, y, z, w, h: ((x, y, z), ('E', w, h), (None, None, None, None)) # build dungeon self.assertTrue(vb.loadFromDungeon(d)) for a, b, c in vb.data: # only show in case of an error print(a, "\t", b, "\t", c) self.assertEqual(len(vb.data), 20) black = (0.0, 0.0, 0.0) # (1, 0) is void with walls in N/W/E self.assertEqual(vb.data[0], ((1, 0, 0), ('N', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[1], ((1, 0, 0), ('W', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[2], ((1, 0, 0), ('E', 3.0, 2.0), (None, None, None, None))) # and deep walls all around (colored black towards the pit) self.assertEqual(vb.data[3], ((1, 0, -1), ('N', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[4], ((1, 0, -1), ('S', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[5], ((1, 0, -1), ('W', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[6], ((1, 0, -1), ('E', 3.0, 2.0), (None, None, black, black))) # (0, 1) is void with wall in N/W/S self.assertEqual(vb.data[7], ((0, 1, 0), ('N', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[8], ((0, 1, 0), ('S', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[9], ((0, 1, 0), ('W', 3.0, 2.0), (None, None, None, None))) # and deep walls all around (colored black towards the pit) self.assertEqual(vb.data[10], ((0, 1, -1), ('N', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[11], ((0, 1, -1), ('S', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[12], ((0, 1, -1), ('W', 3.0, 2.0), (None, None, black, black))) self.assertEqual(vb.data[13], ((0, 1, -1), ('E', 3.0, 2.0), (None, None, black, black))) # (1, 1) is floor with wall in E self.assertEqual(vb.data[14], ((1, 1, 0), ('F', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[15], ((1, 1, 0), ('E', 3.0, 2.0), (None, None, None, None))) # (1, 2) is floor with walls in S/W/E self.assertEqual(vb.data[16], ((1, 2, 0), ('F', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[17], ((1, 2, 0), ('S', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[18], ((1, 2, 0), ('W', 3.0, 2.0), (None, None, None, None))) self.assertEqual(vb.data[19], ((1, 2, 0), ('E', 3.0, 2.0), (None, None, None, None)))
hud.texture = heart weapon = draw.Sprite2D(196, 196) weapon.moveTo(420, 510) weapon.centerTo(0.5, 1.0) weapon.clip(0.0, 0.0, 0.25, 1.0) weapon.texture = sword weapon.animator = draw.FrameAnimator(weapon, 4, 8) # demo terrain d = dungeon.Dungeon() d.loadFromFile('demo.txt') renderer.loadDungeon(d) vb = dungeon.VertexBuilder() #vb.no_walls() vb.loadFromDungeon(d) next_fps_update = 0 sprite1 = draw.Sprite3D() sprite1.moveTo(4.5, 0.0, 4.5) sprite1.centerTo(0.5, 0.0, 0.5) sprite1.texture = goblin sprite1.animator = draw.FrameAnimator(sprite1, 4, 8) sprite1.animator.start(loop=True) sprite2 = draw.Sprite3D() sprite2.resize(0.5, 0.5) sprite2.moveTo(5.0, 0.0, 4.0)