Esempio n. 1
0
 def delete_vehicle(id):
     # try:
     Spaceship = SpaceShip.query.get(id)
     SpaceShip.delete(Spaceship)
     # except BaseException:
     # abort(404)
     return jsonify({'Deleted Spaceship': id, 'success': True})
Esempio n. 2
0
 def post(self):
     """ Create a new spaceship (or override existing) """
     try:
         upload = self.get_uploads()[0]
         SpaceShip.save_from_request(self.request, upload)
     except Exception as e:
         self.error(403)
         logging.exception(e)
         self.response.out.write(e)
         return
     self.redirect('/spaceships')
Esempio n. 3
0
 def add_vehicle():
     try:
         data = json.loads(request.data)
         print(data['reuseable'])
         reuseable = False
         if (data['reuseable'] == 'True'):
             reuseable = True
         Spaceship = SpaceShip(name=data['name'],
                               model=data['model'],
                               reuseable=reuseable,
                               capacity=data['capacity'])
         SpaceShip.insert(Spaceship)
     except BaseException:
         abort(403)
     return paginate_SpaceShip()
Esempio n. 4
0
    def __init__(self):
        self._init_pygame()
        self.screen = pygame.display.set_mode((800, 600))
        self.background = load_sprite("space", False)
        self.clock = pygame.time.Clock()
        self.font = pygame.font.Font(None, 64)
        self.message = ""

        self.asteroids = []
        self.bullets = []
        self.spaceship = SpaceShip((400, 300), self.bullets.append)

        for _ in range(6):
            while True:
                position = get_random_position(self.screen)
                if (
                        position.distance_to(self.spaceship.position)
                        > self.MIN_ASTEROID_DISTANCE
                ):
                    break

            self.asteroids.append(Asteroid(position, self.asteroids.append))
Esempio n. 5
0
class SpaceRocks:
	def __init__(self):
		self._init_pygame()
		self.screen = pygame.display.set_mode((800, 600))
		self.background = load_sprite("space", False)
		self.clock = pygame.time.Clock()
		self.spaceship = SpaceShip((400, 300))

	def main_loop(self):
		while True:
			self._handle_input()
			self._process_game_logic()
			self._draw()

	def _init_pygame(self):
		pygame.init()
		pygame.display.set_caption("Space Rocks")

	def _handle_input(self):
		for event in pygame.event.get():
			# Quit the game when user cmd+w or presses escape
			if event.type == pygame.QUIT or (
				event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
				quit()

		is_key_pressed = pygame.key.get_pressed()

		if is_key_pressed[pygame.K_RIGHT]:
			self.spaceship.rotate(clockwise=True)
		elif is_key_pressed[pygame.K_LEFT]:
			self.spaceship.rotate(clockwise=False)

	def _process_game_logic(self):
		self.spaceship.move()

	def _draw(self):
		self.screen.blit(self.background, (0, 0))
		self.spaceship.draw(self.screen)
		pygame.display.flip()
		self.clock.tick(60)
Esempio n. 6
0
	def __init__(self):
		self._init_pygame()
		self.screen = pygame.display.set_mode((800, 600))
		self.background = load_sprite("space", False)
		self.clock = pygame.time.Clock()
		self.spaceship = SpaceShip((400, 300))
Esempio n. 7
0
class SpaceRocks:
    MIN_ASTEROID_DISTANCE = 250

    def __init__(self):
        self._init_pygame()
        self.screen = pygame.display.set_mode((800, 600))
        self.background = load_sprite("space", False)
        self.clock = pygame.time.Clock()
        self.font = pygame.font.Font(None, 64)
        self.message = ""

        self.asteroids = []
        self.bullets = []
        self.spaceship = SpaceShip((400, 300), self.bullets.append)

        for _ in range(6):
            while True:
                position = get_random_position(self.screen)
                if (
                        position.distance_to(self.spaceship.position)
                        > self.MIN_ASTEROID_DISTANCE
                ):
                    break

            self.asteroids.append(Asteroid(position, self.asteroids.append))

    def main_loop(self):
        while True:
            self._handle_input()
            self._process_game_logic()
            self._draw()

    def _init_pygame(self):
        pygame.init()
        pygame.display.set_caption("Space Rocks")

    def _get_game_objects(self):
        game_objects = [*self.asteroids, *self.bullets]

        if self.spaceship:
            game_objects.append(self.spaceship)

        return game_objects

    def _handle_input(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT or (
                event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE
            ):
                quit()
            elif (
                    self.spaceship
                    and event.type == pygame.KEYDOWN
                    and event.key == pygame.K_SPACE
            ):
                self.spaceship.shoot()

        is_key_pressed = pygame.key.get_pressed()

        if self.spaceship:
            if is_key_pressed[pygame.K_RIGHT]:
                self.spaceship.rotate(clockwise=True)
            elif is_key_pressed[pygame.K_LEFT]:
                self.spaceship.rotate(clockwise=False)
            if is_key_pressed[pygame.K_UP]:
                self.spaceship.accelerate()

    def _process_game_logic(self):
        for game_object in self._get_game_objects():
            game_object.move(self.screen)

        if self.spaceship:
            for asteroid in self.asteroids:
                if asteroid.collides_with(self.spaceship):
                    self.spaceship = None
                    self.message = "You dangus!"
                    break

        for bullet in self.bullets[:]:
            for asteroid in self.asteroids[:]:
                if asteroid.collides_with(bullet):
                    self.asteroids.remove(asteroid)
                    self.bullets.remove(bullet)
                    asteroid.split()
                    break

        for bullet in self.bullets[:]:
            if not self.screen.get_rect().collidepoint(bullet.position):
                self.bullets.remove(bullet)

        if not self.asteroids and self.spaceship:
            self.message = "Not quite a dangus!"

    def _draw(self):
        self.screen.blit(self.background, (0, 0))

        for game_object in self._get_game_objects():
            game_object.draw(self.screen)

        if self.message:
            print_text(self.screen, self.message, self.font)

        pygame.display.flip()
        self.clock.tick(60)
Esempio n. 8
0
 def get(self):
     """ Display a SpaceShip creation form """
     ships = SpaceShip.query().fetch()
     html = render('spaceships.html', {'ships': ships})
     self.response.write(html)