Python Forum
[PyGame] Tilemap 3 squares too tall
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Tilemap 3 squares too tall
#3
Hopefully this is it:



class Map:
def __init__(self, f):
self.map_data = []
f = open("C:/Users/owner/Desktop/map.txt", "rt")
for line in f:
self.map_data.append(line.strip())

self.tilewidth = len(self.map_data[0])
self.tileheight = len(self.map_data)
self.width = self.tilewidth * TILESIZE
self.height = self.tilewidth * TILESIZE

class Camera:
def __init__(self, width, height):
self.camera = pygame.Rect(0,0, width, height)
self.width = width
self.height = height

def apply(self, entity):
return entity.rect.move(self.camera.topleft)

def update(self, target):
x = -target.rect.x + int(WIDTH / 2)
y = -target.rect.y + int(HEIGHT / 2)

x = min(0, x)
y = min(0, y)
x = max(-(self.width - WIDTH), x)
y = max(-(self.height - HEIGHT), y)

self.camera = pygame.Rect(x, y, self.width, self.height)



ps.... how to i cut&paste from Thonny and keep indents? lol
Reply


Messages In This Thread
Tilemap 3 squares too tall - by michael1789 - May-26-2019, 04:32 PM
RE: Tilemap 3 squares too tall - by metulburr - May-27-2019, 01:27 AM
RE: Tilemap 3 squares too tall - by michael1789 - May-27-2019, 08:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Infinite generating tilemap pygame Kolterdyx 2 3,864 Jun-14-2020, 09:22 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020