Advertisement Jump to content
Sign in to follow this  
Crazylegs830

How do I make a very basic inventory.

This topic is 1882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Create an item structure that handles the responsibilities of an item in your game. An item might have properties such as its icon, its name, its description, its capabilities (whether it can be consumed/equipped, how it can be used, etc), and a procedure to be executed when activated. Create an inventory structure to contain and maintain the items, using an appropriate data structure. When a frame is drawn, iterate over the contents of your inventory, and draw the item's icon in the appropriate position. Next, use a collision handler such that when the player collides with an item in the field, the item is removed from the world and into the player's inventory.

Share this post


Link to post
Share on other sites

Create an item structure that handles the responsibilities of an item in your game. An item might have properties such as its icon, its name, its description, its capabilities (whether it can be consumed/equipped, how it can be used, etc), and a procedure to be executed when activated. Create an inventory structure to contain and maintain the items, using an appropriate data structure. When a frame is drawn, iterate over the contents of your inventory, and draw the item's icon in the appropriate position. Next, use a collision handler such that when the player collides with an item in the field, the item is removed from the world and into the player's inventory.

I am still very new to programming and just want to know how to make that collision. Just consumable circles that when the player touches them they disappear or something similar.

Share this post


Link to post
Share on other sites
     

you="C:\\Users\\user\\Desktop\\Python Programs\\Snake\\textures\\you.bmp"

import pygame, sys, random
from pygame.locals import *

pygame.init()

screen=pygame.display.set_mode((1600,1120),0,32)
mouse_c=pygame.image.load(you).convert_alpha()

#Variables for shapes

BLUE=(0,64,128)
WHITE=(255,255,255)
pos1=(0,0)
pos2=(0,1130)
pos3=(1600,0)
pos4=(1600,1130)
r1=random.randint(0, 1600), random.randint(0, 1600)
r2=random.randint(0, 1600), random.randint(0, 1600)
r3=random.randint(0, 1600), random.randint(0, 1600)
r4=random.randint(0, 1600), random.randint(0, 1600)
r5=random.randint(0, 1600), random.randint(0, 1600)
r6=random.randint(0, 1600), random.randint(0, 1600)
radius=(5)

#Variables for shapes

x,y=770,560
movex, movey=0,0

#Controls
while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type==KEYDOWN:
            if event.key==K_LEFT:
                movex=-4
            elif event.key==K_RIGHT:
                movex=+4
            elif event.key==K_UP:
                movey=-4
            elif event.key==K_DOWN:
                movey=+4
        if event.type==KEYUP:
            if event.key==K_LEFT:
                movex=0
            elif event.key==K_RIGHT:
                movex=0
            elif event.key==K_UP:
                movey=0
            elif event.key==K_DOWN:
                movey=0
#Controls
           
               
    screen.lock()
    C1=pygame.draw.circle(screen, WHITE, (r1), radius)
    C2=pygame.draw.circle(screen, WHITE, (r2), radius)
    C3=pygame.draw.circle(screen, WHITE, (r3), radius)
    C4=pygame.draw.circle(screen, WHITE, (r4), radius)
    C5=pygame.draw.circle(screen, WHITE, (r5), radius)
    C6=pygame.draw.circle(screen, WHITE, (r6), radius)
    screen.unlock()

    x+=movex
    y+=movey
   
#Wall Collision
    if y < 0:
        y = 0
    elif y > 1080:
        y = 1080
    if x < 0:
        x = 0
    elif x > 1550:
        x = 1550
#Wall Collision
#Consumable Collision
#Consumable Collision
   
    screen.blit(mouse_c,(x,y))
    pygame.display.update()
    screen.fill(pygame.Color(0, 0, 0, 255))

 

What engine or library are you using?  How are you storing item data?

I am using python/pygame and I am just writing code, I guess. Not really classes as much. Very messy code.

 

Code:

Edited by Crazylegs830

Share this post


Link to post
Share on other sites

l

 

My suggestion is that now is the perfect time to learn about classes! You have two types of objects in the game, right now, that you'll want to be checking for collisions on. The "you" sprite (or rather, mouse_c object) and the dots represented by the r1, r2, etc. variables. Start with your mouse_c: there are a few things that can be merged, the 'you' string representing the graphic, the mouse_c image made by pygame, and the movex and movey variables. Make a class that combines those, and then work on doing the same for the dots (I assume that's what you want to pick up?). After that, figure out how to make both classes inherit from pygame.Sprite, and you can start using some of pygame's built in collision checking on each game loop.

Alright ill try

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!