0

so I'm trying to make a game with pygame (Rogue-like type) and I have an issue... I cant make my character starts at the "start" square I can only make him start at 0,0 . My Level is generated with the help of a .txt file where w = wall 0 = path s = start and g = goal

So here is my code they are both in different classes (Level , Character). I tried to get the "start" coordinates with (start_rect = start.get_rect() ) but I wasnt able to use it on the other class , Maybe i just misused it ... So any help would be welcome

part of the Level code

    wall = pygame.image.load(block).convert()
    start = pygame.image.load(sstart).convert()
    goal = pygame.image.load(sgoal).convert_alpha()    
    num_line = 0       
    for line in self.struct:
          num_sqr = 0
          for sprite in line :
            x = num_sqr * size_sprite
            y = num_line * size_sprite
            if sprite == "w":
                window.blit(wall, (x,y))
            elif sprite == "s":
                window.blit(start, (x,y))
            elif sprite == "g":
                window.blit(goal, (x,y))

part of the Character code :

    self.sqrx = 0
    self.sqry = 0
    self.x = 0
    self.y = 0

And sorry for any English mistakes its not my first language .

Haza
  • 97
  • 1
  • 2
  • 10
  • Any errors/traceback ?Where is your get_rect() method ? – iFlo Dec 16 '16 at 12:46
  • 2
    `get_rect()` will always have the coordinates (0, 0). What it does is creating a Rect object the same size of a Surface (image) but since images doesn't have a position, neither does the newly created Rect. You have to specify the coordinates yourself. Preferably `get_rect(topleft=(x, y)` where (x, y) is the coordinates of the start position. – Ted Klein Bergman Dec 16 '16 at 12:47
  • So what can i do to get the coordinate of my start image if get_rect doesnt ? – Haza Dec 16 '16 at 12:58
  • 1
    as said @TedKleinBergman - you have to set start position manually `start_rect.topleft = (x, y)` - you can do it in `elif sprite == "s":` Or you should find `"s"` in text data before you draw level. – furas Dec 16 '16 at 13:20

0 Answers0