Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import pygame
- from pygame import *
- pygame.init()
- size = width, height = 640, 480
- window = pygame.display.set_mode(size)
- pygame.display.set_caption('hello, pygame!')
- screen = pygame.Surface((640,480))
- class Sprite:
- def __init__(self, xpos, ypos, filename):
- self.x = xpos
- self.y = ypos
- self.bitmap = pygame.image.load(filename)
- self.bitmap.set_colorkey((255,255,255))
- def render(self):
- screen.blit(self.bitmap, (self.x, self.y))
- def Intersect (x1, x2, y1, y2):
- if (x1>x2-32) and (x1<x2+32) and (y1>y2-32) and (y1<y2+32):
- return 1
- else:
- return 0
- #PLATFORM_COLOR = (0, 45, 16)
- level = [
- '------*---',
- '----------',
- '---------*',
- '*---*-----',
- '------*---',
- '-----*----',
- '-------*--',
- '---*--*---',
- '*----*--*-',
- '----------',
- '-*---*----',
- '---*------',
- '----*-----',
- '----------',
- '---*------',
- '-------*--',
- '-----*----',
- '--*-------',
- '------*-*-',
- '---*------']
- hero = Sprite(0.0, 448.0, "rsz_hero.png")
- hero.go_right = True
- hero.go_left = True
- hero.go_down = True
- hero.go_up = True
- hero.jump = True
- hero.move_speed = 0.7
- hero.jump_altitude = 0.5
- hero.gravity = -0.2
- target = Sprite(300.0, 0.0, "target.png")
- platform = Sprite(0,0, "ground.png")
- #platform = pygame.image.load("ground.png")
- done = True
- while done:
- for e in pygame.event.get():
- if e.type == pygame.QUIT:
- done = False
- screen.fill((0,40,58))
- x=y=0
- width = 64
- height = 20
- for row in level:
- for col in row:
- if col == '*':
- platform.render()
- #pf = pygame.Surface((PLATFORM_WIDTH,PLATFORM_HEIGHT))
- #pf.fill(PLATFORM_COLOR)
- #pf.blit(platform, (0,0))
- #screen.blit(pf, (x,y))
- x += width
- y += height
- x = 0
- #движение вправо
- if e.type == KEYDOWN and e.key == K_RIGHT:
- if hero.x > 640 - 32:
- hero.go_right = False
- else:
- hero.go_right = True
- hero.x += hero.move_speed
- #движение влево
- if e.type == KEYDOWN and e.key == K_LEFT:
- if hero.x <= 0:
- hero.go_left = False
- else:
- hero.go_left = True
- hero.x -= hero.move_speed
- #движение вверх
- if e.type == KEYDOWN and e.key == K_SPACE:
- if hero.y < 480 and hero.y > 0:
- hero.jump = True
- hero.y -= hero.jump_altitude
- if hero.y !=0:
- hero.y = hero.gravity
- else:
- hero.jump = False
- if Intersect (target.x, hero.x, target.y, hero.y) == True:
- hero.go_right = True
- hero.go_down = True
- hero.x += 0.00000001
- hero.y += 0.00000001
- hero.render()
- target.render()
- window.blit(screen, (0,0))
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement