Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import pygame
import os
from settings import *
class Map:
def __init__(self, filename):
self.data = []
with open(filename, 'rt') as f:
for line in f:
self.data.append(line)
self.tilewidth = len(self.data[0])
self.tileheight = len(self.data)
self.width = self.tilewidth * tilesize
self.height = self.tileheight * tilesize
class Camera:
def __init__(self, width, height):
self.camera = pygame.Rect(0, 0, width, height)
self.width, self.height = width, height
def apply(self, entity):
return entity.rect.move(self.camera.topleft)
def update(self, target):
x = -target.rect.x + width // 2
y = -target.rect.y + height // 2
# limit scrolling
x = min(0,x) #left
self.camera = pygame.Rect(x, y, self.width, self.height)