def test_rotate1(self): logging.basicConfig(level=logging.DEBUG) worldMap = [] lay = MatrixSceneLayer(None, worldMap) lay.playerTurnRight()
def test_rotate1(self): logging.basicConfig(level = logging.DEBUG) worldMap=[ ] lay = MatrixSceneLayer(None,worldMap) lay.playerTurnRight()
class GameState(object): """ Contains : * Canvas * List of layers """ def __init__(self, rows, cols): self.canvas = [] self.rows = rows self.cols = cols self.debugLayer = DebugLayer() worldMap = [ [1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1], [3, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 2, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 8, 8, 8, 8, 1], [3, 0, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1], [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ] self.sceneLayer = MatrixSceneLayer(self.debugLayer, worldMap) # load Texture self.sceneLayer.texmapping[1] = StrechedTexture( "wolfenscii/asset/test/tex1") self.sceneLayer.texmapping[2] = StrechedTexture( "wolfenscii/asset/test/tex2") self.sceneLayer.texmapping[3] = StrechedTexture( "wolfenscii/asset/test/tex3") self.sceneLayer.texmapping[4] = StrechedTexture( "wolfenscii/asset/test/tex4") self.sceneLayer.texmapping[5] = StrechedTexture( "wolfenscii/asset/test/tex3") self.sceneLayer.texmapping[6] = StrechedTexture( "wolfenscii/asset/test/tex3") self.sceneLayer.texmapping[7] = StrechedTexture( "wolfenscii/asset/test/tex3") self.sceneLayer.texmapping[8] = StrechedTexture( "wolfenscii/asset/test/tex3") self.sceneLayer.texmapping[9] = StrechedTexture( "wolfenscii/asset/test/tex3") self.layers = [ClearCanvas(), self.sceneLayer, self.debugLayer] self.lastKey = "" self.__populateCanvas() def resetCanvas(self, rows, cols): self.canvas = [] self.rows = rows self.cols = cols self.__populateCanvas() def __populateCanvas(self): # populateCanvas for i in range(self.rows): self.canvas.append([Pixel() for j in range(self.cols)]) def update(self): """ Call every layer to fill the canvas. """ # play random player move timeStart = time.time() for layer in self.layers: layer.update(self.canvas) self.debugLayer.setText("gs.update / s ", str(1.0 / (time.time() - timeStart))) self.debugLayer.setText("lastKey", str(self.lastKey)) return self.canvas def keyEvent(self, key): """ Dispatch key pressed as an action """ self.lastKey = key # 104 h # 105 i # 106 j # 107 k # 108 l # 109 m if key == 104: # h self.sceneLayer.playerTurnLeft() elif key == 72: # H self.sceneLayer.playerStepLeft() elif key in (75, 107): # k self.sceneLayer.playerFront() elif key in (74, 106): # j self.sceneLayer.playerBack() elif key == 108: # l self.sceneLayer.playerTurnRight() elif key == 76: # L self.sceneLayer.playerStepRight() elif key == 100: # d # stop debug self.debugLayer.muted = not self.debugLayer.muted elif key == 97: # a # enable autoMove self.sceneLayer.setAutoMove(not self.sceneLayer.autoPlayerMove) elif key == 111: # o # decrease magic factor self.sceneLayer.magicFactor -= 0.1 elif key == 112: # p # increase magic factor self.sceneLayer.magicFactor += 0.1