Skip to content

Commit e20891e

Browse files
committed
New features:
* Added level background. * Added a test HUD * Map titles, if available, are now saved for display in the HUD. * The height of the screen has been increased, so that the aspect ratio is 4:3. * Other changes
1 parent e973f9f commit e20891e

11 files changed

+83
-32
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,6 @@ cython_debug/
164164
*.zip
165165
AppDir
166166
build
167-
appimage-build/
167+
appimage-build/
168+
build_pyxapp/
169+
.vscode

assets.pyxres

415 Bytes
Binary file not shown.

globals.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Screen size
2+
SCREEN_W = 240
3+
SCREEN_H = 180
4+
5+
# Collide values
6+
COL_WALL = 1
7+
COL_ROCK = 2

levels.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def loadLevels(self):
2929
self.total = 0
3030
self.current = 0
3131

32-
with open(path.join(LEVELS_DIR, self.levelsFile)) as data:
32+
with open(path.join(LEVELS_DIR, self.levelsFile), 'r', encoding='utf-8') as data:
3333
levelStartLine = 0
3434
levelEnd = True
3535
width = 0
@@ -43,11 +43,13 @@ def loadLevels(self):
4343

4444
if len(line) > 0:
4545
if line.startswith('title'):
46+
4647
if not levelEnd:
4748
self.levels.append({
4849
'start': levelStartLine,
4950
'end': i,
50-
'width': width
51+
'width': width,
52+
'title': line.replace('title:', '').strip()
5153
})
5254
levelEnd = True
5355
width = 0
@@ -62,12 +64,12 @@ def loadLevels(self):
6264
width = len(line)
6365

6466
if not levelEnd:
65-
6667
end = totalLines if '#' in lastLine else totalLines - 1
6768
self.levels.append({
6869
'start': levelStartLine,
6970
'end': end,
70-
'width': width
71+
'width': width,
72+
'title': ''
7173
})
7274

7375
data.close()
@@ -76,7 +78,7 @@ def loadLevels(self):
7678
def getLevel(self, index):
7779
level = self.levels[index]
7880
lines = []
79-
with open(path.join(LEVELS_DIR, self.levelsFile)) as f:
81+
with open(path.join(LEVELS_DIR, self.levelsFile), 'r', encoding='utf8') as f:
8082
for fline in f.readlines()[level['start']:level['end']]:
8183
line = []
8284
for i in range(level['width']):
@@ -92,14 +94,15 @@ def getLevel(self, index):
9294
height = level['end'] - level['start']
9395

9496
start_x = floor(((30 - width) / 2) - 1)
95-
start_y = floor(((17 - height) / 2) - 1)
97+
start_y = floor(((22 - height) / 2) - 1)
9698

9799
return {
98100
'width': width,
99101
'height': height,
100102
'lines': lines,
101103
'start_x': start_x,
102-
'start_y': start_y
104+
'start_y': start_y,
105+
'title': level['title']
103106
}
104107

105108
def next(self):

player.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def checkCol(self):
1111
print(self.x, self.y)
1212

1313
def draw(self):
14-
pyxel.tilemap(1).pset(self.x, self.y, self.sprite)
14+
pyxel.tilemaps[1].pset(self.x, self.y, self.sprite)
1515

1616
def setPos(self, x, y):
1717
self.x = x

pyxel-image0.png

4.27 KB
Loading

rock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def checkCol(self):
1111
print(self.x, self.y)
1212

1313
def draw(self):
14-
pyxel.tilemap(1).pset(self.x, self.y, self.sprite)
14+
pyxel.tilemaps[1].pset(self.x, self.y, self.sprite)
1515

1616
def setPos(self, x, y):
1717
self.x = x

ticoban-pyxel.pyxapp

0 Bytes
Binary file not shown.

ticoban.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
from rock import Rock
33
from levels import Levels
44
from player import Player
5-
6-
# Globals
7-
SCREEN_W = 240
8-
SCREEN_H = 136
9-
10-
# Collide values
11-
COL_WALL = 1
12-
COL_ROCK = 2
5+
from globals import SCREEN_H, SCREEN_W, COL_ROCK, COL_WALL
136

147

158
def centerText(text, posy, color):
@@ -33,9 +26,10 @@ def __init__(self):
3326
# 4: Level complete, 5: Pause
3427
self.game_state = 1
3528
self.cursorMenuPos = 0
29+
self.moves = 0
3630

3731
# self.level = self.levels.levels[0]
38-
pyxel.init(SCREEN_W, SCREEN_H, title='Ticoban', display_scale=3,
32+
pyxel.init(SCREEN_W, SCREEN_H, title='Ticoban', display_scale=2,
3933
capture_scale=3, capture_sec=20)
4034
pyxel.load('assets.pyxres')
4135

@@ -45,8 +39,8 @@ def getPlayerRock(self):
4539
w = self.curLevel['width']
4640
h = self.curLevel['height']
4741

48-
self.start_x = pyxel.floor(((30 - w) / 2) - 1)
49-
self.start_y = pyxel.floor(((17 - h) / 2) - 1)
42+
self.start_x = pyxel.floor(((30 - w) / 2) + 1)
43+
self.start_y = pyxel.floor(((22 - h) / 2))
5044

5145
tile_x = self.start_x
5246
tile_y = self.start_y
@@ -236,7 +230,7 @@ def draw(self):
236230
if self.game_state == 1 or self.game_state == 2:
237231
pyxel.bltm(0, 0, 0, 0, 0, SCREEN_W, SCREEN_H)
238232
centerText('Press A (Z key) to start.', 72, 12)
239-
centerText('(c) 2020 - 2024 Alfonso Saavedra "Son Link"', 120, 12)
233+
centerText('(c) 2020 - 2024 Alfonso Saavedra "Son Link"', SCREEN_H - 16, 12)
240234

241235
if self.game_state == 2:
242236
centerText('Press UP or DOWN to select file.', 80, 12)
@@ -248,11 +242,17 @@ def draw(self):
248242
self.game_state == 5
249243
):
250244
pyxel.bltm(0, 0, 1, 0, 0, SCREEN_W, SCREEN_H)
245+
pyxel.tilemaps[1].load(0, 0, 'ticoban.tmx', 0)
251246
w = self.curLevel['width']
252247
h = self.curLevel['height']
253248

254-
self.start_x = pyxel.floor(((30 - w) / 2) - 1)
255-
self.start_y = pyxel.floor(((17 - h) / 2) - 1)
249+
# Show movements and map's name
250+
pyxel.rect(0, 0, SCREEN_W, 8, 15)
251+
pyxel.text(8, 1, f"Map: {self.curLevel['title']}", 12)
252+
pyxel.text(SCREEN_W - 48, 1, f'Moves: {self.moves:03}', 12)
253+
254+
self.start_x = pyxel.floor(((30 - w) / 2) + 1)
255+
self.start_y = pyxel.floor(((22 - h) / 2))
256256

257257
tile_x = self.start_x
258258
tile_y = self.start_y
@@ -261,16 +261,16 @@ def draw(self):
261261
draw_floor = False
262262
for char in line:
263263
if char == '#':
264-
pyxel.tilemap(1).pset(tile_x, tile_y, (7, 1))
264+
pyxel.tilemaps[1].pset(tile_x, tile_y, (7, 1))
265265
draw_floor = True
266266
elif char == '.' or char == '*':
267-
pyxel.tilemap(1).pset(tile_x, tile_y, (4, 0))
267+
pyxel.tilemaps[1].pset(tile_x, tile_y, (4, 0))
268268
else:
269269
if char == '':
270270
draw_floor = False
271271

272272
if draw_floor:
273-
pyxel.tilemap(1).pset(tile_x, tile_y, (3, 0))
273+
pyxel.tilemaps[1].pset(tile_x, tile_y, (3, 0))
274274

275275
tile_x += 1
276276

@@ -327,12 +327,14 @@ def collide_map(self, obj, aim):
327327
x1 = x
328328
y1 = y + 1
329329

330-
tile_x, tile_y = pyxel.tilemap(1).pget(x1, y1)
330+
tile_x, tile_y = pyxel.tilemaps[1].pget(x1, y1)
331331
if tile_x == 7 and tile_y == 1:
332332
return (COL_WALL, x1, y1)
333-
elif tile_x == 1 and tile_y == 0:
333+
334+
if tile_x == 1 and tile_y == 0:
334335
return (COL_ROCK, x1, y1)
335336

337+
self.moves += 1
336338
return (False, x1, y1)
337339

338340
def compLevelComplete(self):
@@ -351,15 +353,15 @@ def clearMap(self):
351353
w = self.curLevel['width']
352354
h = self.curLevel['height']
353355

354-
self.start_x = pyxel.floor(((30 - w) / 2) - 1)
355-
self.start_y = pyxel.floor(((17 - h) / 2) - 1)
356+
self.start_x = pyxel.floor(((30 - w) / 2) + 1)
357+
self.start_y = pyxel.floor(((22 - h) / 2))
356358

357359
tile_x = self.start_x
358360
tile_y = self.start_y
359361

360362
for line in self.curLevel['lines']:
361363
for char in line:
362-
pyxel.tilemap(1).pset(tile_x, tile_y, (0, 0))
364+
pyxel.tilemaps[1].pset(tile_x, tile_y, (0, 0))
363365
tile_x += 1
364366

365367
tile_x = self.start_x

ticoban.tmx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="23" tilewidth="8" tileheight="8" infinite="0" nextlayerid="2" nextobjectid="1">
3+
<tileset firstgid="1" name="pyxel-image0" tilewidth="8" tileheight="8" tilecount="1024" columns="32">
4+
<image source="pyxel-image0.png" width="256" height="256"/>
5+
</tileset>
6+
<layer id="1" name="bg" width="30" height="23">
7+
<data encoding="csv">
8+
43,43,43,43,43,43,43,46,43,45,43,43,42,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,
9+
43,42,43,43,44,44,43,46,46,45,43,43,42,43,45,43,44,44,45,45,43,46,43,43,43,43,43,43,43,44,
10+
43,43,43,43,43,44,44,43,43,43,43,42,46,43,45,43,43,44,43,43,43,46,43,45,44,43,42,43,43,44,
11+
43,45,43,42,43,43,43,43,42,43,43,42,43,45,45,43,43,43,43,42,42,42,43,45,44,44,43,46,46,44,
12+
43,45,45,42,42,43,43,43,42,43,43,43,43,45,43,43,43,43,43,43,43,43,43,43,43,44,44,43,43,44,
13+
43,45,43,44,44,43,43,43,43,43,43,43,43,43,42,43,43,44,44,43,43,46,43,43,43,43,43,44,43,43,
14+
46,46,43,44,44,44,44,44,44,44,43,42,46,43,43,45,43,43,44,44,43,43,46,43,42,43,43,44,43,43,
15+
43,46,43,43,43,43,42,42,43,43,43,43,42,43,43,45,43,43,43,44,44,43,46,46,43,43,43,44,43,43,
16+
43,43,42,43,43,43,42,43,43,43,43,43,43,43,43,45,43,43,42,43,43,43,43,43,43,43,43,42,43,43,
17+
43,42,42,43,43,43,43,46,46,42,42,43,43,43,44,43,43,43,42,42,43,45,45,43,43,43,43,43,43,43,
18+
43,42,43,45,45,43,43,43,43,46,43,43,43,44,44,42,43,43,43,42,43,45,43,42,42,43,43,43,43,43,
19+
43,42,43,45,43,42,43,43,43,42,42,43,43,44,43,43,43,43,43,43,43,43,43,43,43,46,46,43,42,43,
20+
43,42,43,43,43,43,43,43,43,43,42,43,43,43,43,43,43,46,43,43,43,43,46,44,43,46,43,43,42,43,
21+
43,43,43,45,43,43,44,43,43,43,43,43,43,42,43,43,43,46,46,43,43,43,46,44,43,43,43,43,43,43,
22+
43,43,45,45,43,43,44,43,43,45,43,43,45,45,43,44,43,43,42,43,43,43,43,44,44,42,46,43,43,43,
23+
43,43,43,43,43,43,43,44,43,43,45,43,42,42,43,44,43,43,42,43,42,43,43,43,44,43,46,46,44,44,
24+
43,43,44,42,44,44,43,44,44,43,43,43,43,42,42,43,44,43,43,43,42,43,43,43,44,43,44,46,44,43,
25+
43,44,44,43,43,44,43,43,44,43,43,46,43,43,43,43,43,43,43,43,42,43,43,43,44,43,43,43,43,43,
26+
43,44,43,43,42,42,43,43,44,44,43,46,44,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,
27+
44,44,43,43,42,43,43,43,43,44,43,43,44,44,43,43,43,43,45,43,43,43,45,43,43,42,42,43,45,46,
28+
42,42,43,43,42,42,43,43,43,44,44,43,43,44,44,44,46,43,42,42,43,45,45,46,46,43,43,43,43,43,
29+
43,43,43,43,43,42,43,43,43,43,42,42,43,43,43,46,46,43,43,43,43,43,43,43,43,43,42,42,42,43,
30+
43,46,46,46,46,43,43,43,43,43,43,43,43,43,43,46,43,43,43,43,43,42,43,43,43,43,43,43,43,43
31+
</data>
32+
</layer>
33+
</map>

ticoban.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tileset version="1.10" tiledversion="1.11.0" name="pyxel-image0" tilewidth="8" tileheight="8" tilecount="1024" columns="32">
3+
<image source="pyxel-image0.png" width="256" height="256"/>
4+
</tileset>

0 commit comments

Comments
 (0)