im supposed to do a maze and have a character moving on it.
for loops is used to create the maze.
the thing is how am i going to tell it to move one tile at a time each time a btn is pressed?
Try something like this:
def __init__(self):
#...
self.tilesize=4
self.accept("w",self.move,[0,1])
self.accept("a",self.move,[-1,0])
self.accept("s",self.move,[0,-1])
self.accept("d",self.move,[1,0])
#..
def move(self,x,y):
self.character.setPos(self.character.getPos() + Point3(x*self.tilesize,y*self.tilesize,0))
Replace self.tilesize with the size of your tiles.
how do you determine the tilesize?
how do u measure distance in panda?
1 you set that
2 in panda units
btw thanks for helping me on it.
when i tried to add collision to it, it doesn’t move.
here is the script i used
def move(self,x,y):
self.mother.setPos(self.mother.getPos() + Point3(xself.tilesize,yself.tilesize,0))
if ((self.maze.mazeList[self.maze.row][self.maze.col])==0):
self.motherZPos=0
self.mother.setPos(self.motherXPos, self.motherYPos,self.motherZPos)
self.mother.setHpr(self.motherZRot,0,0)
wat can be the problem? my maze is on ZPos=1 so if the mother dropped down, it cannot come back up
def move(self,x,y):
so its the move function relative to mother? or just move any where like a teleport … assuming its teleport
self.mother.setPos(self.mother.getPos() + Point3(x*self.tilesize,y*self.tilesize,0))
why are we setting mothers position before we know if we can move there?
if ((self.maze.mazeList[self.maze.row][self.maze.col])==0):
where did self.maze.row self.maze.col come from??? We have x and y and mother’s position but that looks like the size of the maze … should be more like:
if self.maze.mazeList[x][y]:
==0 is implisit in python and extra () are not needed
self.motherZPos=0
why are we setting this? If we never set mothers postion to any thing but zero … its a tiled map why set it back to 0 it always 0 as it is
self.mother.setPos(self.motherXPos, self.motherYPos,self.motherZPos)
ahah? where did self.motherYPos,self.motherZPos come form should it be x and y?
self.mother.setHpr(self.motherZRot,0,0)
why we rotate mother in random direction? Shouln’t it be at least facing a way from the position we teleported from?
i guess you want some thing like this
def move(self,x,y):
if self.maze.mazeList[x][y]:
self.mother.setPos(x*self.tilesize,y*self.tilesize,0)