SHARE
TWEET

Dlya_YArika6

a guest Jan 24th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import pygame
  3. import pygame.locals
  4. pygame.init()
  5.  
  6. MONITOR=pygame.display.set_mode((800, 800))
  7. clock=pygame.time.Clock()
  8.  
  9. dimension=pygame.display.set_caption('Defence Of The Pudge')
  10.  
  11. WHITE = (255, 255, 255)
  12.  
  13. TIME=0
  14.  
  15.  
  16. class building(pygame.sprite.Sprite):
  17.     def __init__(self, hp, building_hp_regen,armour, team, placeX, placeY, imagepath):
  18.         pygame.sprite.Sprite.__init__(self)
  19.         self.hp=hp
  20.         self.building_hp_regen=building_hp_regen
  21.         self.armour=armour
  22.         self.team=team
  23.         self.placeX=placeX
  24.         self.placeY=placeY
  25.         self.image =  pygame.image.load(imagepath).convert_alpha()
  26.         self.rect = self.image.get_rect(center=(self.placeX, self.placeY))
  27.  
  28.  
  29. class tower(building):
  30.     def __init__(self, tower_damage, hp, building_hp_regen, armour, team, Tier, placeX, placeY, surf, image):
  31.         self.tower_damage=tower_damage
  32.         self.team=team
  33.         self.Tier=Tier
  34.         self.surf=surf
  35.        
  36.         super().__init__(hp, building_hp_regen, armour, team, placeX, placeY, image)
  37.  
  38.     def attack(self, target_name):
  39.         if (int( self.placeX - target_name.placeX )**2 + int(self.placeY - target_name.placeY)**2)**(1/2) <= 150 and target_name.team != self.team :
  40.             target_name.hp-=self.tower_damage
  41.        
  42.  
  43.  
  44.  
  45.  
  46.  
  47. class Soldier(pygame.sprite.Sprite):
  48.     def __init__(self, team, damage, hp, placeX, placeY, imagepath, Line):
  49.         pygame.sprite.Sprite.__init__(self)
  50.  
  51.         self.team=team
  52.         self.damage=damage
  53.         self.hp=hp
  54.         self.placeX = placeX
  55.         self.placeY = placeY
  56.         self.image =  pygame.image.load(imagepath).convert_alpha()
  57.         self.rect = self.image.get_rect(center=(self.placeX, self.placeY))
  58.         self.Line=Line
  59.    
  60.     def creep_attack(self):
  61.         for i in list_of_soldiers:
  62.             if (int( self.placeX - i.placeX )**2 + int(self.placeY - i.placeY)**2)**(1/2) <=15 and i.team != self.team:
  63.                 i.hp-=self.damage
  64.                 return
  65.             else:
  66.                 if self.Line=='Bottom' and self.team=='radiant':
  67.                     if self.placeX<775:
  68.                         self.placeX+=1
  69.                         self.rect.move_ip(1, 0)
  70.                     else:
  71.                         self.rect.move_ip(0, -1)
  72.                         self.placeY-=1
  73.                 elif self.Line=='Middle' and self.team=='radiant':
  74.                     self.placeX+=1
  75.                     self.placeY-=1
  76.                     self.rect.move_ip(1, -1)
  77.                 elif self.Line=='Top' and self.team=='radiant':
  78.                     if self.placeY>=100:
  79.                         self.placeY-=1
  80.                         self.rect.move_ip(0, -1)
  81.                     else:
  82.                         self.placeX+=1
  83.                         self.rect.move_ip(1, 0)
  84.            
  85.         for i in creepsradiant:
  86.             if (int( self.placeX - i.placeX )**2 + int(self.placeY - i.placeY)**2)**(1/2) <=10 and i.team != self.team:
  87.                 i.hp-=self.damage
  88.                 return
  89.             else:
  90.                 if self.Line=='Top' and self.team=='dire':
  91.                     if self.placeX>775:
  92.                         self.placeX-=1
  93.                         self.rect.move_ip(-1, 0)
  94.                     else:
  95.                         self.rect.move_ip(0, 1)
  96.                         self.placeY+=1
  97.                 elif self.Line=='Middle' and self.team=='dire':
  98.                     self.placeX-=1
  99.                     self.placeY-=1
  100.                     self.rect.move_ip(-1, -1)
  101.                 elif self.Line=='Bottom' and self.team=='dire':
  102.                     if self.placeY<=775:
  103.                         self.placeY+=1
  104.                         self.rect.move_ip(0, 1)
  105.                     else:
  106.                         self.placeX-=1
  107.                         self.rect.move_ip(-1, 0)
  108.         for i in list_of_towers:
  109.             if (int( self.placeX - i.placeX )**2 + int(self.placeY - i.placeY)**2)**(1/2) <=10 and i.team != self.team:
  110.                 i.hp-=self.damage
  111.             else:
  112.                 for c in creepsradiant:
  113.                     if (int( self.placeX - i.placeX )**2 + int(self.placeY - i.placeY)**2)**(1/2) <=10 and i.team != self.team:
  114.                         return
  115.                
  116.                 for c in list_of_soldiers:
  117.                     if (int( self.placeX - i.placeX )**2 + int(self.placeY - i.placeY)**2)**(1/2) <=10 and i.team != self.team:
  118.                         return
  119.                 if self.Line=='Bottom' and self.team=='radiant':
  120.                     if self.placeX<775:
  121.                         self.placeX+=1
  122.                         self.rect.move_ip(1, 0)
  123.                     else:
  124.                         self.rect.move_ip(0, -1)
  125.                         self.placeY-=1
  126.                 elif self.Line=='Middle' and self.team=='radiant':
  127.                     self.placeX+=1
  128.                     self.placeY+=1
  129.                     self.rect.move_ip(1, 1)
  130.                 elif self.Line=='Top' and self.team=='radiant':
  131.                     if self.placeY<=775:
  132.                         self.placeX+=1
  133.                         self.rect.move_ip(1, 0)
  134.     def creep_check_hp(self):
  135.         if self.hp<=0 and self.team=='dire':
  136.             list_of_soldiers.remove(self)
  137.         elif self.hp<=0 and self.team=='radiant':
  138.             creepsradiant.remove(self)
  139.  
  140.            
  141.  
  142.  
  143.  
  144.        
  145.  
  146.  
  147.  
  148. # Return the number of the current active tower
  149. def checkTowers(list_of_towers):
  150.     current = 1
  151.     for tower in list_of_towers:
  152.         if tower.hp < 1:
  153.             current += 1
  154.  
  155.     return current
  156.  
  157.  
  158.  #class ANCIENT(building):
  159.      #pass
  160.  
  161.  
  162.        
  163. class shrine(building):
  164.      def restore(self, teammate):
  165.          teammate.hp=teammate.max_hp
  166.  
  167.  
  168. class barrack(building):
  169.      pass
  170.    
  171.  
  172. class melee_barrack(barrack):
  173.      def destroyed(self, enemy_team):
  174.          if self.hp==0:
  175.              if self.team=='radiant':
  176.                  t2.HeroDire.hp*=2
  177.              elif self.team=='dire':
  178.                  t1.HeroRadiant.hp*=2
  179.  
  180.  
  181. class range_barrack(barrack):
  182.     def destroyed(self, enemy_team):
  183.         if self.hp==0:
  184.             if self.team=='radiant':
  185.                 t2.HeroDire.damage*=2
  186.             elif self.team=='dire':
  187.                 t1.HeroRadiant.damage*=2
  188.  
  189.  
  190. class item:
  191.     def __init__(self, cost, Item_damage):
  192.         self.cost=cost
  193.         self.Item_damage=Item_damage
  194.    
  195.  
  196.  
  197.  
  198. class Hero:
  199.     def __init__(self, lvl, team, damage, hp, gold, Item_slots, stash, max_hp, placeX, placeY, movespeed):
  200.  
  201.          self.lvl=lvl
  202.          self.damage=damage
  203.          self.hp=hp
  204.          self.gold=gold
  205.          self.Item_slots=Item_slots
  206.          self.stash=stash
  207.          self.max_hp=max_hp
  208.          self.placeX=placeX
  209.          self.placeY=placeY
  210.          # self.place=place,
  211.          self.movespeed=movespeed
  212.  
  213.     def farm(self, team):
  214.         if team==radiant():
  215.             dire.countD-=1
  216.         elif team==dire():
  217.             radiant.countR-=1
  218.  
  219.         if  dire.countD==0:
  220.             radiant.HeroRadiant.lvl+=1
  221.         elif radiant.countR==0:
  222.             dire.HeroDire.lvl+=1
  223.         else:
  224.             pass
  225.  
  226.     def attack(self, target_name):
  227.         target_name.hp-=self.damage*(target_name.armour/100)
  228.  
  229.     def buy_Item(self, desired_Item):
  230.         if self.gold>=desired_Item.cost:
  231.             if self.Item_slots>0:
  232.                 self.damage+=desired_Item.Item_damage
  233.                 self.gold-=desired_Item.cost
  234.             else:
  235.                 pass
  236.         else:
  237.             pass
  238.  
  239.     def move(self, ):
  240.         pass    
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247. class radiant:
  248.     #if time==30:
  249.         #time=0
  250.         #for N in range(1, 5):
  251.             #creepsradiant.append(Soldier('radiant', 10, 1000, 500, 500, 'rogue.png'))
  252.        
  253.     HeroRadiant=Hero(1, 'radiant', 55, 600, 1000, 6, 3, 600, 5, 100, 27)
  254.     countR=0
  255.  
  256. map_surf=pygame.image.load('DOTAMAP.jpg').convert_alpha()
  257. map_rect = map_surf.get_rect(center=(300, 200))
  258.  
  259. class dire:
  260.     #creepsdire=[]
  261.     #for N in range(6, 11):
  262.         #creepsdire.append(Soldier('dire', 10, 1000, 500, 500, 'knight.png'))
  263.        
  264.     HeroDire=Hero(1, 'dire', 60, 560, 0, 6, 3, 560, 70, 502, 32)
  265.     T1TowerDire=tower(100, 1000, 50, 50, 'dire', 1, 350, 450, map_surf, 'DOTATOWERDIRE.png')
  266.    
  267.  
  268.  
  269. Daedalus=item(200, 80)
  270. t1=radiant()
  271. t2=dire()
  272.  
  273.  
  274.  
  275. # map image
  276.  
  277.  
  278.  
  279.  
  280. tower1 = tower(100, 1000, 50, 50, 'radiant', 1, 350, 450, map_surf, 'DOTATOWERDIRE.png')
  281. tower2 = tower(100, 1000, 50, 50, 'radiant', 2, 250, 550, map_surf, 'DOTATOWERDIRE.png')
  282. tower3 = tower(100, 5000, 50, 50, 'radiant', 3, 150, 620, map_surf, 'DOTATOWERDIRE.png')
  283. tower4 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 550, map_surf, 'DOTATOWERDIRE.png')
  284. tower5 = tower(100, 10000, 50, 50, 'radiant', 4, 200, 750, map_surf, 'DOTATOWERDIRE.png')
  285.  
  286. tower6 = tower(100, 10000, 50, 50, 'radiant', 4, 70, 440, map_surf, 'DOTATOWERDIRE.png')
  287. #tower7 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  288. #tower8 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  289.  
  290. #tower9 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  291. #tower10 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  292. #tower11 = tower(100, 10000, 50, 50, 'radiant', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  293.  
  294.  
  295. #tower12 = tower(100, 1000, 50, 50, 'dire', 1, 350, 450, map_surf, 'DOTATOWERDIRE.png')
  296. #tower13 = tower(100, 1000, 50, 50, 'dire', 2, 250, 550, map_surf, 'DOTATOWERDIRE.png')
  297. #tower14 = tower(100, 5000, 50, 50, 'dire', 3, 150, 650, map_surf, 'DOTATOWERDIRE.png')
  298. #tower15 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  299. #tower16 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  300.  
  301. #tower17 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  302. #tower18 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  303. #tower19 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  304.  
  305. #tower20 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  306. #tower21 = tower(100, 10000, 50, 50, 'dire', 4, 50, 750, map_surf, 'DOTATOWERDIRE.png')
  307. #tower22 = tower(100, 10000, 50, 50, 'dire', 4, 50, 550, map_surf, 'DOTATOWERDIRE.png')
  308.  
  309.  
  310. shrine1 = shrine(500, 5, 5, 'radiant', 700, 700, 'SHRINERADIANT.png' )
  311. shrine2 = shrine(500, 5, 5, 'dire', 150, 150, 'SHRINEDIRE.png' )
  312.  
  313. list_of_towers = [tower1, tower2, tower3,tower4, tower5, tower6]
  314. # list of Tower objects
  315. #list_of_towers = [tower1, tower2, tower3,tower4, tower5, tower6, tower7, tower8, tower9, tower10, tower11, tower12,
  316.  #tower13, tower14, tower15, tower16, tower17, tower18, tower19, tower20, tower21, tower22]
  317. list_of_shirnes = [shrine1, shrine2]
  318. creepsradiant=[]
  319. list_of_soldiers = []
  320.  
  321. # list of Soldier objects
  322.  
  323.  
  324. print(f'Current tower: {checkTowers(list_of_towers)}')
  325. print(f'Overlapping soldiers with such indexes: {tower1.rect.collidelistall(list_of_soldiers)}')
  326.  
  327.  
  328. # Make the map smaller
  329. scale = pygame.transform.scale(map_surf, (map_surf.get_width()*4,
  330.                                           map_surf.get_height()*4))
  331. scale_rect = scale.get_rect(center=(400, 400))
  332.  
  333.  
  334. PLACEXR=300
  335. PLACEYR=775
  336.  
  337. PLACEXD=775
  338. PLACEYD=300
  339.  
  340.  
  341.  
  342. while 1:
  343.     TIME+=1
  344.     clock.tick(5)
  345.     MONITOR.blit(scale, scale_rect)
  346.     pressed_key=pygame.key.get_pressed()
  347.     for i in pygame.event.get():
  348.         if i.type==pygame.QUIT:exit
  349.  
  350.     if pressed_key[pygame.K_LALT]:
  351.             for tower in list_of_towers:
  352.                     pygame.draw.circle(MONITOR, (0, 70, 225), (tower.placeX, tower.placeY), 50, 2)
  353.  
  354.  
  355.  
  356.     if TIME%90==0:
  357.         for i in range(5):
  358.             creepsradiant.append(Soldier('radiant', random.randint(18, 22), 550, random.randint(298, 302), random.randint(773, 777), 'rogue.png', 'Bottom'))
  359.         for i in range(5):
  360.             creepsradiant.append(Soldier('radiant', random.randint(18, 22), 550, random.randint(48, 52), random.randint(548, 552), 'rogue.png', 'Top'))
  361.         for i in range(5):
  362.             creepsradiant.append(Soldier('radiant', random.randint(18, 22), 550, random.randint(148, 152), random.randint(618, 622), 'rogue.png', 'Middle'))
  363.  
  364.  
  365.    
  366.     if TIME%90==0:
  367.         for i in range(5):
  368.             list_of_soldiers.append(Soldier('dire', random.randint(18, 22), 550, PLACEXD, PLACEYD, 'knight.png', 'Bottom'))
  369.             PLACEXD-=random.randint(-2, 3)
  370.             PLACEYD-=random.randint(-2, 3)
  371.         for i in range(5):
  372.             list_of_soldiers.append(Soldier('dire', random.randint(18, 22), 550, PLACEXD, PLACEYD, 'knight.png', 'Top'))
  373.             PLACEXD-=random.randint(-2, 3)
  374.             PLACEYD-=random.randint(-2, 3)
  375.     else:
  376.         PLACEXD=775
  377.         PLACEYD=300
  378.  
  379.        
  380.  
  381.  
  382.                    
  383.     # Draw each tower
  384.     for tower in list_of_towers:
  385.         MONITOR.blit(tower.image, tower.rect)
  386.  
  387.     # Draw each soldier
  388.     for soldier in list_of_soldiers:
  389.         MONITOR.blit(soldier.image, soldier.rect)
  390.  
  391.     for shrine in list_of_shirnes:
  392.          MONITOR.blit(shrine.image, shrine.rect)
  393.     #releaze creeps attack
  394.     for creep in creepsradiant:
  395.         MONITOR.blit(creep.image, creep.rect)
  396.     for s in creepsradiant:
  397.         s.creep_attack()
  398.         print(s.placeX, s.placeY)
  399.     for s in list_of_soldiers:
  400.         s.creep_attack()
  401.     for i in list_of_soldiers:
  402.         i.creep_check_hp()
  403.     for i in creepsradiant:
  404.         i.creep_check_hp()
  405.    
  406.  
  407.  
  408.     pygame.display.update()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top