Python Forum
[pygame] Inventory items not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pygame] Inventory items not working
#14
I decided to start it from scratch. I fro one wanted your opinion on how I am starting and I also need to know how to fix one of my problems. Originally I had the login and two text boxes. The button was only detecting clicks at certain times though so I separated it to give it a bigger range of detection. It still won't work though.
Here is the full code if you could take a quick scan and grade it
import pygame, random, os, sys
from functools import partial
from pathlib import Path
from DestinationFunc import Screen_Display as SD, Button as BT, TextBox as TB

pygame.init()

width = 800
height = 800
fps = 80

Screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()

UserData = {'Sheepposu' : {'password' : 'password'}}

class Player():
    def __init__():
        pass


class Enemy():
    def __init__():
        pass


def SignIn():
    #Intro
    sizeVar = 1
    OrganizationTup = (((205, 0, 0), 405, 295), ((215, 0, 0), 404, 296), ((225, 0, 0), 403, 297),
                       ((235, 0, 0), 402, 298), ((245, 0, 0), 401, 299), ((255, 0, 0), 400, 300))
    while sizeVar < 120:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                EndGame(True)
        sizeVar += 1
        Screen.fill((0, 0, 255))
        for x in OrganizationTup:
            SD.message_display(Screen, 'Destination', sizeVar, x[0], x[1], x[2])
        pygame.display.update()
        clock.tick(fps)

    Logging = True
    while Logging:
        #Login
        username = TB((200, 500, 400, 100), 'Type Username', 50, (0, 0, 255))
        password = TB((200, 650, 400, 100), 'Type Password', 50, (0, 0, 255))
        login = BT((650, 550, 100, 50), 'Log In', 40, (0, 0, 255))
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    EndGame(True)
            username.start(Screen, (255, 0, 0), 20)
            password.start(Screen, (255, 0, 0), 20)
            if username.text != '' and password.text != '':
                break
            pygame.display.update()
            clock.tick(fps)

        #Verification
        done = False
        while not done:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    EndGame()
            login.draw(Screen, (0, 255, 0))
            done = login.optClick(Screen, (0, 200, 0), (0, 255, 0))
            pygame.display.update()
            clock.tick(fps)
        UserName = username.text
        PassWord = password.text
        for name in UserData:
            if UserName.lower() == name.lower():
                if PassWord == UserData[name]['password']:
                    Logging = False
                else:
                    pygame.draw.rect(Screen, (0, 0, 255), (0, 350, 800, 50))
                    SD.message_display(Screen, 'Invalid Password', 40, (255, 0, 0), 400, 450)
            else:
                pygame.draw.rect(Screen, (0, 0, 255), (0, 350, 800, 50))
                SD.message_display(Screen, 'Invalid Username', 40, (255, 0, 0), 400, 450)

def LevelMaker():
    pass


def Main():
    SignIn()


def EndGame(leaving=None):
    if leaving:
        pass
    
    else:
        pass

Main()
pygame.quit()
sys.exit()
Button Code -
for event in pygame.event.get():
            clicked = pygame.mouse.get_pressed()
            if event.type == pygame.MOUSEBUTTONDOWN and clicked[0] == 1 and pygame.Rect((200, 650, 400, 100)).collidepoint(pygame.mouse.get_pos()):
                #code
Reply


Messages In This Thread
[pygame] Inventory items not working - by SheeppOSU - May-12-2019, 12:36 AM
RE: [pygame] Inventory items not working - by SheeppOSU - May-27-2019, 07:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding an inventory and a combat system to a text based adventure game detkitten 2 6,980 Dec-17-2019, 03:40 AM
Last Post: detkitten
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,113 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,952 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,832 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  [pyGame] Key Event not Working !... JamieVanCadsand 7 20,869 Sep-29-2017, 08:59 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020