Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Screen Class created
Screen now follows the player and the map created can be as big as necessary.
- Loading branch information
Showing
5 changed files
with
75 additions
and
30 deletions.
There are no files selected for viewing
BIN
+1.38 KB
__pycache__/tylemap.cpython-38.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
............................................................ | ||
....P.....1................................................. | ||
............................................................ | ||
............................................................ | ||
...............11........................................... | ||
............................................................ | ||
....111..................................................... | ||
...................111...................................... | ||
...........111.............................................. | ||
................111.............1111111111.................. | ||
.................................................11111111... | ||
.....111............11111111................................ | ||
1..........11111............................................ | ||
1............................1.............................. | ||
111111111111111111111111111111.............................. | ||
..............................111111111111111111111111111111 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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) |