Sprite-based text rendering

This commit is contained in:
theo@manjaro 2021-11-22 09:56:55 +01:00
parent a0e74238a3
commit f14339a6e7
6 changed files with 150 additions and 126 deletions

BIN
gamedata/assets/fontmap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -30,6 +30,7 @@ class Game():
self.sprite_lib = self.init_assets("gamedata/assets/",load_image) # Dico qui contient chaques images du dossier assets
pygame.display.set_icon(self.sprite_lib["icon.png"])
self.sound_lib = self.init_assets("gamedata/sounds/",pygame.mixer.Sound) # Pareil, mais pour les musiques / sons
self.fontmap = self.sprite_lib["fontmap.png"]
# Chargement des niveaux
def loadlvldata(mapfolder):
@ -282,3 +283,21 @@ class Game():
self.globals["camerah"] = newh
self.globals["tempsubsurface"] = pygame.Surface((neww,newh))
def getchar(self,char,width=9,height=9):
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@\"#&()*:;?!abcdefghijklmnopqrstuvwxyz"
charsperline = self.fontmap.get_width()//width
result = None
if char in chars:
index = chars.index(char)
line = index//charsperline
column = index%charsperline
result = self.pygame.Surface((width,height),flags=self.pygame.SRCALPHA)
result.blit(self.fontmap,[-width*column,-height*line])
return result
def getchars(self,chars):
result = []
for i in chars:
result.append(self.getchar(i))
return result

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -3357,6 +3357,9 @@
[-1],
[-1],
[-1],
[6, 6],
[7, 6],
[8, 6],
[-1],
[-1],
[-1],
@ -3388,6 +3391,92 @@
[-1],
[-1],
[-1],
[9, 8],
[-1],
[9, 8],
[-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],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 7],
[7, 7],
[8, 7],
[-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],
@ -3420,6 +3509,13 @@
[-1],
[-1],
[-1],
[10, 6],
[9, 6],
[10, 6],
[9, 6],
[10, 6],
[9, 6],
[10, 6],
[-1],
[-1],
[-1],
@ -3430,6 +3526,22 @@
[-1],
[-1],
[-1],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[9, 8],
[6, 8],
[7, 8],
[8, 8],
[9, 8],
[15, 0],
[14, 0],
[15, 0],
[-1],
[-1],
[-1],
@ -3438,6 +3550,9 @@
[-1],
[-1],
[-1],
[15, 0],
[14, 0],
[15, 0],
[-1],
[-1],
[-1],
@ -3464,33 +3579,7 @@
[-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],
[9, 8],
[-1],
[-1],
[-1],
@ -3509,102 +3598,13 @@
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[14, 0],
[15, 0],
[-1],
[-1],
[-1],
[-1],
[-1],
[15, 0],
[14, 0],
[15, 0],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[15, 0],
[14, 0],
[15, 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],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[10, 7],
[9, 7],
[10, 7],
[9, 7],
[10, 7],
[9, 7],
[10, 7],
[-1],
[-1],
[-1],
@ -4928,12 +4928,12 @@
"name": "WaterChange",
"id": 40,
"_eid": "48957583",
"x": 208,
"y": 208,
"x": 64,
"y": 176,
"originX": 0,
"originY": 0,
"nodes": [
{"x": 240, "y": 240}
{"x": 96, "y": 240}
],
"values": {"Speed": 1}
}

View File

@ -15,6 +15,7 @@ class Player(Movable):
self.spritefalling = game.sprite_lib["player/falling.png"] # Descending
self.spritehurt = game.sprite_lib["player/hurt.png"] # Being hurted
self.spritelanding = game.sprite_lib["player/landing.png"]
self.testsprites = self.game.getchars("Test")
self.landingtimer = 0
self.maxlandtime = 0.15
self.spriteindex = 0
@ -276,3 +277,7 @@ class Player(Movable):
flipy = self.fastfall<0
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,flipy)
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])
for i,spr in enumerate(self.testsprites):
if spr:
self.game.window.blit(spr,[self.rect[0]+i*9-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])