forked from ismailhasannnnnn/PyMario
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtilemap.py
More file actions
73 lines (65 loc) · 3.56 KB
/
tilemap.py
File metadata and controls
73 lines (65 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pygame as pg
from entity import Entity
from coords import Coords
class Tile():
def __init__(self, game):
self.game = game
self.screen = game.screen
# self.world_tile = [[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0],
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# [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]]
self.x = 0
self.y = 0
self.bg_x = game.bg_x
self.ground_brick = pg.transform.rotozoom(self.game.spritesheet.image_at(Coords.coords["BROKEN_BRICK"]), 0, 2.5).convert_alpha()
self.empty_brick = pg.transform.rotozoom(self.game.spritesheet.image_at(Coords.coords["BRICK"]), 0, 2.5).convert_alpha()
self.item_brick = pg.transform.rotozoom(self.game.spritesheet.image_at(Coords.coords["?_1"]), 0, 2.5).convert_alpha()
self.stair_brick = pg.transform.rotozoom(self.game.spritesheet.image_at(Coords.coords["BLOCK"]), 0, 2.5).convert_alpha()
self.flag = pg.transform.rotozoom(self.game.spritesheet.image_at(Coords.coords["FLAG_POLE"]), 0, 2.5).convert_alpha()
self.tilemap = open("tiles/world1.txt", 'r')
self.scaling_factor = 2.5
self.enemies = game.enemies
self.entities = game.entities
self.world_tile = self.tilemap.read()
with open("tiles/world1.txt") as file:
for line in file:
print(line.rstrip())
def draw(self):
with open("tiles/world1.txt") as file:
self.y = 0
for line in file:
self.x = 0
for char in line:
if char == 'X':
self.entities.create_entity((self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor), self.ground_brick)
if char == 'B':
self.entities.create_entity(
(self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor), self.empty_brick)
if char == '?' or char == 'M':
self.entities.create_entity(
(self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor), self.item_brick)
if char == 'G':
self.enemies.create_goomba((self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor))
if char == 'R':
self.entities.create_entity(
(self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor), self.stair_brick)
if char == 'K':
self.enemies.create_koopa((self.x * 16 * self.scaling_factor, self.y * 16 * self.scaling_factor))
if char == 'F':
self.entities.create_entity((self.x * 16 * self.scaling_factor, (self.y * 16 * self.scaling_factor) - 152 * self.scaling_factor), self.flag)
self.x += 1
self.y += 1
# self.y = 0
# for row in self.world_tile:
# self.x = 0
# for tile in row:
# if tile == 'X':
#
# self.screen.blit(pg.transform.rotozoom(self.ground_brick, 0, 2.5),
# ((self.x * 40) + self.bg_x, self.y * 40))
# self.x += 1
# self.y += 1
def update(self):
if self.game.scrolling:
self.bg_x -= 8