Advertisement
habib257

Untitled

Jul 12th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.51 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
  13. def button(msg,x,y,w,h,ic,ac,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.  
  36.        
  37. def game_intro():
  38.  
  39.     # this makes it            
  40.     snow_list=[]
  41.     no_of_circles=100;
  42.     clock = pygame.time.Clock()
  43.     FPS = 60
  44.     clock.tick(FPS)
  45.     for i in range(no_of_circles):
  46.         x = random.randrange(0, 800)
  47.         y = random.randrange(0, 700)
  48.         snow_list.append([x,y])
  49.  
  50.     # the background image
  51.        
  52.     red = (200,0,0)
  53.     green = (255,250,250)
  54.     bright_red = (255,250,0)
  55.     bright_green = (0,255,0)
  56.     clock = pygame.time.Clock()
  57.     intro = True
  58.     while intro:
  59.         clock.tick(FPS)
  60.         for event in pygame.event.get():
  61.             if event.type == pygame.QUIT:
  62.                 intro = False
  63.                 pygame.quit()
  64.  
  65.  
  66.  
  67.  
  68.     # GAME INTRO IMAGE
  69.         button("Click To Play!",40,310,220,60,green,bright_green,main_loop)
  70.         bls = pygame.image.load("intros.png")
  71.         window.blit(bls,(0,0))
  72.  
  73.  
  74.  
  75.         for point in snow_list:
  76.             point[1]+=1
  77.             pygame.draw.circle(window, (255,255,255), point, 2)
  78.  
  79.             if(point[1] >= 600):
  80.                 point[0] = random.randrange(0, 600)
  81.                 point[1] = random.randrange(-10, -5)
  82.  
  83.         clock.tick(FPS)
  84.  
  85.  
  86.  
  87.                    
  88.  
  89.  
  90.  
  91.     # ---------------------------------------------------------------------
  92.  
  93.  
  94.  
  95.  
  96.  
  97.      
  98.  
  99.         pygame.display.update()
  100.  
  101.  
  102.  
  103.  
  104.  
  105. def main_loop():
  106.     # player class
  107.  
  108.     class player:
  109.         def __init__(self,x,y,height,width,color):
  110.             self.x = x
  111.             self.y = y
  112.             self.color = color
  113.             self.height  = height
  114.             self.width = width
  115.             self.speed = 7
  116.             self.isJump = False
  117.             self.JumpCount = 10
  118.             self.fall = 0
  119.                 #hit box
  120.             self.hitbox = (self.x + 20, self.y, 28, 60)
  121.             self.rights = [pygame.image.load("w1.png"),
  122.             pygame.image.load("w2.png"),
  123.             pygame.image.load("w3.png"),
  124.             pygame.image.load("w4.png"),
  125.             pygame.image.load("w5.png"),
  126.             pygame.image.load("w6.png")]
  127.  
  128.             self.lefts = [pygame.image.load("e1.png"),
  129.                 pygame.image.load("e2.png"),
  130.                 pygame.image.load("e3.png"),
  131.                 pygame.image.load("e4.png"),
  132.                 pygame.image.load("e5.png"),
  133.                 pygame.image.load("e6.png")]
  134.  
  135.             self.hitright = [pygame.image.load("h1.png"),
  136.                 pygame.image.load("h2.png"),
  137.                 pygame.image.load("h3.png"),
  138.                 pygame.image.load("h4.png"),
  139.                 pygame.image.load("h5.png"),
  140.                 pygame.image.load("h6.png")]
  141.  
  142.  
  143.             self.hitleft = [pygame.image.load("h11.png"),
  144.                 pygame.image.load("h12.png"),
  145.                 pygame.image.load("h13.png"),
  146.                 pygame.image.load("h14.png"),
  147.                 pygame.image.load("h15.png"),
  148.                 pygame.image.load("h16.png")]
  149.  
  150.  
  151.  
  152.             self.standingright = [pygame.image.load("d1.png"),
  153.                         pygame.image.load("d2.png"),
  154.                         pygame.image.load("d3.png"),
  155.                         pygame.image.load("d4.png")]
  156.             self.standingleft =[pygame.image.load("s1.png"),
  157.  
  158.                     pygame.image.load("s2.png"),
  159.                     pygame.image.load("s3.png"),
  160.                     pygame.image.load("s4.png")]
  161.             self.rights = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.rights]
  162.             self.lefts = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.lefts]
  163.             self.standingright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingright]
  164.             self.standingleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingleft]
  165.  
  166.             self.hitright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitright]
  167.  
  168.  
  169.             self.hitleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitleft]
  170.  
  171.             self.bo_index = 0
  172.             self.anim_index = 0
  173.             self.stans_index = 0
  174.             self.direction = "right"
  175.             self.direction = "left"
  176.             self.direction = "standright"
  177.             self.direction = "standleft"
  178.             self.direction = "hitright"
  179.             self.direction = "hitleft"
  180.             self.health = 10
  181.             self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  182.             self.hit = (self.x + -30, self.y + 0, 31, 57)
  183.  
  184.                 # playerman hitbox
  185.             self.hits = (self.x + 20, self.y, 28,60)
  186.  
  187.             # the health bar image
  188.             self.healthimage = pygame.image.load("yup.png")
  189.             self.klox = (self.x + -30, self.y + 0, 31, 57)
  190.  
  191.             self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
  192.  
  193.             self.healthimage = pygame.transform.scale(self.healthimage,(self.healthimage.get_width()//7,self.healthimage.get_height()//7))
  194.  
  195.             self.fps = 30
  196.             self.FPS = 115
  197.             self.clock = pygame.time.Clock()
  198.  
  199.         def draw(self):
  200.             window.blit(self.healthimage,self.klox)
  201.             self.rect.topleft = (self.x,self.y)
  202.  
  203.             if self.direction == "right":
  204.                 self.clock.tick(self.fps)
  205.  
  206.                 image_list = self.rights
  207.  
  208.             elif self.direction == "standright":
  209.                 self.clock.tick(self.fps)
  210.                 image_list = self.standingright
  211.             elif self.direction == "left":
  212.                 self.clock.tick(self.fps)
  213.                 image_list = self.lefts
  214.  
  215.             elif self.direction == "hitright":
  216.                 self.clock.tick(self.FPS)
  217.                 image_list = self.hitright
  218.  
  219.             elif self.direction == "hitleft":
  220.                 self.clock.tick(self.FPS)
  221.                 image_list = self.hitleft
  222.  
  223.             else:
  224.                 self.clock.tick(self.fps)
  225.                 image_list = self.standingleft
  226.  
  227.  
  228.             if self.anim_index >= len(image_list):
  229.                 self.anim_index = 0
  230.             player_image = image_list[self.anim_index]
  231.             self.anim_index += 1
  232.  
  233.             self.hits = (self.x + 20, self.y, 26,60)
  234.             pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 40, 170, 15)) # NEW
  235.             pygame.draw.rect(window, (0,200,0), (self.hitbox[0], self.hitbox[1] - 40, 170 - (5 * (10 - self.health)), 15))
  236.  
  237.             self.hitbox = (10,  97, 61, 57)
  238.             # health image
  239.             self.klox = (2,  50, 61, 57)
  240.             self.hit = (self.x + 22, self.y + 30, 31, 57)
  241.  
  242.             window.blit(player_image, self.rect)
  243.             pygame.draw.rect(window,self.color,self.hit,2)
  244.            
  245.     white = 255,255,255
  246.     playerman = player(200,300,90,50,white)
  247.  
  248.  
  249.  
  250.     # player class
  251.  
  252.     class player:
  253.         def __init__(self,x,y,height,width,color):
  254.             self.x = x
  255.             self.y = y
  256.             self.color = color
  257.             self.height  = height
  258.             self.width = width
  259.  
  260.  
  261.             # run dust frame
  262.             self.dusts = [pygame.image.load("dust1.png"),
  263.                 pygame.image.load("dust2.png"),
  264.                 pygame.image.load("dust3.png"),
  265.                 pygame.image.load("dust4.png"),
  266.                 pygame.image.load("dust5.png"),
  267.                 pygame.image.load("dust6.png"),
  268.                 pygame.image.load("dust7.png"),
  269.                 pygame.image.load("dust8.png")]
  270.  
  271.  
  272.             self.anim_index = 0
  273.             self.direction = "dustright"
  274.  
  275.             self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
  276.  
  277.             self.fps = 20
  278.             self.clock = pygame.time.Clock()
  279.  
  280.         def draw(self):
  281.            
  282.             self.rect.topleft = (self.x,self.y)
  283.  
  284.            
  285.  
  286.             if self.direction == "dustright":
  287.                 self.clock.tick(self.fps)
  288.                 image_list = self.dusts
  289.  
  290.  
  291.  
  292.             if self.anim_index >= len(image_list):
  293.                 self.anim_index = 0
  294.             player_image = image_list[self.anim_index]
  295.             self.anim_index += 1
  296.  
  297.  
  298.  
  299.  
  300.            
  301.     white = 255,255,255
  302.     dudel = player(200,200,50,50,white)
  303.     # apple class
  304.  
  305.     # bomb class
  306.  
  307.     # slow motion rect
  308.     class slow:
  309.         def __init__(self,x,y,height,width,color):
  310.             self.x = x
  311.             self.y =y
  312.             self.height = height
  313.             self.width = width
  314.             self.color = color
  315.             self.rect = pygame.Rect(x,y,height,width)
  316.         def draw(self):
  317.             self.rect.topleft = (self.x,self.y)
  318.             pygame.draw.rect(window,self.color,self.rect)
  319.  
  320.     slowmoition1 = slow(100,100,30,450,white)
  321.     slowmoition2 = slow(690,100,30,450,white)
  322.     # fade effect
  323.  
  324.  
  325.     # platform class
  326.     class platform:
  327.         def __init__(self,x,y,height,width,color):
  328.             self.x = x
  329.             self.y = y
  330.             self.height = height
  331.             self.width = width
  332.             self.color = color
  333.             self.image1 = pygame.image.load("Tile_25.png")
  334.             self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()*2,self.image1.get_height()*2))
  335.             self.rect = pygame.Rect(x,y,height,width)
  336.         def draw(self):
  337.             self.rect.topleft = (self.x,self.y)
  338.             window.blit(self.image1,self.rect)
  339.  
  340.     class platform2:
  341.         def __init__(self,x,y,height,width,color):
  342.             self.x = x
  343.             self.y = y
  344.             self.height = height
  345.             self.width = width
  346.             self.color = color
  347.             self.rect = pygame.Rect(x,y,height,width)
  348.             self.block2 = pygame.image.load("Tile_12.png")
  349.             self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
  350.         def draw(self):
  351.             self.rect.topleft = (self.x,self.y)
  352.             window.blit(self.block2,self.rect)
  353.  
  354.  
  355.     class plat:
  356.         def __init__(self,x,y,height,width,color):
  357.             self.x = x
  358.             self.y = y
  359.             self.height = height
  360.             self.width = width
  361.             self.color = color
  362.             self.block2 = pygame.image.load("Tile_07.png")
  363.             self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
  364.             self.rect  = pygame.Rect(x,y,height,width)
  365.         def draw(self):
  366.             self.rect.topleft = (self.x,self.y)
  367.             window.blit(self.block2,self.rect)
  368.  
  369.     # player projectile
  370.     class projectile(object):
  371.         def __init__(self, x, y, dirx, diry, color):
  372.            
  373.             self.x = x
  374.             self.y = y
  375.             self.dirx = dirx
  376.             self.diry = diry
  377.             self.image1 = pygame.image.load("pros.png")
  378.             self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()//2,self.image1.get_height()//2))
  379.  
  380.             self.rect  = self.image1.get_rect()
  381.             self.rect.topleft = ( self.x, self.y )
  382.             self.speed = 17
  383.             self.color = color
  384.         def move(self):
  385.            
  386.             self.x += self.dirx * self.speed
  387.             self.y += self.diry * self.speed
  388.         def draw(self, window):
  389.            
  390.             self.rect.topleft = (round(self.x), round(self.y))
  391.             window.blit(self.image1,self.rect)
  392.  
  393.  
  394.  
  395.     plats = []
  396.            
  397.     platforms2   = []    
  398.     platforms = []
  399.     platformGroup = pygame.sprite.Group
  400.  
  401.     level = [
  402.     "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",
  403.     "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                                                                               ",
  404.              "                                                                             ",
  405.              "l                                                                       l              ",
  406.              "g                                                                       g        ",
  407.              "g                                                                       g          ",
  408.              "g                                                                       g       ",
  409.              "g                                                                       g            ",
  410.              "                                                                                ",
  411.              "c     c     c     c     c     c     c     c     c     c     c     c     c     c     ",
  412.              "                     ",
  413.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  414.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  415.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d",
  416.              "d    d    d    d    d    d    d    d    d    d    d    d    d    d    d d"]
  417.  
  418.     for iy, row in enumerate(level):
  419.         for ix, col in enumerate(row):
  420.             if col == "c":
  421.                 new_platforms = platform(ix*9.8, iy*50, 60,90,(255,255,255))
  422.                 platforms.append(new_platforms)
  423.  
  424.     for iy, row in enumerate(level):
  425.         for ix, col in enumerate(row):
  426.             if col == "d":
  427.                 new_platforms = platform2(ix*10.6, iy*45.9, 60,70,(255,255,255))
  428.                 platforms2.append(new_platforms)
  429.  
  430.     for iy, row in enumerate(level):
  431.         for ix, col in enumerate(row):
  432.             if col == "g":
  433.                 new_platforms = platform2(ix*10.6, iy*55.9, 60,70,(255,255,255))
  434.                 platforms2.append(new_platforms)
  435.  
  436.     for iy, row in enumerate(level):
  437.         for ix, col in enumerate(row):
  438.             if col == "l":
  439.                 new_platforms = platform(ix*10.6, iy*55.9, 60,670,(255,255,255))
  440.                 platforms.append(new_platforms)
  441.  
  442.     for iy, row in enumerate(level):
  443.         for ix, col in enumerate(row):
  444.             if col == "s":
  445.                 new_platforms = platform2(ix*10.6, iy*-45.9, 60,70,(255,255,255))
  446.                 platforms2.append(new_platforms)
  447.  
  448.     for iy, row in enumerate(level):
  449.         for ix, col in enumerate(row):
  450.             if col == "n":
  451.                 new_platforms = plat(ix*10.6, iy*79, 60,70,(255,255,255))
  452.                 plats.append(new_platforms)
  453.  
  454.  
  455.     # ReDrawing the window
  456.     block2 = pygame.image.load("1.png")
  457.     block2 = pygame.transform.scale(block2,(block2.get_width()*2,block2.get_height()*2))
  458.     bg = pygame.image.load("bl.png")
  459.  
  460.     class particle:
  461.         def __init__(self,x,y):
  462.             self.x = x
  463.             self.y = y
  464.             self.x_vel = random.randrange(-10,13)*1
  465.             self.y_vel = random.randrange(-10,-1)*1
  466.             self.lifetime = 0
  467.             self.partilight = pygame.image.load("cls.png")
  468.             self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//2,self.partilight.get_height()//2))        
  469.         def draw(self,window):
  470.             self.lifetime += 1
  471.             if self.lifetime <30:
  472.                 self.x -= self.x_vel
  473.                 self.y -= self.y_vel
  474.                 window.blit(self.partilight,(self.x,self.y,16,16))
  475.  
  476.  
  477.     # the falling apples:
  478.     class apple:
  479.         def __init__(self,x,y,height,width,color):
  480.             self.x = x
  481.             self.y =y
  482.             self.height = height
  483.             self.width = width
  484.             self.color = color
  485.             self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  486.  
  487.             self.speed = 3
  488.             self.appleimage = pygame.image.load("fish1.png")
  489.             self.appleimage = pygame.transform.scale(self.appleimage,(self.appleimage.get_width()*2,self.appleimage.get_height()*2))        
  490.             self.rect = pygame.Rect(x,y,height,width)
  491.         def draw(self):
  492.             self.rect.topleft = (self.x,self.y)
  493.             player_rect = self.appleimage.get_rect(center = self.rect.center)
  494.             player_rect.centerx += 10 # 10 is just an example
  495.             player_rect.centery += -20 # 15 is just an example
  496.             window.blit(self.appleimage, player_rect)
  497.             pygame.draw.rect(window,self.color,self.rect)
  498.  
  499.     apple1 = apple(300,100,50,50,white)
  500.     apple2 = apple(0,510,900,10,white)
  501.     apple4 = apple(-532,10,590,590,white)
  502.     apple3 = apple(765,10,590,590,white)
  503.  
  504. # the scoring
  505.     font = pygame.font.Font("do.ttf", 50)
  506.     apple = 0
  507.     text = font.render(" Fish " + str(apple), True, (255,255,255))
  508.     rect = text.get_rect()
  509.  
  510.  
  511.     # bg  image
  512.     bg = pygame.image.load("bs;.png")
  513.     def ReDrawwindow():
  514.         dudel.draw()
  515.         window.blit(bg,(0,0))
  516.  
  517.  
  518.        
  519.         for bullet in bullets:
  520.             bullet.draw(window)
  521.         apple1.draw()
  522.  
  523.         for plat in plats:
  524.             plat.draw()
  525.         playerman.draw()
  526.  
  527.         for platform in platforms:
  528.             platform.draw()
  529.  
  530.         for platform2 in platforms2:
  531.             platform2.draw()
  532.            
  533.         for particle in particles:
  534.             particle.draw(window)
  535.  
  536.  
  537.         window.blit(text,rect)
  538.         pygame.display.update()
  539.  
  540.  
  541.     fps = 50
  542.     clock = pygame.time.Clock()
  543.     # main loo
  544.     bullets = []
  545.     particles = []
  546.     runninggame = True
  547.     while runninggame:
  548.         clock.tick(fps)
  549.         for event in pygame.event.get():
  550.             if event.type == pygame.QUIT:
  551.                 runninggame = False
  552.        
  553.  
  554.  
  555.             if event.type == pygame.MOUSEBUTTONDOWN:
  556.      
  557.  
  558.  
  559.  
  560.                     # this is for the bullets
  561.                 if len(bullets) < 2:
  562.  
  563.  
  564.  
  565.                     start_x, start_y = playerman.x+playerman.width//2, playerman.y + playerman.height-35
  566.                     mouse_x, mouse_y = event.pos
  567.  
  568.                     dir_x, dir_y = mouse_x - start_x, mouse_y - start_y
  569.                     distance = math.sqrt(dir_x**2 + dir_y**2)
  570.                     if playerman.direction == "hitleft":
  571.                         if distance > 0:
  572.                             new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
  573.                             bullets.append(new_bullet)
  574.                     if playerman.direction == "hitright":
  575.                         if distance > 0:
  576.                             new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
  577.                             bullets.append(new_bullet)
  578.  
  579.  
  580.  
  581.  
  582.                        
  583.                 if playerman.direction == "right" or playerman.direction == "standright":
  584.                     playerman.direction = "hitright"
  585.                
  586.                 if playerman.direction == "left" or playerman.direction == "standleft":
  587.                     playerman.direction = "hitleft"
  588.  
  589.  
  590.  
  591.  
  592.             # this is displaying the bullets for the player            
  593.         for bullet in bullets[:]:
  594.             bullet.move()
  595.             if bullet.x < 0 or bullet.x > 900 or bullet.y < 0 or bullet.y > 900:
  596.                 bullets.pop(bullets.index(bullet))
  597.  
  598.         apple1.y += apple1.speed
  599.         if apple1.rect.colliderect(apple2.rect):
  600.             apple1.speed += 0.2
  601.             apple1.x = random.randrange(0, 300)
  602.             apple1.y = random.randrange(0, 1)
  603.  
  604.         if apple1.rect.colliderect(playerman.rect):
  605.             apple += 100
  606.             text = font.render(" Fish " + str(apple), True, (255,255,255))
  607.             rect = text.get_rect()
  608.             apple1.x = random.randrange(0, 300)
  609.             apple1.y = random.randrange(0, 1)
  610.  
  611.  
  612.        # camera movement up down
  613.  
  614.  
  615.         if playerman.y < 240:
  616.             playerman.y += 1
  617.             for platform in platforms:
  618.                 platform.y += playerman.speed
  619.             for platform2 in platforms2:
  620.                 platform2.y += playerman.speed
  621.             for plat in plats:
  622.                 plat.y += playerman.speed
  623.             slowmoition1.y += playerman.speed
  624.             slowmoition2.y += playerman.speed
  625.             apple1.y += playerman.speed
  626.             apple2.y += playerman.speed
  627.  
  628.             apple3.y += playerman.speed
  629.             apple4.y += playerman.speed
  630.  
  631.  
  632.            
  633.             for bullet in bullets:
  634.                 bullet.y += playerman.speed
  635.                
  636.         for bullet in bullets:
  637.             if bullet.rect.colliderect(slowmoition1) or bullet.rect.colliderect(slowmoition2.rect):
  638.                 bullet.speed = 3
  639.                 playerman.fall = 10
  640.  
  641.             else:
  642.                 bullet.speed = 17
  643.                 playerman.fall = 3
  644.  
  645.         for platform in platforms:
  646.             for bullet in bullets:
  647.                 if bullet.rect.colliderect(platform.rect):
  648.                     for x in range(50):
  649.                         x,y = bullet.rect.center
  650.                         particles.append(particle(x,y))
  651.                     bullets.pop(bullets.index(bullet))        
  652.                    
  653.  
  654.      
  655.         if playerman.y > 300:
  656.             playerman.y -= playerman.fall
  657.             for platform in platforms:
  658.                 platform.y -= playerman.fall
  659.             for platform2 in platforms2:
  660.                 platform2.y -= playerman.fall
  661.             for plat in plats:
  662.                 plat.y -= playerman.fall
  663.             for bullet in bullets:
  664.                 bullet.y -= playerman.fall
  665.             apple1.y -= playerman.fall
  666.             apple2.y -= playerman.fall
  667.             slowmoition1.y -= playerman.fall
  668.             slowmoition2.y -= playerman.fall
  669.  
  670.  
  671.             apple3.y -= playerman.fall
  672.             apple4.y -= playerman.fall
  673.         # key event for the player
  674.         keys = pygame.key.get_pressed()
  675.         if keys[pygame.K_d]:
  676.             playerman.x += playerman.speed
  677.             playerman.direction = "right"
  678.             dudel.direction  = "dustright"
  679.             if playerman.x > 350:
  680.                playerman.x -= playerman.speed
  681.                for platform in platforms:
  682.                    platform.x -= playerman.speed
  683.                for platform2 in platforms2:
  684.                    platform2.x -= playerman.speed
  685.                for plat in plats:
  686.                    plat.x -= playerman.speed
  687.                slowmoition1.x -= playerman.speed
  688.                slowmoition2.x -= playerman.speed
  689.                apple1.x -= playerman.speed
  690.                apple2.x -= playerman.speed
  691.  
  692.                apple3.x -= playerman.speed
  693.                apple4.x -= playerman.speed
  694.                
  695.                for bullet in bullets:
  696.                    bullet.x -= playerman.speed
  697.  
  698.         elif keys[pygame.K_a]:
  699.             playerman.x -= playerman.speed
  700.             playerman.direction = "left"
  701.             if playerman.x < 350:
  702.                playerman.x += playerman.speed
  703.                for platform in platforms:
  704.                    platform.x += playerman.speed
  705.                for platform2 in platforms2:
  706.                    platform2.x += playerman.speed
  707.                for plat in plats:
  708.                    plat.x += playerman.speed
  709.                slowmoition1.x += playerman.speed
  710.                slowmoition2.x += playerman.speed
  711.                
  712.                for bullet in bullets:
  713.                    bullet.x += playerman.speed
  714.                apple1.x += playerman.speed
  715.                apple2.x += playerman.speed
  716.  
  717.                apple3.x += playerman.speed
  718.                apple4.x += playerman.speed
  719.                
  720.         else:
  721.            
  722.             if playerman.direction == "right":
  723.                 playerman.direction = "standright"
  724.             else:
  725.                 if playerman.direction == "left":
  726.                     playerman.direction = "standleft"
  727.  
  728.  
  729.         if not playerman.isJump:
  730.             playerman.y += playerman.fall
  731.             playerman.fall += 1
  732.             playerman.isJump = False
  733.  
  734.  
  735.  
  736.  
  737.                 # this part lets you jump on platform
  738.             collide = False
  739.             for platform in platforms:
  740.                 if playerman.rect.colliderect(platform.rect):
  741.                     collide = True
  742.                     playerman.isJump = False
  743.                     playerman.y = platform.rect.top - playerman.height + 1
  744.                     if playerman.rect.right > platform.rect.left and playerman.rect.left < platform.rect.left - playerman.width:
  745.                         playerman.x = platform.rect.left - playerman.width
  746.                     if playerman.rect.left < platform.rect.right and playerman.rect.right > platform.rect.right + playerman.width:
  747.                         playerman.x = platform.rect.right
  748.  
  749.  
  750.  
  751.  
  752.                        
  753.                         # this makes the player fall down up to
  754.             if playerman.rect.bottom >= 410:
  755.                 collide = True
  756.                 playerman.isJump = False
  757.                 playerman.JumpCount = 10
  758.                 playerman.y = 410 - playerman.height
  759.  
  760.  
  761.  
  762.             if collide:
  763.                 if keys[pygame.K_SPACE]:
  764.                     playerman.isJump = True
  765.  
  766.                 playerman.fall = 5
  767.  
  768.  
  769.         else:
  770.             if playerman.JumpCount >0:
  771.                 playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount)) * 0.2
  772.                 playerman.JumpCount -= 1
  773.             else:
  774.                 playerman.JumpCount = 10
  775.                 playerman.isJump = False
  776.                
  777.            
  778.  
  779.         ReDrawwindow()
  780.         pygame.display.update()
  781.     pygame.quit()
  782. game_intro()
  783. main_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement