def search(self, start, end, Glist): a = A_star(start, end, Glist) self.path = a.solve() exitGame = False pos_x = self.start_point_x pos_y = self.start_point_y self.de_occupy_grid(pos_x, pos_y) self.screen.blit(self.ship, (pos_x, pos_y)) pygame.display.update() while not exitGame: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() for x, y in self.path: self.screen.blit(self.held_image, (0, 0)) for i in self.objects: i.print_obj() for i in self.obstacles: i.print_obj() self.screen.blit(self.ship, (pos_x, pos_y)) pos_x = x pos_y = y #head=pygame.transform.rotate(self.ship,270) if it goes to right pygame.display.update() self.clock.tick(self.FPS) exitGame = True pygame.display.update()
def search(self,start,end,Glist): a=A_star(start,end,Glist) self.path=a.solve() exitGame=False pos_x=self.start_point_x pos_y=self.start_point_y self.de_occupy_grid(pos_x,pos_y) self.screen.blit(self.ship,(pos_x,pos_y)) pygame.display.update() while not exitGame: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() for x,y in self.path: self.screen.blit(self.held_image,(0,0)) for i in self.objects: i.print_obj() for i in self.obstacles: i.print_obj() self.screen.blit(self.ship,(pos_x,pos_y)) pos_x=x pos_y=y #head=pygame.transform.rotate(self.ship,270) if it goes to right pygame.display.update() self.clock.tick(self.FPS) exitGame=True pygame.display.update()
def search(self, start, end, Glist): exitGame = False pos_x = self.start_point_x pos_y = self.start_point_y self.de_occupy_grid(pos_x, pos_y) for i in range(end[0] - 30, end[0] + 30, 30): for j in range(end[1] - 30, end[1] + 30, 30): self.de_occupy_grid(i, j) a = A_star(end, start, Glist) self.path = a.solve() first_x, first_y = self.path[0] while not exitGame: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() for x, y in self.path: if x > first_x and y > first_y: #direction='down_right' ship = pygame.transform.rotate(self.ship, 225) elif x > first_x and y == first_y: #direction=='right' ship = pygame.transform.rotate(self.ship, 270) elif x > first_x and y < first_y: #direction='up_right' ship = pygame.transform.rotate(self.ship, 315) elif x == first_x and y < first_y: ship = self.ship elif x == first_x and y == first_y: ship = self.ship elif x == first_x and y > first_y: #direction='down' ship = pygame.transform.rotate(self.ship, 180) elif x < first_x and y > first_y: #direction='down_left' ship = pygame.transform.rotate(self.ship, 135) if x < first_x and y == first_y: #direction='left' ship = pygame.transform.rotate(self.ship, 90) if x < first_x and y < first_y: #direction='up_left' ship = pygame.transform.rotate(self.ship, 45) self.t_current = time.time() if (self.t_current - self.t1) > self.seconds: exitGame = True break self.screen.blit(self.held_image, (0, 0)) first_x = x first_y = y for i in self.objects: i.print_obj() for i in self.obstacles: i.print_obj() pos_x = x pos_y = y self.screen.blit(ship, (pos_x, pos_y)) pygame.display.update() self.clock.tick(self.FPS) for i in self.good_list: if end == i.get_coord(): x = i self.good_list.remove(x) self.objects.remove(x) self.sort_list.append(x) exitGame = True pygame.display.update()
def search(self,start,end,Glist): exitGame=False pos_x=self.start_point_x pos_y=self.start_point_y self.de_occupy_grid(pos_x,pos_y) for i in range(end[0]-30,end[0]+30,30): for j in range(end[1]-30,end[1]+30,30): self.de_occupy_grid(i,j) a=A_star(end,start,Glist) self.path=a.solve() first_x,first_y=self.path[0] while not exitGame: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() for x,y in self.path: if x>first_x and y>first_y: #direction='down_right' ship=pygame.transform.rotate(self.ship,225) elif x>first_x and y==first_y: #direction=='right' ship=pygame.transform.rotate(self.ship,270) elif x>first_x and y<first_y: #direction='up_right' ship=pygame.transform.rotate(self.ship,315) elif x==first_x and y<first_y: ship=self.ship elif x==first_x and y==first_y: ship=self.ship elif x==first_x and y>first_y: #direction='down' ship=pygame.transform.rotate(self.ship,180) elif x<first_x and y>first_y: #direction='down_left' ship=pygame.transform.rotate(self.ship,135) if x<first_x and y==first_y: #direction='left' ship=pygame.transform.rotate(self.ship,90) if x<first_x and y<first_y: #direction='up_left' ship=pygame.transform.rotate(self.ship,45) self.t_current=time.time() if (self.t_current-self.t1)>self.seconds: self.breakloop=1 exitGame=True break self.screen.blit(self.held_image,(0,0)) first_x=x first_y=y for i in self.objects: i.print_obj() self.message_display_price(str(i.get_price()),i.get_x(),i.get_y()) for i in self.obstacles: i.print_obj() pos_x=x pos_y=y self.screen.blit(ship,(pos_x,pos_y)) pygame.display.update() self.clock.tick(self.FPS) for i in self.good_list: if end==i.get_coord(): x=i self.good_list.remove(x) self.objects.remove(x) self.sort_list.append(x) if self.breakloop==1: self.sort_list.remove(x) exitGame=True pygame.display.update()
def search(self,start,end,Glist): exitGame=False pos_x=self.start_point_x pos_y=self.start_point_y self.de_occupy_grid(pos_x,pos_y) for i in range(end[0]-30,end[0]+30,30): for j in range(end[1]-30,end[1]+30,30): self.de_occupy_grid(i,j) a=A_star(end,start,Glist) self.path=a.solve() try: first_x,first_y=self.path[0] except: print("TypeError: 'NoneType' object is not subscriptable") while not exitGame: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() for x,y in self.path: if x>first_x and y>first_y: #direction='down_right' ship=pygame.transform.rotate(self.ship,225) elif x>first_x and y==first_y: #direction=='right' ship=pygame.transform.rotate(self.ship,270) elif x>first_x and y<first_y: #direction='up_right' ship=pygame.transform.rotate(self.ship,315) elif x==first_x and y<first_y: ship=self.ship elif x==first_x and y==first_y: ship=self.ship elif x==first_x and y>first_y: #direction='down' ship=pygame.transform.rotate(self.ship,180) elif x<first_x and y>first_y: #direction='down_left' ship=pygame.transform.rotate(self.ship,135) if x<first_x and y==first_y: #direction='left' ship=pygame.transform.rotate(self.ship,90) if x<first_x and y<first_y: #direction='up_left' ship=pygame.transform.rotate(self.ship,45) self.t_current=time.time() if (self.t_current-self.t1)>self.seconds: self.breakloop=1 exitGame=True break self.screen.blit(self.held_image,(0,0)) first_x=x first_y=y for i in self.objects: i.print_obj() self.message_display_price(str(i.get_price()),i.get_x(),i.get_y()) for i in self.obstacles: i.print_obj() pos_x=x pos_y=y self.screen.blit(ship,(pos_x,pos_y)) # Call the asteroid update function, checking if ship hits an asteroid. self.asteroidMovement(self.A_list, pos_x, pos_y) if self.health >=70: healthLabel = self.freeSansBold.render("Ship health: " + str(self.health), 1, (255,255,255)) elif self. health >= 50 and self.health < 70: healthLabel = self.freeSansBold.render("Ship health: " + str(self.health), 1, (255,255,0)) elif self. health >= 25 and self.health < 50: healthLabel = self.freeSansBold.render("Ship health: " + str(self.health), 1, (255,162,0)) else: healthLabel = self.freeSansBold.render("Ship health: " + str(self.health), 1, (255,0,0)) self.screen.blit(healthLabel, (30, 600)) pygame.display.update() self.clock.tick(self.FPS) a=A_star(end,(pos_x,pos_y),Glist) self.path=a.solve() first_x,first_y=self.path[0] for i in self.good_list: if end==i.get_coord(): x=i self.good_list.remove(x) self.objects.remove(x) self.sort_list.append(x) if self.breakloop==1: self.sort_list.remove(x) exitGame=True pygame.display.update()