Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import time
- import sys
- import random
- WIDTH, HEIGHT = 900, 600
- WHITE = (255, 255, 255)
- BLACK = (0,0,0)
- PINK = (255, 0, 120)
- #### SETTINGS ###
- MIN_ENEMY_SPEED = 4
- MAX_ENEMY_SPEED = 6
- PLAYER_SPEED = pygame.math.Vector2(0,1)
- #### SETTINGS ###
- pygame.init()
- canvas = pygame.display.set_mode((WIDTH,HEIGHT))
- pygame.display.set_caption('Asterodis')
- clock = pygame.time.Clock()
- def quitGame():
- pygame.quit()
- sys.exit(0)
- class Ship():
- def __init__(self, a):
- self.apex = [pygame.math.Vector2(-a, a), pygame.math.Vector2(a, a), pygame.math.Vector2(0, -a)]
- self.newApex = [0, 0, 0]
- self.offset = pygame.math.Vector2(WIDTH / 2, HEIGHT / 2)
- def rotate(self, angle):
- self.apex[0] = self.apex[0].rotate(angle)
- self.apex[1] = self.apex[1].rotate(angle)
- self.apex[2] = self.apex[2].rotate(angle)
- self.newApex = [self.apex[0] + self.offset, self.apex[1] + self.offset, self.apex[2] + self.offset]
- def move(self, direction):
- self.speed = PLAYER_SPEED
- self.apex[0] += self.speed * direction
- self.apex[1] += self.speed * direction
- self.apex[2] += self.speed * direction
- self.offset += self.speed * direction
- def show(self):
- pygame.draw.polygon(canvas, PINK, self.newApex, 2)
- pygame.draw.circle(canvas, WHITE, (int(self.offset.x), int(self.offset.y)), 2)
- ship = Ship(30)
- while True:
- canvas.fill((BLACK))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- quitGame()
- angle = 0
- direction = 0
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT]:
- angle = -1
- elif keys[pygame.K_RIGHT]:
- angle = 1
- if keys[pygame.K_UP]:
- direction = -1
- elif keys[pygame.K_DOWN]:
- direction = 1
- ship.rotate(angle)
- ship.move(direction)
- ship.show()
- pygame.display.flip()
- clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment