--- /dev/null
+import World
+import Debug
+
+def computeVisibility(player):
+ for y in range(World.worldHeight):
+ for x in range(World.worldWidth):
+ # reset visibility
+ World.world[y][x].visible = False
+ #circle = generateCircle(player.worldX, player.worldY, player.sightRange)
+ circle = generateSquare(player.worldX, player.worldY, player.sightRange)
+ for x, y in circle:
+ Debug.debugRects.append((x, y, (255, 255, 255)))
+ # debugs = [(x, y, (255, 255, 255)) for x, y in circle]
+ # debugRects.append(debugs)
+ for coord in circle:
+ #world[coord[1]][coord[0]].visible = True
+ pass
+
+ for coord in circle:
+ line(player.worldX, player.worldY, coord[0], coord[1])
+
+def generateSquare(x, y, radius):
+ square = []
+ for i in range(radius):
+ square.append((x + i, y + radius))
+ square.append((x - i, y + radius))
+ square.append((x + i, y - radius))
+ square.append((x - i, y - radius))
+ square.append((x + radius, y - i))
+ square.append((x + radius, y + i))
+ square.append((x - radius, y - i))
+ square.append((x - radius, y + i))
+ square.append((x + radius, y + radius))
+ square.append((x - radius, y - radius))
+ square.append((x + radius, y - radius))
+ square.append((x - radius, y + radius))
+ return square
+
+def generateCircle(x0, y0, radius):
+ circle = []
+ f = 1 - radius
+ ddf_x = 1
+ ddf_y = -2 * radius
+ x = 0
+ y = radius
+ circle.append((x0, y0 + radius))
+ circle.append((x0, y0 - radius))
+ circle.append((x0 + radius, y0))
+ circle.append((x0 - radius, y0))
+
+ while x < y:
+ if f >= 0:
+ y -= 1
+ ddf_y += 2
+ f += ddf_y
+ x += 1
+ ddf_x += 2
+ f += ddf_x
+ circle.append((x0 + x, y0 + y))
+ circle.append((x0 - x, y0 + y))
+ circle.append((x0 + x, y0 - y))
+ circle.append((x0 - x, y0 - y))
+ circle.append((x0 + y, y0 + x))
+ circle.append((x0 - y, y0 + x))
+ circle.append((x0 + y, y0 - x))
+ circle.append((x0 - y, y0 - x))
+ return circle
+
+def line(x0, y0, x1, y1):
+ dx = abs(x1 - x0)
+ dy = abs(y1 - y0)
+ x, y = x0, y0
+ sx = -1 if x0 > x1 else 1
+ sy = -1 if y0 > y1 else 1
+ if dx > dy:
+ err = dx / 2.0
+ while x != x1:
+ if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[y][x].containsSolid():
+ World.world[y][x].visible = True
+ Debug.debugRects.append((x, y, (255, 0, 0)))
+ err -= dy
+ if err < 0:
+ y += sy
+ err += dx
+ x += sx
+ else:
+ break
+ else:
+ err = dy / 2.0
+ while y != y1:
+ if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[y][x].containsSolid():
+ World.world[y][x].visible = True
+ Debug.debugRects.append((x, y, (255, 0, 0)))
+ err -= dx
+ if err < 0:
+ x += sx
+ err += dy
+ y += sy
+ else:
+ break
+ World.world[y][x].visible = True
+ Debug.debugRects.append((x, y, (255, 0, 0)))
--- /dev/null
+debugRects = []
\ No newline at end of file
--- /dev/null
+import Texture
+
+class GameObject:
+ def __init__(self, worldX, worldY, texture, solid):
+ self.texture = texture
+ self.worldX = worldX
+ self.worldY = worldY
+ self.solid = solid
+ self.textureX = Texture.spriteDict[self.texture][0]
+ self.textureY = Texture.spriteDict[self.texture][1]
+
+class AnimationObject(GameObject):
+ def __init__(self, worldX, worldY, texture, solid, fps):
+ GameObject.__init__(self, worldX, worldY, texture, solid)
+ self.fps = fps
+ self.timer = 0
+
+ def update(self, deltaTime):
+ self.timer += deltaTime
+ if self.timer > 1 / self.fps:
+ self.timer = 0
+ # increment animation frame
+ if self.textureX < Texture.animationDict[self.texture][2]:
+ self.textureX += 1
+ else:
+ self.textureX = 0
+
+class WorldCell():
+ def __init__(self):
+ self.objects = [] # order this list somehow to get Z
+ self.visible = True
+
+ def containsSolid(self):
+ return any(ob.solid for ob in self.objects)
\ No newline at end of file
class InputState:
xy: Tuple = (0, 0)
quit: bool = False
- zoomLevel: float = 1.0
+ zoomLevel: float = 0.5
showDebug: bool = False
+ debugLevel: int = 0
inputMade: bool = False
maxZoom = 3.0
minZoom = 1.0
-
+maxDebugLevel = 2
globalInputState = InputState()
def handleInputs():
elif event.key == pygame.K_LEFTBRACKET and newInputState.zoomLevel >= minZoom:
newInputState.zoomLevel -= 0.5
elif event.key == pygame.K_F3:
- newInputState.showDebug = not newInputState.showDebug
+ if newInputState.debugLevel < maxDebugLevel:
+ newInputState.debugLevel += 1
+ else: newInputState.debugLevel = 0
newInputState.inputMade = not newInputState == globalInputState
# now replace the global one with our new one
import pygame
import pygame.font
-from pygame import transform
-import os
-from collections import namedtuple
-from pygame import sprite
-from pygame.constants import SCRAP_SELECTION, SYSTEM_CURSOR_SIZENESW
-import WorldTemplates
-import Texture
+import Player
+import WorldGen
+import World
import InputHandler
+import Renderer
+import Algorithm
+import Debug
-screenWidth = 1920
-screenHeight = 1080
-worldWidth = 20 * 3
-worldHeight = 20 * 3
-objPixelWidth = 32
-objPixelHeight = 32
-
-# int a = 1
-# int b = -1
-# unsigned int a = 5
-# uint8 myint = 255;
-# float myFloat = 0.0001f;
-# double myDouble = 0.0000000001f;
-
-pygame.init()
-pygame.display.set_caption("Medieval Game")
-gameFolder = os.path.dirname(__file__)
-screen = pygame.display.set_mode([screenWidth, screenHeight])
-playerImage = pygame.image.load(os.path.join('Assets', 'player_debug.png'))
-dirtImage = pygame.image.load(os.path.join('Assets', 'dirt.png'))
-grassImage = pygame.image.load(os.path.join('Assets', 'grass.png'))
-woodWallImage = pygame.image.load(os.path.join('Assets', 'woodWall.png'))
-
-debugRects = []
-
-class GameObject():
- def __init__(self, worldX, worldY, texture, solid):
- self.texture = texture
- self.worldX = worldX
- self.worldY = worldY
- self.solid = solid
- self.textureX = Texture.spriteDict[self.texture][0]
- self.textureY = Texture.spriteDict[self.texture][1]
-
-class AnimationObject(GameObject):
- def __init__(self, worldX, worldY, texture, solid, fps):
- GameObject.__init__(self, worldX, worldY, texture, solid)
- self.fps = fps
- self.timer = 0
-
- def update(self, deltaTime):
- self.timer += deltaTime
- if self.timer > 1 / self.fps:
- self.timer = 0
- # increment animation frame
- if self.textureX < Texture.animationDict[self.texture][2]:
- self.textureX += 1
- else:
- self.textureX = 0
-
-class Door(GameObject):
- def __init__(self, worldX, worldY, texture, open):
- GameObject.__init__(self, worldX, worldY, texture, not open)
-
- def interact():
- print("player interacted with the door")
-
-class WorldCell():
- def __init__(self):
- self.objects = [] # order this list somehow to get Z
- self.visible = True
-
- def containsSolid(self):
- return any(ob.solid for ob in self.objects)
-
-def genWorld():
- template = WorldTemplates.worldTemplate5
- output = [[]]
- for y in range(worldHeight):
- row = []
- for x in range(worldWidth):
- cell = WorldCell()
- if template[y][x] == 0:
- cell.objects.append(GameObject(x, y, "dirt", False))
- elif template[y][x] == 1:
- cell.objects.append(GameObject(x, y, "grass", False))
- elif template[y][x] == 2:
- cell.objects.append(GameObject(x, y, "wood_wall", True))
- elif template[y][x] == 3:
- cell.objects.append(GameObject(x, y, "wood_wall_side", True))
- elif template[y][x] == 4:
- cell.objects.append(GameObject(x, y, "floor_planks", False))
- elif template[y][x] == 5:
- cell.objects.append(GameObject(x, y, "floor_planks_shadow", False))
- elif template[y][x] == 6:
- cell.objects.append(GameObject(x, y, "wood_wall_shadow", True))
- elif template[y][x] == 7:
- cell.objects.append(GameObject(x, y, "grass_border_right", False))
- elif template[y][x] == 8:
- cell.objects.append(GameObject(x, y, "grass_border_top", False))
- elif template[y][x] == 9:
- cell.objects.append(GameObject(x, y, "grass_border_top_right_inner", False))
- elif template[y][x] == 10:
- cell.objects.append(GameObject(x, y, "grass_border_top_right_outer", False))
- elif template[y][x] == 11:
- cell.objects.append(GameObject(x, y, "grass_border_top_left_outer", False))
- elif template[y][x] == 12:
- cell.objects.append(GameObject(x, y, "grass_border_top_left_inner", False))
- elif template[y][x] == 13:
- cell.objects.append(GameObject(x, y, "grass_border_left", False))
- row.append(cell)
- output.insert(y, row)
- return output
-
-world = genWorld()
-
-class Player(GameObject):
- def __init__(self, worldX, worldY):
- GameObject.__init__(self, worldX, worldY, "player", False)
- self.direction = (0, 1)
- self.sightRange = 16
-
- def update(self):
- self.direction = InputHandler.globalInputState.xy
-
- if self.direction == (0, 1):
- self.texture = "player"
- elif self.direction == (0, -1):
- self.texture = "player_north"
- elif self.direction == (1, 0):
- self.texture = "player_east"
- elif self.direction == (-1, 0):
- self.texture = "player_west"
-
- self.textureX = Texture.spriteDict[self.texture][0]
- self.textureY = Texture.spriteDict[self.texture][1]
-
- desiredX, desiredY = self.worldX + self.direction[0], self.worldY + self.direction[1]
-
- if -1 < desiredX < worldWidth and -1 < desiredY < worldHeight:
- if not world[int(desiredY)][int(desiredX)].containsSolid():
- self.worldX = desiredX
- self.worldY = desiredY
-
-player = Player(30,30)
-testAnim = AnimationObject(10, 10, "test_anim", False, 8)
-door = Door(11, 13, "wood_door_open", True)
-world[13][11].objects.append(door)
-world[10][10].objects.append(testAnim)
-
-def computeVisibility():
- for y in range(worldHeight):
- for x in range(worldWidth):
- # reset visibility
- world[y][x].visible = False
- circle = generateCircle(player.worldX, player.worldY, player.sightRange)
- for x, y in circle:
- debugRects.append((x, y, (255, 255, 255)))
- # debugs = [(x, y, (255, 255, 255)) for x, y in circle]
- # debugRects.append(debugs)
- for coord in circle:
- #world[coord[1]][coord[0]].visible = True
- pass
-
- for coord in circle:
- line(player.worldX, player.worldY, coord[0], coord[1])
-
-def generateCircle(x0, y0, radius):
- circle = []
- f = 1 - radius
- ddf_x = 1
- ddf_y = -2 * radius
- x = 0
- y = radius
- circle.append((x0, y0 + radius))
- circle.append((x0, y0 - radius))
- circle.append((x0 + radius, y0))
- circle.append((x0 - radius, y0))
-
- while x < y:
- if f >= 0:
- y -= 1
- ddf_y += 2
- f += ddf_y
- x += 1
- ddf_x += 2
- f += ddf_x
- circle.append((x0 + x, y0 + y))
- circle.append((x0 - x, y0 + y))
- circle.append((x0 + x, y0 - y))
- circle.append((x0 - x, y0 - y))
- circle.append((x0 + y, y0 + x))
- circle.append((x0 - y, y0 + x))
- circle.append((x0 + y, y0 - x))
- circle.append((x0 - y, y0 - x))
- return circle
-
-def line(x0, y0, x1, y1):
- dx = abs(x1 - x0)
- dy = abs(y1 - y0)
- x, y = x0, y0
- sx = -1 if x0 > x1 else 1
- sy = -1 if y0 > y1 else 1
- if dx > dy:
- err = dx / 2.0
- while x != x1:
- if x in range(0, worldWidth - 1) and y in range (0, worldHeight - 1) and not world[y][x].containsSolid():
- world[y][x].visible = True
- debugRects.append((x, y, (255, 0, 0)))
- err -= dy
- if err < 0:
- y += sy
- err += dx
- x += sx
- else:
- break
- else:
- err = dy / 2.0
- while y != y1:
- if x in range(0, worldWidth - 1) and y in range (0, worldHeight - 1) and not world[y][x].containsSolid():
- world[y][x].visible = True
- debugRects.append((x, y, (255, 0, 0)))
- err -= dx
- if err < 0:
- x += sx
- err += dy
- y += sy
- else:
- break
- debugRects.append((x, y, (255, 0, 0)))
- world[y][x].visible = True
-
-
-
-def renderAll(cam, zoomLevel):
- actualWidth = int(objPixelWidth * zoomLevel)
- actualHeight = int(objPixelHeight * zoomLevel)
- screenTopX = (cam[0] * actualWidth) - (screenWidth / 2)
- screenTopY = (cam[1] * actualHeight) - (screenHeight / 2)
-
- sheet = pygame.transform.scale(Texture.spriteSheet, (int(Texture.sheetWidth * zoomLevel), int(Texture.sheetHeight * zoomLevel)))
-
- for y in range(worldHeight):
- for x in range(worldWidth):
- if (world[y][x].visible):
- for gameObj in world[y][x].objects:
- worldX = (gameObj.worldX * actualWidth) - (actualWidth / 2)
- worldY = (gameObj.worldY * actualHeight) - (actualHeight / 2)
- screen.blit(sheet,
- (worldX - screenTopX, worldY - screenTopY),
- (gameObj.textureX * actualWidth,
- gameObj.textureY * actualHeight,
- actualWidth,
- actualHeight))
-
- worldX = (player.worldX * actualWidth) - (actualWidth / 2)
- worldY = (player.worldY * actualHeight) - (actualHeight / 2)
- sheetPos = Texture.spriteDict[player.texture]
- screen.blit(sheet, (worldX - screenTopX, worldY - screenTopY),
- (player.textureX * actualWidth,
- player.textureY * actualHeight,
- actualWidth,
- actualHeight))
-
-def renderDebugUI():
- headerSurf = Texture.font.render("Medieval Game Debug Mode", False, (255,0,0))
- playerPosSurf = Texture.font.render("Player Pos ({x},{y})".format(x=player.worldX, y=player.worldY),
- False, (255, 255, 255))
- screen.blit(headerSurf, (0, 0))
- screen.blit(playerPosSurf, (0, 30))
- infoSurf = Texture.font.render("Standing on:", False, (255, 255, 255))
- screen.blit(infoSurf, (0, 60))
-
- y = 90
- for gameObj in world[int(player.worldY)][int(player.worldX)].objects:
- objSurf = Texture.font.render("{t}".format(t=gameObj.texture), False, (0, 0, 255))
- screen.blit(objSurf, (16, y))
- y += 30
-
-def renderDebug(cam, zoomLevel):
- actualWidth = int(objPixelWidth * zoomLevel)
- actualHeight = int(objPixelHeight * zoomLevel)
- screenTopX = (cam[0] * actualWidth) - (screenWidth / 2)
- screenTopY = (cam[1] * actualHeight) - (screenHeight / 2)
-
- for r in debugRects:
- worldX = (r[0] * actualWidth) - (actualWidth / 2)
- worldY = (r[1] * actualHeight) - (actualHeight / 2)
+def main():
+ renderer = Renderer.Renderer(1920, 1080)
- s = pygame.Surface((actualWidth, actualHeight))
- s.set_alpha(128)
- s.fill(r[2])
- screen.blit(s, (worldX - screenTopX, worldY - screenTopY))
+ World.world = WorldGen.generateWorld()
- # for r in debugRects:
- # playerWorldX = (player.worldX * actualWidth) - (actualWidth / 2)
- # playerWorldY = (player.worldY* actualHeight) - (actualHeight / 2)
- # worldX = (r[0] * actualWidth) - (actualWidth / 2)
- # worldY = (r[1] * actualHeight) - (actualHeight / 2)
+ player = Player.Player(2, 2)
- # pygame.draw.line(screen, (255, 0, 0),
- # (playerWorldX - screenTopX, playerWorldY - screenTopY),
- # (worldX - screenTopX, worldY - screenTopY),
- # 1)
-def main():
+ # begin game loop
getTicksLastFrame = 0
t = 0
deltaTime = 0
- #zoomLevel = 1.0
while not InputHandler.globalInputState.quit:
+ # Compute delta time
t = pygame.time.get_ticks()
deltaTime = (t - getTicksLastFrame) / 1000.0
getTicksLastFrame = t
+
+ Debug.debugRects.clear()
+
InputHandler.handleInputs()
+
player.update()
- debugRects.clear()
- #circle(player.worldX, player.worldY, 16)
- computeVisibility()
- #line(player.worldX, player.worldY, 40, 40)
- testAnim.update(deltaTime)
+
+ Algorithm.computeVisibility(player)
+
+
cam = (player.worldX, player.worldY)
- screen.fill((14, 40, 37))
- renderAll(cam, InputHandler.globalInputState.zoomLevel)
- if InputHandler.globalInputState.showDebug: renderDebug(cam, InputHandler.globalInputState.zoomLevel)
- renderDebugUI()
+
+ renderer.renderWorld(cam, InputHandler.globalInputState.zoomLevel, player)
+ if InputHandler.globalInputState.debugLevel > 0:
+ renderer.renderDebugUI(player, deltaTime)
+ if InputHandler.globalInputState.debugLevel > 1:
+ renderer.renderDebugRects(cam, InputHandler.globalInputState.zoomLevel)
+
pygame.display.flip()
pygame.quit()
--- /dev/null
+import GameObject
+import InputHandler
+import Texture
+import World
+
+class Player(GameObject.GameObject):
+ def __init__(self, worldX, worldY):
+ GameObject.GameObject.__init__(self, worldX, worldY, "player_south", False)
+ self.direction = (0, 1)
+ self.sightRange = 18
+
+ def update(self):
+ self.direction = InputHandler.globalInputState.xy
+
+ if self.direction == (0, 1):
+ self.texture = "player_south"
+ elif self.direction == (0, -1):
+ self.texture = "player_north"
+ elif self.direction == (1, 0):
+ self.texture = "player_east"
+ elif self.direction == (-1, 0):
+ self.texture = "player_west"
+
+ self.textureX = Texture.spriteDict[self.texture][0]
+ self.textureY = Texture.spriteDict[self.texture][1]
+
+ desiredX, desiredY = self.worldX + self.direction[0], self.worldY + self.direction[1]
+
+ if -1 < desiredX < World.worldWidth and -1 < desiredY < World.worldHeight:
+ if not World.world[int(desiredY)][int(desiredX)].containsSolid():
+ self.worldX = desiredX
+ self.worldY = desiredY
\ No newline at end of file
--- /dev/null
+import pygame
+import Texture
+import World
+import Debug
+
+class Renderer:
+ def __init__(self, screenWidth, screenHeight):
+ self.screenWidth = screenWidth
+ self.screenHeight = screenHeight
+ pygame.init()
+ pygame.display.set_caption("pyRogue")
+ self.screen = pygame.display.set_mode([self.screenWidth, self.screenHeight])
+
+ def renderWorld(self, cam, zoomLevel, player):
+ actualWidth = int(Texture.spriteSize * zoomLevel)
+ actualHeight = int(Texture.spriteSize * zoomLevel)
+ screenTopX = (cam[0] * actualWidth) - (self.screenWidth / 2)
+ screenTopY = (cam[1] * actualHeight) - (self.screenHeight / 2)
+
+ sheet = pygame.transform.scale(Texture.spriteSheet, (int(Texture.sheetWidth * zoomLevel), int(Texture.sheetHeight * zoomLevel)))
+
+ self.screen.fill((14, 40, 37))
+
+ for y in range(World.worldHeight):
+ for x in range(World.worldWidth):
+ if (World.world[y][x].visible):
+ for gameObj in World.world[y][x].objects:
+ worldX = (gameObj.worldX * actualWidth) - (actualWidth / 2)
+ worldY = (gameObj.worldY * actualHeight) - (actualHeight / 2)
+ self.screen.blit(sheet,
+ (worldX - screenTopX, worldY - screenTopY),
+ (gameObj.textureX * actualWidth,
+ gameObj.textureY * actualHeight,
+ actualWidth,
+ actualHeight))
+
+ worldX = (player.worldX * actualWidth) - (actualWidth / 2)
+ worldY = (player.worldY * actualHeight) - (actualHeight / 2)
+ self.screen.blit(sheet, (worldX - screenTopX, worldY - screenTopY),
+ (player.textureX * actualWidth,
+ player.textureY * actualHeight,
+ actualWidth,
+ actualHeight))
+
+ def renderDebugUI(self, player, deltaTime):
+ drawY = 0
+ headerSurf = Texture.font.render("PyRoguelike Debug Mode", False, (255,0,0))
+ fpsSurf = Texture.font.render(f'{int(1 / deltaTime)} FPS', False, (255, 255, 255))
+ playerPosSurf = Texture.font.render("Player Pos ({x},{y})".format(x=player.worldX, y=player.worldY),
+ False, (255, 255, 255))
+ self.screen.blit(headerSurf, (0, drawY))
+ drawY += 30
+ self.screen.blit(fpsSurf, (0, drawY))
+ drawY += 30
+ self.screen.blit(playerPosSurf, (0, drawY))
+ drawY += 30
+ infoSurf = Texture.font.render("Standing on:", False, (255, 255, 255))
+ self.screen.blit(infoSurf, (0, drawY))
+ drawY += 30
+
+ for gameObj in World.world[int(player.worldY)][int(player.worldX)].objects:
+ objSurf = Texture.font.render("{t}".format(t=gameObj.texture), False, (0, 0, 255))
+ self.screen.blit(objSurf, (16, drawY))
+ drawY += 30
+
+ def renderDebugRects(self, cam, zoomLevel):
+ actualWidth = int(Texture.spriteSize * zoomLevel)
+ actualHeight = int(Texture.spriteSize * zoomLevel)
+ screenTopX = (cam[0] * actualWidth) - (self.screenWidth / 2)
+ screenTopY = (cam[1] * actualHeight) - (self.screenHeight / 2)
+
+ for r in Debug.debugRects:
+ worldX = (r[0] * actualWidth) - (actualWidth / 2)
+ worldY = (r[1] * actualHeight) - (actualHeight / 2)
+
+ s = pygame.Surface((actualWidth, actualHeight))
+ s.set_alpha(128)
+ s.fill(r[2])
+ self.screen.blit(s, (worldX - screenTopX, worldY - screenTopY))
\ No newline at end of file
import os
pygame.font.init()
gameFolder = os.path.dirname(__file__)
-spriteSheet = pygame.image.load(os.path.join('Assets', 'sheet.png'))
+spriteSheet = pygame.image.load(os.path.join('Assets', 'doomSheet.png'))
animationSheet = pygame.image.load(os.path.join('Assets', 'animation.png'))
font = pygame.font.Font(os.path.join('Assets','alagard.ttf'), 30)
sheetWidth = spriteSheet.get_width()
sheetHeight = spriteSheet.get_height()
# multiply coords by sprite size :)
-spriteSize = 32
+spriteSize = 128
spriteDict = {
- "player" : (1, 19),
- "player_north" : (0, 19),
- "player_east" : (2, 19),
- "player_west" : (3, 19),
- "dirt" : (1, 0),
- "grass" : (2, 0),
- "stone" : (3, 0),
- "wood" : (4, 0),
- "floor_planks" : (5, 0),
- "wood_wall" : (6, 0),
- "wood_idk" : (7, 0),
- "wood_wall_side" : (8, 0),
- "floor_planks_shadow" : (9, 0),
- "wood_wall_shadow" : (0, 1),
- "grass_border_bottom_right_inner" : (1, 1),
- "grass_border_bottom" : (2, 1),
- "grass_border_bottom_left_inner" : (3, 1),
- "grass_border_right" : (4, 1),
- "grass_border_bottom_left_outer" : (5, 1),
- "grass_border_left" : (6, 1),
- "grass_border_top_right_inner" : (7, 1),
- "grass_border_top" : (8, 1),
- "grass_border_top_left_inner" : (9, 1),
- "grass_border_top_left_outer" : (0, 2),
- "grass_border_top_right_outer" : (1, 2),
- "grass_border_bottom_right_outer" : (2, 2),
- "wood_door_closed" : (3, 2),
- "wood_door_open" : (4, 2),
- "test_anim" : (0, 6)
+ "player_south" : (0, 0),
+ "player_west" : (1, 0),
+ "player_north" : (2, 0),
+ "player_east" : (3, 0),
+ "wall_green" : (0, 1),
+ "wall_brick" : (1, 1),
+ "wall_pipes" : (2, 1),
+ "wall_vent" : (3, 1),
+ "wall_slime" : (4, 1),
+ "wall_side" : (5, 1),
+ "floor_tile" : (0, 2),
+ "floor_panels" : (1, 2)
}
+# spriteDict = {
+# "player" : (1, 19),
+# "player_north" : (0, 19),
+# "player_east" : (2, 19),
+# "player_west" : (3, 19),
+# "dirt" : (1, 0),
+# "grass" : (2, 0),
+# "stone" : (3, 0),
+# "wood" : (4, 0),
+# "floor_planks" : (5, 0),
+# "wood_wall" : (6, 0),
+# "wood_idk" : (7, 0),
+# "wood_wall_side" : (8, 0),
+# "floor_planks_shadow" : (9, 0),
+# "wood_wall_shadow" : (0, 1),
+# "grass_border_bottom_right_inner" : (1, 1),
+# "grass_border_bottom" : (2, 1),
+# "grass_border_bottom_left_inner" : (3, 1),
+# "grass_border_right" : (4, 1),
+# "grass_border_bottom_left_outer" : (5, 1),
+# "grass_border_left" : (6, 1),
+# "grass_border_top_right_inner" : (7, 1),
+# "grass_border_top" : (8, 1),
+# "grass_border_top_left_inner" : (9, 1),
+# "grass_border_top_left_outer" : (0, 2),
+# "grass_border_top_right_outer" : (1, 2),
+# "grass_border_bottom_right_outer" : (2, 2),
+# "wood_door_closed" : (3, 2),
+# "wood_door_open" : (4, 2),
+# "test_anim" : (0, 6)
+# }
#Animation name, startX, startY, endX
animationDict = {
+
+worldWidth = 10
+worldHeight = 10
+world = [[]]
\ No newline at end of file
--- /dev/null
+import WorldTemplates
+import World
+import GameObject
+
+def generateWorld():
+ template = WorldTemplates.worldTemplate6
+ output = [[]]
+ for y in range(World.worldHeight):
+ row = []
+ for x in range(World.worldWidth):
+ cell = GameObject.WorldCell()
+ if template[y][x] == 1:
+ cell.objects.append(GameObject.GameObject(x, y, "wall_vent", True))
+ elif template[y][x] == 2:
+ cell.objects.append(GameObject.GameObject(x, y, "wall_side", True))
+ elif template[y][x] == 3:
+ cell.objects.append(GameObject.GameObject(x, y, "floor_tile", False))
+ row.append(cell)
+ output.insert(y, row)
+ return output
\ No newline at end of file
+# Some simple world layouts to use for debug
+
# 0 = Dirt
# 1 = Grass
# 2 = Wood Wall
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8,12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8,12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8,12, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+]
+
+worldTemplate6 = [
+ [2, 1, 1, 1, 1, 1, 1, 1, 1, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [2, 3, 3, 3, 3, 3, 3, 3, 3, 2],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
\ No newline at end of file