Re: Help with movement on Map in Python

Jaws seems to be a recuring problem for a lot of things, i'm not sure if PyHook will help that or not. For a better response rate though you can set up a pre-trigger with the existing timer mechanism. This would give you an instant reaction, then count out until the next reaction as you hold the key:

#initialize move timer
move_timer = pygame.time.get_ticks() + 100
self.keyPress = {"left": False, "right": False, "up": False, "down": False, "time": 0, "start left":False, "start right":False, "start up":False, "start down":False}


#update state
    def update(self):
        if self.keyPress['left'] == True:
        #apply first move immediately
            if self.keyPress['start left'] == False:
                move_timer = pygame.time.get_ticks() + 100
                self.keyPress['start left'] = True
        #move left
                if self.currentPosition[1]-1 >= 0:
                    if self.mapList[self.currentPosition[0]][self.currentPosition[1]-1] == "w":
                        soundHandler.playSound(self.wallSound, 0.7, 0)
                    elif self.mapList[self.currentPosition[0]][self.currentPosition[1]-1] == "p":
                        self.currentPosition[1] -= 1
                        soundHandler.playSound(self.footstepSound, 1, 0)
                else:
                    soundHandler.playSound(self.wallSound, 0.7, 0)
        #apply further moves after X time
            elif pygame.time.get_ticks() >= move_timer:
                move_timer = pygame.time.get_ticks() + 100 # 100MS of delay to move again
        #move left
                if self.currentPosition[1]-1 >= 0:
                    if self.mapList[self.currentPosition[0]][self.currentPosition[1]-1] == "w":
                        soundHandler.playSound(self.wallSound, 0.7, 0)
                    elif self.mapList[self.currentPosition[0]][self.currentPosition[1]-1] == "p":
                        self.currentPosition[1] -= 1
                        soundHandler.playSound(self.footstepSound, 1, 0)
                else:
                    soundHandler.playSound(self.wallSound, 0.7, 0)

    #if left isn't pressed anymore, reset the quick start trigger
        elif self.keyPress['start left'] == True:
            self.keyPress['start left'] = False
_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : majno via Audiogames-reflector

Reply via email to