Question

i am going to have multiple questions so i figure i would put it into one thread so i do not flood the website with my stupid questions.

i will list all questions as an edited question, and hope it will be answered. the first question is as follows (on my 2nd question):

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. 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 alot even though i want to be able to press i again to exit. any advice would be appreciated!

Was it helpful?

Solution

If your room class is working correctly you shouldn't need a global, think about using instance attributes which are set in the constructor.

Also I don't think a separate class per room type is needed. It feels unnecessarily complex, as essentially each room behaves the same - it may look different - but you can handle to look of the room via instance attributes. What you need I think is to create separate instances of the single room class, and when you create the instance, pass in the walls, enemies, floors etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top