[Tutor] Newbie: game problem

Kemal Taskin kemal.taskin@pandora.be
07 Jul 2002 22:57:05 +0200


Hi list
(my English is not perfect, so sorry for that)

I'm a newbie and I'm writing now a game called robots.  You're being
chased by robots.  They are armed, and if a robot manages to catch you
you're dead.  The robots are always moving towards you, even if there's
something in the way.

Now I'm trying to write the code used to move the player. I use the
numeric keypad of the keyboard to allow the player to move. To write
this game I use the Livewires package. ( see
www.livewires.org.uk/python)

This is my code for the moment:
------------------------------
#!/usr/bin/python
from livewires import *
begin_graphics()
allow_moveables()
def place_player():
	global player_x
	global player_y
	global player_shape
	player_x = random_between(0,63)
	player_y = random_between(0,47)
	player_shape = circle(10*player_x, 10*player_y, 5, filled=1)

def move_player():
	global player_x 
	global player_y
	keys = keys_pressed()
	if 'q' in keys:
		pass #later this will exit the game
	elif '1' in keys:
		move_to(player_shape, player_x - 10, player_y - 10)
		player_x = player_x
		player_y = player_y
		return
	elif '8' in keys:
		move_to(player_shape, player_x + 0, player_y + 10)
		player_x = player_x
		player_y = player_y
		return
	#and so on ....

place_player()
finished = 0
while not finished:
	move_player()

end_graphics()

-------------------------------
The problem is that I can only move the robot one time. I think that the
problem is in the function move_player()
Can somebody help me with this problem.

Thanks