Advertisement
Ridz112

Untitled

Oct 30th, 2021
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.57 KB | None | 0 0
  1. from pygame import *
  2. import random
  3.  
  4. spawnpoint = 0
  5. x = 1
  6. while x != 10:
  7.     spawnpoint += random.randint(1, 10)
  8.     x = x + 1
  9.  
  10. init()
  11. width = 1500  # width of window
  12. height = 800  # height of window
  13. window = display.set_mode((width, height))  # draws window
  14. screen = display.get_surface()  # draws ontop of window
  15. exitProg = False  # allows to exit while loop
  16. overallTime = time.Clock()  # starts a clock
  17.  
  18.  
  19. ######################################################################
  20. # player interaction
  21. class Character():
  22.     def __init__(self, m, n, movement, spawnpoint):  # initialises the objects
  23.         self.Posx = m  # sets the image to the center of the map
  24.         self.Posy = n  # sets the image to the center of the map
  25.         self.dx = 0  # sets horizontal acceleration to 0
  26.         self.dy = 0  # sets vertical acceleration to 0
  27.         self.Movespeed = movement  # sets how fast the player moves(it can change)
  28.         self.image = image.load('Isaac.xcf')  # loads the sprite for the player
  29.         self.sword = image.load('swordSwish2.png')  # loads the sword for the sprite
  30.         self.roomCounter = 0  # sets the room counter
  31.         self.ATK = 8  # sets the attack of the player
  32.         self.HP = 25  # sets the hp of the player
  33.         self.maxhp = 25  # the hp and masx hp will be equal to beging with and only the curhp should change when damage is taken
  34.         self.attackspeed = 1  # sets attack speed of the player
  35.         self.spawnpoint = spawnpoint  # assigns where the player has begun on the map
  36.  
  37.     def collisionDoor(self, door, locked):  # detects door collisions for the player
  38.         rect = self.image.get_rect()  # gets the dimensions of the sprite
  39.         rect.x = self.Posx  # sets coords for a rectangle == to the sprite
  40.         rect.y = self.Posy  # sets coords for a rectangle == to the sprite
  41.         spawnRoom = None  # changes it so that the value that shows the room the player begun in is changed
  42.         if rect.colliderect(door) == True and locked == False:  # checks for collision between player and door
  43.             clock.resettime()
  44.             if self.Posx > 1342:  # collisionDoor also changes the position of the player and then changes where the player is on the map
  45.                 self.Posx = 95
  46.                 self.spawnpoint += 1
  47.                 spawnRoom = self.spawnpoint
  48.             if self.Posx < 94:
  49.                 self.Posx = 1341
  50.                 self.spawnpoint -= 1
  51.                 spawnRoom = self.spawnpoint
  52.             if self.Posy > 642:
  53.                 self.Posy = 103
  54.                 self.spawnpoint += 10
  55.                 spawnRoom = self.spawnpoint
  56.             if self.Posy < 102:
  57.                 self.Posy = 643
  58.                 self.spawnpoint -= 10
  59.                 spawnRoom = self.spawnpoint
  60.             character.update()
  61.             if spawnRoom != None and not (
  62.                     spawnRoom in visited):  # if the player is in a room they havent visited before, append it to the visited list
  63.                 visited.append(spawnRoom)
  64.                 self.roomCounter += 1  # increase the room counter
  65.             else:
  66.                 return False
  67.             return True  # the code also checks for a change in the room and returns true, I use it for this purpose a bit
  68.         return False
  69.  
  70.     def collisiondoorother(self, door, locked, dead):
  71.         rect = self.image.get_rect()  # gets the dimensions of the sprite
  72.         rect.x = self.Posx  # sets coords for a rectangle == to the sprite
  73.         rect.y = self.Posy  # sets coords for a rectangle == to the sprite
  74.         if rect.colliderect(
  75.                 door) == True and locked == False and dead == True:  # checks for collision between player and door
  76.             return True
  77.         return False
  78.  
  79.     def getPosition(self):  # allows other classes to get the poisition of the player
  80.         return self.Posx, self.Posy
  81.  
  82.     def moveleft(self):  # sets the change in speed
  83.         self.dx = -self.Movespeed
  84.         return self.Posx
  85.  
  86.     def moveright(self):  # sets the change in speed
  87.         self.dx = self.Movespeed
  88.         return self.Posx
  89.  
  90.     def movedown(self):  # sets the change in speed
  91.         self.dy = -self.Movespeed
  92.         return self.Posy
  93.  
  94.     def moveup(self):  # sets the change in speed
  95.         self.dy = self.Movespeed
  96.         return self.Posy
  97.  
  98.     def stopHorizontal(self):  # stops character moving
  99.         self.dx = 0
  100.  
  101.     def stopVertical(self):  # stops character moving
  102.         self.dy = 0
  103.  
  104.     def bordercheckx(self):  # stops character moving past screen
  105.         if self.Posx > 1364:
  106.             self.Posx = 1364
  107.         if self.Posx < 89:
  108.             self.Posx = 89
  109.         return self.Posx
  110.  
  111.     def borderchecky(self):  # stops char moving past screen
  112.         if self.Posy > 652:
  113.             self.Posy = 652
  114.         if self.Posy < 90:
  115.             self.Posy = 90
  116.         return self.Posy
  117.  
  118.     def update(self):  # changes the coords for the sprite
  119.         self.Posx = self.Posx + self.dx
  120.         self.Posy = self.Posy + self.dy
  121.  
  122.     def show(self):  # updates the players position on the map
  123.         screen.blit(self.image, (self.Posx, self.Posy))
  124.  
  125.     def returnRect(self):  # gets the rect for the player to compare for collision
  126.         rect = Rect(self.Posx, self.Posy, self.image.get_width(), self.image.get_height())
  127.         return rect
  128.  
  129.     def returnSwordrect(
  130.             self):  # sword rect based on the players position and returns it to check for collision against enemies
  131.         rect = Rect(self.Posx - 20, self.Posy - 20, self.sword.get_width(), self.sword.get_height())
  132.         return rect
  133.  
  134.     def GetRoomCount(self):  # returns room counter
  135.         return self.roomCounter
  136.  
  137.     def attack(self, target):
  138.         target.reduceHP(self.ATK)  # damage done to the monster being attacked
  139.  
  140.     def ShowAttack(self):  # shows the sword when called
  141.         screen.blit(self.sword, (self.Posx - 20, self.Posy - 14))
  142.  
  143.     def reduceHP(self, amount):  # HP stat is encaptulated so it cant be
  144.         self.HP -= amount
  145.  
  146.     def returncurHP(self):  # returns the current health of the player
  147.         return self.HP
  148.  
  149.     def returnmaxHP(self):  # returns the max health of the player
  150.         return self.maxhp
  151.  
  152.     def isDead(self):  # This checks how high the monsters health
  153.         if self.HP <= -1:
  154.             return True  # is and then returns true or false if its
  155.         else:
  156.             return False
  157.  
  158.     def levelUP(self):  # this levels up the player and increases the players stats and heals them fully
  159.         self.ATK = round(self.ATK * 1.5)
  160.         self.maxhp = round(self.maxhp * 1.2)
  161.         self.HP = self.maxhp
  162.  
  163.     def changemodel(self):
  164.         health = (self.HP / self.maxhp)
  165.         if health <= 0.1:
  166.             self.image = image.load('Isaacdam5.png')
  167.         elif health <= 0.2 and health > 0.1:
  168.             self.image = image.load('Isaacdam4.png')
  169.         elif health <= 0.4 and health > 0.2:
  170.             self.image = image.load('Isaacdam3.png')
  171.         elif health <= 0.6 and health > 0.4:
  172.             self.image = image.load('Isaacdam2.png')
  173.         elif health <= 0.8 and health > 0.6:
  174.             self.image = image.load('Isaacdam1.png')
  175.         else:
  176.             self.image = image.load('Isaac.png')
  177.  
  178.     def getatkspd(self):
  179.         return self.attackspeed
  180.  
  181.     def resetroomcount(self):
  182.         self.roomCounter = 0
  183.     ######################################################################
  184.  
  185.  
  186. # Door interactions with player
  187. class doors(Rect):  # draws the doors in their positions
  188.     def draw(self, screen):
  189.         draw.rect(screen, (225, 225, 225), self)
  190.  
  191.     def lock(self, screen):  # changes colour of the doors if they are locked
  192.         draw.rect(screen, (255, 215, 0), self)
  193.  
  194.  
  195. ######################################################################
  196. # levels up the player
  197. class levelUp():
  198.  
  199.     def __init__(self, currentXP, NeededtoLVL):  # initialises the level up system
  200.         self.currentXP = currentXP
  201.         self.neededtoLVL = NeededtoLVL
  202.         self.level = 1
  203.  
  204.     def xpgain(self, xpgained):  # levels up the player
  205.         self.currentXP += xpgained
  206.         if self.currentXP >= self.neededtoLVL:
  207.             self.currentXP -= self.neededtoLVL
  208.             self.neededtoLVL *= 1.7
  209.             self.level += 1
  210.             character.levelUP()
  211.  
  212.     def drawXPbar(self):  # Draws the xp bar on the screen and changes it
  213.         width = 1000 * (self.currentXP / self.neededtoLVL)
  214.         bar1 = Rect(250, 760, 1000, 10)
  215.         bar2 = Rect(250, 760, width, 10)
  216.         draw.rect(screen, (166, 16, 30), bar1)
  217.         draw.rect(screen, (0, 229, 238), bar2)
  218.  
  219.     def getLVL(self):  # returns the level of the player to be drawn on the screen
  220.         return self.level
  221.  
  222.  
  223. ######################################################################
  224. # Creates and controls the enemies
  225. class Enemy():
  226.     def __init__(self):  # initialises the enemies
  227.         self.Enx = 0  # sets the position of every enemy to begin with in the top right corner
  228.         self.Eny = 0  # sets all the stats for the enemy to be 0 as the stats need to be set with the enemy type
  229.         self.dx = 0  # they all need to be set to 0 except for health so they cant do anything
  230.         self.dy = 0  # the health is so high so that it doesnt accidentally trigger the death function for the enemies
  231.         self.speed = 0
  232.         self.HP = 99999999999
  233.         self.ATK = 0
  234.         self.image = image.load('blank.png')
  235.  
  236.         self.attackspeed = 0
  237.         self.xpGain = 7
  238.         self.levelmult = 1
  239.         self.levelmultboss = 1
  240.         self.xpmodifier = 1
  241.         self.height = 0
  242.         self.width = 0
  243.  
  244.     def moveToPlayer(self, x, y, time):  # checks where the player is then moves to the position
  245.         if time > 1:
  246.             if x - self.width < self.Enx:
  247.                 self.dx = -self.speed
  248.             if x - self.width > self.Enx:
  249.                 self.dx = self.speed
  250.             if y - self.height > self.Eny:
  251.                 self.dy = self.speed
  252.             if y - self.height < self.Eny:
  253.                 self.dy = -self.speed
  254.  
  255.     def playerCollidesDoor(self,
  256.                            enter):  # checks if the player has entered a door, if it has then it resets the enemies
  257.         if enter == True:
  258.             self.Enx = random.randint(300, 1200)
  259.             self.Eny = random.randint(300, 500)
  260.             self.dx = 0
  261.             self.dy = 0
  262.  
  263.     def collisionSword(self, sword):  # checks if the enemy collides with the swords hit box
  264.         enemy = Rect(self.Enx, self.Eny, self.image.get_width(), self.image.get_height())
  265.         if enemy.colliderect(sword) == True:
  266.             return True
  267.         return False
  268.  
  269.     def collisionPlayer(self, player):  # checks if the player touches the enemy
  270.         rect = Rect(self.Enx, self.Eny, self.image.get_width(), self.image.get_height())
  271.         if rect.colliderect(player) == True:
  272.             EnATKSpd.resettime()
  273.             return True
  274.         return False
  275.  
  276.     def Archer(self):  # sets the Archer class for enemies
  277.         self.HP = round(8 * self.levelmult)
  278.         self.ATK = round(3 * self.levelmult)
  279.         self.speed = 1.5
  280.         self.attackspeed = 1
  281.         self.image = image.load('Archer.png')
  282.         self.width = -5
  283.  
  284.     def Orc(self):  # sets the Orc class for enemies
  285.         self.HP = round(22 * self.levelmult)
  286.         self.ATK = round(3 * self.levelmult)
  287.         self.speed = 1.3
  288.         self.attackspeed = 1
  289.         self.image = image.load('Orc2.png')
  290.         self.height = 25
  291.         self.width = 5
  292.  
  293.     def Soldier(self):  # sets the Soldier class for enemies
  294.         self.HP = round(14 * self.levelmult)
  295.         self.ATK = round(2 * self.levelmult)
  296.         self.speed = 1.7
  297.         self.attackspeed = 1
  298.         self.image = image.load('soldier.png')
  299.         self.width = -5
  300.  
  301.     def blank(self):
  302.         self.HP = 9999999
  303.         self.ATK = 0
  304.         self.speed = 0
  305.         self.image = image.load('blank.png')
  306.         self.Enx = 1
  307.         self.Eny = 1
  308.  
  309.     def update(self):  # changes the speed of the enemy
  310.         self.Enx = self.Enx + self.dx
  311.         self.Eny = self.Eny + self.dy
  312.  
  313.     def show(self):  # updates the enemy on the map
  314.         screen.blit(self.image, (self.Enx, self.Eny))
  315.  
  316.     def attack(self, target):
  317.         target.reduceHP(self.ATK)  # damage done to the monster being attacker
  318.  
  319.     def reduceHP(self, amount):  # HP stat is encapsulated so it cant be
  320.         self.HP -= amount
  321.  
  322.     def isDead(self):  # This checks how high the monsters health
  323.         if self.HP <= 0:  # is and then returns true or false if its
  324.             self.image = image.load('blank.png')
  325.             self.ATK = 0
  326.             self.Enx = 1
  327.             self.Eny = 1
  328.             self.HP = 9999999
  329.             self.speed = 0
  330.             xpgain = self.xpGain * self.xpmodifier
  331.             CharLVL.xpgain(xpgain)
  332.  
  333.             return True
  334.         else:
  335.             return False
  336.  
  337.     def returnHP(self):
  338.         return self.HP
  339.  
  340.     def Boss(self):
  341.         self.HP = round(50 * self.levelmultboss)
  342.         self.ATK = round(5 * self.levelmultboss)
  343.         self.speed = 1
  344.         self.attackspeed = 4
  345.         self.image = image.load('boss.png')
  346.         self.Enx = 750
  347.         self.Eny = 350
  348.         self.height = 40
  349.         self.width = 30
  350.  
  351.     def levelup(self):
  352.         self.levelmultboss = self.levelmultboss * 1.2
  353.         self.levelmult = self.levelmult * 1.25
  354.         self.xpmodifier = self.xpmodifier * 1.2
  355.  
  356.  
  357. ######################################################################
  358. # Sets the time for the game
  359. class gameTime():
  360.     duration = 0
  361.  
  362.     def __init__(self):  # just initialises the objects
  363.         pass
  364.  
  365.     def increase(self):
  366.         self.duration += 0.016  # how long a frame is in secs
  367.  
  368.     def gettime(self):
  369.         return self.duration  # returns time
  370.  
  371.     def printtime(self):
  372.         print(self.duration)  # shows the time
  373.  
  374.     def resettime(self):
  375.         self.duration = 0  # resets the clock
  376.  
  377.  
  378. ######################################################################
  379. # draws User interface stuff and changes it
  380. class UI():
  381.     def __init__(self, HP):  # inititalises the objects
  382.         pass
  383.  
  384.     def drawHPbar(self, curHP,
  385.                   maxHP):  # draws the hp bar in relation to how much health the player has left compared to the max health of the player
  386.         width = 400 * (int(curHP) / int(maxHP))
  387.         bar1 = Rect(40, 40, 400, 10)
  388.         bar2 = Rect(40, 40, width, 10)
  389.         draw.rect(screen, (166, 16, 30), bar1)  # draws bar that shows lost health
  390.         draw.rect(screen, (0, 255, 0), bar2)  # draws bar that shows how much health the player has
  391.  
  392.     def showhealth(self, curHP, maxHP):  # writes out with numbers how much health the player has as a fraction
  393.         text.showtext(str(character.returncurHP()), screen, (200, 0, 200), 465, 34)
  394.         text.showtext("___", screen, (200, 0, 200), 465, 34)
  395.         text.showtext(str(maxHP), screen, (200, 0, 200), 465, 61)
  396.  
  397.     def dead(self, curHP):  # if the player dies, replace the screen with a balck screen and write game over
  398.         if curHP < 1:
  399.             text.showtext("Game Over", screen, (255, 255, 255), 700, 400)
  400.             return True
  401.         return False
  402.  
  403.     def drawattackbar(self,
  404.                       attackspeed):  # draws the attack speed bar in relation to how fast the player can attack compared to how long it has been since the players last successful hit
  405.         width = 100 * attackspeed
  406.         if width > 100:
  407.             width = 100
  408.         bar1 = Rect(1200, 40, 100, 10)
  409.         bar2 = Rect(1200, 40, width, 10)
  410.  
  411.         draw.rect(screen, (166, 16, 30), bar1)  # draws how much time left to wait for next attack
  412.         draw.rect(screen, (0, 255, 0), bar2)  # draws how much tiem waited for next attack
  413.  
  414.  
  415. ######################################################################
  416. class Text():
  417.     def __init__(self):  # initialises text
  418.         pass
  419.  
  420.     def showtext(self, text, screen, colour, x, y):  # calls the message display function
  421.         self.message_display(text, screen, colour, x, y)
  422.  
  423.     def message_display(self, text, screen, colour, x, y):  # blits the text onto the screen
  424.         largetext = font.Font("freesansbold.ttf", 25)  # sets size and font of text
  425.         TextSurf, TextRect = self.text_objects(text, largetext, colour)  # calls text objects function
  426.         TextRect.center = (x, y)  # gets the center of the rectangle with position x,y
  427.         screen.blit(TextSurf, TextRect)  # blits the text
  428.  
  429.     def text_objects(self, text, font, colour):  # assigns the colour and renders the text
  430.         textSurface = font.render(text, True, (colour))
  431.         return textSurface, textSurface.get_rect()  # returns the rendered text and rectangle of text
  432.  
  433.  
  434. ######################################################################
  435. ######################################################################
  436.  
  437. gameMap = [[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
  438.     , [[10], [11], [12], [13], [14], [15], [16], [17], [18], [19]]
  439.     , [[20], [21], [22], [23], [24], [25], [26], [27], [28], [29]]
  440.     , [[30], [31], [32], [33], [34], [35], [36], [37], [38], [39]]
  441.     , [[40], [41], [42], [43], [44], [45], [46], [47], [48], [49]]
  442.     , [[50], [51], [52], [53], [54], [55], [56], [57], [58], [59]]
  443.     , [[60], [61], [62], [63], [64], [65], [66], [67], [68], [69]]
  444.     , [[70], [71], [72], [73], [74], [75], [76], [77], [78], [79]]
  445.     , [[80], [81], [82], [83], [84], [85], [86], [87], [88], [89]]
  446.     , [[90], [91], [92], [93], [94], [95], [96], [97], [98], [99]]]
  447.  
  448. firstroom = 1
  449. visited = []  # creates an empty array for visited rooms
  450. visited.append(spawnpoint)  # appends the place where the player starts to the visited list
  451.  
  452. textpos = 400  # this is just setting variables used later
  453. text = Text()  # creates an object for the text class
  454.  
  455. justonce = True
  456. showdamage = 0
  457. enemycount = 0
  458. number = 1
  459. nextlevel = False
  460. boss = False
  461. bossisdead = False
  462. locked = False  # this is just setting variables used later
  463. collided = False  # this is just setting variables used later
  464. plyAtkSpd = gameTime()  # creates an object for the player attack speed
  465. EnATKSpd = gameTime()  # creates an object for the enemy attack speed
  466. clock = gameTime()  # creates an object for the clock
  467. m, n = 720, 370  # this is just setting variables used later
  468. x, y = 0, 0  # this is just setting variables used later
  469. length = random.randint(6, 10)
  470.  
  471. enemy1 = Enemy()  # sets the enemies
  472. enemy2 = Enemy()
  473. enemy3 = Enemy()
  474. enemy4 = Enemy()
  475. enemy5 = Enemy()
  476. enemy6 = Enemy()
  477. enemies = [enemy1, enemy2, enemy3, enemy4, enemy5, enemy6]  # creates list of enemies
  478.  
  479. character = Character(m, n, 3.2, spawnpoint)  # sets character class
  480. CharLVL = levelUp(0, 100)  # sets char level class
  481. HPbar = UI(character.returncurHP())
  482.  
  483. doorwest = doors(85, 350, 10, 100)  # sets a door
  484. dooreast = doors(1405, 350, 10, 100)  # sets a door
  485. doornorth = doors(700, 85, 100, 10)  # sets a door
  486. doorsouth = doors(700, 705, 100, 10)  # sets a door
  487.  
  488. roomModel = (90, 90, 1320, 620)  # sets background size
  489. key.set_repeat(1, 30)  # sets keys to repeat
  490.  
  491. nextleveldoor = doors(700, 350, 100, 100)
  492. doors = [doorwest, dooreast, doornorth, doorsouth]  # creates list of doors
  493.  
  494. fill = (40, 0, 0)
  495. once = 1
  496.  
  497. while exitProg == False:  # loops while the program is running
  498.     for e in event.get():
  499.         if e.type == constants.QUIT:  # if quit buttom pressed, end loop
  500.             exitProg = True
  501.  
  502.         if e.type == KEYDOWN:  # if key is pressed, move the character in the direction
  503.             if (e.key == constants.K_a):
  504.                 character.moveleft()
  505.             if (e.key == constants.K_d):
  506.                 character.moveright()
  507.             if (e.key == constants.K_w):
  508.                 character.movedown()
  509.             if (e.key == constants.K_s):
  510.                 character.moveup()
  511.             if (e.key == constants.K_SPACE):
  512.                 character.ShowAttack()
  513.  
  514.         if e.type == KEYUP:  # stops the character moving after the key is let go
  515.             if (e.key == constants.K_a):
  516.                 character.stopHorizontal()
  517.             if (e.key == constants.K_d):
  518.                 character.stopHorizontal()
  519.             if (e.key == constants.K_w):
  520.                 character.stopVertical()
  521.             if (e.key == constants.K_s):
  522.                 character.stopVertical()
  523.             if (e.key == constants.K_SPACE):
  524.                 character.ShowAttack()
  525.     screen.fill(fill)  # fills the screen
  526.     draw.rect(screen, (20, 173, 70), roomModel)  # draws the green background
  527.  
  528.     for door in doors:
  529.         door.draw(screen)
  530.         if character.collisionDoor(door, locked) == True:
  531.             collided = True
  532.  
  533.         if nextlevel == True:
  534.             nextleveldoor.draw(screen)
  535.             if character.collisionDoor(nextleveldoor, locked) == True:
  536.                 collided = True
  537.  
  538.     EnATKSpd.increase()
  539.     plyAtkSpd.increase()
  540.     clock.increase()  # increases clock time
  541.     p, q = character.getPosition()  # gets position of the player
  542.     time = clock.gettime()  # gets current time
  543.  
  544.     for enemy in enemies:  # for each enemy
  545.         if enemycount != 0:  # if there are enemies on the screen
  546.             for door in doors:
  547.                 door.lock(screen)  # lock the doors
  548.             locked = True  # set the lock to be true
  549.         else:
  550.             locked = False  # if there are no enemies, then unlock
  551.  
  552.         if boss == True and once == 1:
  553.             enemy.Boss()
  554.             once += 1
  555.             enemycount += 1
  556.  
  557.         if boss == True and enemycount == 0:
  558.             nextlevel = True
  559.             once = 1
  560.             boss = False
  561.             bossisdead = True
  562.  
  563.         if enemy.attackspeed < EnATKSpd.gettime():  # if the enemy can attack as its time before next attack is above time since last attack
  564.             if enemy.collisionPlayer(character.returnRect()) == True:  # if its touching the player
  565.                 enemy.attack(character)  # attack the player
  566.  
  567.         if e.type == KEYDOWN:  # if the plasyer presses space
  568.             if (e.key == constants.K_SPACE):
  569.                 character.ShowAttack()  # show the sword
  570.                 if enemy.collisionSword(
  571.                         character.returnSwordrect()) == True and plyAtkSpd.gettime() >= character.getatkspd():  # if the sword collides with the enemy
  572.                     character.attack(enemy)  # then attack
  573.                     plyAtkSpd.resettime()  # reset the players time to next attack
  574.                     number = 10
  575.  
  576.         if enemy.returnHP() < 1:
  577.             enemycount -= 1
  578.             enemy.isDead()
  579.  
  580.         if character.GetRoomCount() >= length:
  581.             collided = False
  582.             boss = True
  583.             character.resetroomcount()
  584.  
  585.             length = length + random.randint(-1, 6)
  586.  
  587.         if collided == True:  # if the doors are touched and entered
  588.             spawnRate = random.randint(1, 100)
  589.             if spawnRate <= 20:
  590.                 enemy.Archer()
  591.                 enemycount += 1
  592.             if spawnRate >= 21 and spawnRate <= 40:
  593.                 enemy.Orc()
  594.                 enemycount += 1
  595.             if spawnRate >= 41 and spawnRate <= 60:
  596.                 enemy.Soldier()
  597.                 enemycount += 1
  598.             if spawnRate >= 61:
  599.                 enemy.blank()  # select the enemies
  600.  
  601.         enemy.playerCollidesDoor(collided)  # randomly spawn in enemies on the map
  602.         enemy.moveToPlayer(p, q, time)  # moves the enemy to the player
  603.         enemy.update()
  604.  
  605.         if showdamage % number <= 5:
  606.             enemy.show()  # update enemies position and blits it
  607.  
  608.     character.update()  # updates players position
  609.  
  610.     CharLVL.drawXPbar()  # draws the xp bar for the player
  611.     text.showtext("level " + str(CharLVL.getLVL()), screen, (200, 0, 200), 200,
  612.                   765)  # writes the level of the player next to the xp bar
  613.  
  614.     character.bordercheckx()  # checks if player is out of bounds
  615.     character.borderchecky()  # checks if player is out of bounds
  616.     character.changemodel()
  617.     text.showtext("attack speed", screen, (200, 0, 200), 1110, 45)  # writes attack speed onto the screen
  618.  
  619.     a = character.returncurHP()  # sets a variable for the current hp of the player
  620.     b = character.returnmaxHP()  # sets a variable for the max hp of player
  621.     HPbar.drawHPbar(a, b)  # draws the hp bar in relation to the cur and max hp
  622.     HPbar.showhealth(a, b)  # writes the total health and current health as a fraction
  623.     HPbar.drawattackbar(plyAtkSpd.gettime())  # draws the attack speed bar for the player
  624.  
  625.     if HPbar.dead(character.returncurHP()) == True:  # if the player dies
  626.         screen.fill((0, 0, 0))  # make the screen go black
  627.         HPbar.dead(character.returncurHP())  # the player dies and the screen says game over
  628.         firstroom = 10
  629.  
  630.     print(character.GetRoomCount())
  631.  
  632.     if character.collisiondoorother(nextleveldoor, locked, bossisdead) == True:
  633.         enemy.levelup()
  634.         red = random.randint(0, 80)
  635.         green = random.randint(0, 80)
  636.         blue = random.randint(0, 80)
  637.         fill = (red, green, blue)
  638.         bossisdead = False
  639.         nextlevel = False
  640.         firstroom += 1
  641.  
  642.     character.show()  # shows players position on screen
  643.  
  644.     if e.type == KEYDOWN:
  645.         if (e.key == constants.K_SPACE):  # if the player presses space
  646.             character.ShowAttack()  # show the attack
  647.  
  648.     if plyAtkSpd.gettime() >= 0.8:
  649.         number = 1
  650.     if length < 6:
  651.         length == 6
  652.     showdamage = showdamage + 1
  653.     collided = False  # resets collided
  654.     overallTime.tick(60)  # sets fps
  655.     display.flip()  # shows the entire screen
  656.  
  657.  
  658.  
  659.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement