salut, j'aimerais crée un petit jeu de plateforme en utilisant le tiles mapping que j'ai plus trouver en C.

j'ai donc adapté le code pour l'utiliser avec pygame mais cela fonctionne a moitié... La fenêtre s'ouvre, les tiles s'affichent correctement mais quand j'utilise les flèches pour bouger, les tiles tout en bas et tout a gauche font vraiment n’importe quoi (voir les images a la suite) . c'est assez compliqué d'expliquer donc je met les fichiers sur mega pour que vous puissiez tester vous même. source ici

les images pour montrer le problème (j'ai mis les trait noir avec paint pour montrer ou se situe le problème) :
Nom : debut.PNG
Affichages : 1206
Taille : 13,1 KoNom : nimp.PNG
Affichages : 937
Taille : 15,8 Ko

J'ai déjà longuement cherché une réponse mais je n'ai absolument rien trouvé.

Si vous avez la flemme de telecharger la source je met le code source et l'image dans ce post.

L'image pour les tiles : Nom : tiles.png
Affichages : 850
Taille : 8,5 Ko

le code du fichier level.py :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pygame
class Level():
    def __init__(self) :
        self.move_speed = 5
        self.tile_width = 24
        self.tile_height = 16
        self.nb_tilesx_screen = 15
        self.nb_tilesy_screen = 13
        self.nb_tilesx_world = 75
        self.nb_tilesy_world = 17
        self.screen_width = self.tile_width*self.nb_tilesx_screen
        self.screen_height = self.tile_height*self.nb_tilesy_screen
        self.xscroll = 0
        self.yscroll = (self.nb_tilesy_world-self.nb_tilesy_screen)*self.tile_height
        self.level = []
        self.tiles = pygame.image.load('pictures\\tiles.png')
        self.tileset = {'0' : [self.tiles.subsurface((0,0,24,16)),'empty','sky'],
                        '1' : [self.tiles.subsurface((24,0,24,16)),'full','treat'],
                        '2' : [self.tiles.subsurface((48,0,24,16)),'full','brick'],
                        '3' : [self.tiles.subsurface((72,0,24,16)),'full','tubetop1'],
                        '4' : [self.tiles.subsurface((96,0,24,16)),'full','tubetop2'],
                        '5' : [self.tiles.subsurface((120,0,24,16)),'full','tubebody1'],
                        '6' : [self.tiles.subsurface((144,0,24,16)),'full','tubebody2'],
                        '7' : [self.tiles.subsurface((168,0,24,16)),'full','block']}
 
 
    def load_map(self,level):
        with open(level,'r') as level :
            m = []
            item = ''
            for line in level :
                line_level = []
                for col in line :
                    if col != '\n' and col != ' ' :
                        item += col
                    else :
                        line_level.append(item)
                        item = ''
                m.append(line_level)
            self.level = m
 
 
 
    def display_map(self,screen):
        xmin = (self.xscroll/self.tile_width)-1
        xmax = (self.xscroll+self.screen_width)/self.tile_width
        ymin = (self.yscroll/self.tile_height)-1
        ymax = (self.yscroll+self.screen_height)/self.tile_height
 
        for i in range(ymin,ymax) :
            for j in range(xmin,xmax) :
                x = j*self.tile_width-self.xscroll
                y = i*self.tile_height-self.yscroll
                item = self.level[i][j]
                screen.blit(self.tileset[item][0],(x,y))
 
 
        pygame.display.flip()
 
 
    def screen_size(self):
        return (self.tile_width*self.nb_tilesx_screen,self.tile_height*self.nb_tilesy_screen)
 
    def move(self,direction):
        xscroll = self.xscroll
        yscroll = self.yscroll
        if direction == 'right' :
            xscroll += self.move_speed
            if xscroll > self.nb_tilesx_world*self.tile_width-self.screen_width-1 :
                self.xscroll = self.nb_tilesx_world*self.tile_width-self.screen_width-1
            else :
                self.xscroll = xscroll
 
        elif direction == 'left' :
            xscroll -= self.move_speed
            if xscroll < 0:
                self.xscroll = 0
            else :
                self.xscroll = xscroll
 
        elif direction == 'up' :
            yscroll -= self.move_speed
            if yscroll < 0 :
                self.yscroll = 0
            else :
                self.yscroll = yscroll
 
        elif direction == 'down' :
            yscroll += self.move_speed
            if yscroll > self.nb_tilesy_world*self.tile_height-self.screen_height-1 :
                self.yscroll = self.nb_tilesy_world*self.tile_height-self.screen_height-1
            else :
                self.yscroll = yscroll
Le code principal :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import pygame
from level import *
 
pygame.init()
horloge = pygame.time.Clock()
level = Level()
level.load_map('level.txt')
screen = pygame.display.set_mode(level.screen_size())
main = 1
direction = ''
while main :
    horloge.tick(30)
    for event in pygame.event.get() :
        if event.type == pygame.QUIT :
            main = 0
        if event.type == pygame.KEYDOWN :
            if event.key == pygame.K_RIGHT :
                direction = 'right'
            elif event.key == pygame.K_LEFT :
                direction = 'left'
            elif event.key == pygame.K_UP :
                direction = 'up'
            elif event.key == pygame.K_DOWN :
                direction = 'down'
 
        if event.type == pygame.KEYUP :
            if event.key == pygame.K_RIGHT and direction == 'right' :
                direction = ''
            elif event.key == pygame.K_LEFT and direction == 'left' :
                direction == ''
            elif event.key == pygame.K_UP and direction == 'up' :
                direction == ''
            elif event.key == pygame.K_DOWN and direction == 'down' :
                direction == ''
 
    level.move(direction)
    level.display_map(screen)
pygame.quit()
et enfin le fichier texte qui contient la structure du niveau (a coller dans un fichier nommé level.txt) :

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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