def action(self, bk): screen = pygame.display.get_surface() s = Spaceship(1, 320) asteroid = Asteroid(500, 100) asteroid2 = Asteroid(800, 200) asteroid3 = Asteroid(1200, 350) asterow = [asteroid, asteroid2, asteroid3] air = [s] asteroids = pygame.sprite.RenderPlain(asterow) ss = pygame.sprite.RenderPlain(air) timer = pygame.time.Clock() while 1: timer.tick(600) if self.input(pygame.event.get()) == 1: return 1, -1 blocks_hit_list = pygame.sprite.spritecollide(s, asteroids, False) if len(blocks_hit_list) > 0: self.score -= len(blocks_hit_list) asteroids.draw(screen) ss.draw(screen) if self.score < 1: return 3, self.total_score // 100 s.rect.x = self.x_coord s.rect.y = self.y_coord asteroid.rect.x = asteroid.rect.x - 1 asteroid2.rect.x = asteroid2.rect.x - 1 asteroid3.rect.x = asteroid3.rect.x - 1 if asteroid.rect.x < 0: asteroid.rect.x = 500 asteroid.rect.y = 100 if asteroid2.rect.x < 0: asteroid2.rect.x = 800 asteroid2.rect.y = 200 if asteroid3.rect.x < 0: asteroid3.rect.x = 1200 asteroid3.rect.y = 350 if self.shag > 300: # self.shag = 0 self.go1 = random.randint(-1, 1) self.go2 = random.randint(-1, 1) self.go3 = random.randint(-1, 1) asteroid.rect.y += self.go1 asteroid2.rect.y += self.go2 asteroid3.rect.y += self.go3 self.shag += 1 screen.blit(bk, (0, 0)) font = pygame.font.Font(None, 25) white = (255, 255, 255) life = int(self.score / 10) text = font.render("Health: " + str(life), True, white) screen.blit(text, [10, 10]) text = font.render("Score: " + str(self.total_score // 100), 1, white) screen.blit(text, (475, 10)) asteroids.update() ss.update() asteroids.draw(screen) ss.draw(screen) pygame.display.flip() self.total_score += timer.get_time()
def _emit(self): aster_x, aster_y = self.random_xy_func() asteroid = Asteroid(aster_x, aster_y, self.game_surface) if self.asteroids_in_motion: asteroid.random_nudge() self.asteroids.add(asteroid) self.last_emit_time = time.time()
def split_asteroids(self): temp_asteroids = [] for asteroid in self.asteroids: if not asteroid.live and asteroid.size == 60: temp_asteroids.append((Asteroid(location=asteroid.location, velocity=6, direction=(asteroid.direction + 1) % 20, size=30, color=asteroid.color))) temp_asteroids.append((Asteroid(location=asteroid.location, velocity=6, direction=(asteroid.direction - 1) % 20, size=30, color=asteroid.color))) if not asteroid.live and asteroid.size == 30: temp_asteroids.append((Asteroid(location=asteroid.location, velocity=12, direction=(asteroid.direction + 1) % 20, size=15, color=asteroid.color))) temp_asteroids.append((Asteroid(location=asteroid.location, velocity=12, direction=(asteroid.direction - 1) % 20, size=15, color=asteroid.color))) return self.asteroids.extend(temp_asteroids)
def init(): # print "init" global clock global screen global ship pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((WIDTH, HEIGHT)) ship = Ship(screen.get_rect().center) entities.append(ship) asteroid1 = Asteroid((100, 100), 50, 5) asteroid1.angVel = 0.01 asteroid2 = Asteroid((130, 152), 20, 3) entities.append(asteroid1) entities.append(asteroid2) for i in range(100): x = random.randrange(0, WIDTH) y = random.randrange(0, HEIGHT) r = random.randint(20, 40) n = random.randint(3, 9) asteroid = Asteroid((x, y), r, n) asteroid.angVel = (random.random() - 0.5) / 10.0 entities.append(asteroid)
def add_asteroids(self, layout): self.asteroid_id = 0 for size in range(len(layout)): for i in range(layout[size]): if size == 0: self.active_asteroids.append(Asteroid(0, self.canvas, 1, self.asteroid_id)) else: self.active_asteroids.append(Asteroid(0, self.canvas, 2 * size, self.asteroid_id)) self.asteroid_id += 1
def playTimerFired(data): if data.timerCalled % int(100 * (4. / 5)**data.level) == 0: x = random.randint(data.margin, data.fieldSizeW - data.margin) y = random.randint(data.margin, data.fieldSizeH - data.margin) ast = Asteroid(x, y) print(ast) data.asteroids.append(ast) for ast in data.asteroids: ast.update()
def main(): width = 800 height = 600 num_asteroids = 10 pygame.init() screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("Asteroids") font = pygame.font.Font('Planetnv2.ttf', 32) clock = pygame.time.Clock() # create some asteroids asteroids = [] for i in range(num_asteroids): x = random.randint(0, width) y = random.randint(0, height) a = Asteroid(x, y) asteroids.append(a) running = True while running: clock.tick(30) # check for quit for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: # if the left button is pressed if event.button == 1: for a in asteroids: if a.inside(event.pos): parts = a.explode() if len(parts) > 0: asteroids.extend(parts) else: asteroids.remove(a) # update asteroids for a in asteroids: a.move(width, height) # draw screen screen.fill(BLACK) for a in asteroids: a.draw(screen) text = font.render('Asteroids: %d' % (len(asteroids)), True, WHITE, BLACK) text_rect = text.get_rect() text_rect.x = 20 text_rect.y = 20 screen.blit(text, text_rect) pygame.display.flip()
def splitAsteroid(self, a): childRadius = a.radius / math.sqrt(2.0) theta1 = a.theta + math.pi / 8.0 theta2 = a.theta - math.pi / 8.0 pos1 = a.pos + childRadius * np.array( [math.cos(theta1), math.sin(theta1)]) pos2 = a.pos + childRadius * np.array( [math.cos(theta2), math.sin(theta2)]) a1 = Asteroid(pos1[0], pos1[1], childRadius, a.color, a.speed, theta1) a2 = Asteroid(pos2[0], pos2[1], childRadius, a.color, a.speed, theta2) self.asteroidsGroup.add(a1) self.asteroidsGroup.add(a2) # print("Splitting", a.name, "into", a1.name, ",", a2.name) self.destroyAsteroid(a)
def random_asteroid(self): rad = random.randint(1, 4) circumference = math.pi * rad * 2 pos = [random.randint(-5, 5), random.randint(-5, 5), random.randint(-5, 5)] vel = [random.randint(-5, 5), random.randint(-5, 5), random.randint(-5, 5)] return Asteroid(circumference, pos, vel)
def start_game(self) -> str: """Resets the game field and draws the initial game back at level 1.""" # Initial empty group for bullets self.MIN_SPAWN_DIST = 50 self.LEVEL_TIMER_IN_SEC = 10 self.bullets = pygame.sprite.Group() # Player ship self.player_ship = Ship(*self.WINDOW_RES, self.bullets) self.player_ship.update() # Initial asteroids self.asteroids = pygame.sprite.Group() self.asteroid_emitters = [] for _ in range(0, 10): aster_x, aster_y = self.random_offset_from_ship() asteroid = Asteroid(aster_x, aster_y, self.DISPLAYSURF) self.asteroids.add(asteroid) # Initial asteroid emitter emitter = AsteroidEmitter(self.asteroids, self.DISPLAYSURF, self.random_offset_from_ship) self.asteroid_emitters.append(emitter) return 'level_1'
def generate_asteroids(self): if pygame.time.get_ticks() - self.last_asteroid > self.asteroid_time: self.asteroids.append( Asteroid(self.window, (self.player.x, self.player.y))) self.last_asteroid = pygame.time.get_ticks() if len(self.asteroids) > self.max_asteroids: self.asteroids = self.asteroids[1:]
def create_FallingObject(self, typ, minmax, speed, screen, info_x): if typ == "Star": return Star(minmax, speed, screen, info_x) if typ == "Asteroid": return Asteroid(minmax, speed, screen, info_x)
def AsteroidLocations(path): """ Reads in a text file. Makes an a new Asteroid object evreytime it finds a # symble and marks its x, y location. Returns a list of all the Asteroids it found Input ---------- path: Path to the file we want to read in for our Asteroid """ Asteroids = [] x = 0 y = 0 # Read in the text file and get locations of the "#". file = open(path, 'r') text = file.read() file.close() text = text.split('\n') for line in text: for c in line: if c == '#': NewAsteroid = Asteroid(x, y) Asteroids.append(NewAsteroid) x += 1 y += 1 x = 0 return Asteroids
def init(self): self.bgColor = (0, 0, 0) Ship.init() ship = Ship(self.width / 2, self.height / 2) self.shipGroup = pygame.sprite.GroupSingle(ship) Asteroid.init() self.asteroids = pygame.sprite.Group() for i in range(5): x = random.randint(0, self.width) y = random.randint(0, self.height) self.asteroids.add(Asteroid(x, y)) self.bullets = pygame.sprite.Group() Explosion.init() self.explosions = pygame.sprite.Group()
def get_rocks(self): # any, 1.5, True stage, speed, linear, amount = levelData[self.level] Base_stats.base_stage = stage Base_stats._speed = speed if speed else Base_stats._speed Base_stats.linear_divide = linear return [Asteroid(self.surf) for _ in range(amount)]
def doAsteroids(self): dir = False mnt = self.rnd.randint(1, 50) if mnt % 2 == 1: dir = True for x in range(mnt): md = self.atmos + 10 wide = self.rnd.randint(5, 25) o_ang = math.radians(self.rnd.randint(0, 360)) ap = Vex(math.sin(o_ang) * (md + wide), math.cos(o_ang) * (md + wide)) self.asteroids += [Asteroid(self.rnd, self, (md + wide), ap + self.pos, dir)]
def update(cam): env = Environment env.clear_visible_objects() env.getScreen().fill((0, 0, 0)) env.clear_edges() if not env.player.inatmosphere: cam.top = False Stars.update(cam) Asteroid.updateTempAsteroids(cam) else: cam.top = True #Objects.Update(cam) env.sun.update2(cam) Emitter.update(cam) Shot.update(cam) env.player.update(cam) Mind.update(cam) Ship.updateUnOccupied(cam) DrawINFO.update(cam) env.draw()
def init(data): data.timerCalled = 0 data.mode = "title" data.level = 1 data.fieldSizeW = 3 * data.width data.fieldSizeH = 3 * data.height data.scrollX = data.width data.scrollY = data.height data.scrollMarginX = data.width / 2 data.scrollMarginY = data.height / 2 Asteroid.init() data.asteroids = [] data.margin = 51 for i in range(5): x = random.randint(data.margin, data.fieldSizeW - data.margin) y = random.randint(data.margin, data.fieldSizeH - data.margin) data.asteroids.append(Asteroid(x, y, data.level)) data.paused = False pilImg = baseImg = Image.open("images/asteroids2.png") data.astimage2 = [pilImg, baseImg, ImageTk.PhotoImage(pilImg)] data.angle = 0 data.angleSpeed = 10 data.background = Image.open("images/starryspace.png") data.background = data.background.resize((data.fieldSizeW, data.fieldSizeH), \ Image.ANTIALIAS) data.background = ImageTk.PhotoImage(data.background) # testing scroll data.pX = data.fieldSizeW / 2. data.pY = data.fieldSizeH / 2. data.scrollSpeedX = data.width / 10. data.scrollSpeedY = data.height / 10.
def ManipulateDate(): global results global button_Asteroid #destroy the previous buttons of Asteroid NO.n for a in button_Asteroid: a.destroy() #clean and reset variables button_Asteroid = [] results = [] asteroid_NO = 1 startdate = textbox_sDate.get() #validate the date type of the value validate(startdate) enddate = textbox_eDate.get() validate(enddate) url = ("https://api.nasa.gov/neo/rest/v1/feed?start_date=" + startdate + "&end_date=" + enddate + "&api_key=YOUR-API-KEY") response = requests.get(url) json_data = response.json() asteroids_data = json_data.get('near_earth_objects') for date in asteroids_data: for asteroid in asteroids_data[date]: results.append([asteroid_NO] + Asteroid( asteroid['links']['self'], asteroid['id'], asteroid['name'], asteroid['nasa_jpl_url'], asteroid['close_approach_data'][0] ['relative_velocity']['miles_per_hour'], asteroid['close_approach_data'][0]['miss_distance'] ['miles']).ToList()) asteroid_NO += 1 for result in results: print(result) print(asteroid_NO) for n in range(asteroid_NO - 1): button_a = Button(main_window, text=("Asteroid No." + str(n + 1)), bg="Blue", fg="White") button_a.grid(row=n + 5, column=0, sticky=NW) button_Asteroid.append(button_a) for n in range(len(button_Asteroid)): addCommand(n)
def MostInView(Asteroids): """ Finds the asteroid that can see the most asteroid """ BestAst = Asteroid(-1, -1) for refA in Asteroids: InView(refA, Asteroids) for A in Asteroids: if A.inView > BestAst.inView: BestAst = A print( "The asteroid with the best view is at, x = {} y = {}.\nIt can see {} asteroids." .format(BestAst.x, BestAst.y, BestAst.inView)) return BestAst
def _generateAsteroid(self, asteroidManager, velocityLimit=2): if (time.time() - self.lastAsteroidTime >= self.timeToMakeAsteroid): self.lastAsteroidTime = time.time() self.timeToMakeAsteroid *= self.makeTimeModifier #make asteroids appear faster as time progresses # Generate beyond the border so it doesn't appear in middle of screen # random velocity will make it appear evenly on either side position = (random.uniform(-20, 0), random.uniform(-20, 0)) velocity = (random.uniform(-velocityLimit, velocityLimit), random.uniform(-velocityLimit, velocityLimit)) asteroid = Asteroid(4, position, velocity, wrapping=True, boundary=self.board.getBoundary()) asteroidManager.addObject(asteroid)
def createAsteroids(self, number): # print("Creating", number, "asteroidsGroup") for i in range(number): # choose random color randColor = random.randint(150, 255) randColor = (randColor, randColor, randColor) # choose position outside of screen # First choose one of the 4 borders border = random.randint(0, 3) x = -1 y = -1 if border == 0: # left border x = random.uniform(0, BORDER_SIZE) y = random.uniform(0, SCREEN_HEIGHT + 2 * BORDER_SIZE) elif border == 1: # right border x = random.uniform(SCREEN_WIDTH + BORDER_SIZE, SCREEN_WIDTH + 2 * BORDER_SIZE) y = random.uniform(0, SCREEN_HEIGHT + 2 * BORDER_SIZE) elif border == 2: # top border x = random.uniform(0, SCREEN_WIDTH + 2 * BORDER_SIZE) y = random.uniform(0, BORDER_SIZE) elif border == 3: # top border x = random.uniform(0, SCREEN_WIDTH + 2 * BORDER_SIZE) y = random.uniform(SCREEN_HEIGHT + BORDER_SIZE, SCREEN_HEIGHT + 2 * BORDER_SIZE) else: # print("WAT", border) pass destX = random.uniform(BORDER_SIZE + SCREEN_WIDTH * 0.25, BORDER_SIZE + SCREEN_WIDTH * 0.75) destY = random.uniform(BORDER_SIZE + SCREEN_HEIGHT * 0.25, BORDER_SIZE + SCREEN_HEIGHT * 0.75) theta = math.atan2(destY - y, destX - x) c = Asteroid(x=x, y=y, radius=random.uniform(20.0, 50.0), color=randColor, speed=ASTEROID_MAX_SPEED * random.uniform(0.5, 1.0), theta=theta) self.asteroidsGroup.add(c)
def GetRequest(window, main_frame, Sdate, Edate, API, FilterKey): #function to make the data from the API show up if CheckDate(Sdate) == CheckDate(Edate) == True: #validating the dates inputted if CheckStartEnd(Sdate, Edate) == True: #labels for the data that you need to show Label(main_frame, text='ID', borderwidth=1, bg='Blue', fg= 'White' ,relief='solid').grid(row=0, column=1, sticky='nsew') Label(main_frame, text='Name', borderwidth=1, bg='Blue', fg= 'White', relief='solid').grid(row=0, column=2, sticky='nsew') Label(main_frame, text='Size', borderwidth=1, bg='Blue', fg= 'White', relief='solid').grid(row=0, column=3, sticky='nsew') Label(main_frame, text='Velocity', borderwidth=1, bg='Blue', fg= 'White', relief='solid').grid(row=0, column=4, sticky='nsew') Label(main_frame, text='Distance', borderwidth=1,bg='Blue', fg= 'White', relief='solid').grid(row=0, column=5, sticky='nsew') Label(main_frame, text='Jpl_url', borderwidth=1, bg='Blue', fg= 'White', relief='solid').grid(row=0, column=6, sticky='nsew') RequestString = "https://api.nasa.gov/neo/rest/v1/feed?start_date=" + Sdate + "&end_date=" + Edate + "&api_key=" + API #creating a manipulative URL response = requests.get(RequestString) #getting response from the api json_data = response.json() asteroids_data = json_data.get('near_earth_objects') results = [] for date in asteroids_data: #appending the data in asteroid for asteroid in asteroids_data[date]: results.append(Asteroid(asteroid["id"], asteroid['name'], asteroid['estimated_diameter']['miles']['estimated_diameter_max'], asteroid['close_approach_data'][0]['relative_velocity']["miles_per_hour"], asteroid['close_approach_data'][0]['miss_distance']['miles'], asteroid['nasa_jpl_url'])) buttons=[] results2=[] printable_results=[] for asteroid in results: if ((CheckFilter(asteroid, FilterKey) == True) or (FilterKey=="")): printable_results.append(asteroid) a = printable_results.index(asteroid)+1 b = asteroid.ToList() for i in b: Label(main_frame, text=i).grid(row=a, column=(b.index(i)+1)) RequestString2 = "https://api.nasa.gov/neo/rest/v1/neo/" + asteroid.id + "?api_key=" + API response2 = requests.get(RequestString2) json_data2 = response2.json() try: asteroid2 = Asteroid2(json_data2["name"], json_data2["close_approach_data"][0]["close_approach_date"], json_data2["close_approach_data"][0]["relative_velocity"]["miles_per_hour"], json_data2["close_approach_data"][0]["miss_distance"]["miles"], json_data2["close_approach_data"][1]["relative_velocity"]["miles_per_hour"], json_data2["close_approach_data"][1]["miss_distance"]["miles"], json_data2["orbital_data"]["first_observation_date"], json_data2["orbital_data"]["last_observation_date"]) except IndexError: asteroid2 = Asteroid2(json_data2["name"], json_data2["close_approach_data"][0]["close_approach_date"], json_data2["close_approach_data"][0]["relative_velocity"]["miles_per_hour"], json_data2["close_approach_data"][0]["miss_distance"]["miles"], 0, 0, json_data2["orbital_data"]["first_observation_date"], json_data2["orbital_data"]["last_observation_date"]) results2.append(asteroid2) for i in range(len(results2)): buttons.append(Button(main_frame, text="Click for More information", command=lambda i=i: GetData(results2[i], window)).grid(row=i+1, column=0, sticky='w')) else: Label(main_frame, text = "Start date must be before the End date").grid(row=0, column=0, sticky='nsew') else: Label(main_frame, text="Wrong date format, must be y-m-d").grid(row=0, column=0, sticky='nsew')
def __init__(self): GameUtils.__init__(self) pygame.init() self.CONST = { 'WHITE': (255, 255, 255), 'GRAY': (120, 120, 120), 'BLACK': (0, 0, 0), 'BLUE': (153, 255, 255), 'PINK': (255, 153, 153), 'GREEN': (229, 255, 204), 'PURPLE': (255, 153, 255), 'FPS': 30, } self.display = pygame.display.set_mode((800, 800)) self.clock = pygame.time.Clock() self.font = pygame.font.Font('../assets/arial-bold.ttf', 24) pygame.display.set_caption('Asteroids') self.score = 0 self.bullet_count_down = 0 self.rotation_count_down = 0 self.ship = Ship(location=[400, 400], velocity=0, direction=0) # instantiate lists self.bullets = [] self.asteroids = [] for color, location in { 'BLUE': [random.randint(75, 125), random.randint(75, 125)], 'PINK': [random.randint(675, 725), random.randint(75, 125)], 'GREEN': [random.randint(75, 125), random.randint(675, 725)], 'PURPLE': [random.randint(675, 725), random.randint(675, 725)], }.items(): self.asteroids.append( Asteroid(location=location, velocity=3, direction=random.randint(0, 20), size=60, color=self.CONST[color]))
def main(): help = Helper() help.main_menu() rocks = [] counter = 0 score = 0 run = True while run: help.clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if counter < 8: rocks.append( Asteroid(round(random.randint(20, 1050)), -175, random.randint(5, 30), 160, 160)) counter += 1 for rock in rocks: if help.spaceShip.hitbox[1] < rock.hitbox[1] + rock.hitbox[ 3] and help.spaceShip.hitbox[1] + help.spaceShip.hitbox[ 3] > rock.hitbox[1]: if help.spaceShip.hitbox[0] < rock.hitbox[0] + rock.hitbox[ 2] and help.spaceShip.hitbox[ 0] + help.spaceShip.hitbox[2] > rock.hitbox[0]: help.spaceShip.hit(help.window, help.game_over, help.black_heart, score) rock.destroy(rocks, rock) counter -= 1 score += 1 if rock.y < 700: rock.y += rock.velocity else: rock.destroy(rocks, rock) counter -= 1 score += 1 help.keysPressed() help.redrawGameWindow(score, rocks)
def build(self): self.game = Game() self.keyboard = CreateKeyboard() self.keyboard.set_type() self.keyboard.binding() self.mouse = CreateMouse() self.mouse.set_type() self.mouse.binding() self.settings = Settings() # Create loop with 1/60 sec delay for i in range(0, 200): self.asteroids.append( Asteroid(parent=self.game, user=self.game.usership, coords=Vector(randint(-5000, 5000), randint(-5000, 5000)))) self.game.add_widget(self.asteroids[i]) Clock.schedule_interval(self.update, 1.0 / 30.0) AI1 = AI(user=self.game.usership) self.bots.append(AI1) self.game.add_widget(AI1) return self.game
def spawnasteroid(): #randomly spawn asteroids global asteroids, rock, points, spawnid if 0 <= points < 200: t, speed = 1400, 2 elif 200 <= points < 500: t, speed = 900, 3 #set the difficulty of the game depending on the player's points elif 500 <= points < 700: #increase the rate of the asteroids spawning and the speed of them t, speed = 500, 4 else: t, speed = 400, 5 spawnid = canvas.after(t, spawnasteroid) #timer that repeats the spawning #create the asteroid object asteroids[rock] = Asteroid(canvas, random.randint(0, 2), x=canvas.winfo_reqwidth() + 50, y=random.randint(60, canvas.winfo_reqheight() - 80), speed=speed) asteroids[rock].move() #animate the asteroid rock += 1 if rock == 20: #reset the index of the asteroid list rock = 0
def timerFired3(self, dt): if self.screen3 == False: if self.score3 >= 500: self.win = True if self.counter % 30 == 0: #m x = random.randint(0, self.width) y = 1 self.asteroids.add(Asteroid(x, y)) self.counter += 1 self.shipGroup.sprites()[0].update2(dt, self.isKeyPressed, self.width, self.height) self.asteroids.update(self.width, self.height) self.missiles.update(self.width, self.height) ship = self.shipGroup.sprite for asteroid in pygame.sprite.groupcollide( self.asteroids, self.missiles, True, True, pygame.sprite.collide_circle): #copied self.asteroids.add(asteroid.destroy()) self.score3 += 5 for asteroid in pygame.sprite.groupcollide( self.asteroids, self.planetGroup, True, False, pygame.sprite.collide_circle): #copied self.hitCount += 1 pass if self.hitCount % 5 == 0: self.earthStage += 1 self.earthFlag = True self.hitCount += 1 if self.hitCount == 4: self.lost = True if self.earthFlag == True and (self.earthStage == 2 or self.earthStage == 3): self.planetGroup.update(self.earthStage, self.width / 2, self.height - 100) self.earthFlag = False
def get_rocks(self, level): if level <= 3: Base_stats.base_stage = 2 return [Asteroid(self.surf) for _ in range(level)] elif level <= 6: Base_stats.base_stage = 3 Base_stats.linear_divide = level % 2 return [Asteroid(self.surf) for _ in range(level)] elif level <= 10: Base_stats.base_stage = 4 Base_stats._speed = 2 Base_stats.linear_divide = level % 3 return [Asteroid(self.surf) for _ in range(int(level // 1.2))] elif level <= 15: Base_stats.base_stage = 5 Base_stats._speed = 2.5 Base_stats.linear_divide = level % 4 return [Asteroid(self.surf) for _ in range(int(level // 1.5))] elif level <= 20: Base_stats.base_stage = 6 Base_stats._speed = 3 Base_stats.linear_divide = level % 5 return [Asteroid(self.surf) for _ in range(int(level // 1.7))] elif level <= 25: Base_stats.base_stage = 7 Base_stats._speed = 4 Base_stats.linear_divide = level % 5 return [Asteroid(self.surf) for _ in range(int(level // 2))] else: Base_stats.base_stage = 8 Base_stats._speed = 5 Base_stats.linear_divide = level % 5 return [Asteroid(self.surf) for _ in range(level)]
def callAsteroid(): for widget in center.winfo_children(): widget.destroy() center.grid(row=0, sticky="ew") startDate = str(textbox1.get()) endDate = str(textbox2.get()) dateRange = dateManip(startDate, endDate) response = requests.get(dateRange) json_data = response.json() asteroids_data = json_data.get('near_earth_objects') results = [] for date in asteroids_data: for asteroid in asteroids_data[date]: results.append( Asteroid( asteroid["id"], asteroid['name'], asteroid['close_approach_data'][0]['relative_velocity'] ['miles_per_hour'], asteroid['close_approach_data'][0] ['miss_distance']['miles'], asteroid['nasa_jpl_url'])) i = 0 for asteroid in results: Button(center, text="Details", command=asteroid.specifyAsteroid).grid(row=i, column=0) Label(center, text=asteroid.id, width=10, pady=1, padx=1).grid(row=i, column=1) Label(center, text=asteroid.name, width=10, pady=1, padx=1).grid(row=i, column=2) Label(center, text=asteroid.miles_per_hour, width=10, pady=1, padx=1).grid(row=i, column=3) Label(center, text=asteroid.miles, width=20, pady=20, padx=1).grid(row=i, column=4) Label(center, text=asteroid.url, width=40, pady=20, padx=1).grid(row=i, column=5) i += 1 return
size = width, height = 1024, 760 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) level = Level(4000, 4000) fps = 1000/60 ball = pygame.image.load("circle.png") ballRect = ball.get_rect() nsimg = pygame.image.load("neutronstarcircle.png") nsRect = nsimg.get_rect() player = Player(100, 100, ball, ballRect) neutronStar1 = NeutronStar(512, 380, nsimg, nsRect) neutronStar2 = NeutronStar(2000, 700, nsimg, nsRect) asteroid = Asteroid(200,3000) level.addObj(asteroid) level.addObj(neutronStar1) level.addObj(neutronStar2) level.addObj(player) camera = Camera(player.posX, player.posY) map = Map(width, height, player.posX, player.posY, level) player.imgRect.center = (player.posX, player.posY) for obj in level.objects: print(obj.posX, obj.posY) lastUpdateTime = int(round(time.time() * 1000)) mapPlayerColor = 255, 0 , 0 mapNeutronStarColor = 198, 253, 255 mapAsteroidColor = 253, 171, 0 while 1: