Advertisement
habib257

Untitled

Jul 13th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 35.48 KB | None | 0 0
  1. import pygame
  2. import math
  3. import random
  4. pygame.init()
  5.  
  6. width = 800
  7. height = 700
  8. window = pygame.display.set_mode((width, height), pygame.NOFRAME)
  9. pygame.display.set_caption("Game")
  10.  
  11.  
  12. # game intro buttons
  13. def button(msg,x,y,w,h,ic,ac,fadescreen,action=None):
  14.     mouse = pygame.mouse.get_pos()
  15.     click = pygame.mouse.get_pressed()
  16.  
  17.     if x+w > mouse[0] > x and y+h > mouse[1] > y:
  18.         pygame.draw.rect(window, ac,(x,y,w,h))
  19.         if click[0] == 1 and action != None:
  20.             action()        
  21.     else:
  22.         pygame.draw.rect(window, ic,(x,y,w,h ))
  23.         smallText = pygame.font.SysFont("Candarai.ttf",40)
  24.         textSurf, textRect = text_objects(msg, smallText)
  25.         textRect.center = ( (x+(w/2)), (y+(h/2)) )
  26.         window.blit(textSurf, textRect)
  27.        
  28.     #------------------------------------------------------
  29.  
  30.  
  31. def text_objects(text, font):
  32.     black = (255,255,255)
  33.     textSurface = font.render(text, True, black)
  34.     return textSurface, textSurface.get_rect()
  35. # you lose screen
  36. whs = (255,255,255)
  37. def text_objects(text, font):
  38.     textSurface = font.render(text, True, whs)
  39.     return textSurface, textSurface.get_rect()
  40.  
  41.  
  42.  
  43. def message_display(text):
  44.     largeText = pygame.font.Font('freesansbold.ttf',35)
  45.     TextSurf, TextRect = text_objects(text, largeText)
  46.     TextRect.center = ((590/2),(580/2))
  47.     window.blit(TextSurf, TextRect)
  48.  
  49.     pygame.display.update()
  50.     game_intro()
  51.     time.sleep(0)
  52.  
  53.  
  54.    
  55.  
  56.  
  57.  
  58. def crash():
  59.     message_display('......')
  60.  
  61. # the scoring
  62. font = pygame.font.Font("do.ttf", 50)
  63. apple = 0
  64. text = font.render(" Fish " + str(apple), True, (255,255,255))
  65. rect = text.get_rect()
  66.  
  67. # end screen
  68. def end_screen():
  69.  
  70.     # this makes it            
  71.     snow_list=[]
  72.     no_of_circles=100;
  73.     clock = pygame.time.Clock()
  74.     FPS = 60
  75.     clock.tick(FPS)
  76.     for i in range(no_of_circles):
  77.         x = random.randrange(0, 800)
  78.         y = random.randrange(0, 700)
  79.         snow_list.append([x,y])
  80.  
  81.     # the background image
  82.        
  83.     red = (200,0,0)
  84.     green = (255,250,250)
  85.     bright_red = (255,250,0)
  86.     bright_green = (0,255,0)
  87.     clock = pygame.time.Clock()
  88.     intro = True
  89.     while intro:
  90.         clock.tick(FPS)
  91.         for event in pygame.event.get():
  92.             if event.type == pygame.QUIT:
  93.                 intro = False
  94.                 pygame.quit()
  95.  
  96.  
  97.  
  98.  
  99.     # GAME INTRO IMAGE
  100.         button("Click To Play!",40,310,220,60,green,bright_green,crash)
  101.         bls = pygame.image.load("end.png")
  102.         window.blit(bls,(0,0))
  103.  
  104.  
  105.         window.blit(text,rect)
  106.  
  107.         for point in snow_list:
  108.             point[1]+=1
  109.             pygame.draw.circle(window, (255,255,255), point, 2)
  110.  
  111.             if(point[1] >= 600):
  112.                 point[0] = random.randrange(0, 600)
  113.                 point[1] = random.randrange(-10, -5)
  114.  
  115.         clock.tick(FPS)
  116.  
  117.  
  118.  
  119.                    
  120.  
  121.  
  122.  
  123.     # ---------------------------------------------------------------------
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      
  130.  
  131.         pygame.display.update()
  132.  
  133.  
  134.  
  135.            
  136. # start screen
  137. def game_intro():
  138.    
  139.     def fade(width, height):
  140.         fade = pygame.Surface((width,height))
  141.         fade.fill((0,0,0))
  142.         for alpha in range(0, 300):
  143.             fade.set_alpha(alpha)
  144.             redraw()
  145.             window.blit(fade, (0,0))
  146.             pygame.display.update()
  147.             pygame.time.delay(5)
  148.  
  149.            
  150.     bls = pygame.image.load("gametitle.png")
  151.  
  152.     def redraw():
  153.         window.blit(bls,(0,0))
  154.  
  155.     # this makes it            
  156.     snow_list=[]
  157.     no_of_circles=100;
  158.     clock = pygame.time.Clock()
  159.     FPS = 60
  160.     clock.tick(FPS)
  161.     for i in range(no_of_circles):
  162.         x = random.randrange(0, 800)
  163.         y = random.randrange(0, 700)
  164.         snow_list.append([x,y])
  165.  
  166.     # the background image
  167.        
  168.     red = (200,0,0)
  169.     green = (255,250,250)
  170.     bright_red = (255,250,0)
  171.     bright_green = (0,255,0)
  172.     clock = pygame.time.Clock()
  173.     intro = True
  174.     while intro:
  175.         clock.tick(FPS)
  176.         for event in pygame.event.get():
  177.             if event.type == pygame.QUIT:
  178.                 intro = False
  179.                 pygame.quit()
  180.  
  181.  
  182.  
  183.  
  184.     # GAME INTRO IMAGE
  185.         button("Click To Play!",40,310,220,60,green,bright_green,fade(800,800),main_loop)
  186.         redraw()
  187.  
  188.  
  189.  
  190.         for point in snow_list:
  191.             point[1]+=1
  192.             pygame.draw.circle(window, (255,255,255), point, 2)
  193.  
  194.             if(point[1] >= 600):
  195.                 point[0] = random.randrange(0, 600)
  196.                 point[1] = random.randrange(-10, -5)
  197.  
  198.         clock.tick(FPS)
  199.  
  200.  
  201.  
  202.                    
  203.  
  204.  
  205.  
  206.     # ---------------------------------------------------------------------
  207.  
  208.  
  209.  
  210.  
  211.  
  212.      
  213.  
  214.         pygame.display.update()
  215.  
  216.  
  217.  
  218.  
  219.  
  220. def main_loop():
  221.     # player class
  222.  
  223.     class player:
  224.         def __init__(self,x,y,height,width,color):
  225.             self.x = x
  226.             self.y = y
  227.             self.color = color
  228.             self.height  = height
  229.             self.width = width
  230.             self.speed = 7
  231.             self.isJump = False
  232.             self.JumpCount = 10
  233.             self.fall = 0
  234.                 #hit box
  235.             self.hitbox = (self.x + 20, self.y, 28, 60)
  236.             self.rights = [pygame.image.load("w1.png"),
  237.             pygame.image.load("w2.png"),
  238.             pygame.image.load("w3.png"),
  239.             pygame.image.load("w4.png"),
  240.             pygame.image.load("w5.png"),
  241.             pygame.image.load("w6.png")]
  242.  
  243.             self.lefts = [pygame.image.load("e1.png"),
  244.                 pygame.image.load("e2.png"),
  245.                 pygame.image.load("e3.png"),
  246.                 pygame.image.load("e4.png"),
  247.                 pygame.image.load("e5.png"),
  248.                 pygame.image.load("e6.png")]
  249.  
  250.             self.hitright = [pygame.image.load("h1.png"),
  251.                 pygame.image.load("h2.png"),
  252.                 pygame.image.load("h3.png"),
  253.                 pygame.image.load("h4.png"),
  254.                 pygame.image.load("h5.png"),
  255.                 pygame.image.load("h6.png")]
  256.  
  257.  
  258.             self.hitleft = [pygame.image.load("h11.png"),
  259.                 pygame.image.load("h12.png"),
  260.                 pygame.image.load("h13.png"),
  261.                 pygame.image.load("h14.png"),
  262.                 pygame.image.load("h15.png"),
  263.                 pygame.image.load("h16.png")]
  264.  
  265.  
  266.  
  267.             self.standingright = [pygame.image.load("d1.png"),
  268.                         pygame.image.load("d2.png"),
  269.                         pygame.image.load("d3.png"),
  270.                         pygame.image.load("d4.png")]
  271.             self.standingleft =[pygame.image.load("s1.png"),
  272.  
  273.                     pygame.image.load("s2.png"),
  274.                     pygame.image.load("s3.png"),
  275.                     pygame.image.load("s4.png")]
  276.             self.rights = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.rights]
  277.             self.lefts = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.lefts]
  278.             self.standingright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingright]
  279.             self.standingleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingleft]
  280.  
  281.             self.hitright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitright]
  282.  
  283.  
  284.             self.hitleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitleft]
  285.  
  286.             self.bo_index = 0
  287.             self.anim_index = 0
  288.             self.stans_index = 0
  289.             self.direction = "right"
  290.             self.direction = "left"
  291.             self.direction = "standright"
  292.             self.direction = "standleft"
  293.             self.direction = "hitright"
  294.             self.direction = "hitleft"
  295.             self.health = 10
  296.             self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  297.             self.hit = (self.x + -30, self.y + 0, 31, 57)
  298.  
  299.                 # playerman hitbox
  300.             self.hit = (self.x + 22, self.y + 60, 31, 27)
  301.  
  302.             # the health bar image
  303.             self.healthimage = pygame.image.load("yup.png")
  304.             self.klox = (self.x + -30, self.y + 0, 31, 57)
  305.  
  306.             self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
  307.  
  308.             self.healthimage = pygame.transform.scale(self.healthimage,(self.healthimage.get_width()//7,self.healthimage.get_height()//7))
  309.  
  310.             self.fps = 30
  311.             self.FPS = 115
  312.             self.clock = pygame.time.Clock()
  313.  
  314.         def draw(self):
  315.             window.blit(self.healthimage,self.klox)
  316.             self.rect.topleft = (self.x,self.y)
  317.  
  318.             if self.direction == "right":
  319.                 self.clock.tick(self.fps)
  320.  
  321.                 image_list = self.rights
  322.  
  323.             elif self.direction == "standright":
  324.                 self.clock.tick(self.fps)
  325.                 image_list = self.standingright
  326.             elif self.direction == "left":
  327.                 self.clock.tick(self.fps)
  328.                 image_list = self.lefts
  329.  
  330.             elif self.direction == "hitright":
  331.                 self.clock.tick(self.FPS)
  332.                 image_list = self.hitright
  333.  
  334.             elif self.direction == "hitleft":
  335.                 self.clock.tick(self.FPS)
  336.                 image_list = self.hitleft
  337.  
  338.             else:
  339.                 self.clock.tick(self.fps)
  340.                 image_list = self.standingleft
  341.  
  342.  
  343.             if self.anim_index >= len(image_list):
  344.                 self.anim_index = 0
  345.             player_image = image_list[self.anim_index]
  346.             self.anim_index += 1
  347.  
  348.             self.hits = (self.x + 20, self.y, 26,60)
  349.             pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 40, 170, 15)) # NEW
  350.             pygame.draw.rect(window, (0,200,0), (self.hitbox[0], self.hitbox[1] - 40, 170 - (5 * (10 - self.health)), 15))
  351.  
  352.             self.hitbox = (10,  97, 61, 47)
  353.             # health image
  354.             self.klox = (2,  50, 61, 57)
  355.             self.hit = (self.x + 22, self.y + 30, 41, 57)
  356.  
  357.             window.blit(player_image, self.rect)
  358.             pygame.draw.rect(window,self.color,self.hit,2)
  359.            
  360.     white = 255,255,255
  361.     playerman = player(200,300,90,50,white)
  362.  
  363.  
  364.  
  365.     class slime:
  366.         def __init__(self,x,y,height,width,end):
  367.             self.x = x
  368.             self.y =y
  369.             self.esright = [pygame.image.load("esright1.png"),
  370.                     pygame.image.load("esright2.png"),
  371.                     pygame.image.load("esright3.png"),
  372.                     pygame.image.load("esright4.png"),
  373.                     pygame.image.load("esright5.png"),
  374.                     pygame.image.load("esright6.png"),
  375.                     pygame.image.load("esright7.png"),
  376.                     pygame.image.load("esright8.png")
  377.                                       ]
  378.             self.esleft = [pygame.image.load("esleft1.png"),
  379.                     pygame.image.load("esleft2.png"),
  380.                     pygame.image.load("esleft3.png"),
  381.                     pygame.image.load("esleft4.png"),
  382.                     pygame.image.load("esleft5.png"),
  383.                     pygame.image.load("esleft6.png"),
  384.                     pygame.image.load("esleft7.png"),
  385.                     pygame.image.load("esleft8.png")
  386.                                       ]
  387.             self.esright = [pygame.transform.scale(image,(image.get_width()//1,image.get_height()//1)) for image in self.esright]
  388.             self.esleft = [pygame.transform.scale(image,(image.get_width()//1,image.get_height()//1)) for image in self.esleft]
  389.             self.height = height
  390.             self.width = width
  391.             self.anim_index = 0
  392.             self.distance = 80
  393.             self.speed = 8
  394.             self.vel = 3
  395.             self.path = [x,end]
  396.             self.Walking_index = 0
  397.             self.hitbox = (self.x + 17, self.y + 2, 31, 57)
  398.             self.rect = pygame.Rect(x,y,height,width)
  399.             COOLDOWN = 30
  400.                 # enemys health
  401.             self.health = 10
  402.             self.visible = True
  403.             self.Walking =  0
  404.                 # this makes the enemy move right and left
  405.         def draw(self,window):
  406.             if self.Walking + 1 >= 33:
  407.                 self.Walking = 0
  408.  
  409.             if self.vel > 0:        # left
  410.                 window.blit(self.esright[self.Walking %3], (self.x,self.y))
  411.                 self.Walking += 1
  412.             else:                   # right
  413.                 window.blit(self.esleft[self.Walking %3], (self.x,self.y))
  414.                 self.Walking += 1
  415.  
  416.             pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 20, 10)) # NEW
  417.             pygame.draw.rect(window, (255, 87, 51), (self.hitbox[0], self.hitbox[1] - 20, 20 - (5 * (10 - self.health)), 10))
  418.             self.hitbox = (self.x + 2, self.y + 101, 60, 52)
  419.  
  420.              
  421.             # THIS PART MAKES  the enemy not scroll with the playzer
  422.             def scroll(self,sx, sy):
  423.                 self.x += sx
  424.                 self.y += sy
  425.                 self.path[0] += sx
  426.                 self.path[1] += sx
  427.  
  428.  
  429.     slime1 = slime(100,301,50,50,white)
  430.  
  431.     # player class
  432.  
  433.     class player:
  434.         def __init__(self,x,y,height,width,color):
  435.             self.x = x
  436.             self.y = y
  437.             self.color = color
  438.             self.height  = height
  439.             self.width = width
  440.  
  441.  
  442.             # run dust frame
  443.             self.dusts = [pygame.image.load("dust1.png"),
  444.                 pygame.image.load("dust2.png"),
  445.                 pygame.image.load("dust3.png"),
  446.                 pygame.image.load("dust4.png"),
  447.                 pygame.image.load("dust5.png"),
  448.                 pygame.image.load("dust6.png"),
  449.                 pygame.image.load("dust7.png"),
  450.                 pygame.image.load("dust8.png")]
  451.  
  452.  
  453.             self.anim_index = 0
  454.             self.direction = "dustright"
  455.  
  456.             self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
  457.  
  458.             self.fps = 20
  459.             self.clock = pygame.time.Clock()
  460.  
  461.         def draw(self):
  462.            
  463.             self.rect.topleft = (self.x,self.y)
  464.  
  465.            
  466.  
  467.             if self.direction == "dustright":
  468.                 self.clock.tick(self.fps)
  469.                 image_list = self.dusts
  470.  
  471.  
  472.  
  473.             if self.anim_index >= len(image_list):
  474.                 self.anim_index = 0
  475.             player_image = image_list[self.anim_index]
  476.             self.anim_index += 1
  477.  
  478.  
  479.  
  480.  
  481.            
  482.     white = 255,255,255
  483.     dudel = player(200,200,50,50,white)
  484.     # apple class
  485.  
  486.     # bomb class
  487.  
  488.     # slow motion rect
  489.     class slow:
  490.         def __init__(self,x,y,height,width,color):
  491.             self.x = x
  492.             self.y =y
  493.             self.height = height
  494.             self.width = width
  495.             self.color = color
  496.             self.rect = pygame.Rect(x,y,height,width)
  497.         def draw(self):
  498.             self.rect.topleft = (self.x,self.y)
  499.             pygame.draw.rect(window,self.color,self.rect)
  500.  
  501.     slowmoition1 = slow(100,100,30,450,white)
  502.     slowmoition2 = slow(690,100,30,450,white)
  503.     # fade effect
  504.  
  505.  
  506.     # platform class
  507.     class platform:
  508.         def __init__(self,x,y,height,width,color):
  509.             self.x = x
  510.             self.y = y
  511.             self.height = height
  512.             self.width = width
  513.             self.color = color
  514.             self.image1 = pygame.image.load("Tile_25.png")
  515.             self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()*2,self.image1.get_height()*2))
  516.             self.rect = pygame.Rect(x,y,height,width)
  517.         def draw(self):
  518.             self.rect.topleft = (self.x,self.y)
  519.             window.blit(self.image1,self.rect)
  520.  
  521.     class platform2:
  522.         def __init__(self,x,y,height,width,color):
  523.             self.x = x
  524.             self.y = y
  525.             self.height = height
  526.             self.width = width
  527.             self.color = color
  528.             self.rect = pygame.Rect(x,y,height,width)
  529.             self.block2 = pygame.image.load("Tile_12.png")
  530.             self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
  531.         def draw(self):
  532.             self.rect.topleft = (self.x,self.y)
  533.             window.blit(self.block2,self.rect)
  534.  
  535.  
  536.     class plat:
  537.         def __init__(self,x,y,height,width,color):
  538.             self.x = x
  539.             self.y = y
  540.             self.height = height
  541.             self.width = width
  542.             self.color = color
  543.             self.block2 = pygame.image.load("Tile_07.png")
  544.             self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
  545.             self.rect  = pygame.Rect(x,y,height,width)
  546.         def draw(self):
  547.             self.rect.topleft = (self.x,self.y)
  548.             window.blit(self.block2,self.rect)
  549.  
  550.     # player projectile
  551.     class projectile(object):
  552.         def __init__(self, x, y, dirx, diry, color):
  553.            
  554.             self.x = x
  555.             self.y = y
  556.             self.dirx = dirx
  557.             self.diry = diry
  558.             self.image1 = pygame.image.load("pros.png")
  559.             self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()//2,self.image1.get_height()//2))
  560.  
  561.             self.rect  = self.image1.get_rect()
  562.             self.rect.topleft = ( self.x, self.y )
  563.             self.speed = 17
  564.             self.color = color
  565.         def move(self):
  566.            
  567.             self.x += self.dirx * self.speed
  568.             self.y += self.diry * self.speed
  569.         def draw(self, window):
  570.            
  571.             self.rect.topleft = (round(self.x), round(self.y))
  572.             window.blit(self.image1,self.rect)
  573.  
  574.  
  575.  
  576.     plats = []
  577.            
  578.     platforms2   = []    
  579.     platforms = []
  580.     platformGroup = pygame.sprite.Group
  581.  
  582.     level = [
  583.     "n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n    n",
  584.     "s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s    s                                                                               ",
  585.              "                                                                             ",
  586.              "l                                                                       l              ",
  587.              "g                                                                       g        ",
  588.              "g                                                                       g          ",
  589.              "g                                                                       g       ",
  590.              "g                                                                       g            ",
  591.              "                                                                                ",
  592.              "c     c     c     c     c     c     c     c     c     c     c     c     c     c     ",
  593.              "                     ",
  594.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  595.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  596.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  597.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  598.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  599.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d"]
  600.  
  601.     for iy, row in enumerate(level):
  602.         for ix, col in enumerate(row):
  603.             if col == "c":
  604.                 new_platforms = platform(ix*9.8, iy*50, 60,90,(255,255,255))
  605.                 platforms.append(new_platforms)
  606.  
  607.     for iy, row in enumerate(level):
  608.         for ix, col in enumerate(row):
  609.             if col == "d":
  610.                 new_platforms = platform2(ix*10.6, iy*45.9, 60,70,(255,255,255))
  611.                 platforms2.append(new_platforms)
  612.  
  613.     for iy, row in enumerate(level):
  614.         for ix, col in enumerate(row):
  615.             if col == "g":
  616.                 new_platforms = platform2(ix*10.6, iy*55.9, 60,70,(255,255,255))
  617.                 platforms2.append(new_platforms)
  618.  
  619.     for iy, row in enumerate(level):
  620.         for ix, col in enumerate(row):
  621.             if col == "l":
  622.                 new_platforms = platform(ix*10.6, iy*55.9, 60,670,(255,255,255))
  623.                 platforms.append(new_platforms)
  624.  
  625.     for iy, row in enumerate(level):
  626.         for ix, col in enumerate(row):
  627.             if col == "s":
  628.                 new_platforms = platform2(ix*10.6, iy*-45.9, 60,70,(255,255,255))
  629.                 platforms2.append(new_platforms)
  630.  
  631.     for iy, row in enumerate(level):
  632.         for ix, col in enumerate(row):
  633.             if col == "n":
  634.                 new_platforms = plat(ix*10.6, iy*79, 60,70,(255,255,255))
  635.                 plats.append(new_platforms)
  636.  
  637.  
  638.     # ReDrawing the window
  639.     block2 = pygame.image.load("1.png")
  640.     block2 = pygame.transform.scale(block2,(block2.get_width()*2,block2.get_height()*2))
  641.     bg = pygame.image.load("bl.png")
  642.  
  643.     class particle:
  644.         def __init__(self,x,y):
  645.             self.x = x
  646.             self.y = y
  647.             self.x_vel = random.randrange(-10,13)*1
  648.             self.y_vel = random.randrange(-10,-1)*1
  649.             self.lifetime = 0
  650.             self.partilight = pygame.image.load("cls.png")
  651.             self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//2,self.partilight.get_height()//2))        
  652.         def draw(self,window):
  653.             self.lifetime += 1
  654.             if self.lifetime <30:
  655.                 self.x -= self.x_vel
  656.                 self.y -= self.y_vel
  657.                 window.blit(self.partilight,(self.x,self.y,16,16))
  658.  
  659.     class partic:
  660.         def __init__(self,x,y):
  661.             self.x = x
  662.             self.y = y
  663.             self.x_vel = random.randrange(-10,13)*1
  664.             self.y_vel = random.randrange(-10,-1)*1
  665.             self.lifetime = 0
  666.             self.partilight = pygame.image.load("smoke.png")
  667.             self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//2,self.partilight.get_height()//2))        
  668.         def draw(self,window):
  669.             self.lifetime += 1
  670.             if self.lifetime <5:
  671.                 self.x += self.x_vel
  672.                 self.y += self.y_vel
  673.                 window.blit(self.partilight,(self.x,self.y,16,16))
  674.     class partic:
  675.         def __init__(self,x,y):
  676.             self.x = x
  677.             self.y = y
  678.             self.x_vel = random.randrange(-10,13)*1
  679.             self.y_vel = random.randrange(-10,-1)*1
  680.             self.lifetime = 0
  681.             self.partilight = pygame.image.load("sds.png")
  682.             self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//3,self.partilight.get_height()//3))        
  683.         def draw(self,window):
  684.             self.lifetime += 1
  685.             if self.lifetime <6:
  686.                 self.x += self.x_vel
  687.                 self.y += self.y_vel
  688.                 window.blit(self.partilight,(self.x,self.y,5,5))
  689.  
  690.     class parti:
  691.         def __init__(self,x,y):
  692.             self.x = x
  693.             self.y = y
  694.             self.x_vel = random.randrange(-10,13)*1
  695.             self.y_vel = random.randrange(-10,-1)*1
  696.             self.lifetime = 0
  697.             self.partilight = pygame.image.load("sds.png")
  698.             self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//3,self.partilight.get_height()//3))        
  699.         def draw(self,window):
  700.             self.lifetime += 1
  701.             if self.lifetime <26:
  702.                 self.x -= self.x_vel
  703.                 self.y -= self.y_vel
  704.                 pygame.draw.rect(window,(255,255,255),(self.x,self.y,10,10))
  705.                
  706.     # the falling apples:
  707.     class apple:
  708.         def __init__(self,x,y,height,width,color):
  709.             self.x = x
  710.             self.y =y
  711.             self.height = height
  712.             self.width = width
  713.             self.color = color
  714.             self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  715.            
  716.  
  717.             self.speed = 3
  718.             self.appleimage = pygame.image.load("fish1.png")
  719.             self.appleimage = pygame.transform.scale(self.appleimage,(self.appleimage.get_width()*2,self.appleimage.get_height()*2))        
  720.             self.rect = pygame.Rect(x,y,height,width)
  721.         def draw(self):
  722.             self.rect.topleft = (self.x,self.y)
  723.             player_rect = self.appleimage.get_rect(center = self.rect.center)
  724.             player_rect.centerx += 10 # 10 is just an example
  725.             player_rect.centery += -20 # 15 is just an example
  726.             window.blit(self.appleimage, player_rect)
  727.  
  728.  
  729.  
  730.     apple1 = apple(240,170,50,50,white)
  731.     apple2 = apple(0,510,900,10,white)
  732.     apple3 = apple(100,20,600,5,white)
  733.  
  734. # the scoring
  735.     font = pygame.font.Font("do.ttf", 50)
  736.     apple = 0
  737.     text = font.render(" Fish " + str(apple), True, (255,255,255))
  738.     rect = text.get_rect()
  739.  
  740.  
  741.     defont = pygame.font.Font("do.ttf", 30)
  742.     texts = font.render("    + 5" , True, (0,255,0))
  743.     rects = text.get_rect()
  744.  
  745.  
  746.  
  747.        
  748.     # bg  image
  749.     bg = pygame.image.load("bs;.png")
  750.     def ReDrawwindow():
  751.  
  752.        
  753.         dudel.draw()
  754.         window.blit(bg,(0,0))
  755.        
  756.  
  757.        
  758.         for bullet in bullets:
  759.             bullet.draw(window)
  760.         apple1.draw()
  761.  
  762.         for plat in plats:
  763.             plat.draw()
  764.         playerman.draw()
  765.  
  766.         for platform in platforms:
  767.             platform.draw()
  768.  
  769.         for platform2 in platforms2:
  770.             platform2.draw()
  771.            
  772.         for particle in particles:
  773.             particle.draw(window)
  774.         apple3.draw()
  775.  
  776.         window.blit(texts,apple1.rect)
  777.         slime1.draw(window)
  778.         window.blit(text,rect)
  779.         pygame.display.update()
  780.  
  781.  
  782.     fps = 50
  783.     clock = pygame.time.Clock()
  784.     # main loo
  785.     bullets = []
  786.     particles = []
  787.     runninggame = True
  788.     while runninggame:
  789.         clock.tick(fps)
  790.         for event in pygame.event.get():
  791.             if event.type == pygame.QUIT:
  792.                 runninggame = False
  793.        
  794.  
  795.  
  796.             if event.type == pygame.MOUSEBUTTONDOWN:
  797.      
  798.  
  799.  
  800.  
  801.                     # this is for the bullets
  802.                 if len(bullets) < 2:
  803.  
  804.  
  805.  
  806.                     start_x, start_y = playerman.x+playerman.width//2, playerman.y + playerman.height-35
  807.                     mouse_x, mouse_y = event.pos
  808.  
  809.                     dir_x, dir_y = mouse_x - start_x, mouse_y - start_y
  810.                     distance = math.sqrt(dir_x**2 + dir_y**2)
  811.                     if playerman.direction == "hitleft":
  812.                         if distance > 0:
  813.                             new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
  814.                             bullets.append(new_bullet)
  815.                     if playerman.direction == "hitright":
  816.                         if distance > 0:
  817.                             new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
  818.                             bullets.append(new_bullet)
  819.  
  820.  
  821.  
  822.  
  823.                        
  824.                 if playerman.direction == "right" or playerman.direction == "standright":
  825.                     playerman.direction = "hitright"
  826.                
  827.                 if playerman.direction == "left" or playerman.direction == "standleft":
  828.                     playerman.direction = "hitleft"
  829.  
  830.  
  831.  
  832.  
  833.             # this is displaying the bullets for the player            
  834.         for bullet in bullets[:]:
  835.             bullet.move()
  836.             if bullet.x < 0 or bullet.x > 900 or bullet.y < 0 or bullet.y > 900:
  837.                 bullets.pop(bullets.index(bullet))
  838.  
  839.         apple1.y += apple1.speed
  840.  
  841.  
  842.         if apple1.rect.colliderect(playerman.hit):
  843.             for platform in platforms:
  844.                 apple += 1
  845.                 text = font.render(" Fish " + str(apple), True, (255,255,255))
  846.                 rect = text.get_rect()
  847.                 apple1.x = random.randint(apple3.rect.x,apple3.rect.x + apple3.rect.width)
  848.                 apple1.y = random.randrange(0, 1 + 12)
  849.                 apple1.speed += 0.01
  850.  
  851.  
  852.         if apple2.rect.colliderect(apple1.rect):
  853.                
  854.                 text = font.render(" Fish " + str(apple), True, (255,255,255))
  855.                 rect = text.get_rect()
  856.                 apple1.x = random.randint(apple3.rect.x,apple3.rect.x + apple3.rect.width)
  857.                 apple1.y = random.randrange(0, 1)
  858.                 playerman.health -= 51
  859.  
  860.  
  861.  
  862.     # slime enemy movement
  863.         slime1.x += 2
  864.  
  865.  
  866.         # the end screen
  867.         if playerman.health < -5:
  868.             end_screen()
  869.  
  870.  
  871.  
  872.  
  873.         # collisions between the fish so they dont get out the box
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.         for bullet in bullets:
  881.             if bullet.rect.colliderect(apple1.rect):
  882.                 bullet.speed = 0.02
  883.                 playerman.fall = 10
  884.                 apple1.speed = 1
  885.                 if playerman.direction == "hitright":
  886.                     playerman.clock.tick(10)
  887.  
  888.             else:
  889.                 bullet.speed = 17
  890.                 playerman.fall = 3
  891.                 apple1.speed = 3
  892.  
  893.        # camera movement up down
  894.  
  895.  
  896.         if playerman.y < 240:
  897.             playerman.y += 1
  898.             for platform in platforms:
  899.                 platform.y += playerman.speed
  900.             for platform2 in platforms2:
  901.                 platform2.y += playerman.speed
  902.             for plat in plats:
  903.                 plat.y += playerman.speed
  904.             slowmoition1.y += playerman.speed
  905.             slowmoition2.y += playerman.speed
  906.             apple1.y += playerman.speed
  907.             apple2.y += playerman.speed
  908.             apple3.y += playerman.speed
  909.             slime1.y += playerman.speed
  910.  
  911.            
  912.             for bullet in bullets:
  913.                 bullet.y += playerman.speed
  914.                
  915.         for bullet in bullets:
  916.             if bullet.rect.colliderect(slowmoition1) or bullet.rect.colliderect(slowmoition2.rect):
  917.                 bullet.speed = 3
  918.                 playerman.fall = 10
  919.  
  920.             else:
  921.                 bullet.speed = 17
  922.                 playerman.fall = 3
  923.  
  924.         for platform in platforms:
  925.             for bullet in bullets:
  926.                 if bullet.rect.colliderect(platform.rect):
  927.                     for x in range(50):
  928.                         x,y = bullet.rect.center
  929.                         particles.append(particle(x,y))
  930.                     bullets.pop(bullets.index(bullet))        
  931.                    
  932.         for x in range(1):
  933.             x,y = apple1.rect.center
  934.             particles.append(partic(x,y))
  935.            
  936.         if apple1.rect.colliderect(playerman.rect):
  937.             for x in range(21):
  938.                 x,y = playerman.rect.center
  939.                 particles.append(parti(x,y))
  940.      
  941.         if playerman.y > 300:
  942.             playerman.y -= playerman.fall
  943.             for platform in platforms:
  944.                 platform.y -= playerman.fall
  945.             for platform2 in platforms2:
  946.                 platform2.y -= playerman.fall
  947.             for plat in plats:
  948.                 plat.y -= playerman.fall
  949.             for bullet in bullets:
  950.                 bullet.y -= playerman.fall
  951.             apple1.y -= playerman.fall
  952.             apple2.y -= playerman.fall
  953.             slowmoition1.y -= playerman.fall
  954.             slowmoition2.y -= playerman.fall
  955.             apple3.y -= playerman.fall
  956.             slime1.y -= playerman.fall
  957.  
  958.  
  959.         # key event for the player
  960.         keys = pygame.key.get_pressed()
  961.         if keys[pygame.K_d]:
  962.             playerman.x += playerman.speed
  963.             playerman.direction = "right"
  964.             dudel.direction  = "dustright"
  965.             if playerman.x > 350:
  966.                playerman.x -= playerman.speed
  967.                for platform in platforms:
  968.                    platform.x -= playerman.speed
  969.                for platform2 in platforms2:
  970.                    platform2.x -= playerman.speed
  971.                for plat in plats:
  972.                    plat.x -= playerman.speed
  973.                slowmoition1.x -= playerman.speed
  974.                slowmoition2.x -= playerman.speed
  975.                apple1.x -= playerman.speed
  976.                apple2.x -= playerman.speed
  977.                apple3.x -= playerman.speed
  978.  
  979.                slime1.x -= playerman.speed
  980.  
  981.                
  982.                for bullet in bullets:
  983.                    bullet.x -= playerman.speed
  984.  
  985.         elif keys[pygame.K_a]:
  986.             playerman.x -= playerman.speed
  987.             playerman.direction = "left"
  988.             if playerman.x < 350:
  989.                playerman.x += playerman.speed
  990.                for platform in platforms:
  991.                    platform.x += playerman.speed
  992.                for platform2 in platforms2:
  993.                    platform2.x += playerman.speed
  994.                for plat in plats:
  995.                    plat.x += playerman.speed
  996.                slowmoition1.x += playerman.speed
  997.                slowmoition2.x += playerman.speed
  998.                
  999.                for bullet in bullets:
  1000.                    bullet.x += playerman.speed
  1001.                apple1.x += playerman.speed
  1002.                apple2.x += playerman.speed
  1003.                apple3.x += playerman.speed
  1004.                slime1.x += playerman.speed
  1005.  
  1006.  
  1007.                
  1008.         else:
  1009.            
  1010.             if playerman.direction == "right":
  1011.                 playerman.direction = "standright"
  1012.             else:
  1013.                 if playerman.direction == "left":
  1014.                     playerman.direction = "standleft"
  1015.  
  1016.  
  1017.         if not playerman.isJump:
  1018.             playerman.y += playerman.fall
  1019.             playerman.fall += 1
  1020.             playerman.isJump = False
  1021.  
  1022.  
  1023.  
  1024.  
  1025.                 # this part lets you jump on platform
  1026.             collide = False
  1027.             for platform in platforms:
  1028.                 if playerman.rect.colliderect(platform.rect):
  1029.                     collide = True
  1030.                     playerman.isJump = False
  1031.                     playerman.y = platform.rect.top - playerman.height + 1
  1032.                     if playerman.rect.right > platform.rect.left and playerman.rect.left < platform.rect.left - playerman.width:
  1033.                         playerman.x = platform.rect.left - playerman.width
  1034.                     if playerman.rect.left < platform.rect.right and playerman.rect.right > platform.rect.right + playerman.width:
  1035.                         playerman.x = platform.rect.right
  1036.  
  1037.  
  1038.  
  1039.  
  1040.                        
  1041.                         # this makes the player fall down up to
  1042.             if playerman.rect.bottom >= 410:
  1043.                 collide = True
  1044.                 playerman.isJump = False
  1045.                 playerman.JumpCount = 10
  1046.                 playerman.y = 410 - playerman.height
  1047.  
  1048.  
  1049.  
  1050.             if collide:
  1051.                 if keys[pygame.K_SPACE]:
  1052.                     playerman.isJump = True
  1053.  
  1054.                 playerman.fall = 5
  1055.  
  1056.  
  1057.         else:
  1058.             if playerman.JumpCount >0:
  1059.                 playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount)) * 0.2
  1060.                 playerman.JumpCount -= 1
  1061.             else:
  1062.                 playerman.JumpCount = 10
  1063.                 playerman.isJump = False
  1064.                
  1065.            
  1066.  
  1067.         ReDrawwindow()
  1068.         pygame.display.update()
  1069.     pygame.quit()
  1070. game_intro()
  1071. main_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement