Skip to content
Snippets Groups Projects
Commit aa72b94d authored by Philipp Stahl's avatar Philipp Stahl
Browse files

Added map loading

parent e9974997
Branches master
No related tags found
No related merge requests found
"""
Author: Kirill Schmidt, Lukas Weichelt, Robert Seimetz
Author: Kirill Schmidt, Philipp Stahl, Robert Seimetz
A game with an isometric (2.5D) view.
"""
# Import modules
import sys
import pygame
import pygame, pytmx
from pygame.locals import *
# Set constants
......@@ -15,19 +14,48 @@ SCREEN_WIDTH = 720
TILE_HEIGHT = 46
TILE_WIDTH = 46
# Spritegroups
all_sprites = pygame.sprite.RenderClear()
passable = pygame.sprite.RenderClear()
building = pygame.sprite.RenderClear()
screen = pygame.display.set_mode((SCREEN_HEIGHT, SCREEN_WIDTH))
class Way(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = "sprites/grass.png"
self.rect = self.images.get_rect()
self.rect.topleft = twoDtoIso(x, y)
class Map():
def __init__(self, surface):
self.Map = pytmx.load_pygame(surface, pixelalpha = True)
self.width = self.Map.width * self.Map.tilewidth
self.height = self.Map.height * self.Map.tileheight
self.data = self.Map
def render(self, surface):
tile_image = self.data.get_tile_image_by_gid
for layer in self.data.visible_layers:
if isinstance(layer, pytmx.TiledTileLayer):
for x, y, gid, in layer:
tile = tile_image(gid)
if tile:
surface.blit(tile, (x * self.Map.tilewidth, y * self.Map.tileheight))
def draw():
screen.fill((0,0,0))
all_sprites.draw(screen)
pygame.display.flip()
def main():
# Initialise screen
pygame.init()
screen = pygame.display.set_mode((SCREEN_HEIGHT, SCREEN_WIDTH))
pygame.display.set_caption(SCREEN_NAME)
# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 0))
# Blit everything to the screen
screen.blit(background, (0, 0))
screen.fill((0, 0, 0))
pygame.display.update()
# Initialise map
......@@ -40,6 +68,17 @@ def main():
[1, 1, 1, 1, 1]
]
'''
map1 = Map("foo.tmx")
for obejects in map1.data.objects:
if objects.name == "way":
sprite = Way(obejcts.x, objects.y)
if objects.type == "passable":
passable.add(sprite)
all_sprites.add(sprite)
'''
# Load images
wall = pygame.image.load('sprites/wall.png').convert()
grass = pygame.image.load('sprites/grass.png').convert()
......@@ -68,10 +107,10 @@ def main():
# Event loop
while 1:
#draw()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
exit(0)
# Function to convert cartesian coordinates to isometric
def twoDtoIso(cartX, cartY):
isoX = cartX - cartY
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment