Пример #1
0
class Game(object):
    def __init__(self):
        pyxel.init(80, 120, caption="Super Pong")
        pyxel.load('./../assets/resorces.pyxres')

        self.score = Score()

        self.players = [Racket(0), Racket(1)]
        self.ball = Ball(self.score.add_score_to_player)
        self.sprites = [self.players[0], self.players[1], self.ball]

        pyxel.run(self.update, self.draw)

    def update(self):
        for sprite in self.sprites:
            sprite.update()

        for player in self.players:
            if (self.ball.intersects(player)):
                player.notify_hit()
                self.ball.hit(player.speed)

    def draw(self):
        pyxel.cls(0)
        for sprite in self.sprites:
            sprite.draw()

        self.score.draw()
Пример #2
0
    def __init__(self):
        pyxel.init(80, 120, caption="Super Pong")
        pyxel.load('./../assets/resorces.pyxres')

        self.score = Score()

        self.players = [Racket(0), Racket(1)]
        self.ball = Ball(self.score.add_score_to_player)
        self.sprites = [self.players[0], self.players[1], self.ball]

        pyxel.run(self.update, self.draw)
Пример #3
0
 def activate(self, game):
     super().activate()
     balls = game.get_balls()
     new_balls = []
     for ball in balls:
         ball_position = ball.get_position()
         ball_velocity = ball.get_velocity()
         new_ball = Ball(ball_position[0],
                         ball_position[1],
                         ball_velocity[0],
                         -ball_velocity[1],
                         clone_id=id(self),
                         stick_to_paddle=ball.is_attached())
         new_ball.set_velocity(ball_velocity[0], -ball_velocity[1])
         new_balls.append(new_ball)
     for new_ball in new_balls:
         game.add_ball(new_ball)
Пример #4
0
 def __add_shoots(self):
     for i in self.__power_ups:
         if i.get_type() == "shoot":
             if int(time.time() -
                    self.__start_time) != self.__shoot_time and int(
                        time.time() - self.__start_time) % 5 == 0:
                 self.__shoot_time = int(time.time() - self.__start_time)
             new_ball_1 = Ball(
                 self.__paddle.get_position()[0] - int(
                     (self.__paddle.get_width() - 1) / 2),
                 self.__paddle.get_position()[1] - 2, 0, 1, False)
             self.__balls.append(new_ball_1)
             new_ball_2 = Ball(
                 self.__paddle.get_position()[0] + int(
                     (self.__paddle.get_width() - 1) / 2),
                 self.__paddle.get_position()[1] - 2, 0, 1, False)
             self.__balls.append(new_ball_2)
Пример #5
0
 def reset_game_balls(self):
     ball_y_position = self.__paddle.get_position()[1] - 1
     paddle_side_length = int((self.__paddle.get_width() - 1) / 2)
     ball_x_position = random.choice(
         list(
             range(self.__paddle.get_position()[0] - paddle_side_length,
                   self.__paddle.get_position()[0] + paddle_side_length +
                   1)))
     starting_ball = Ball(ball_x_position, ball_y_position, 0, 0)
     self.__balls = [starting_ball]
Пример #6
0
    def generate_balls(self, number):
        """Генерирует объекты Ball в количестве равном number шт в случайных ячейках сетки"""

        try:
            for i in range(number):
                matrix_pos = self.get_random_ball_matrix_position()
                pos_x, pos_y = self.grid.matrix_pos_to_grid_coords(matrix_pos)
                predefined_color = self._next_colors[
                    i] if self._next_colors else None
                ball = Ball(pos_x, pos_y, matrix_pos[0], matrix_pos[1],
                            predefined_color)
                self.grid.update_grid(matrix_pos, ball, self.window)

            if self.is_no_empty_cells():
                raise ValueError("Grid is full!")

            self.predict_next_colors()
            self.ui.render_next_colors(self.window, self._next_colors)
            self.destroy_similar()

        except ValueError:
            # Сетка заполнена
            self.end_game()
Пример #7
0
#fig1.set_figheight(7)
#fig1.set_figwidth(7)
#ax1 = fig1.add_subplot(111, projection = '3d')

ball_r = 0.5
ball_b = 1
ball_m = 100
ball_I = 0.5 * ball_m * ball_r**2
const = -scipy.constants.g / (1 + (ball_I / (ball_m * ball_b ^ 2)))

#normal = np.array([0,1,10])
normal = np.array([0, 0, 1])

point = np.array((0, 0, 0))
plate = Plate(point, normal)
ball = Ball(ball_r, plate.normal)

plane = plate.DrawPlate(ax1)
sphere = ball.DrawBall(ax1)

#angle_text = ax1.text(0.05, 0.9, '', transform = ax1.transAxes)
#time_template = 'Angle = %i[deg]'

#def press(event):
##    if self.angle < np.deg2rad(45) and self.angle > np.deg2rad(-45):
#    if event.key == 'a'and plate.angle < np.deg2rad(angle_limit):
#        plate.TiltPlate(1 * (np.pi/180))
#    if event.key == 'd' and plate.angle > np.deg2rad(-angle_limit):
#        plate.TiltPlate(-1 * (np.pi/180))
#    sys.stdout.flush()
Пример #8
0
from src.display import *

pygame.init()
pygame.mixer.init()
pygame.font.init()
w_size = (W_WIDTH, W_HEIGHT)
screen = pygame.display.set_mode(w_size, pygame.FULLSCREEN)
pygame.display.set_caption(W_TITLE)
pygame.mixer.music.load("assets/audio/elevator.wav")
pygame.mouse.set_visible(False)
goal_sound = pygame.mixer.Sound("assets/audio/coin.wav")
nice = pygame.mixer.Sound("assets/audio/nice.wav")

left_paddle = Paddle(0)
right_paddle = Paddle(W_WIDTH - PADDLE_WIDTH)
ball = Ball()

score_left = 0
score_right = 0

font = pygame.font.Font(None, 74)
sprites_list = pygame.sprite.Group()
sprites_list.add(left_paddle)
sprites_list.add(right_paddle)
sprites_list.add(ball)


def move_paddles(keys: list, left_paddle: Paddle, right_paddle: Paddle):
    move_left_paddle(keys, left_paddle)
    move_right_paddle(keys, right_paddle)