Re: Help with movement on Map in Python
Re: Help with movement on Map in Python Try to add a python.jkm each time the game is initialized and delete that python.jkm when the game close. only with it jaws will not interfere with arrows keys.The python.jkm should contain: the leftarrow, rightarrow, uparrow and downarrow set to = so jaws will ignore those keys. also you can use others keys instead of arrows. URL: http://forum.audiogames.net/viewtopic.php?pid=271348#p271348 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
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 URL: http://forum.audiogames.net/viewtopic.php?pid=268659#p268659 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
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: 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 URL: http://forum.audiogames.net/viewtopic.php?pid=268659#p268659 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
2016-07-18
Thread
AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
Re: Help with movement on Map in Python So I figured out part of the issue I was having with map. So it I use jaws and it seems that Jaws was intercepting my keyboard commands for the arrow keys. I had this problem once before, but once I got my code fixed, pygame was playing nicely with Jaws, but with the way this code is set up, it seems that Jaws does not like this, again. I was looking into some solutions to this problem, and I found a library called pyHook that might solve my problem with Jaws for good, but I am unsure how to implement the library in my map. I found some examples, but I could not find anything that made sense to me working with pygame. Is anyone familiar with this library? Do you think it would solve my keyboard hooking problem with Jaws? Also, I wanted to see if there is a way to change the code here so it is a little more responsive, I have played with it with NVDA, but because the counter is set up before the key is pressed there is a delay in action on the map when you press an arrow key , and the if you press the key to quickly the action is not even accomplished. I could change the number so that it responds quicker, but then when you hold down the arrow keys the player moves too quickly across the map. I have tried playing with putting a timer at the end of the update function, but it still seems very clunky. I just started playing an audio game called crazy party, and I was impressed by the keyboard responsiveness. It also works with Jaws. I think it is built in BGT though. I am curious how they were able to get such a responsive keyboard handler working. URL: http://forum.audiogames.net/viewtopic.php?pid=268613#p268613 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python Another way to adjust the speed of updating in myposted example would be to adjust the keyPress["time"] check from 100, to, say 10. def update(self): if self.keyPress["time"] >= 10: self.keyPress["time"] = 0I noticed it was updating very quickly so I must have set the threshold too low, although thggamers solution for using pygame clock ticks for pacing is an equally good approach. I think the implementation for that might look something like this:#initialize move timer move_timer = pygame.time.get_ticks() + 100 #update state def update(self): if pygame.time.get_ticks() >= move_timer: move_timer = pygame.time.get_ticks() + 100 # 100MS of delay to move again #move left if self.keyPress['left'] == True: 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) URL: http://forum.audiogames.net/viewtopic.php?pid=267069#p267069 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
2016-07-06
Thread
AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
Re: Help with movement on Map in Python Thanks thggamer, I found that using pygame.time.wait(10) helped, however I don't understand where you were referring to for inserting the if pygame.time.get_ticks() >= move_timer: # Move code goes here move_timer = pygame.time.get_ticks() + 100 # 100MS of delay to move againpeace of code. Where should I use this? what should I initialize move_timer to,? URL: http://forum.audiogames.net/viewtopic.php?pid=267053#p267053 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python Hello.I think that the problem is that your character is moving everyiteration of the loop.To solve this, you could try something like that inside your movingcode:if pygame.time.get_ticks() >= move_timer: # Move code goes here move_timer = pygame.time.get_ticks() + 100 # 100MS of delay to move againAbout your previous question, you can use the pygame.time.wait functionto make the computer spend less resources while your loop is running,like that: def run(self): while self.exitGame == False: self.mapKeys() pygame.time.wait(10)In this way, when the computer finishes every iteration, it will pause 10ms before going to the next one.I think with these adjustments you can try to use the pygame.event.get()function that returns the events immediately to your program. URL: http://forum.audiogames.net/viewtopic.php?pid=267039#p267039 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python Try setting your event.key to null at the bottom of the loop. URL: http://forum.audiogames.net/viewtopic.php?pid=267019#p267019 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
2016-07-06
Thread
AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
Re: Help with movement on Map in Python That is strange, I have spent the past several hours trying tomake this work, but I can't seem to get it working just right.I am unable to get this event loop working, I changed it back to pygame.event.wait() and I was able to get some results, but I was having some other problems, and I would like to use the event loop so that I can test for other events that I create later. I found that if I press the arrow keys several times for a long period of time, I can get the map to respond, else, nothing. I apologize, the game module I was importing actually had no purpose, I must have forgotten to remove it after some test. I did try running the map as a stand alone module, but got the same result. So after changing my map a lot, I just recopied my code from my last post and I will start from where I was. I just don't know what to do. This looks like it should work, but it is not. I think that it has something to do with the KEYDOWN and KEYUP statements that check for the key state .Using the event loop, I also noticed that my computer seems to be working a lot harder when I use the event loop, that is why I originally switched over to using the pygame.event.wait(). Is there a way to reduce the load on the CPU while using the event loop? URL: http://forum.audiogames.net/viewtopic.php?pid=267018#p267018 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python Hm, I'm not sure what the rest of the code your importing looks like, such as game, menu, and soundHandler. I don't normally use Pygame and don't have accessible_ouput2 installed, but I tinkered with it abit to get it working by opening a window in the MapParser __init__ function and it seems to work alright.class MapParser(object): """Import the data from map.txt and add it to a list to be parced.""" def __init__(self, ): self.mapList = [] self.exitGame = False self.currentPosition = [1,1] # y value, x value self.footstepSound = pygame.mixer.Sound("data/sounds/footstep.ogg") self.wallSound = pygame.mixer.Sound("data/sounds/wall.ogg") self.keyPress = {"left": False, "right": False, "up": False, "down": False, "time": 0} self.screen = pygame.display.set_mode((640,480)) URL: http://forum.audiogames.net/viewtopic.php?pid=266942#p266942 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
2016-07-05
Thread
AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
Re: Help with movement on Map in Python Thanks magurp244, I thought I needed something like that, but I just couldn't think of how to set it up. So I tried it, but I am now unable to move at all. It loads my map and I have no footstep or wall sounds when I press the arrow keys. I would say it is safe to assume that all my sound and conditionals concerning the currentPosition variable are correct because it was working before, and I just copied and pasted the code. So, I have some logic error somewhere in the keyPress dictionary manipulation. I through in a s().output statement to speak out the value of the down arrow keyPress, at the top of the update function and it is returning false even while I am holding down the key. I am not sure if there is some logic error or what, but there is some issue with the dictionary value for the key being pressed not sticking. I actually had a problem similar with my pauseMenuOptions list, I was trying to change the list as an instance variable, but the modifications I would make would not hold for some reason so I declared it as a global variable and it worked. it did not work this time though, I tried declaring the keyPress dictionary as a global, but I am still unable to move. Here is my modified codefrom accessible_output2.outputs.auto import Auto as s import pygame import menu import soundHandler import game pauseMenuOptions = [["Return to Game", "exit"], ["Settings", "exit"], ["Return to main menu", "exit"], ["Quit Game", "exit game"]] class MapParser(object): """Import the data from map.txt and add it to a list to be parced.""" def __init__(self, ): self.mapList = [] self.exitGame = False self.currentPosition = [0, 0] # y value, x value self.footstepSound = pygame.mixer.Sound("data/sounds/footstep.ogg") self.wallSound = pygame.mixer.Sound("data/sounds/wall.ogg") self.keyPress = {"left": False, "right": False, "up": False, "down": False, "time": 0} def playMapMusic(self, music): if music == None: pass else: soundHandler.playMusic(music, 0.03, -1) def exitMap(self): pauseMenuOptions[len(pauseMenuOptions)-2][1] = "exit game" def readMap(self): with open("resources/map1.txt", "r") as mapFile: # loop through the map file and add each row as a sublist for line in mapFile: row = line.split() self.mapList.append(row) def mapKeys(self): pauseMenu = menu.Menu(pauseMenuOptions, "Paused") for event in pygame.event.get(): # set keypress to true if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: soundHandler.pauseAndUnpauseMusic("pause") s().output("paused", interrupt=True) pauseMenu.run() if pauseMenuOptions[len(pauseMenuOptions)-2][1] == "exit game": s().output("returning to main menu") else: s().output("unpaused", interrupt=True) soundHandler.pauseAndUnpauseMusic("unpause") if event.key == pygame.K_RIGHT: self.keyPress["right"] = True elif event.key == pygame.K_LEFT: self.keyPress["left"] = True elif event.key == pygame.K_UP: self.keyPress["up"] = True elif event.key == pygame.K_DOWN: self.keyPress["down"] = True # set key release to false elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: self.keyPress["right"] = False elif event.key == pygame.K_LEFT: self.keyPress["left"] = False elif event.key == pygame.K_UP: self.keyPress["up"] = False elif event.key == pygame.K_DOWN: self.keyPress["down"] = False def update(self): if self.keyPress["time"] >= 100: self.keyPress["time"] = 0 # Moving right if self.keyPress["right"] == True: if self.currentPosition[1]+1 <= len(self.mapList[0])-1: if self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "w": soundHandler.playSound(self.wallSound, 0, 0.7) elif self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "p":
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python I haven't used python, so I don't know if this is correct. I think what you're running into is an issue with your event.key variable.I don't think it's updating after each frame, so when you push up, it sets the key to up, but I'm not sure if it's clearing it or not after it loops back to the top. So it's true every time. HTH. URL: http://forum.audiogames.net/viewtopic.php?pid=266925#p266925 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Help with movement on Map in Python
Re: Help with movement on Map in Python I think the problem may be that your input handling is bottlenecking. Your using "pygame.event.wait()" which handles one element in the event buffer at a time, and then forcing the system to wait between each item in the buffer with time delay. Try this:class MapParser(object): """Import the data from map.txt and add it to a list to be parsed.""" def __init__(self, ): self.mapList = [] self.exitGame = False self.currentPosition = [0, 0] # y value, x value pauseMenuOptions = [["Return to Game", "exit"], ["Settings", "exit"], ["Return to main menu", "exit"], ["Quit Game", exit]] #key input handling dictionary self.keyPress = {'left':False,'right':False,'up':False,'down':False,'time':0} def playMapMusic(self, music): if music == None: pass else: soundHandler.playMusic(music, 0.03, -1) def exitMap(self): pauseMenuOptions[len(pauseMenuOptions)-2][1] = "exit game" def readMap(self): with open("resources/map1.txt", "r") as mapFile: # loop through the map file and add each row as a sublist for line in mapFile: row = line.split() self.mapList.append(row) def mapKeys(self): pauseMenu = menu.Menu(pauseMenuOptions, "Paused") for event in pygame.event.get() #set key press to True if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: soundHandler.pauseAndUnpauseMusic("pause") s().output("paused", interrupt=True) pauseMenu.run() s().output("unpaused", interrupt=True) soundHandler.pauseAndUnpauseMusic("unpause") if event.key == pygame.K_f: s().output(pauseMenuOptions[len(pauseMenuOptions)-2][0]) s().output(pauseMenuOptions[len(pauseMenuOptions)-2][1]) if event.key == pygame.K_RIGHT: self.keyPress['right'] = True elif event.key == pygame.K_LEFT: self.keyPress['left'] = True elif event.key == pygame.K_UP: self.keyPress['up'] = True elif event.key == pygame.K_DOWN: self.keyPress['down'] = True #set key release to False elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: self.keyPress['right'] = False elif event.key == pygame.K_LEFT: self.keyPress['left'] = False elif event.key == pygame.K_UP: self.keyPress['up'] = False elif event.key == pygame.K_DOWN: self.keyPress['down'] = False #update state def update(self): #if X amount of time has passed, update move code if self.keyPress['time'] >= 100: self.keyPress['time'] = 0 #move left if self.keyPress['left'] == True: 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) #move right if self.keyPress['right'] == True: if self.currentPosition[1]+1 <= len(self.mapList[0])-1: if self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "w": soundHandler.playSound(self.wallSound, 0, 0.7) elif self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "p": self.currentPosition[1] += 1 soundHandler.playSound(self.footstepSound, 0, 1) else: soundHandler.playSound(self.wallSound, 0, 0.7) #move up if self.keyPress['up'] == True: if self.currentPosition[0]-1 >= 0: if self.mapList[self.currentPosition[0]-1][self.currentPosition[1]] == "w": soundHandler.playSound(self.wallSound, 0.5, 0.5)