A little background: I'm working on a VN/adventure game hybrid and trying to write a fairly simple movement engine for top-down exploration. I'm using pygame keyboard events to handle the movement. I wrote the engine in pygame (outside of renpy) originally, then learned from the game designer that I needed the map to be displayable behind the ren'py screens. I wrote a very silly roundabout system of return methods to get around this while calling the original movement engine script through renpygame, then realized that I would much rather implement it properly in ren'py than import it like that, since I want to integrate it more closely with the script.
Anyhow, I've tracked down that somehow the freeze is occurring during this loop.
Code: Select all
#main game loop
while not goOn:
ui.clear() # clear layer to start
# handle events
for event in pygame.event.get():
if (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1) or (event.type == KEYDOWN and event.key == K_SPACE):
interactSprite = self.checkInteraction() # checks if there are any sprites in reach that the player can interact with
if interactSprite != None:
investigateReturn = interactSprite.message # sprite has a "message" if it can be interacted with
if investigateReturn != None:
goOn = investigateReturn() # return True if we want to close the movement engine
# handle player movement
else:
self.getMoveDirKeys(event) # method to collect keydown and keyup events and update moveDir appropriately
# move the player if there are no collisions in the direction given
moveDirTrans = translateDirect(self.moveDir) # makes moveDir more readable for the program
newpos = self.calculateNewPos() # calculates player's theoretical new position
if (moveDirTrans is not STILL) and (self.inBounds(newpos)): # ensures that the player is inside the map bounds
collide = checkCollision(newpos) # looks to see if the player will collide with any sprite obstacles
if collide:
if sprite.isDoor: # if you collide with a door, walk through it. doors should be set as "obstacles" though they can be walked through obviously
self.player.move(newpos) # make it appear as if the player is walking into the door as it implements stuff
self.player.updateFacing(moveDirTrans)
investigateReturn = sprite.message # this isn't fully implemented, but you can walk through a door to automatically call their method
goOn = investigateReturn
else:
self.player.move(newpos)
self.player.updateFacing(moveDirTrans)
collide = False # reset collision flag for next game loop
self.showMap(self.player.loc, self.player.facing) # finally display updated mapSome of the other methods in here are fairly simple and hopefully are self-explanatory. I can post the code snippets for those if you're curious.
I'm hoping someone has an idea of what could be going on here, because I'm rather baffled. Sorry for such a long post!
