movement help

i try make simple move like mario game. this is my simple class.can someone help me develop and improve the script?

class Panda(DirectObject):
    
    def __init__(self):
        print "dupa"
        self.skala=0.5
        self.x=0
        self.y=0
        self.z=0
        self.szybkosc=1
        
        self.panda = Actor('panda.egg.pz', {
        'chodzi':'panda-walk.egg.pz'
        })
        self.panda.setScale(self.skala)
        self.panda.setPos(self.x,self.y,self.z)
        self.panda.setHpr(180,0,0)
        self.panda.reparentTo(render)
        
        
        
        #kamera
        base.disableMouse()
        
        camera.setPos(self.panda.getX()+40,self.panda.getY(),0)
        
        camera.lookAt(self.panda) 
        print camera.getX()
        print camera.getY()
        print camera.getZ()
        #guziki
        self.lista_guzikow={"a" : False,
            "s" : False,
            "d" : False,
            "w" : False}
        self.accept("w", self.odbior, ["w", True])
        self.accept("s", self.odbior, ["s", True])
        self.accept("a", self.odbior, ["a", True])
        self.accept("d", self.odbior, ["d", True])
        self.accept("w-up", self.odbior, ["w", False])
        self.accept("s-up", self.odbior, ["s", False])
        self.accept("a-up", self.odbior, ["a", False])
        self.accept("d-up", self.odbior, ["d", False])
        
        
        
        self.pandaInterval2=self.panda.posInterval(1,Point3(0, 3, 0))
    
        '''
        self.accept('escape', sys.exit)
        self.accept('a-repeat', self.lewo)
        self.accept('d-repeat', self.prawo)
        '''
        
    def odbior(self, key, wartosc):
        self.lista_guzikow[key] = wartosc
        dt = globalClock.getDt()
        move=70*dt
        if(self.lista_guzikow["a"] == True):
            a=self.panda.getY()
            print a
            self.pandaInterval=self.panda.posInterval(1,Point3(0, -move, 0))
            self.pandaInterval.start()
            return
            print a

        if(self.lista_guzikow["d"] == True):
            a=self.panda.getY()
            print a
            #self.panda.setY(self.panda, 20 * dt)
            self.pandaInterval2.start()
            print a

I think the reason nobody’s responding is due to several issues:

  • Is there some sort of problem with this code? You weren’t very clear on this.
  • Your code doesn’t have any comments. Comments help other programmers understand what you’re trying to do.

I think when you clear up the above issues, everyone will be able to help you with your problem/question.

It’ll work better if you separate the method that responds to key presses from the method that does motion. leave this function just like this:

    def odbior(self, key, wartosc):
        self.lista_guzikow[key] = wartosc 

then have a different one with the movement code:

    def update(self,task):
        dt = globalClock.getDt()
        move=70*dt
        if self.lista_guzikow["a"]:
            self.panda.setY(self.panda,-move)  
        if self.lista_guzikow["d"]:
            self.panda.setY(self.panda,move)   
        return task.cont

and make sure to start the update task using the task manager.