Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- from pygame.locals import *
- pygame.init()
- screen = pygame.display.set_mode((700,700)) #Window Size
- screen.fill((100,100,0))
- pygame.display.update()
- background = pygame.image.load("space.gif") # Background
- class Character(pygame.sprite.Sprite):
- def __init__(self,position):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.image.load('Tanks.png')
- self.rect = self.image.get_rect()
- self.right = False
- self.left = False
- self.mass = 60 #kg
- self.velocity = 0
- self.rect.topleft = position
- self.lives = 3
- def update(self):
- if self.right:
- self.velocity += .02
- elif self.velocity > 0:
- self.velocity -= .01
- if self.left:
- self.velocity -= .02
- elif self.velocity < 0:
- self.velocity += .01
- if self.velocity > 2:
- self.velocity = 2
- if self.velocity < -2:
- self.velocity = -2
- self.rect.right += self.velocity
- if self.rect.right >= 700:
- self.rect.right = 700
- if self.rect.left <= 0:
- self.rect.left = 0
- class Platform(pygame.sprite.Sprite):
- def __init__(self,position):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.image.load('platform.png')
- self.rect = self.image.get_rect()
- self.topleft = position
- def player_input():
- for event in pygame.event.get():
- if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
- pygame.quit()
- if event.type == KEYDOWN and event.key == K_a:
- character.left=True
- if event.type == KEYDOWN and event.key == K_d:
- character.right=True
- if event.type == KEYUP and event.key == K_a:
- character.left=False
- if event.type == KEYUP and event.key == K_d:
- character.right=False
- if event.type == MOUSEBUTTONDOWN and event.button == 1: #left
- print 'check'
- if event.type == MOUSEBUTTONDOWN and event.button == 3: #right
- print 'rcheck'
- screen.blit(background, (0,0))
- pygame.display.update()
- character = Character((450,450))
- platform = Platform((500,500))
- screen.blit(platform.image, platform.rect.topleft)
- pygame.display.update()
- while True:
- screen.blit(background, (0,0))
- player_input()
- character.update()
- screen.blit(character.image, character.rect.topleft)
- pygame.display.update()
Add Comment
Please, Sign In to add comment