Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import pygame
- import sys
- pygame.init()
- screen = pygame.display.set_mode((800,400))
- pygame.display.set_caption('Game Title')
- clock = pygame.time.Clock()
- angle=0
- turretLen = 75
- moveAmt = 0
- x1=100
- y1=100
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT]:
- angle -= 5
- if keys[pygame.K_RIGHT]:
- angle += 5
- print(angle)
- if keys[pygame.K_UP]:
- moveAmt += 1
- if keys[pygame.K_DOWN]:
- moveAmt -= 1
- if moveAmt <= 0:
- moveAmt = 0
- moveAmt = moveAmt*.95
- x1 += math.cos(math.radians(angle))*moveAmt
- y1 += math.sin(math.radians(angle))*moveAmt
- x2 = math.cos(math.radians(angle))*turretLen
- y2 = math.sin(math.radians(angle))*turretLen
- screen.fill((70,70,70))
- pygame.draw.circle(screen, 'red', (x1,y1), 50, 1)
- pygame.draw.line(screen, 'blue', (x1,y1), (x1+x2,y1+y2), 3)
- pygame.display.update() ## vs. flip()
- clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment