Python Forum
drawing, moving, and collision problems (pygame)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
drawing, moving, and collision problems (pygame)
#21
Ok I'll work on that

Alrighty, it should work now

Sorry one more problem I forgot to mention is the enemies only pointing their sticks bottom right.

Last thing, the game code on github does not work for creating new users. Problems with updating dicts, if you test it just use "Sheepposu"
Reply
#22
Deleted

I fixed the problem with new players
Reply
#23
Just posted my new code for leveling up in github
Reply
#24
https://github.com/Sheepposu/Destination
Reply
#25
That's really simple use input. If you learn how to use input you should be able to acquire the results you want

Also... you posted a question on my question, you need to create a new thread and this should go in General Coding Help

Go here to learn about input - https://www.w3schools.com/python/ref_func_input.asp
Reply
#26
I didn't know what to call this so I just said problems. I am making a game and when both monsters are killed the level is complete. If I kill monster 2 then 1 it works fine. BTW - the level is complete when you touch the side of the screen with the character, like exiting the level). If I kill monster 1 before 2 I'm allowed to leave the level and win. The second problem is getting the enemies to aim their weapons. They only aim it towards the bottom right corner of the map and I cant figure out why. TIA for you help. Also to download the game for a visual go here - https://github.com/Sheepposu/Destination

Destination.py
import pygame
import random
import time
import os
from DestinationFunc import Screen_Display as SD
from DestinationFunc import Button as BT
from pathlib import Path

"""
Xx Goal 1 - Adventuring across borders of pygame xX
Goal 2 - Use Krita ans get some more armor for enemies and players
Xx Goal 3 - Adding leveling and Exp xX
Goal 4 - Add upgrading stas with stat pts gained by leveling up
Goal 5 - Add more levels
Goal 6 - Add shops/gain gold by killing
"""

width = 1000
height = 800
pygame.init()
gD = pygame.display.set_mode((width, height))

#Files
file = Path(__file__).parent
print(file)
EnWoodenArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "EnWoodArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnWoodArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnWoodArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnWoodArmorLeft.png")))
EnDiamondArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "EnDiamondArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnDiamondArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnDiamondArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "EnDiamondArmorLeft.png")))
En2WoodenArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "En2WoodArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2WoodArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2WoodArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2WoodArmorLeft.png")))
En2DiamondArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "En2DiamondArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2DiamondArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2DiamondArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "En2DiamondArmorLeft.png")))
WoodenArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "WoodArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "WoodArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "WoodArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "WoodArmorLeft.png")))
DiamondArmor = (pygame.image.load(os.path.join(file, "Destination Pics", "DiamondArmorUp.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "DiamondArmorRight.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "DiamondArmor.png")),
               pygame.image.load(os.path.join(file, "Destination Pics", "DiamondArmorLeft.png")))
WoodBat = (pygame.image.load(os.path.join(file, "Destination Pics", "WoodenBat.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "WoodenBatRight.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "WoodenBatDown.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "WoodenBatLeft.png")))
SpikeBat = (pygame.image.load(os.path.join(file, "Destination Pics", "Spiked_Bat.png")),
            pygame.image.load(os.path.join(file, "Destination Pics", "Spiked_BatRight.png")),
            pygame.image.load(os.path.join(file, "Destination Pics", "Spiked_BatDown.png")),
            pygame.image.load(os.path.join(file, "Destination Pics", "Spiked_BatLeft.png")))
IronBat = (pygame.image.load(os.path.join(file, "Destination Pics", "MetalBat.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "MetalBatRight.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "MetalBatDown.png")),
           pygame.image.load(os.path.join(file, "Destination Pics", "MetalBatLeft.png")))
IronSword = (pygame.image.load(os.path.join(file, "Destination Pics", "IronSword.png")),
             pygame.image.load(os.path.join(file, "Destination Pics", "IronSwordRight.png")),
             pygame.image.load(os.path.join(file, "Destination Pics", "IronSwordDown.png")),
             pygame.image.load(os.path.join(file, "Destination Pics", "IronSwordLeft.png")))
DiamondSword = (pygame.image.load(os.path.join(file, "Destination Pics", "DiamondSword.png")),
                pygame.image.load(os.path.join(file, "Destination Pics", "DiamondSwordRight.png")),
                pygame.image.load(os.path.join(file, "Destination Pics", "DiamondSwordDown.png")),
                pygame.image.load(os.path.join(file, "Destination Pics", "DiamondSwordLeft.png")))

#Colors
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
darker_red = (200,0,0)
green = (0,255,0)
lightest_blue = (0,0,255)
lighter_blue = (0,0,200)
light_blue = (0,0,160)
blue = (0,0,120)
brown = (165,42,42)
light_brown = (139,69,19)
CustomColor1 = (48,150,140)
CustomColor2 = (36,112.5,105)
Unique_Color = (190,140,210)
ColorList = [black, red, green, blue, white, brown, lightest_blue, lighter_blue, light_blue]

pause = False
signInList = {'Sheepposu' : 'password', 'gg' : 'password', 'Tallish Walk' : '092404Aw'}
UserArmor = {'Sheepposu' : DiamondArmor, 'gg' : WoodenArmor, 'Tallish Walk' : WoodenArmor}
UserWeap = {'Sheepposu' : DiamondSword, 'gg' : WoodBat, 'Tallish Walk' : WoodBat}
UserLvl = {'Sheepposu' : 1, 'gg' : 1, 'Tallish Walk' : 1}
UserDefense = {'Sheepposu' : 5, 'gg' : 1, 'Tallsih Walk' : 1}
UserExp = {'Sheepposu' : 0, 'gg' : 0, 'Tallish Walk' : 0}

UserListings = [signInList, UserArmor, UserWeap, UserLvl, UserDefense, UserExp]

        

#Config
fps = 100
pygame.display.set_caption('Destination')
clock = pygame.time.Clock()
gD.fill(blue)
clock.tick(15)






#Variables
Confirm = True
username = None

class Player():
    def __init__(self, x, y, width, height, color, weapType, defense):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.rect = (x, y, width, height)
        self.color = color
        self.armor = None
        self.direct = 'Down'
        self.weapon = None
        self.weaponPos = None
        self.weapType = weapType
        self.damageDealt = 0
        self.resist = defense
        self.damageTaken = 0
        self.levelComplete = False
        self.levelComplete2 = False
        if weapType == WoodBat:
            self.damage = .5

        elif weapType == DiamondSword:
            self.damage = 5
        
    def draw(self):
        self.drawWeap()
        
    def getDefense(self):
        return self.resist

    def getDamage(self):
        return self.damage

    def lvlCom(self):
        return self.levelComplete

    def lvlCom2(self):
        return self.levelComplete2

    def lvlReset(self):
        self.levelComplete = False

    def drawWeap(self):
        if self.direct == 'Left':
            self.armor = gD.blit(self.color[3], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[3], (self.x - round(self.width*.8), self.y + round(self.height/2)))
            self.weaponPos = (self.x - round(self.width*.8), self.y + round(self.height/2))
        if self.direct == 'Right':
            self.armor = gD.blit(self.color[1], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[1], (self.x + round(self.width*.8), self.y + round(self.height/2)))
            self.weaponPos = (self.x + round(self.width*.8), self.y + round(self.height/2))
        if self.direct == 'Up':
            self.armor = gD.blit(self.color[0], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[0], (self.x + round(self.width/2), self.y - round(self.height*.8)))
            self.weaponPos = (self.x + round(self.width/2), self.y - round(self.height*.8))
        if self.direct == 'Down':
            self.armor = gD.blit(self.color[2], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[2], (self.x + round(self.width/2), self.y + round(self.height*.8)))
            self.weaponPos = (self.x + round(self.width/2), self.y + round(self.height*.8))

        self.update()

    def getRect(self):
        if self.weaponPos != None:
            if self.direct == 'Left':
                colorRect = self.color[3].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Right':
                colorRect = self.color[1].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Up':
                colorRect = self.color[0].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Down':
                colorRect = self.color[2].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect

    def collision(self, e):
        if self.weaponPos != None:
            Pos = e.getRect()
            if Pos != None:
                if self.direct == 'Left':
                    WeapRect = self.weapType[3]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x - round(self.width*.8)
                    WeapRect[1] = self.y + round(self.height/2)
                if self.direct == 'Right':
                    WeapRect = self.weapType[1]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width*.8)
                    WeapRect[1] = self.y + round(self.height/2)
                if self.direct == 'Up':
                    WeapRect = self.weapType[0]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width/2)
                    WeapRect[1] = self.y - round(self.height*.8)
                if self.direct == 'Down':
                    WeapRect = self.weapType[2]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width/2)
                    WeapRect[1] = self.y + round(self.height*.8)
                
                if Pos.colliderect(WeapRect):
                    e.damageTake(username, damage=round(self.damage/e.getDefense(), 1))

    def levelDisplay(self, username):
        SD.message_display(gD, str(UserLvl[username]), 30, white, self.x - 10, self.y - 20)
            
    def move(self, e, e2=None):
        keyed = pygame.key.get_pressed()
        self.collision(e)
        ePos = e.getPos()
        posDiff = (self.x - ePos[0], self.y - ePos[1])
        death = e.checkDeath()
        if e2 != None:
            self.collision(e2)
            ePos2 = e2.getPos()
            posDiff2 = (self.x - ePos2[0], self.y - ePos2[1])
            death2 = e.checkDeath()

        if keyed[pygame.K_LEFT] or keyed[pygame.K_a]:
            self.x -= 1
            self.direct = 'Left'
        if keyed[pygame.K_RIGHT] or keyed[pygame.K_d]:
            self.x += 1
            self.direct = 'Right'
        if keyed[pygame.K_UP] or keyed[pygame.K_w]:
            self.y -= 1
            self.direct = 'Up'
        if keyed[pygame.K_DOWN] or keyed[pygame.K_s]:
            self.y += 1
            self.direct = 'Down'
        if death == False and death2 == False:
            if self.x <= 0:
                self.x += 5
                    
            if self.x + self.width >= width:
                self.x -= 5
            
            if self.y <= 0:
                self.y += 5
            
            if self.y + self.height >= height:
                self.y -= 5
        elif death == False and e2 == None:
            if self.x <= 0:
                self.x += 5
                    
            if self.x + self.width >= width:
                self.x -= 5
            
            if self.y <= 0:
                self.y += 5
            
            if self.y + self.height >= height:
                self.y -= 5

        elif death == True and death2 == True:
            if self.x <= 0:
                self.x = width - self.width
                self.levelComplete = True
                self.levelComplete2 = True   
            if self.x + self.width >= width:
                self.x = 0
                self.levelComplete = True
                self.levelComplete2 = True
            if self.y <= 0:
                self.y = height - self.height
                self.levelComplete = True
                self.levelComplete2 = True
            if self.y + self.height >= height:
                self.y = 0
                self.levelComplete = True
                self.levelComplete2 = True

        elif death == True and e2 == None:
            if self.x <= 0:
                self.x = width - self.width
                self.levelComplete = True
                self.levelComplete2 = True
            if self.x + self.width >= width:
                self.x = 0
                self.levelComplete = True
                self.levelComplete2 = True
            if self.y <= 0:
                self.y = height - self.height
                self.levelComplete = True
                self.levelComplete2 = True
            if self.y + self.height >= height:
                self.y = 0
                self.levelComplete = True
                self.levelComplete2 = True
        self.update()

    def update(self):
        self.rect = (self.x, self.y, self.width, self.height)

    def getPos(self):
        return self.x, self.y, self.x + self.width, self.y + self.height

    def getDamageDealt(self):
        return self.damageTaken

    def healthBar(self, num):
        pygame.draw.rect(gD, black, (self.rect[0], self.rect[1] - 20, self.rect[2], 10))
        pygame.draw.rect(gD, red, (self.rect[0] + 2, self.rect[1] - 18, self.rect[2] - num, 6))
        if self.rect[2] - num <= 0:
            End_Game(Died=True)

    def damageTake(self, damage=None, receive=None):
        if receive == None:
            self.damageTaken += damage
            self.healthBar(self.damageTaken)
        elif receive == True:
            return self.damageTaken
        elif receive == False:
            self.healthBar(self.damageTaken)

class Enemy():
    def __init__(self, x, y, width, height, color, weapType, diff, exp):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.rect = (x, y, width, height)
        self.color = color
        self.direct = 'Down'
        self.weapon = None
        self.armor = None
        self.damageDealt = 0
        self.weapType = weapType
        self.weaponPos = None
        self.diff = diff
        self.dead = False
        self.damageTaken = 0
        self.exp = exp
        if weapType == WoodBat:
            self.damage = .5
        if weapType == SpikeBat:
            self.damage = 1
        if diff == 'noob':
            self.resist = 1
        if diff == 'easy':
            self.resist = 2

    def getDefense(self):
        return self.resist
        
        
    def draw(self):
        if not self.dead:
            self.character()

    def character(self):
        if self.direct == 'Left':
            self.armor = gD.blit(self.color[1], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[3], (self.x - round(self.width*.8), self.y + round(self.height/2)))
            self.weaponPos = (self.x - round(self.width*.8), self.y + round(self.height/2))
        if self.direct == 'Right':
            self.armor = gD.blit(self.color[3], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[1], (self.x + round(self.width*.8), self.y + round(self.height/2)))
            self.weaponPos = (self.x + round(self.width*.8), self.y + round(self.height/2))
        if self.direct == 'Up':
            self.armor = gD.blit(self.color[0], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[0], (self.x + round(self.width/2), self.y - round(self.height*.8)))
            self.weaponPos = (self.x + round(self.width/2), self.y - round(self.height*.8))
        if self.direct == 'Down':
            self.armor = gD.blit(self.color[2], (self.x, self.y))
            self.weapon = gD.blit(self.weapType[2], (self.x + round(self.width/2), self.y + round(self.height*.8)))
            self.weaponPos = (self.x + round(self.width/2), self.y + round(self.height*.8))

        self.update()

    def checkDeath(self):
        return self.dead

    def getRect(self):
        if self.weaponPos != None:
            if self.direct == 'Left':
                colorRect = self.color[3].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Right':
                colorRect = self.color[1].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Up':
                colorRect = self.color[0].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect
            if self.direct == 'Down':
                colorRect = self.color[2].get_rect()
                colorRect[0] = self.x
                colorRect[1] = self.y
                return colorRect

    def collision(self, p):
        if self.weaponPos != None:
            Pos = p.getRect()
            if Pos != None:
                if self.direct == 'Left':
                    WeapRect = self.weapType[3]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x - round(self.width*.8)
                    WeapRect[1] = self.y + round(self.height/2)
                if self.direct == 'Right':
                    WeapRect = self.weapType[1]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width*.8)
                    WeapRect[1] = self.y + round(self.height/2)
                if self.direct == 'Up':
                    WeapRect = self.weapType[0]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width/2)
                    WeapRect[1] = self.y - round(self.height*.8)
                if self.direct == 'Down':
                    WeapRect = self.weapType[2]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.x + round(self.width/2)
                    WeapRect[1] = self.y + round(self.height*.8)

                if Pos.colliderect(WeapRect):
                    p.damageTake(round(self.damage/p.getDefense(), 1))

    def move(self, p):
        if not self.dead:
            plrPos = p.getPos()
            plrX = plrPos[0]
            plrY = plrPos[1]
            self.collision(p)
            DownRight = ['Down', 'Right']
            UpRight = ['Right', 'Up']
            UpLeft = ['Up', 'Left']
            DownLeft = ['Down', 'Left']
            AnyDirect = ['Down', 'Up', 'Left', 'Right']
            
            if plrX > self.x and plrY > self.y:
                self.x += .2
                self.y += .2
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
            elif plrX > self.x and plrY < self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                self.x += .2
                self.y -= .2
            elif plrX < self.x and plrY < self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                self.x -= .2
                self.y -= .2
            elif plrX < self.x and plrY > self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                self.x -= .2
                self.y += .2
            elif plrX == self.x and plrY > self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                    self.direct = 'Down'
                self.y += .2
            elif plrX == self.x and plrY < self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                    self.direct = 'Up'
                self.y -= .2
            elif plrY == self.y and plrX > self.x:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                    self.direct = 'Right'
                self.x += .2
            elif plrY == self.y and plrX < self.x:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                    self.direct = 'Left'
                self.x -= .2
            elif plrX == self.x and plrY == self.y:
                if self.diff == 'noob':
                    num = random.randint(1, 200)
                elif self.diff == 'easy':
                    num = random.randint(1, 100)
                if num < 3:
                    self.direct = random.choice(DownRight)
                    self.direct = random.choice(AnyDirect)
                    
            self.update()

    def plrTele(self, x, y):
        self.x = x
        self.y = y

    def getPos(self):
        return self.x, self.y, self.x + self.width, self.y + self.height

    def getDamageDealt(self):
        return self.damageTaken

    def healthBar(self, num, username):
        if not self.dead:
            pygame.draw.rect(gD, black, (self.rect[0], self.rect[1] - 20, self.rect[2], 10))
            pygame.draw.rect(gD, red, (self.rect[0] + 2, self.rect[1] - 18, self.rect[2] - num, 6))
            if self.rect[2] - num <= 0:
                print('It\'s dead')
                self.dead = True
                exp = UserExp[username]
                UserExp[username] = exp + self.exp

    def damageTake(self, username, damage=None, receive=None):
        if receive == None:
            self.damageTaken += damage
            self.healthBar(self.damageTaken, username)
        elif receive == True:
            return self.damageTaken
        elif receive == False:
            self.healthBar(self.damageTaken, username)

    def update(self):
        self.rect = (self.x, self.y, self.width, self.height)

    def getWeapPos(self):
        if self.weaponPos != None:
            return self.weaponPos


def Confirm_QUIT():
    global Confirm
    Confirm = False

def Confirm_Screen(username):
    global Confirm
    clock.tick(fps)
    while Confirm:
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                End_Game()
        gD.fill(blue)
        SD.message_display(gD, 'You\'re %s, correct?' %username, round(width/17), Unique_Color, round(width/2), height * .25)
        b1 = BT((round(width * .3), round(height * .7), round(width * .4), round(height * .2)),  'Confirm!', round(width/20), blue)
        b2 = BT((round(width * .75), round(height * .8), round(width * .2), round(height * .1)), "No!", round(width/50), blue)
        b1.draw(gD, CustomColor1)
        b2.draw(gD, red)
        b1.optClick(gD, CustomColor2, CustomColor1, Confirm_QUIT)
        b2.optClick(gD, darker_red, red, End_Game, pygame.quit)
        pygame.display.update()
        clock.tick(15)

def SignIn():
    global username
    
    username = input('(Type "new" for new account) Type in username: ')

    if username == 'new':
        newUsername = input('Type your Username: ')
        if newUsername in signInList:
            print('The username %s is already taken' %newUsername)
            SignIn()
        else:
            newPassword = input('Type your Password: ')
            username = newUsername
            print('Now return to Destination and confirm')
            signInList.update({newUsername : newPassword})
            UserDefense.update({newUsername : 1})
            UserLvl.update({newUsername : 1})
            UserExp.update({newUsername, newPassword})
            UserWeap.update({newUsername : WoodBat})
            UserArmor.update({newUsername : WoodenArmor})

            username = newUsername

    else:
        if username in signInList:
            password = input('Please type your password: ')
            if password == signInList[username]:
                print('Now return to Destination and confirm')
            else:
                print('Invalid Password')
                time.sleep(2)
                SignIn()
        else:
            print('Invalid Username')
            time.sleep(2)
            SignIn()

def lvlCheck():
    exp = UserExp[username]
    if exp >= 300 and exp < 900:
        UserLvl[username] = 2
    elif exp >= 900 and exp < 2700:
        UserLvl[username] = 3
    elif exp >= 2700 and exp < 6500:
        UserLvl[username] = 4

def Main():
    global username
    global pause
    SignIn()
    Confirm_Screen(username)
    defense = UserDefense[username]
    armor = UserArmor[username]
    weap = UserWeap[username]
    
    p = Player(width/2, height/2, 50, 50, armor, weap, defense)
    e = Enemy(0 ,0, 50, 50, EnWoodenArmor, WoodBat, 'noob', 100)
    e2 = Enemy(width - 50, height - 50, 50, 50, En2WoodenArmor, SpikeBat, 'easy', 200)
    play = True
    while play:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                End_Game()

        if not pause:
            gD.fill(green)
            p.draw()
            e.draw()
            e2.draw()
            p.healthBar(p.getDamageDealt())
            p.levelDisplay(username)
            e.damageTake(username, receive=False)
            e2.damageTake(username, receive=False)
            p.move(e, e2)
            p.move(e, e2)
            e.move(p)
            e2.move(p)
            lvlCheck()
            Com = p.lvlCom()
            Com2 = p.lvlCom2()
            pygame.display.update()
            clock.tick(fps)
            if Com == True and Com2 == True:
                play = False
                
    End_Game()

def End_Game(Died=None):
    play = False
    listings = UserListings
    for e in listings:
        print(e)
        print(' ')
        print(' ')
    OverPosY = 0
    if Died == None:
        gD.fill(red)
        SD.message_display(gD, 'Congratulations! You win', round(width/10), black, round(width/2), round(height/2))
        pygame.display.update()
    if Died:
        while True:
            OverPosY += 1
            gD.fill(red)
            SD.message_display(gD, 'Game Over', round(width/10), black, round(width/2), OverPosY)
            pygame.display.update()
            if OverPosY == height/2:
                time.sleep(5)
                pygame.quit()

SD.message_display(gD, "Fill in info on console", round(int(width/20)), Unique_Color, width/2, height/2)
pygame.display.update()
Main()
pygame.quit()
DestinationFunc.py
import pygame

class Screen_Display():
    def text_objects(text, font, color):
        textSurface = font.render(text, True, color)
        return textSurface, textSurface.get_rect()

    def message_display(gD, text, size, color, centerX, centerY):
        font = pygame.font.SysFont('arial', size)
        textSurf, TextRect = Screen_Display.text_objects(text, font, color)
        TextRect.center = ((centerX),(centerY))
        gD.blit(textSurf, TextRect)

class Button():
    def __init__(self, rect, text, textsize, textcolor):
        self.rect = rect
        self.font = pygame.font.SysFont('arial', textsize)
        self.textSurf, self.textRect = Screen_Display.text_objects(text, self.font, textcolor)
        self.textRect.center = ((rect[0] + (rect[2]/2), rect[1] + (rect[3]/2)))

    def draw(self, gD, ButColor):
        pygame.draw.rect(gD, ButColor, (self.rect))
        gD.blit(self.textSurf, self.textRect)

    def optClick(self, gD, ShadowColor, ButColor, command=None, command2=None):
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()
        if self.rect[0] + self.rect[2] > mouse[0] > self.rect[0] and self.rect[1] + self.rect[3] > mouse[1] > self.rect[1]:
            pygame.draw.rect(gD, ShadowColor, (self.rect))
            gD.blit(self.textSurf, self.textRect)
            if click[0] == 1:
                    if command != None:
                        command()
                    if command2 != None:
                        command2()
            else:
                pygame.draw.rect(gD, ButColor, (self.rect))
                gD.blit(self.textSurf, self.textRect)
Reply
#27
There are no actual errors but there are errors in what I expect it to do. I have this game and after defeating all of the enemies can touch the side of the canvas. It resets everything to the next level and puts them on the opposite side of the map to give them the idea of a new area. The problems are as follows below -

problem 1 - the player is not placed on the opposite of the canvas after defeating the enemy and touching the edge of the canvas

problem 2 - When they are in the town, they have to go to the Cabin and Shop before anything happens when touching the edge. When they touch the left and top, nothing happens, if they touch the right or bottom, it doesn't end the town func but it places them on the other side of the canvas.

The code and where it can be downloaded is here - https://github.com/Sheepposu/Destination

I'll post some lines to look at that are responsible for this

problem 1 - line 919
problem 2 - 976

The player class starts at line 129
The move func inside the player class starts on line 312

If you do download it you'll need to know that you press "p" to pause and see/upgrade all your stats. The sword deals damage on touch.

He that can have patience can have what he will
- Benjamin Franklin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [PyGame] Problem with collision of player and enemy Nekotrooper 1 599 Dec-08-2023, 03:29 PM
Last Post: deanhystad
  pygame installation problems Gheryk 5 8,497 Nov-29-2023, 08:49 PM
Last Post: E_Mohamed
  can't get collision detection to work in platform game chairmanme0wme0w 10 3,659 Aug-19-2022, 03:51 PM
Last Post: deanhystad
  [PyGame] Problems with jump code in pygame Joningstone 4 5,269 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  [PyGame] drawing images onto pygame window djwilson0495 1 3,423 Feb-22-2021, 05:39 PM
Last Post: nilamo
  [PyGame] Collision in not happening onizuka 3 3,359 Sep-07-2020, 11:30 AM
Last Post: metulburr
  [PyGame] No collision detection onizuka 6 3,596 Aug-18-2020, 01:29 PM
Last Post: onizuka
  [PyGame] pygame, help with making a function to detect collision between player and enemy. Kris1996 3 3,282 Mar-07-2020, 12:32 PM
Last Post: Kris1996
  Problem with collision detection... michael1789 4 3,217 Nov-12-2019, 07:49 PM
Last Post: michael1789
  Pygame sprite not moving michael1789 1 2,782 Nov-10-2019, 03:54 AM
Last Post: michael1789

Forum Jump:

User Panel Messages

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