Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import math
- import random
- pygame.init()
- width = 800
- height = 700
- window = pygame.display.set_mode((width, height), pygame.NOFRAME)
- pygame.display.set_caption("Game")
- # game intro buttons
- def button(msg,x,y,w,h,ic,ac,fadescreen,action=None):
- mouse = pygame.mouse.get_pos()
- click = pygame.mouse.get_pressed()
- if x+w > mouse[0] > x and y+h > mouse[1] > y:
- pygame.draw.rect(window, ac,(x,y,w,h))
- if click[0] == 1 and action != None:
- action()
- else:
- pygame.draw.rect(window, ic,(x,y,w,h ))
- smallText = pygame.font.SysFont("Candarai.ttf",40)
- textSurf, textRect = text_objects(msg, smallText)
- textRect.center = ( (x+(w/2)), (y+(h/2)) )
- window.blit(textSurf, textRect)
- #------------------------------------------------------
- def text_objects(text, font):
- black = (255,255,255)
- textSurface = font.render(text, True, black)
- return textSurface, textSurface.get_rect()
- # you lose screen
- whs = (255,255,255)
- def text_objects(text, font):
- textSurface = font.render(text, True, whs)
- return textSurface, textSurface.get_rect()
- def message_display(text):
- largeText = pygame.font.Font('freesansbold.ttf',35)
- TextSurf, TextRect = text_objects(text, largeText)
- TextRect.center = ((590/2),(580/2))
- window.blit(TextSurf, TextRect)
- pygame.display.update()
- game_intro()
- time.sleep(0)
- def crash():
- message_display('......')
- # the scoring
- font = pygame.font.Font("do.ttf", 50)
- apple = 0
- text = font.render(" Fish " + str(apple), True, (255,255,255))
- rect = text.get_rect()
- # end screen
- def end_screen():
- # this makes it
- snow_list=[]
- no_of_circles=100;
- clock = pygame.time.Clock()
- FPS = 60
- clock.tick(FPS)
- for i in range(no_of_circles):
- x = random.randrange(0, 800)
- y = random.randrange(0, 700)
- snow_list.append([x,y])
- # the background image
- red = (200,0,0)
- green = (255,250,250)
- bright_red = (255,250,0)
- bright_green = (0,255,0)
- clock = pygame.time.Clock()
- intro = True
- while intro:
- clock.tick(FPS)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- intro = False
- pygame.quit()
- # GAME INTRO IMAGE
- button("Click To Play!",40,310,220,60,green,bright_green,crash)
- bls = pygame.image.load("end.png")
- window.blit(bls,(0,0))
- window.blit(text,rect)
- for point in snow_list:
- point[1]+=1
- pygame.draw.circle(window, (255,255,255), point, 2)
- if(point[1] >= 600):
- point[0] = random.randrange(0, 600)
- point[1] = random.randrange(-10, -5)
- clock.tick(FPS)
- # ---------------------------------------------------------------------
- pygame.display.update()
- # start screen
- def game_intro():
- def fade(width, height):
- fade = pygame.Surface((width,height))
- fade.fill((0,0,0))
- for alpha in range(0, 300):
- fade.set_alpha(alpha)
- redraw()
- window.blit(fade, (0,0))
- pygame.display.update()
- pygame.time.delay(5)
- bls = pygame.image.load("gametitle.png")
- def redraw():
- window.blit(bls,(0,0))
- # this makes it
- snow_list=[]
- no_of_circles=100;
- clock = pygame.time.Clock()
- FPS = 60
- clock.tick(FPS)
- for i in range(no_of_circles):
- x = random.randrange(0, 800)
- y = random.randrange(0, 700)
- snow_list.append([x,y])
- # the background image
- red = (200,0,0)
- green = (255,250,250)
- bright_red = (255,250,0)
- bright_green = (0,255,0)
- clock = pygame.time.Clock()
- intro = True
- while intro:
- clock.tick(FPS)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- intro = False
- pygame.quit()
- # GAME INTRO IMAGE
- button("Click To Play!",40,310,220,60,green,bright_green,fade(800,800),main_loop)
- redraw()
- for point in snow_list:
- point[1]+=1
- pygame.draw.circle(window, (255,255,255), point, 2)
- if(point[1] >= 600):
- point[0] = random.randrange(0, 600)
- point[1] = random.randrange(-10, -5)
- clock.tick(FPS)
- # ---------------------------------------------------------------------
- pygame.display.update()
- def main_loop():
- # player class
- class player:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.color = color
- self.height = height
- self.width = width
- self.speed = 7
- self.isJump = False
- self.JumpCount = 10
- self.fall = 0
- #hit box
- self.hitbox = (self.x + 20, self.y, 28, 60)
- self.rights = [pygame.image.load("w1.png"),
- pygame.image.load("w2.png"),
- pygame.image.load("w3.png"),
- pygame.image.load("w4.png"),
- pygame.image.load("w5.png"),
- pygame.image.load("w6.png")]
- self.lefts = [pygame.image.load("e1.png"),
- pygame.image.load("e2.png"),
- pygame.image.load("e3.png"),
- pygame.image.load("e4.png"),
- pygame.image.load("e5.png"),
- pygame.image.load("e6.png")]
- self.hitright = [pygame.image.load("h1.png"),
- pygame.image.load("h2.png"),
- pygame.image.load("h3.png"),
- pygame.image.load("h4.png"),
- pygame.image.load("h5.png"),
- pygame.image.load("h6.png")]
- self.hitleft = [pygame.image.load("h11.png"),
- pygame.image.load("h12.png"),
- pygame.image.load("h13.png"),
- pygame.image.load("h14.png"),
- pygame.image.load("h15.png"),
- pygame.image.load("h16.png")]
- self.standingright = [pygame.image.load("d1.png"),
- pygame.image.load("d2.png"),
- pygame.image.load("d3.png"),
- pygame.image.load("d4.png")]
- self.standingleft =[pygame.image.load("s1.png"),
- pygame.image.load("s2.png"),
- pygame.image.load("s3.png"),
- pygame.image.load("s4.png")]
- self.rights = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.rights]
- self.lefts = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.lefts]
- self.standingright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingright]
- self.standingleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.standingleft]
- self.hitright = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitright]
- self.hitleft = [pygame.transform.scale(image,(image.get_width()*2,image.get_height()*2)) for image in self.hitleft]
- self.bo_index = 0
- self.anim_index = 0
- self.stans_index = 0
- self.direction = "right"
- self.direction = "left"
- self.direction = "standright"
- self.direction = "standleft"
- self.direction = "hitright"
- self.direction = "hitleft"
- self.health = 10
- self.hitbox = (self.x + -30, self.y + 0, 31, 57)
- self.hit = (self.x + -30, self.y + 0, 31, 57)
- # playerman hitbox
- self.hit = (self.x + 22, self.y + 60, 31, 27)
- # the health bar image
- self.healthimage = pygame.image.load("yup.png")
- self.klox = (self.x + -30, self.y + 0, 31, 57)
- self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
- self.healthimage = pygame.transform.scale(self.healthimage,(self.healthimage.get_width()//7,self.healthimage.get_height()//7))
- self.fps = 30
- self.FPS = 115
- self.clock = pygame.time.Clock()
- def draw(self):
- window.blit(self.healthimage,self.klox)
- self.rect.topleft = (self.x,self.y)
- if self.direction == "right":
- self.clock.tick(self.fps)
- image_list = self.rights
- elif self.direction == "standright":
- self.clock.tick(self.fps)
- image_list = self.standingright
- elif self.direction == "left":
- self.clock.tick(self.fps)
- image_list = self.lefts
- elif self.direction == "hitright":
- self.clock.tick(self.FPS)
- image_list = self.hitright
- elif self.direction == "hitleft":
- self.clock.tick(self.FPS)
- image_list = self.hitleft
- else:
- self.clock.tick(self.fps)
- image_list = self.standingleft
- if self.anim_index >= len(image_list):
- self.anim_index = 0
- player_image = image_list[self.anim_index]
- self.anim_index += 1
- self.hits = (self.x + 20, self.y, 26,60)
- pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 40, 170, 15)) # NEW
- pygame.draw.rect(window, (0,200,0), (self.hitbox[0], self.hitbox[1] - 40, 170 - (5 * (10 - self.health)), 15))
- self.hitbox = (10, 97, 61, 47)
- # health image
- self.klox = (2, 50, 61, 57)
- self.hit = (self.x + 22, self.y + 30, 41, 57)
- window.blit(player_image, self.rect)
- pygame.draw.rect(window,self.color,self.hit,2)
- white = 255,255,255
- playerman = player(200,300,90,50,white)
- class slime:
- def __init__(self,x,y,height,width,end):
- self.x = x
- self.y =y
- self.esright = [pygame.image.load("esright1.png"),
- pygame.image.load("esright2.png"),
- pygame.image.load("esright3.png"),
- pygame.image.load("esright4.png"),
- pygame.image.load("esright5.png"),
- pygame.image.load("esright6.png"),
- pygame.image.load("esright7.png"),
- pygame.image.load("esright8.png")
- ]
- self.esleft = [pygame.image.load("esleft1.png"),
- pygame.image.load("esleft2.png"),
- pygame.image.load("esleft3.png"),
- pygame.image.load("esleft4.png"),
- pygame.image.load("esleft5.png"),
- pygame.image.load("esleft6.png"),
- pygame.image.load("esleft7.png"),
- pygame.image.load("esleft8.png")
- ]
- self.esright = [pygame.transform.scale(image,(image.get_width()//1,image.get_height()//1)) for image in self.esright]
- self.esleft = [pygame.transform.scale(image,(image.get_width()//1,image.get_height()//1)) for image in self.esleft]
- self.height = height
- self.width = width
- self.anim_index = 0
- self.distance = 80
- self.speed = 8
- self.vel = 3
- self.path = [x,end]
- self.Walking_index = 0
- self.hitbox = (self.x + 17, self.y + 2, 31, 57)
- self.rect = pygame.Rect(x,y,height,width)
- COOLDOWN = 30
- # enemys health
- self.health = 10
- self.visible = True
- self.Walking = 0
- # this makes the enemy move right and left
- def draw(self,window):
- if self.Walking + 1 >= 33:
- self.Walking = 0
- if self.vel > 0: # left
- window.blit(self.esright[self.Walking %3], (self.x,self.y))
- self.Walking += 1
- else: # right
- window.blit(self.esleft[self.Walking %3], (self.x,self.y))
- self.Walking += 1
- pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 20, 10)) # NEW
- pygame.draw.rect(window, (255, 87, 51), (self.hitbox[0], self.hitbox[1] - 20, 20 - (5 * (10 - self.health)), 10))
- self.hitbox = (self.x + 2, self.y + 101, 60, 52)
- # THIS PART MAKES the enemy not scroll with the playzer
- def scroll(self,sx, sy):
- self.x += sx
- self.y += sy
- self.path[0] += sx
- self.path[1] += sx
- slime1 = slime(100,301,50,50,white)
- # player class
- class player:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.color = color
- self.height = height
- self.width = width
- # run dust frame
- self.dusts = [pygame.image.load("dust1.png"),
- pygame.image.load("dust2.png"),
- pygame.image.load("dust3.png"),
- pygame.image.load("dust4.png"),
- pygame.image.load("dust5.png"),
- pygame.image.load("dust6.png"),
- pygame.image.load("dust7.png"),
- pygame.image.load("dust8.png")]
- self.anim_index = 0
- self.direction = "dustright"
- self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
- self.fps = 20
- self.clock = pygame.time.Clock()
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- if self.direction == "dustright":
- self.clock.tick(self.fps)
- image_list = self.dusts
- if self.anim_index >= len(image_list):
- self.anim_index = 0
- player_image = image_list[self.anim_index]
- self.anim_index += 1
- white = 255,255,255
- dudel = player(200,200,50,50,white)
- # apple class
- # bomb class
- # slow motion rect
- class slow:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y =y
- self.height = height
- self.width = width
- self.color = color
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- pygame.draw.rect(window,self.color,self.rect)
- slowmoition1 = slow(100,100,30,450,white)
- slowmoition2 = slow(690,100,30,450,white)
- # fade effect
- # platform class
- class platform:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.image1 = pygame.image.load("Tile_25.png")
- self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()*2,self.image1.get_height()*2))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.image1,self.rect)
- class platform2:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.rect = pygame.Rect(x,y,height,width)
- self.block2 = pygame.image.load("Tile_12.png")
- self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.block2,self.rect)
- class plat:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.block2 = pygame.image.load("Tile_07.png")
- self.block2 = pygame.transform.scale(self.block2,(self.block2.get_width()*2,self.block2.get_height()*2))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.block2,self.rect)
- # player projectile
- class projectile(object):
- def __init__(self, x, y, dirx, diry, color):
- self.x = x
- self.y = y
- self.dirx = dirx
- self.diry = diry
- self.image1 = pygame.image.load("pros.png")
- self.image1 = pygame.transform.scale(self.image1,(self.image1.get_width()//2,self.image1.get_height()//2))
- self.rect = self.image1.get_rect()
- self.rect.topleft = ( self.x, self.y )
- self.speed = 17
- self.color = color
- def move(self):
- self.x += self.dirx * self.speed
- self.y += self.diry * self.speed
- def draw(self, window):
- self.rect.topleft = (round(self.x), round(self.y))
- window.blit(self.image1,self.rect)
- plats = []
- platforms2 = []
- platforms = []
- platformGroup = pygame.sprite.Group
- level = [
- "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",
- "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 ",
- " ",
- "l l ",
- "g g ",
- "g g ",
- "g g ",
- "g g ",
- " ",
- "c c c c c c c c c c c c c c ",
- " ",
- "d d d d d d d d d d d d d d d d",
- "d d d d d d d d d d d d d d d d",
- "d d d d d d d d d d d d d d d d",
- "d d d d d d d d d d d d d d d d",
- "d d d d d d d d d d d d d d d d",
- "d d d d d d d d d d d d d d d d"]
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "c":
- new_platforms = platform(ix*9.8, iy*50, 60,90,(255,255,255))
- platforms.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "d":
- new_platforms = platform2(ix*10.6, iy*45.9, 60,70,(255,255,255))
- platforms2.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "g":
- new_platforms = platform2(ix*10.6, iy*55.9, 60,70,(255,255,255))
- platforms2.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "l":
- new_platforms = platform(ix*10.6, iy*55.9, 60,670,(255,255,255))
- platforms.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "s":
- new_platforms = platform2(ix*10.6, iy*-45.9, 60,70,(255,255,255))
- platforms2.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "n":
- new_platforms = plat(ix*10.6, iy*79, 60,70,(255,255,255))
- plats.append(new_platforms)
- # ReDrawing the window
- block2 = pygame.image.load("1.png")
- block2 = pygame.transform.scale(block2,(block2.get_width()*2,block2.get_height()*2))
- bg = pygame.image.load("bl.png")
- class particle:
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.x_vel = random.randrange(-10,13)*1
- self.y_vel = random.randrange(-10,-1)*1
- self.lifetime = 0
- self.partilight = pygame.image.load("cls.png")
- self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//2,self.partilight.get_height()//2))
- def draw(self,window):
- self.lifetime += 1
- if self.lifetime <30:
- self.x -= self.x_vel
- self.y -= self.y_vel
- window.blit(self.partilight,(self.x,self.y,16,16))
- class partic:
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.x_vel = random.randrange(-10,13)*1
- self.y_vel = random.randrange(-10,-1)*1
- self.lifetime = 0
- self.partilight = pygame.image.load("smoke.png")
- self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//2,self.partilight.get_height()//2))
- def draw(self,window):
- self.lifetime += 1
- if self.lifetime <5:
- self.x += self.x_vel
- self.y += self.y_vel
- window.blit(self.partilight,(self.x,self.y,16,16))
- class partic:
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.x_vel = random.randrange(-10,13)*1
- self.y_vel = random.randrange(-10,-1)*1
- self.lifetime = 0
- self.partilight = pygame.image.load("sds.png")
- self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//3,self.partilight.get_height()//3))
- def draw(self,window):
- self.lifetime += 1
- if self.lifetime <6:
- self.x += self.x_vel
- self.y += self.y_vel
- window.blit(self.partilight,(self.x,self.y,5,5))
- class parti:
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.x_vel = random.randrange(-10,13)*1
- self.y_vel = random.randrange(-10,-1)*1
- self.lifetime = 0
- self.partilight = pygame.image.load("sds.png")
- self.partilight = pygame.transform.scale(self.partilight,(self.partilight.get_width()//3,self.partilight.get_height()//3))
- def draw(self,window):
- self.lifetime += 1
- if self.lifetime <26:
- self.x -= self.x_vel
- self.y -= self.y_vel
- pygame.draw.rect(window,(255,255,255),(self.x,self.y,10,10))
- # the falling apples:
- class apple:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y =y
- self.height = height
- self.width = width
- self.color = color
- self.hitbox = (self.x + -30, self.y + 0, 31, 57)
- self.speed = 3
- self.appleimage = pygame.image.load("fish1.png")
- self.appleimage = pygame.transform.scale(self.appleimage,(self.appleimage.get_width()*2,self.appleimage.get_height()*2))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- player_rect = self.appleimage.get_rect(center = self.rect.center)
- player_rect.centerx += 10 # 10 is just an example
- player_rect.centery += -20 # 15 is just an example
- window.blit(self.appleimage, player_rect)
- apple1 = apple(240,170,50,50,white)
- apple2 = apple(0,510,900,10,white)
- apple3 = apple(100,20,600,5,white)
- # the scoring
- font = pygame.font.Font("do.ttf", 50)
- apple = 0
- text = font.render(" Fish " + str(apple), True, (255,255,255))
- rect = text.get_rect()
- defont = pygame.font.Font("do.ttf", 30)
- texts = font.render(" + 5" , True, (0,255,0))
- rects = text.get_rect()
- # bg image
- bg = pygame.image.load("bs;.png")
- def ReDrawwindow():
- dudel.draw()
- window.blit(bg,(0,0))
- for bullet in bullets:
- bullet.draw(window)
- apple1.draw()
- for plat in plats:
- plat.draw()
- playerman.draw()
- for platform in platforms:
- platform.draw()
- for platform2 in platforms2:
- platform2.draw()
- for particle in particles:
- particle.draw(window)
- apple3.draw()
- window.blit(texts,apple1.rect)
- slime1.draw(window)
- window.blit(text,rect)
- pygame.display.update()
- fps = 50
- clock = pygame.time.Clock()
- # main loo
- bullets = []
- particles = []
- runninggame = True
- while runninggame:
- clock.tick(fps)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- runninggame = False
- if event.type == pygame.MOUSEBUTTONDOWN:
- # this is for the bullets
- if len(bullets) < 2:
- start_x, start_y = playerman.x+playerman.width//2, playerman.y + playerman.height-35
- mouse_x, mouse_y = event.pos
- dir_x, dir_y = mouse_x - start_x, mouse_y - start_y
- distance = math.sqrt(dir_x**2 + dir_y**2)
- if playerman.direction == "hitleft":
- if distance > 0:
- new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
- bullets.append(new_bullet)
- if playerman.direction == "hitright":
- if distance > 0:
- new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
- bullets.append(new_bullet)
- if playerman.direction == "right" or playerman.direction == "standright":
- playerman.direction = "hitright"
- if playerman.direction == "left" or playerman.direction == "standleft":
- playerman.direction = "hitleft"
- # this is displaying the bullets for the player
- for bullet in bullets[:]:
- bullet.move()
- if bullet.x < 0 or bullet.x > 900 or bullet.y < 0 or bullet.y > 900:
- bullets.pop(bullets.index(bullet))
- apple1.y += apple1.speed
- if apple1.rect.colliderect(playerman.hit):
- for platform in platforms:
- apple += 1
- text = font.render(" Fish " + str(apple), True, (255,255,255))
- rect = text.get_rect()
- apple1.x = random.randint(apple3.rect.x,apple3.rect.x + apple3.rect.width)
- apple1.y = random.randrange(0, 1 + 12)
- apple1.speed += 0.01
- if apple2.rect.colliderect(apple1.rect):
- text = font.render(" Fish " + str(apple), True, (255,255,255))
- rect = text.get_rect()
- apple1.x = random.randint(apple3.rect.x,apple3.rect.x + apple3.rect.width)
- apple1.y = random.randrange(0, 1)
- playerman.health -= 51
- # slime enemy movement
- slime1.x += 2
- # the end screen
- if playerman.health < -5:
- end_screen()
- # collisions between the fish so they dont get out the box
- for bullet in bullets:
- if bullet.rect.colliderect(apple1.rect):
- bullet.speed = 0.02
- playerman.fall = 10
- apple1.speed = 1
- if playerman.direction == "hitright":
- playerman.clock.tick(10)
- else:
- bullet.speed = 17
- playerman.fall = 3
- apple1.speed = 3
- # camera movement up down
- if playerman.y < 240:
- playerman.y += 1
- for platform in platforms:
- platform.y += playerman.speed
- for platform2 in platforms2:
- platform2.y += playerman.speed
- for plat in plats:
- plat.y += playerman.speed
- slowmoition1.y += playerman.speed
- slowmoition2.y += playerman.speed
- apple1.y += playerman.speed
- apple2.y += playerman.speed
- apple3.y += playerman.speed
- slime1.y += playerman.speed
- for bullet in bullets:
- bullet.y += playerman.speed
- for bullet in bullets:
- if bullet.rect.colliderect(slowmoition1) or bullet.rect.colliderect(slowmoition2.rect):
- bullet.speed = 3
- playerman.fall = 10
- else:
- bullet.speed = 17
- playerman.fall = 3
- for platform in platforms:
- for bullet in bullets:
- if bullet.rect.colliderect(platform.rect):
- for x in range(50):
- x,y = bullet.rect.center
- particles.append(particle(x,y))
- bullets.pop(bullets.index(bullet))
- for x in range(1):
- x,y = apple1.rect.center
- particles.append(partic(x,y))
- if apple1.rect.colliderect(playerman.rect):
- for x in range(21):
- x,y = playerman.rect.center
- particles.append(parti(x,y))
- if playerman.y > 300:
- playerman.y -= playerman.fall
- for platform in platforms:
- platform.y -= playerman.fall
- for platform2 in platforms2:
- platform2.y -= playerman.fall
- for plat in plats:
- plat.y -= playerman.fall
- for bullet in bullets:
- bullet.y -= playerman.fall
- apple1.y -= playerman.fall
- apple2.y -= playerman.fall
- slowmoition1.y -= playerman.fall
- slowmoition2.y -= playerman.fall
- apple3.y -= playerman.fall
- slime1.y -= playerman.fall
- # key event for the player
- keys = pygame.key.get_pressed()
- if keys[pygame.K_d]:
- playerman.x += playerman.speed
- playerman.direction = "right"
- dudel.direction = "dustright"
- if playerman.x > 350:
- playerman.x -= playerman.speed
- for platform in platforms:
- platform.x -= playerman.speed
- for platform2 in platforms2:
- platform2.x -= playerman.speed
- for plat in plats:
- plat.x -= playerman.speed
- slowmoition1.x -= playerman.speed
- slowmoition2.x -= playerman.speed
- apple1.x -= playerman.speed
- apple2.x -= playerman.speed
- apple3.x -= playerman.speed
- slime1.x -= playerman.speed
- for bullet in bullets:
- bullet.x -= playerman.speed
- elif keys[pygame.K_a]:
- playerman.x -= playerman.speed
- playerman.direction = "left"
- if playerman.x < 350:
- playerman.x += playerman.speed
- for platform in platforms:
- platform.x += playerman.speed
- for platform2 in platforms2:
- platform2.x += playerman.speed
- for plat in plats:
- plat.x += playerman.speed
- slowmoition1.x += playerman.speed
- slowmoition2.x += playerman.speed
- for bullet in bullets:
- bullet.x += playerman.speed
- apple1.x += playerman.speed
- apple2.x += playerman.speed
- apple3.x += playerman.speed
- slime1.x += playerman.speed
- else:
- if playerman.direction == "right":
- playerman.direction = "standright"
- else:
- if playerman.direction == "left":
- playerman.direction = "standleft"
- if not playerman.isJump:
- playerman.y += playerman.fall
- playerman.fall += 1
- playerman.isJump = False
- # this part lets you jump on platform
- collide = False
- for platform in platforms:
- if playerman.rect.colliderect(platform.rect):
- collide = True
- playerman.isJump = False
- playerman.y = platform.rect.top - playerman.height + 1
- if playerman.rect.right > platform.rect.left and playerman.rect.left < platform.rect.left - playerman.width:
- playerman.x = platform.rect.left - playerman.width
- if playerman.rect.left < platform.rect.right and playerman.rect.right > platform.rect.right + playerman.width:
- playerman.x = platform.rect.right
- # this makes the player fall down up to
- if playerman.rect.bottom >= 410:
- collide = True
- playerman.isJump = False
- playerman.JumpCount = 10
- playerman.y = 410 - playerman.height
- if collide:
- if keys[pygame.K_SPACE]:
- playerman.isJump = True
- playerman.fall = 5
- else:
- if playerman.JumpCount >0:
- playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount)) * 0.2
- playerman.JumpCount -= 1
- else:
- playerman.JumpCount = 10
- playerman.isJump = False
- ReDrawwindow()
- pygame.display.update()
- pygame.quit()
- game_intro()
- main_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement