def moonLaunch(): screen = Surface((mehdi.WIDTH, mehdi.HEIGHT)) FPS = 100 clock = time.Clock() lives = 3 moonPic = transform.scale(image.load("textures/spok.jpg"), (80, 60)) def drawEarth(screen, x, y): draw.circle(screen, (255, 0, 0), (int(x), int(y)), 30, 0) def drawMoon(screen, x, y): screen.blit(moonPic, (int(x - 40), int(y - 30))) running = True #Start and end point earth = Planet(int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.75), 0, 0, 30, 1000, drawEarth) moon = Planet(int(mehdi.WIDTH * 0.9), int(mehdi.HEIGHT * 0.2), 0, 0, 30, 1000, drawMoon) #All asteroids.obstacles #Asteroid 1 Ast1x, Ast1y = int(mehdi.WIDTH * 0.4), int(mehdi.HEIGHT * 0.4) Ast1Pol = [(Ast1x + -5, Ast1y - 20), (Ast1x, Ast1y - 25), (Ast1x + 15, Ast1y - 21), (Ast1x + 5, Ast1y), (Ast1x + 9, Ast1y + 15), (Ast1x - 5, Ast1y + 25), (Ast1x - 15, Ast1y + 10), (Ast1x - 5, Ast1y + 15)] def drawAst1(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 25), (x + 15, y - 21), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 15, y + 10), (x - 5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast1 = Asteroid(Ast1Pol, Ast1x, Ast1y, 0, 0, drawAst1, 0.01) #Asteroid 2 Ast2x, Ast2y = int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.3) Ast2Pol = [(Ast2x + -5, Ast2y - 20), (Ast2x, Ast2y - 30), (Ast2x + 15, Ast2y - 15), (Ast2x + 5, Ast2y), (Ast2x + 9, Ast2y + 15), (Ast2x - 5, Ast2y + 25), (Ast2x - 20, Ast2y + 10), (Ast2x + -5, Ast2y + 15)] def drawAst2(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 30), (x + 15, y - 15), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 20, y + 10), (x + -5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast2 = Asteroid(Ast2Pol, Ast2x, Ast2y, 0, 0, drawAst2, -0.006) #Asteroid 3 Ast3x, Ast3y = int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.4) Ast3Pol = [(Ast3x + -5, Ast3y - 20), (Ast2x, Ast3y - 30), (Ast3x + 15, Ast3y - 15), (Ast3x + 5, Ast3y), (Ast3x + 9, Ast3y + 15), (Ast3x - 5, Ast3y + 25), (Ast3x - 20, Ast3y + 10), (Ast3x + -5, Ast3y + 15)] def drawAst3(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 30), (x + 15, y - 15), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 20, y + 10), (x + -5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast3 = Asteroid(Ast3Pol, Ast3x, Ast3y, 0, 0, drawAst3, -0.007) #Asteroid 4 Ast4x, Ast4y = int(mehdi.WIDTH * 0.5), int(mehdi.HEIGHT * 0.7) Ast4Pol = [(Ast4x + -5, Ast4y - 20), (Ast4x, Ast4y - 30), (Ast4x + 15, Ast4y - 15), (Ast4x + 5, Ast4y), (Ast4x + 9, Ast4y + 15), (Ast4x - 5, Ast4y + 25), (Ast4x - 20, Ast4y + 10), (Ast4x + -5, Ast4y + 15)] def drawAst4(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 30), (x + 15, y - 15), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 20, y + 10), (x + -5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast4 = Asteroid(Ast4Pol, Ast4x, Ast4y, 0, 0, drawAst4, -0.008) #Asteroid 5 Ast5x, Ast5y = int(mehdi.WIDTH * 0.3), int(mehdi.HEIGHT * 0.44) Ast5Pol = [(Ast5x + -5, Ast5y - 20), (Ast5x, Ast5y - 30), (Ast5x + 15, Ast5y - 15), (Ast5x + 5, Ast5y), (Ast5x + 9, Ast5y + 15), (Ast5x - 5, Ast5y + 25), (Ast5x - 20, Ast5y + 10), (Ast5x + -5, Ast5y + 15)] def drawAst5(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 30), (x + 15, y - 15), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 20, y + 10), (x + -5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast5 = Asteroid(Ast5Pol, Ast5x, Ast5y, 0, 0, drawAst5, -0.009) #Asteroid 6 Ast6x, Ast6y = int(mehdi.WIDTH * 0.78), int(mehdi.HEIGHT * 0.31) Ast6Pol = [(Ast6x + -5, Ast6y - 20), (Ast6x, Ast6y - 30), (Ast6x + 15, Ast6y - 15), (Ast6x + 5, Ast6y), (Ast6x + 9, Ast6y + 15), (Ast6x - 5, Ast6y + 25), (Ast6x - 20, Ast6y + 10), (Ast6x + -5, Ast6y + 15)] def drawAst6(screen, x, y, r): p = [(x + -5, y - 20), (x, y - 30), (x + 15, y - 15), (x + 5, y), (x + 9, y + 15), (x - 5, y + 25), (x - 20, y + 10), (x + -5, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (180, 180, 180), p, 0) Ast6 = Asteroid(Ast6Pol, Ast6x, Ast6y, 0, 0, drawAst6, 0.011) #Spaceship being launched def drawShip(screen, x, y, r): p = [(x - 15, y - 25), (x + 15, y - 25), (x + 15, y + 15), (x, y + 35), (x - 15, y + 15)] for i in range(len(p)): p[i] = [int(j) for j in rotateC(p[i][0], p[i][1], x, y, r)] draw.polygon(screen, (250, 250, 250), [p[0], p[1], p[2], p[4]], 0) draw.polygon(screen, (0, 0, 255), [p[2], p[3], p[4]], 0) asteroids = [Ast1, Ast2, Ast3, Ast4, Ast5, Ast6] #Actual spaceship shipx, shipy = int(mehdi.WIDTH * 0.22), int(mehdi.HEIGHT * 0.68) shipPoly = [(shipx - 15, shipy - 25), (shipx + 15, shipy - 25), (shipx + 15, shipy + 15), (shipx, shipy + 35), (shipx - 15, shipy + 15)] spaceShip = Asteroid(shipPoly, int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.69), 0, 0, drawShip, 0) launching = False shipping = False startx, starty = mehdi.WIDTH * 0.2, mehdi.HEIGHT * 0.75 planets = [earth, moon] mehdi.txtScreen( mehdi.TextBox( "Terminal: We must escape and venture out to the reaches of space if we are to save the universe. To pass these asteroids and reach the moon, you must launch the ship all the way to the moon without going out of orbit or colliding with an asteroid. Only 3 ships are available to aid your attempts.", 2, int(800), 20, (255, 255, 255), 100, 100)) while running: keys = key.get_pressed() mx, my = mouse.get_pos() frame_pos = mehdi.center_frame(mehdi.screen, screen) mx -= frame_pos[0] my -= frame_pos[1] for action in event.get(): if action.type == QUIT: return False elif action.type == MOUSEBUTTONDOWN: if action.button == 1: if hypot(mx - mehdi.WIDTH * 0.2, my - mehdi.HEIGHT * 0.75) <= 60: launching = True elif action.type == VIDEORESIZE: mehdi.resizeStuff(action.w, action.h) elif action.type == MOUSEBUTTONUP and launching: if action.button == 1: launching = False shipping = True ang = atan2(my - mehdi.HEIGHT * 0.75, mx - mehdi.WIDTH * 0.2) + pi spaceShip.rot = ang - pi / 2 spaceShip.x = startx + 90 * cos(ang) spaceShip.y = starty + 90 * sin(ang) spaceShip.polygon = [(spaceShip.x - 15, spaceShip.y - 25), (spaceShip.x + 15, spaceShip.y - 25), (spaceShip.x + 15, spaceShip.y + 15), (spaceShip.x, spaceShip.y + 35), (spaceShip.x - 15, spaceShip.y + 15)] for i in range(len(spaceShip.polygon)): spaceShip.polygon[i] = [ int(j) for j in rotateC( spaceShip.polygon[i][0], spaceShip.polygon[i] [1], spaceShip.x, spaceShip.y, spaceShip.rot) ] mag = ((my - mehdi.HEIGHT * 0.75)**2 + (mx - mehdi.WIDTH * 0.2)**2)**0.5 spaceShip.xvel = 0.03 * mag * cos(ang) spaceShip.yvel = 0.03 * mag * sin(ang) if keys[K_END]: return 100 screen.fill((0, 0, 0)) if shipping: spaceShip.update(screen) spaceShip.move(planets) spaceShip.rotate(-spaceShip.rot + atan2(-spaceShip.xvel, spaceShip.yvel)) if any([spaceShip.collide(a) for a in asteroids]): lives -= 1 shipping = False if spaceShip.collide(moon): return lives * 33 + 1 if lives == 0: return 0 if launching: draw.line(screen, (255, 255, 255), (int(startx), int(starty)), (mx, my), 3) for a in asteroids: a.rotate(0) for a in planets + asteroids: a.update(screen) mehdi.drawStuff(screen) clock.tick(FPS) quit()
def solarPropulsion(): screen = Surface((mehdi.WIDTH, mehdi.HEIGHT)) FPS = 100 clock = time.Clock() shipx, shipy = mehdi.WIDTH // 2, mehdi.HEIGHT * 0.9 lightList = [] running = True timer = 3000 lightGathered = 0 maxLight = 100000 def drawPanel(x, y, theta): draw.line(screen, (255, 255, 0), (x - 250 * cos(theta), y - 10 - 250 * sin(theta)), (x + 250 * cos(theta), y - 10 + 250 * sin(theta)), 10) draw.line(screen, (255, 255, 255), (x - 250 * cos(theta), y - 250 * sin(theta)), (x + 250 * cos(theta), y + 250 * sin(theta)), 10) theta = pi // 4 mehdi.txtScreen( mehdi.TextBox( "Terminal: The Sun is far too extreme for a spacecraft such as this. To deal with such an issue, we must venture out even further to find a way to fix this constant collapse of space-time. Considering the sheer amount of nuclear reactions occuring on the Sun, we can use the photons released to push our solar sail! How is this possible? Photons have energy, and according to the famous formula E = mc squared, this energy can be treated as mass, therefore it's high velocity gives the photon a measurable memoentum to push the sail. We must point the sail at the photon rays coming through to maximize our velocity and escape before we burn!", 2, int(800), 20, (255, 255, 255), 100, 100)) while running: keys = key.get_pressed() for action in event.get(): if action.type == QUIT: return False if action.type == VIDEORESIZE: mehdi.resizeStuff(action.w, action.h) screen.fill((0, 0, 0)) if timer == 0: return 0 else: timer -= 1 if timer % 50 == 0 and randint(1, 100) < 80: lightList.append( lightBeam(randint(mehdi.WIDTH * -0.4, mehdi.WIDTH * 1.4), mehdi.HEIGHT, mehdi.WIDTH // 2, mehdi.HEIGHT // 2, randint(0, 4), 100)) if lightGathered >= maxLight: return int(timer / 3000) * 99 + 1 for l in lightList: l.update(screen) lightGathered += l.getFocus(theta) for i in range(len(lightList) - 1, -1, -1): if lightList[i].time <= 0: del lightList[i] draw.rect(screen, (255, 255, 255), (int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.08), int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.07))) draw.rect(screen, (255, 200, 0), (int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.09), int(mehdi.WIDTH * 0.58 * lightGathered / maxLight), int(mehdi.HEIGHT * 0.05))) draw.rect(screen, (255, 255, 255), (int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.01), int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.07))) draw.rect( screen, (255, 200, 0), (int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.02), int(mehdi.WIDTH * 0.58 * timer / 3000), int(mehdi.HEIGHT * 0.05))) if keys[K_LEFT]: theta = min(pi // 2, theta + 0.01) if keys[K_RIGHT]: theta = max(-pi // 4, theta - 0.01) if keys[K_END]: return 100 drawPanel(mehdi.WIDTH // 2, mehdi.HEIGHT // 2, theta) mehdi.drawStuff(screen) #display.flip() clock.tick(FPS) quit()
def asteroidDodge(): screen = Surface((mehdi.WIDTH, mehdi.HEIGHT)) FPS = 100 clock = time.Clock() shipx, shipy = mehdi.WIDTH // 2, mehdi.HEIGHT * 0.9 asteroidList = [] running = True timer = 3000 def drawAst1(screen, x, y): draw.circle(screen, (150, 150, 150), (int(x), int(y)), 20, 0) def drawShip(x, y): p = [(x - 15, y + 25), (x + 15, y + 25), (x + 15, y - 15), (x, y - 35), (x - 15, y - 15)] draw.polygon(screen, (250, 250, 250), [p[0], p[1], p[2], p[4]], 0) draw.polygon(screen, (0, 0, 255), [p[2], p[3], p[4]], 0) mehdi.txtScreen( mehdi.TextBox(mehdi.dialog['asteroidDodge']['dialog'], 2, int(mehdi.WIDTH * 0.7), 20, (255, 255, 255), mehdi.WIDTH * 0.1, mehdi.HEIGHT * 0.1)) while running: keys = key.get_pressed() for action in event.get(): if action.type == QUIT: return False if action.type == VIDEORESIZE: mehdi.resizeStuff(action.w, action.h) screen.fill((0, 0, 0)) if timer == 0: return 100 else: timer -= 1 if timer % 6 == 0 and randint( 1, timer + 5000) <= 3000 and timer > 250: asteroidList.append( fallingStone( randint(int(mehdi.WIDTH * 0.05), int(mehdi.WIDTH * 0.95)), 0, 0, (5000 - timer) * randint(80, 120) * 0.000024, 30, drawAst1)) if any([a.collide([shipx, shipy]) for a in asteroidList]): return 0 for a in asteroidList: a.update(screen) a.move() for i in range(len(asteroidList) - 1, -1, -1): if asteroidList[i].y > mehdi.HEIGHT * 1.2: del asteroidList[i] draw.rect(screen, (255, 255, 255), (int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.01), int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.07))) draw.rect( screen, (255, 200, 0), (int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.02), int(mehdi.WIDTH * 0.58 * timer / 3000), int(mehdi.HEIGHT * 0.05))) drawShip(shipx, shipy) if keys[K_LEFT]: shipx = max(mehdi.WIDTH * 0.05, shipx - 5) if keys[K_RIGHT]: shipx = min(mehdi.WIDTH * 0.95, shipx + 5) if keys[K_END]: return 100 mehdi.drawStuff(screen) #display.flip() clock.tick(FPS) quit()
def game(self): running = True #mehdi.txtScreen(mehdi.TextBox(mehdi.dialog['intro']['dialog'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) while running: self.gameClock.tick(120) for e in event.get(): if e.type == QUIT: running = False return 'menu' break elif e.type == KEYDOWN: if not self.interactionLock: self.mehdi.keyDown(e.key) elif e.type == KEYUP: if not self.interactionLock: self.mehdi.keyUp(e.key) elif e.type == VIDEORESIZE: self.resize(e) keys = key.get_pressed() if keys[K_p]: for p in self.map.minigamePortal: if self.mehdi.playerRect.colliderect(p[0]): # Feature self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 if len(flame.master_user['education'] ) >= self.mehdigameeducation[p[1]]: if mehdi.eat_zhekkos(1000000): if mehdi.multipleChoice(mehdi.generate_quiz()): try: result = self.mehdigames[p[1]]() if result: self.mehdi.teleport( self.map.destinations[ self.postmehdigames[p[1]]]) flame.master_user[ 'score'] += result flame.save() else: mehdi.txtScreen( mehdi.TextBox( 'You failed the mission! Luckily, NASA Software Engineers were able recover your mind from a backup and restore your last position.', 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) except: print('it broke!', p[1]) traceback.print_exc() break else: mehdi.txtScreen( mehdi.TextBox( 'You failed the pre-flight exam! The rocket was not able to launch.', 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) break else: mehdi.txtScreen( mehdi.TextBox( 'You do not have enough education! To fly to the next location, you must have atleast %i degrees. (You currently have %i degrees)~~Visit the University to obtain a degree!' % (self.mehdigameeducation[p[1]], len(flame.master_user['education'])), 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) else: for p in self.map.teleports: if self.mehdi.playerRect.colliderect(p[0]): self.mehdi.teleport(p[1]) break for p in self.map.informationTiles: if self.mehdi.playerRect.colliderect(p[0]): info = mehdi.dialog[p[1] + ('1' if 'Intro' in p[1] else '')] if (info['automatic'] or keys[K_p] ) and p[1] not in flame.master_user['dialogCompleted']: self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 print('Dialog triggered', p[1]) if 'Intro' in p[1]: if 'EQ' in p[ 1] and not flame.master_user['tremble']: flame.master_user['tremble'] = True flame.master_user['trembleTime'] = t.time() count = 1 while p[1] + str(count) in mehdi.dialog: mehdi.txtScreen( mehdi.TextBox( mehdi.dialog[p[1] + str(count)]['dialog'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) count += 1 else: mehdi.txtScreen( mehdi.TextBox(mehdi.dialog[p[1]]['dialog'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) if info['singleTrigger']: flame.master_user['dialogCompleted'].append(p[1]) break if keys[K_p]: for npc in self.map.npc: dialogue = npc.interact(self.mehdi) if dialogue: # Feature self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 for d in dialogue: mehdi.txtScreen( mehdi.TextBox(d, 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) for p in self.map.bank: if self.mehdi.playerRect.colliderect(p[0]): # Feature self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 if t.time( ) >= flame.master_user['lastFreeZhekko'] + 86400: mehdi.txtScreen( mehdi.TextBox( 'Bank of Mehdi~~Yay! You got 10 000 000 free Zhekkos!', 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) flame.master_user['lastFreeZhekko'] = t.time() flame.master_user['zhekkos'] += 10000000 flame.save() else: mehdi.txtScreen( mehdi.TextBox( 'Bank of Mehdi~~Whoa whoa whoa...~~You must wait %i more seconds to get free zhekkos.' % (flame.master_user['lastFreeZhekko'] + 86400 - t.time()), 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) for p in self.map.slotmachine: if self.mehdi.playerRect.colliderect(p[0]): # Feature self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 amount = 5000 if mehdi.eat_zhekkos(amount): if random.randint(0, 10) == 0: flame.master_user['zhekkos'] = ( flame.master_user['zhekkos'] + amount) * 5 mehdi.txtScreen( mehdi.TextBox( 'MehdiCasino~~Yay! You won at x5 multiplier !!!!! You now have %i Zhekkos.' % flame.master_user['zhekkos'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) flame.save() else: mehdi.txtScreen( mehdi.TextBox( 'MehdiCasino~~You lost. You now have %i Zhekkos.' % flame.master_user['zhekkos'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) for p in self.map.universities: if self.mehdi.playerRect.colliderect(p[0]): # Feature self.mehdi.klist = [False, False, False, False] self.mehdi.vx = 0 self.mehdi.vy = 0 if mehdi.eat_zhekkos(1000): lessonNames = list(mehdi.fullLessons.keys()) random.shuffle(lessonNames) for topic in lessonNames: if topic not in flame.master_user['education']: mehdi.txtScreen( mehdi.TextBox( 'Here\'s your daily dose of education!~~' + mehdi.fullLessons[topic]['dialog'], 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) flame.master_user['score'] += 50 flame.master_user['education'].append( topic) flame.save() mehdi.txtScreen( mehdi.TextBox( 'Congrats! You now have a degree in %s!~~The University of Loowater has issued 50 points!~~You now have a total of %i degrees.' % (topic.split('Lesson')[0].upper(), len(flame. master_user['education'])), 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) break else: mehdi.txtScreen( mehdi.TextBox( 'You are a big nerd and have too much education', 2, int(self.WIDTH * 0.7), 20, (255, 255, 255), self.WIDTH * 0.1, self.HEIGHT * 0.1)) # mx, my = mouse.get_pressed()[:2] self.update()
def sunProtection(): screen = Surface((mehdi.WIDTH, mehdi.HEIGHT)) FPS = 100 clock = time.Clock() shipx, shipy = mehdi.WIDTH // 2, mehdi.HEIGHT * 0.9 asteroidList = [] running = True timer = 6000 def drawAst1(screen, x, y): draw.circle(screen, (150, 150, 150), (int(x), int(y)), 20, 0) def drawShip(x, y): p = [(x - 15, y + 25), (x + 15, y + 25), (x + 15, y - 15), (x, y - 35), (x - 15, y - 15)] draw.polygon(screen, (250, 250, 250), [p[0], p[1], p[2], p[4]], 0) draw.polygon(screen, (0, 0, 255), [p[2], p[3], p[4]], 0) hp = 2000 theta = 0 timer = 6000 lightList = [] mehdi.txtScreen(mehdi.TextBox( "Terminal: We've almost arrived at the Sun. Prepare for intense radiation rays. Prolonged exposure to high frequency radiation can cause corruoption of cell DNA, resulting in cancer and other health issues. Move around our defensive shield to protect from the oncoming rays until we reach the Sun.", 2, int(800), 20, (255, 255, 255), 100, 100)) while running: keys = key.get_pressed() for action in event.get(): if action.type == QUIT: return False if action.type == VIDEORESIZE: mehdi.resizeStuff(action.w, action.h) screen.fill((0, 0, 0)) draw.line(screen, (150, 150, 150), (mehdi.WIDTH//2+200*cos(theta-0.2), mehdi.HEIGHT//4+200*sin(theta-0.2)), (mehdi.WIDTH//2+200*cos(theta+0.2), mehdi.HEIGHT//4+200*sin(theta+0.2)), 15) if keys[K_LEFT]: theta = min(pi, theta + 0.05) if keys[K_RIGHT]: theta = max(0, theta - 0.05) if keys[K_END]: return 100 if timer == 0: return int(hp/2000)*99+1 else: timer -= 1 if timer % 50 == 0 and randint(1, 100) < 50: lightList.append(lightBeam(randint(0, mehdi.WIDTH), mehdi.HEIGHT, mehdi.WIDTH//2, mehdi.HEIGHT//4, randint(0, 4), 50)) for l in lightList: l.update(screen) if abs(l.ang-theta+pi) > 0.2: hp -= 1 l.x2, l.y2 = mehdi.WIDTH//2, mehdi.HEIGHT//4 else: mag = ((mehdi.WIDTH//2 - l.x)**2 + (mehdi.HEIGHT//4 - l.y)**2)**0.5 - 200 l.x2, l.y2 = int(l.x+mag*cos(l.ang)), (l.y+mag*sin(l.ang)) if hp <= 0: return 0 draw.rect(screen, (255, 255, 255), (int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.08), int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.07))) draw.rect(screen, (255, 200, 0), ( int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.09), int(mehdi.WIDTH * 0.58 * hp / 2000), int(mehdi.HEIGHT * 0.05))) draw.rect(screen, (255, 255, 255), (int(mehdi.WIDTH * 0.2), int(mehdi.HEIGHT * 0.01), int(mehdi.WIDTH * 0.6), int(mehdi.HEIGHT * 0.07))) draw.rect(screen, (255, 200, 0), (int(mehdi.WIDTH * 0.21), int(mehdi.HEIGHT * 0.02), int(mehdi.WIDTH * 0.58 * timer / 6000), int(mehdi.HEIGHT * 0.05))) for i in range(len(lightList)-1, -1, -1): if lightList[i].time == 0: del lightList[i] mehdi.drawStuff(screen) clock.tick(FPS) quit() #SunProtection(screen, 1)