This is my first "real" graphics based game I will create, but I know I need assistance.
def update(self):
if games.keyboard.is_pressed(games.K_w):
self.y -= 1
if games.keyboard.is_pressed(games.K_a):
self.x -= 1
if games.keyboard.is_pressed(games.K_s):
self.y += 1
if games.keyboard.is_pressed(games.K_d):
self.x += 1
if games.keyboard.is_pressed(games.K_i):
Inventory()
The above is in my update function of my player class, checking to see if "i" is pressed.
def Inventory():
global LEVEL, TOTAL_XP, MAX_HEALTH, MAX_MAGICKA, viewing_inv
viewing_inv = True
inventory_items = []
while viewing_inv == True:
print "yo"
score = games.Text(value = "Points", size = 25, color = color.green, top = 5,
left = games.screen.width/2 + 14)
games.screen.add(score)
if games.keyboard.is_pressed(games.K_i):
games.screen.remove(score)
viewing_inv = False
the above is a temp inventory function I am using to make sure things are working, which they are not. I added the print statement so i can view what is going on behind the scenes. I see the word "yo" print roughly 2-4 times each time I hit "i".
The Question
How can I successfully get it so that if I press "i", I go into the inventory function w/o having the computer loop through 2+ times before i can remove my finger? This question is already a lot even though I want to be able to press "i" again to exit. Any advice would be appreciated!
The Text was ripped straight out of my pong game I created if anyone was curious (which is why points was shown when viewing inventory)