Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- # our window
- window = pygame.display.set_mode((800,700), pygame.NOFRAME)
- pygame.display.set_caption("new world")
- jumpCountStart = 35
- # our player class
- class player:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.idle = [pygame.image.load("grey_mouse/idle (" + str(i) + ").png") for i in range(1, 21)]
- self.leftid = [pygame.image.load("grey_mouse/id (" + str(i) + ").png") for i in range(1, 21)]
- self.Right = [pygame.image.load("grey_mouse/walk (" + str(i) + ").png") for i in range(1, 9)]
- self.left = [pygame.image.load("grey_mouse/left (" + str(i) + ").png") for i in range(1, 9)]
- self.jump = [pygame.image.load("grey_mouse/jump (6).png")]
- self.jump2 = [pygame.image.load("grey_mouse/jump 06.png")]
- repeat = jumpCountStart // 9
- self.jump = [self.jump[i // repeat] for i in range(len(self.jump) * repeat)]
- self.color = color
- self.rect = pygame.Rect(x,y,height,width)
- self.fps = 60
- self.clock = pygame.time.Clock()
- self.next_frame_time = 0
- self.anim_index = 0
- self.isJump = False
- self.JumpCount = 10
- self.JumpCount = jumpCountStart
- self.direction = "jump"
- self.direction = "jump2"
- self.direction = "Idle"
- self.direction = "right"
- self.direction = "left"
- self.direction = "leftid"
- self.speed = 3
- self.fall = 0
- def get_rect(self):
- self.rect.topleft = (self.x,self.y)
- return self.rect
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- if self.direction == "Idle":
- self.clock.tick(self.fps)
- image_list = self.idle
- elif self.direction == "right":
- image_list = self.Right
- elif self.direction == "left":
- image_list = self.left
- elif self.direction == "leftid":
- image_list = self.leftid
- elif self.direction == "jump":
- image_list = self.jump
- elif self.direction == "jump2":
- image_list = self.jump2
- time_now = pygame.time.get_ticks()
- if (time_now > self.next_frame_time):
- # Time until the next game
- inter_time_delay = 2000 // self.fps
- self.next_frame_time = time_now + inter_time_delay
- # Showing next frame
- self.anim_index += 1
- if self.anim_index >= len(image_list):
- self.anim_index = 0
- if self.anim_index >= len(image_list):
- self.anim_index = 0
- player_image = image_list[self.anim_index]
- self.hitbox = (self.x, self.y + 30, 46,60)
- player_rect = player_image.get_rect(center = self.get_rect().center)
- player_rect.centerx += 0
- player_rect.centery += -20
- window.blit(player_image, player_rect)
- class cloud:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.image = pygame.image.load("top_left_outer.png").convert_alpha()
- self.image = pygame.transform.scale(self.image,(self.image.get_width()//4,self.image.get_height()//4))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.image,self.rect)
- class clou:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.image = pygame.image.load("top_variation_02.png").convert_alpha()
- self.image = pygame.transform.scale(self.image,(self.image.get_width()//4,self.image.get_height()//4))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.image,self.rect)
- class clo:
- def __init__(self,x,y,height,width,color):
- self.x = x
- self.y = y
- self.height = height
- self.width = width
- self.color = color
- self.image = pygame.image.load("top_right_outer.png").convert_alpha()
- self.image = pygame.transform.scale(self.image,(self.image.get_width()//4,self.image.get_height()//4))
- self.rect = pygame.Rect(x,y,height,width)
- def draw(self):
- self.rect.topleft = (self.x,self.y)
- window.blit(self.image,self.rect)
- # define our player
- white = 255,255,255
- playerman = player(200,599,50,50,white)
- clouds = []
- clos = []
- clay = []
- platformGroup = pygame.sprite.Group
- level = [" ",
- " ",
- " c d d d o ",
- " ",
- " ",
- " c d d d o ",
- " ",
- " ",
- " ",
- " ",
- " c d d d o ",
- " ",
- " ",
- " ",
- " c d d d d d d d d d d d d d o",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " "
- ]
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "c":
- new_platforms = cloud(ix*9.9, iy*45, 120,20,(23, 32, 42))
- clouds.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "d":
- new_platforms = clou(ix*9.9, iy*45, 120,20,(23, 32, 42))
- clay.append(new_platforms)
- for iy, row in enumerate(level):
- for ix, col in enumerate(row):
- if col == "o":
- new_platforms = clo(ix*9.9, iy*45, 120,20,(23, 32, 42))
- clos.append(new_platforms)
- # our game fps
- fps = 60
- clock = pygame.time.Clock()
- bg_shift = 0
- bg_speed = 5
- bg = pygame.image.load("bg22.png").convert_alpha()
- # our redraw
- bg_shift2 = 0
- bg_speed = 5
- bg1 = pygame.image.load("bg11.png").convert_alpha()
- def redraw():
- window.fill((249, 213, 255))
- bg_width = bg.get_width()
- bg_offset = bg_shift % bg_width
- window.blit(bg, (-bg_offset, 200))
- window.blit(bg, (bg_width - bg_offset, 200))
- bg_width2 = bg1.get_width()
- bg_offset2 = bg_shift % bg_width2
- window.blit(bg1, (-bg_offset2, 400))
- window.blit(bg1, (bg_width2 - bg_offset2, 400))
- for cloud in clouds:
- cloud.draw()
- for clou in clay:
- clou.draw()
- for clo in clos:
- clo.draw()
- playerman.draw()
- right = True
- left = True
- # our main loop
- run = True
- while run:
- clock.tick(fps)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- keys = pygame.key.get_pressed()
- if playerman.direction == "right":
- playerman.direction = "Idle"
- if playerman.direction == "left":
- playerman.direction = "leftid"
- if keys[pygame.K_RIGHT]:
- playerman.x += playerman.speed
- # screen movement
- if playerman.x > 300:
- playerman.x -= playerman.speed
- for cloud in clouds:
- cloud.x -= playerman.speed
- for clou in clos:
- clou.x -= playerman.speed
- for clo in clay:
- clo.x -= playerman.speed
- bg_shift += round(playerman.speed / 2)
- bg_shift2 += round(playerman.speed / 2)
- if right:
- playerman.direction = "right"
- if keys[pygame.K_LEFT]:
- playerman.x -= playerman.speed
- if playerman.x < 500:
- playerman.x += playerman.speed
- for cloud in clouds:
- cloud.x += playerman.speed
- for clou in clos:
- clou.x += playerman.speed
- for clo in clay:
- clo.x += playerman.speed
- bg_shift -= round(playerman.speed / 2)
- bg_shift2 -= round(playerman.speed / 2)
- if left:
- playerman.direction = "left"
- if keys[pygame.K_RIGHT] and keys[pygame.K_SPACE]:
- if playerman.direction == "right" or playerman.direction == "Idle":
- playerman.direction = "jump"
- if keys[pygame.K_LEFT] and keys[pygame.K_SPACE]:
- if playerman.direction == "left" or playerman.direction == "leftid":
- playerman.direction = "jump2"
- # player moving
- if not playerman.isJump:
- pass
- collide = False
- if playerman.rect.bottom >= 636:
- collide = True
- playerman.y = 636 - playerman.height
- if collide:
- if keys[pygame.K_SPACE]:
- playerman.isJump = True
- if playerman.direction == "right" or playerman.direction == "Idle":
- playerman.direction = "jump"
- if playerman.direction == "left" or playerman.direction == "leftid":
- playerman.direction = "jump2"
- else:
- if playerman.JumpCount >= -jumpCountStart:
- jumpHeight = playerman.JumpCount * 10 / jumpCountStart
- playerman.y -= (jumpHeight * abs(jumpHeight)) * 0.3 * 10 / jumpCountStart
- playerman.JumpCount -= 1
- right = False
- left = False
- if keys[pygame.K_RIGHT]:
- if playerman.direction == "jump2":
- playerman.direction = "jump"
- if keys[pygame.K_LEFT]:
- if playerman.direction == "jump":
- playerman.direction = "jump2"
- else:
- playerman.JumpCount = jumpCountStart
- playerman.isJump = False
- right = True
- left = True
- if playerman.direction == "jump":
- playerman.direction = "Idle"
- if playerman.direction == "jump2":
- playerman.direction = "leftid"
- redraw()
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment