0

i am trying to make a Python "Sokoban" game using Pygame, i am having some trouble when it actually comes down to moving my player with Key_UP/Key_Down etc functions, i think i have the idea down but my code is not working because i am not too familiar with Pygame itself.

Any help would be much appreciated! :)

def moveSobRight():
    x = maze.getCharAtPos(sob.getRow(), sob.getCol() + 1)
    y = maze.getCharAtPos(sob.getRow(), sob.getCol() + 2)
    print "x/y init works"
    if x == "#":
        print "You have hit a wall, you cannot move!"
    elif x == " ":
        print "This is a space!"
        sob.moveRight()
        maze.placeSob(sob.getChar(), sob.getRow(), sob.getCol())
        maze.clearAtPos(sob.getRow(), sob.getCol()-1)
    elif (x == "@" and y == " "):
        print "You have collided with a sprout, the sprout will move away now"
        crate.pushboxright()
        maze.placeCrate(crate.getRow(), crate.getcol())
        sob.moveRight()
        maze.placeSob(sob.getChar(), sob.getRow(), sob.getCol())
        maze.clearAtPos(sob.getRow(), sob.getCol()-1)
    else:
        pass
cmd
  • 5,754
  • 16
  • 30
Jamie Law
  • 13
  • 4
  • 1
    Not working how? Is the method called? Do you get an exception? Is it now moving? Does the movement not look good? In the classical [Sokoban file format](http://www.sokobano.de/wiki/index.php?title=Level_format), isn't `@` the symbol for the player? Did you mean `x == "$" and y == " "`? – tobias_k Nov 24 '15 at 17:22
  • Also, given that you will likely have four versions of this method, I suggest changing it to `def move(dx, dy)`, with `dx` and `dy` being 0, +1, or -1 depending on where to go. – tobias_k Nov 24 '15 at 17:29
  • The player is only moving to the right, but no others. The "#" char is the wall, the "@" is the crate that the player has to move, and the "$" is the player, even though you can't see it – Jamie Law Nov 24 '15 at 17:39
  • I dont see anything in what you have posted that looks "wrong", but you have allot of custom code you are not exposing. Also it looks like you have made things more complicated then they need to be. – cmd Nov 24 '15 at 18:03
  • How can i simplify things :)? – Jamie Law Nov 24 '15 at 20:27
  • The player isn't actually moving up, left or down – Jamie Law Nov 24 '15 at 21:31

0 Answers0