Hey, I recognize this game. The email address threw me off a little.
It's good to see activity on the mailing list. :)
I noticed one problem. It isn't related to your question, but I
think you'll want to solve it. Not sure if this was added by you, or
a bug that I later fixed.
gummworld2/toolkit.py:
import urllib.request, urllib.parse, urllib.error
(These raise an exception in Python 2.7.)
To get the avatar behavior that you seem to want, I did the
following. These changes don't check the bounds of the world. I just
wanted to keep it simple so it is easy to understand.
1. In gameEngine.__init__:
change: self.step = None
to: self.step = Vec2d(0, 0)
2. Changes to gameEngine.update_keyboard_movement (see the changes
marked "Gummchange" here):
#keyboard movement between cells
def update_keyboard_movement(self):
# Gummchange
if self.move_x == 0 and self.move_y == 0:
return
print('CALCULATING MOVE_TO')
# end Gummchange
# Current position.
camera = State.camera
wx, wy = camera.target.position
cell_id = self.world.index_at(wx,wy)
row,col = self.world.get_cell_grid(cell_id)
#print("actual position: ",wx,wy," inside the cell:
",cell_id," row and col: ",row,col)
#new situation of new cell
if(row == 0 and self.move_y < 0):
new_row = row
else:
new_row = row + self.move_y
if(col == 0 and self.move_x < 0):
new_col = col
else:
new_col = col + self.move_x
#does it exist?
cell = self.world.get_cell_by_grid(new_col,new_row)
if(cell == None):
#doesnt exist
return
else:
cell_id = self.world.index(cell)
self.new_x,self.new_y =
self.world.get_cell_pos(cell_id)
row,col = self.world.get_cell_grid(cell_id)
self.new_x += self.cell_size/2
self.new_y += self.cell_size/2
# Gummchange
self.move_to = Vec2d(self.new_x, self.new_y)
self.step = Vec2d(self.move_x, self.move_y)
#print("a la position: ",self.new_x,self.new_y,"
inside the cell: ",cell_id," row and col: ",row,col)
# self.step.clear()
# end Gummchange
3. Rename gameEngine.update_camera_position (or comment the method
to save your original code).
4. Add the following update_camera_position method:
# Gummchange
def update_camera_position(self):
# if move_to, then the camera needs to keep
stepping towards the destination tile.
if self.move_to:
print('STEP pos{} -> dest{} by
step{}'.format(
tuple(self.camera.position),
tuple(self.move_to), tuple(self.step)))
camx, camy = self.camera.position
stepx, stepy = self.step
# Check if camx has arrived at the move_to
point. If it has set stepx to 0.
if camx == self.move_to.x:
stepx = 0
# Check if camy has arrived at the move_to
point. If it has set stepy to 0.
if camy == self.move_to.y:
stepy = 0
# If steps remain on the x or y axis, update
the camera position. Else, the
# camera/avatar is done moving, so set
self.move_to = None.
if stepx or stepy:
self.camera.position += stepx, stepy
else:
self.move_to = None
The behavior is that when a key is pressed the avatar wants to move
to the next tile. Then each update takes a small step towards the
next tile until the avatar's position == the destination.
Hope this helps.
Gumm