-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavigation.py
More file actions
87 lines (71 loc) · 2.22 KB
/
navigation.py
File metadata and controls
87 lines (71 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pygame
import random
import time
pygame.init()
screen = pygame.display.set_mode((800, 600))
done = False
rocketX = 30
rocketY = 30
rocket = pygame.image.load('rocketShip.png')
asteroid = pygame.image.load('asteroid.png')
goal = pygame.image.load('goal.png')
goalX = 600
goalY = 250
goalrect = pygame.Rect(goalX + 56,goalY+24,151,131)
asteroidWidth = 48
asteroidHeight = 48
#Decrease this number for lower difficulty
numAsteroids = 20
movable = True
countTime = True
asteroids = []
score = 0
for i in range(numAsteroids):
astX = random.randrange(2,16)*50
astY = random.randrange(0, 12)*50
if not ((astX > 550) and (astY < 451) and (astY > 249)):
asteroids.append((astX, astY))
#TODO: Make helper methods to detect imminent collisions with asteroids
#how can you use the asteroid positions to know if you will have a collision?
def getTopCollision():
return False
def getBottomCollision():
return False
def getLeftCollision():
return False
def getRightCollision():
return False
#TODO: Use this method to decide how much your rocket moves each time
def moveRocket():
return (1,1)
pygame.font.init() # you have to call this at the start,
# if you want to use this module.
myfont = pygame.font.SysFont('Comic Sans MS', 30)
timeStart = time.time()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill((0, 0, 0))
screen.blit(goal, (goalX, goalY))
rocketrect = pygame.Rect(rocketX + 3, rocketY + 3, 33, 23)
for i in range(len(asteroids)):
screen.blit(asteroid, (asteroids[i][0], asteroids[i][1]))
asteroidrect = pygame.Rect(asteroids[i][0], asteroids[i][1], 48, 48)
if(rocketrect.colliderect(asteroidrect)):
movable = False
if(rocketrect.colliderect(goalrect)):
movable = False
if countTime == True:
timeStop = time.time()
countTime = False
score = min(max(int((15-(timeStop-timeStart))*10),0),100)
textsurface = myfont.render('You Won with a score of ' + str(score) + ' out of 100', False, (255, 255, 255))
screen.blit(textsurface,(250,50))
if movable:
move = moveRocket()
rocketX += min(move[0], 5)
rocketY += min(move[1], 5)
screen.blit(rocket, (rocketX, rocketY))
pygame.display.flip()
time.sleep(5)