Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import pygame
- from pygame import *
- window = pygame.display.set_mode((640, 480))
- pygame.display.set_caption("test")
- 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))
- """white = ( 255, 255, 255)
- class Block (pygame.sprite.Sprite):
- def __init__(self, width, height):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.Surface([width, height])
- self.image = pygame.image.load("wood.png").convert()
- self.image.set_colorkey(white)
- self.rect = self.image.get_rect() """
- def Intersect (s1_x, s2_x, s1_y, s2_y):
- if (s1_x > s2_x - 24) and (s1_x < s2_x + 24) and (s1_y > s2_y - 26) and (s1_y < s2_y +24):
- return 1
- else:
- return 0
- hero = Sprite(0, 454, "hero.png")
- hero.go_right = True
- hero.go_left = True
- target = Sprite(500,0, 'target.jpg')
- #platform = Sprite(0,0, "wood.png")
- img = pygame.image.load("wood.png")
- #blockx = Block(31,22)
- move_speed = 0.7
- altitude = 2
- block = [
- "----x------x---x--x-",
- "x---------x------x--",
- "---x--x--x---x--x---",
- "---x--xxx---------xx",
- "-----------xx---x---",
- "-------x-----x------",
- "xxx-------xx----xx--",
- "-----xxx-----xx----x",
- "---xx-----xx-----xx-",
- "------xx------xx----",
- "---xxx----xx-----xx-",
- "xx------xx-----xx---",
- "----xx-----xx-------",
- "---x----xx-----x-xx-",
- "xxxxxx------xx------",
- "----------xx---xx---",
- "xxx----xx----x----xx",
- "x--xxx----xx--xx--xx",
- "-------xx-----------",
- "----------xxx----xxx",
- "--xx----xx-----xx---",
- "-----xx-----xx------"]
- PLATFORM_WIDTH = 31
- PLATFORM_HEIGHT = 20
- done =True
- while done:
- for e in pygame.event.get():
- if e.type == pygame.QUIT:
- done = False
- screen.fill((0,127,0))
- hero.render()
- target.render()
- window.blit(screen, (0,0))
- x=y=0
- for row in block:
- for col in row:
- if col == "x":
- pf = Surface ((PLATFORM_WIDTH, PLATFORM_HEIGHT))
- pf.blit(img, (0,0))
- window.blit(pf, (x, y))
- x += PLATFORM_WIDTH
- y+= PLATFORM_HEIGHT
- x=0
- #Движение вправо
- if e.type == KEYDOWN and e.key == K_RIGHT:
- if hero.x < 640 - 24:
- hero.go_right = True
- hero.x += move_speed
- #проверка на столкновение
- #if Intersect (hero.x, pf.x, hero.y, pf.y):
- hero.go_right = False
- else:
- hero.go_right = False
- #Движение влево
- if e.type == KEYDOWN and e.key == K_LEFT:
- if hero.x >= 0:
- hero.go_left = True
- hero.x -= move_speed
- else:
- hero.go_left = False
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement