def make_brick(): global bricks bricks = [] b = 0 gap = 30 colour = ("green", "orange", "yellow", "purple") while b < 12: n = 1 while n < 15: x = random.randrange(1, 11) i = 80 if x == (1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10): brick = bat.Bat(table=my_table, width=78, height=20, x_posn=(n * i), y_posn=120 + (b * gap), colour="red") else: brick = bat.Bat(table=my_table, width=78, height=20, x_posn=(n * i), y_posn=120 + (b * gap), colour=(colour[(b - 1) % 4])) bricks.append(brick) n = n + 1 b = b + 1
def __init__(self): """Initialise the game state""" # Initialise the terminal writer with the serial output self.output = terminal_writer.Writer(consts.SERIAL_OUTPUT, True) # Initialise the two bats self.left_bat = bat.Bat(consts.LEFT_BAT_RETURN_ANGLES, consts.CONTROL_1_ADDR) self.left_bat.position = consts.LEFT_BAT_INIT_POSITION self.left_bat.size = consts.BAT_SIZE self.left_bat.colour = consts.LEFT_BAT_COLOUR self.right_bat = bat.Bat(consts.RIGHT_BAT_RETURN_ANGLES, consts.CONTROL_2_ADDR) self.right_bat.position = consts.RIGHT_BAT_INIT_POSITION self.right_bat.size = consts.BAT_SIZE self.right_bat.colour = consts.RIGHT_BAT_COLOUR self.serving_pattern = cycle( chain(repeat(self.left_bat, 5), repeat(self.right_bat, 5))) # Initialise the ball and attach it to the left bat ready for serving self.ball = ball.Ball() self.ball.size = consts.BALL_SIZE self.ball.colour = consts.BALL_COLOUR self.ball.attached_bat = next(self.serving_pattern) # Initialise the score self.left_score = 0 self.right_score = 0 # Setup the callbacks for the controller buttons # The callbacks themselves are functions which take one argument. This # is because the API which is being utilised here provides the GPIO pin # number as an argument. This is discarded as it is unneeded # The controller address is provided to the serve functions so that the # ball knows if the correct controller is trying to serve it GPIO.add_event_detect(consts.PLAYER_1_SERVE, GPIO.RISING, lambda x: self.ball.serve(consts.CONTROL_1_ADDR), bouncetime=200) GPIO.add_event_detect(consts.PLAYER_1_ENLARGE, GPIO.RISING, lambda x: self.left_bat.enlarge(), bouncetime=200) GPIO.add_event_detect(consts.PLAYER_2_SERVE, GPIO.RISING, lambda x: self.ball.serve(consts.CONTROL_2_ADDR), bouncetime=200) GPIO.add_event_detect(consts.PLAYER_2_ENLARGE, GPIO.RISING, lambda x: self.right_bat.enlarge(), bouncetime=200) # Create the glow sequencer self.glow_seq = glow_seq.GlowSequencer() self.glow_seq.insert(consts.NORMAL_PATTERN, float("inf"))
def __init__(self): # adicionando as formas(obstaculos) self.Circulo_0 = obstaculos.Circulo(385, 583, 39) self.Circulo_1 = obstaculos.Circulo(257, 302, 39) self.space.add(self.Circulo_0.circulo, self.Circulo_1.circulo) self.Triangulo1_0 = obstaculos.Triangulo1(270, 444, 42) self.Triangulo1_1 = obstaculos.Triangulo1(181, 560, 42) self.Triangulo1_2 = obstaculos.Triangulo1(413, 385, 42) self.space.add(self.Triangulo1_0.triangulo1, self.Triangulo1_1.triangulo1, self.Triangulo1_2.triangulo1) self.Triangulo2_0 = obstaculos.Triangulo2(210, 121, 40, 90, -40) self.Triangulo2_1 = obstaculos.Triangulo2(385, 121, -40, 90, 40) self.space.add(self.Triangulo2_0.triangulo2, self.Triangulo2_1.triangulo2) self.criaremov() # Criando os bastoes aux = func.ancorar(pyglet.image.load('resources/images/bastao1.png'), 'esq') self.batE = bat.Bat(-1, aux, x_e, y_e) self.space.add( self.batE.body, self.batE.shape ) # adicionando os elementos a simulação fisica do pymunk self.space.add(self.batE.j, self.batE.s) self.physicalObjects.append(self.batE) aux = func.ancorar(pyglet.image.load('resources/images/bastao-1.png'), 'dir') self.batD = bat.Bat(1, aux, x_d, y_d) self.space.add( self.batD.body, self.batD.shape ) # adicionando os elementos a simulação fisica do pymunk self.space.add(self.batD.j, self.batD.s) self.physicalObjects.append(self.batD) for line in self.borders: line.elasticity = 0.7 line.group = 1 self.space.add(self.borders) self.status = 'BEGINING' self.molaS = 'GO' self.molaX = 0
def create_bats(self): self.bats = [] self.bestBat = None for i in range(self.population): b = bat.Bat(self.dim) b.fitness = self.problem.evaluate(b.bestSolution) self.bats.append(b) if self.bestBat is None or self.bestBat.fitness > b.fitness: self.bestBat = b
window.title("MyPong") my_table = table.Table(window, net_color="green", vertical_net=True) my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, color="red", x_start=288, y_start=188) bat_L = bat.Bat(table=my_table, width=15, height=100, x_posn=20, y_posn=150, color="blue") bat_R = bat.Bat(table=my_table, width=15, height=100, x_posn=575, y_posn=150, color="yellow") def game_flow(): # 배트가 공을 받아치는지 확인: bat_L.detect_collision(my_ball) bat_R.detect_collision(my_ball)
score_right = 0 first_serve = True # order a window from the tkinter window factory window = Tk() window.title("Pingpong For IS3020 SPRING 19") # order a table from the table class pp_table = table.Table(window, net_colour="white", vertical_net=True) # order a ball from the ball factory pp_ball = ball.Ball(table=pp_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, colour="yellow", x_start=288, y_start=188) # order a left and right bat from the bat class bat_L = bat.Bat(table=pp_table, width=15, height=100, x_posn=20, y_posn=150, colour="blue") bat_R = bat.Bat(table=pp_table, width=15, height=100, x_posn=575, y_posn=150, colour="red") #### functions: def game_flow(): global first_serve global score_left global score_right # wait for first serve: if(first_serve == True): pp_ball.stop_ball() first_serve = False # detect if ball has hit the bats: bat_L.detect_collision(pp_ball)
x_start y_start 공 위치 정하는 부분 width, height 공 크기 정하는 부분 colour 공 색 정하는 부분 """ my_ball = ball.Ball(table = my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, colour="red", x_start=610, y_start=650) # Bat 공장으로부터 배트를 주문합니다 """ a_posn, y_posn은 막대의 위치 정하는 부분 width, height는 막대 크기 정하는 부분 color은 막대 색 정하는 부분 """ bat_B = bat.Bat(table = my_table, width=100, height=10, x_posn=570, y_posn=700, colour="blue") #벽돌을 만드는 함수 def make_brick(): global bricks bricks = [] b = 0 gap = 30 colour = ("green", "orange", "yellow", "purple") while b < 12: n = 1 while n < 15: x = random.randrange(1,11) i=80
y_velocity = -10 first_serve = True direction = "right" # order a missile from the ball class my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, height=15, width=8, colour="black") # order a defender from the bat class bat_B = bat.Bat(table=my_table, width=50, height=30, x_posn=250, y_posn=350, colour="blue") # order invaders from the bat class and start them moving to the right invaders = [] rows = 0 gap = 100 colour = ("green", "black", "yellow", "purple") while rows < 2: n = 1 while n < 7: i = 0 invader = bat.Bat(table=my_table, width=100, height=25,
first_serve = True # Ball 공장으로부터 볼을 주문합니다 my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, colour="red", x_start=288, y_start=188) # Bat 공장으로부터 배트를 주문합니다 bat_B = bat.Bat(table=my_table, width=100, height=10, x_posn=250, y_posn=370, colour="blue") # Bat 클래스로부터 배트를 주문하지만 이것은 벽돌을 호출하는 것은 아닙니다. bricks = [] b = 1 while b < 7: i = 80 bricks.append( bat.Bat(table=my_table, width=50, height=20, x_posn=(b * i), y_posn=75, colour="green"))
# create a ball from the ball factory my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, color="red", x_start=288, y_start=188) # order a left and right bat from the bat class #### This is where we adjust the bats attributes #### bat_L = bat.Bat(table=my_table, width=10, height=100, x_posn=20, y_posn=150, color="brown") bat_R = bat.Bat(table=my_table, width=10, height=100, x_posn=575, y_posn=150, color="pink") #### functions: def game_flow(): global first_serve global score_left global score_right
def Calc(field_data, P1, P2, pulse_info_list): """ main calc P : sound pressure n : time step i : x-axis j : y-axis d : density v : sound speed dx : spatial resolution dt : time resolution P[n+1](i,j) = 2P[n](i,j) - P[n-1](i,j)+d(i,j)*(v(i,j)**2*dt**2/dx**2) """ tim = 0 width = field_data.width height = field_data.height if gpu_flag: density = cp.round(field_data.density_arr, 2) alpha = cp.round((sound_speed_list["air"] * dt / dx) ** 2, 2) else: density = np.round(field_data.density_arr, 2) alpha = np.round((sound_speed_list["air"] * dt / dx) ** 2, 2) velocity = field_data.velocity_arr # alpha = np.round((velocity[1:width - 1, 1:height - 1] * dt / dx)** 2, 2) BAT = bat.Bat() # test directivity_list = [] for pulse_info in pulse_info_list: print(f"-----calc with emit pulse{pulse_info}-----") receive_points = BAT.set_position(pulse_info) time_start = time.perf_counter() ims = [] tim_list = [] emit_list = [] for i in range(nmax): print("step:{}".format(i)) P2 = BAT.emit_pulse(i, P2, density) # if i < sig_duration: # P2[pulse_info[0], pulse_info[1] # ] = P2[pulse_info[0], pulse_info[1]] + sig P1[1:width - 1, 1:height - 1] = ( 2*P2[1:width - 1, 1:height - 1] - P1[1:width - 1, 1:height - 1] + alpha * density[1:width - 1, 1:height - 1] * (P2[2:width, 1: height - 1]/density[2:width, 1: height - 1] + P2[: width - 2, 1: height - 1] / density[: width - 2, 1: height - 1] + P2[1: width - 1, 2:height]/density[1: width - 1, 2:height] + P2[1: width - 1, : height - 2] / density[1: width - 1, : height - 2] ) - 4 * alpha * P2[1: width - 1, 1: height - 1] ) P1 = field_data.update(P2, P1) BAT.get_echo(P1, P2, density) tim_list.append(i * dt) emit_list.append(P2[pulse_info[0], pulse_info[1]]) if debug_flag and i % savestep == 0: im = MakeFigure(P1, pulse_info, receive_points, field_data) ims.append([im]) P1, P2 = P2, P1 with open(f"{pulse_info}.csv", "w") as f: writer = csv.writer(f) writer.writerow(["time", "emit", "right_echo", "left_echo"]) tim_list = np.array(tim_list)[:, np.newaxis] emit_list = np.array(emit_list)[:, np.newaxis] echo_r = np.array(BAT.echo_right_ear)[:, np.newaxis] echo_l = np.array(BAT.echo_left_ear)[:, np.newaxis] target_data = np.hstack([tim_list, emit_list, echo_r, echo_l]) writer.writerows(target_data) time_end = time.perf_counter() tim = time_end - time_start print(f"calc time:{np.round(tim,2)}[s]") # plt.plot(BAT.echo_right_ear, label=f"{pulse_info[2]}") # directivity test # directivity_list.append([pulse_info[2], np.nanmax(BAT.echo_right_ear)]) # plt.plot(BAT.echo_left_ear, label="p1") # plt.plot(receive_test) ims_list.append(ims) # plt.plot(receive_left) # plt.show() # emit_power = max(abs(np.array(receive_points[-1]))) # for idx, receive_point in enumerate(receive_points[:-1]): # recived_wave_arr = abs(np.array(receive_point)) # recived_wave_max = max(recived_wave_arr) # recived_wave_log = 20 * np.log(recived_wave_arr / emit_power) # recived_max_log = 20 * np.log(recived_wave_max / emit_power) # plt.scatter(N_list[idx][0], recived_max_log, label=f"{idx}") # # plt.ylim(-200, 0) # # plt.subplots_adjust(right=0.1) # plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0) # plt.xlabel("N") # plt.ylabel("P [dB]") # plt.savefig("recived_wave_diffraction_N.png",bbox_inches='tight', pad_inches=0) # plt.plot(BAT.echo_left_ear, label="no_directivity") # # test # ax1 = plt.subplot(111, projection="polar") # ax1.set_theta_direction(-1) # ax1.set_rlabel_position(0) # ax1.set_xticks(np.pi / 180. * np.linspace(0, 360, 12, endpoint=False)) # ax1.spines['polar'].set_color('darkgray') # # plt.ylim(-60.1, 5) # for directivity_data in directivity_list: # ax1.scatter(directivity_data[0] * np.pi / 180, directivity_data[1]) # plt.rcParams['font.family'] = 'Times New Roman' # plt.rcParams['font.size'] = 12 # plt.legend() # plt.show() # plt.savefig("echo.png") return ims_list
def run(self): pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.init() surface = pygame.display.set_mode(self.size, pygame.HWSURFACE, 32) # pygame.FULLSCREEN pygame.display.set_caption("My Arcade Game") clock = pygame.time.Clock() background_main = pygame.image.load(self.background_img_name).convert() background_left = pygame.image.load(self.background_img_left).convert() background_right = pygame.transform.rotate(background_left, 180) background_top = pygame.image.load(self.background_img_top).convert() heart = pygame.image.load(self.heart_img_name).convert_alpha() blocks_explosion_img = pygame.image.load( self.blocks_explosion_img_name).convert_alpha() font = pygame.font.SysFont(name="arial", size=20, bold=True) text_enter = font.render("Press Enter ...", True, (0, 255, 0)) text_pause = font.render("Pause", True, (0, 255, 0)) text_lost = font.render("Lost !", True, (0, 255, 0)) text_win = font.render("Win ! ", True, (0, 255, 0)) text_game_over = font.render("Game Over ", True, (0, 255, 0)) text_player = font.render(self.Player, True, (0, 255, 0)) text_player = pygame.transform.scale(text_player, (100, 20)) text_player = pygame.transform.rotate(text_player, 90) tick_bat = pygame.mixer.Sound('data/sound/bat_tick.ogg') tick_blocks = pygame.mixer.Sound('data/sound/blocks_tick.ogg') background_music = pygame.mixer.Sound('data/sound/background.oga') background_music.set_volume(0.3) tick_bat.set_volume(0.5) tick_blocks.set_volume(.5) background_music.play(-1) blocks_obj = blocks.Blocks(surface) blocks_obj.draw() ball_obj = ball.Ball(surface) bat_obj = bat.Bat(surface) random.seed() randint = random.randint ball_dir_x = randint(-1, 1) ball_dir_y = 10 rotate = 0 angle = .01 state = "Start" blocks_explosion_slide = 0 blocks_state = "Normal" while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() pressed_keys = pygame.key.get_pressed() if pressed_keys[pygame.K_RIGHT] and state == "Play": bat_obj.drive(1) elif pressed_keys[pygame.K_LEFT] and state == "Play": bat_obj.drive(-1) if pressed_keys[pygame.K_RETURN] or pressed_keys[ pygame.K_KP_ENTER]: state = "Play" if pressed_keys[pygame.K_SPACE] and state == "Play": state = "Pause" text_lives = font.render(str(self.Lives), True, (0, 255, 0)) text_score = font.render(str(self.Score), True, (0, 255, 0)) text_score = pygame.transform.scale( text_score, (10 * (len(str(self.Score)) + 1), 30)) text_level = font.render("Level 0" + str(self.Level), True, (0, 255, 0)) rotate += angle if rotate >= 20: angle = angle * -1 if rotate <= 0: angle = angle * -1 background_rotated = pygame.transform.rotate( background_main, rotate) # pygame.draw.rect(surface,(255,0,0),(45,45,600-45,480-45-35),2) surface.blit(background_rotated, (0, 0)) surface.blit(background_top, (0, 0)) surface.blit(background_left, (0, 0)) surface.blit(background_right, (600, 0)) surface.blit(heart, (3, 10 + 280)) surface.blit(text_lives, (13, 15 + 280)) surface.blit(text_score, (510, 7)) surface.blit(text_level, (80, 10)) surface.blit(text_player, (610, 280)) if ball_obj.ball_rect.left <= 45: ball_dir_x = 1 * abs(ball_dir_x + randint(-1, 1)) tick_bat.play() elif ball_obj.ball_rect.right >= 600: ball_dir_x = -1 * abs(ball_dir_x + randint(-1, 1)) tick_bat.play() elif ball_obj.ball_rect.top <= 45: ball_dir_y = 1 * abs(ball_dir_y + randint(-1, 1)) tick_bat.play() elif ball_obj.ball_rect.bottom >= 480: # ball_dir_y = -1 * abs(ball_dir_y) if self.Lives: self.Lives -= 1 state = "Lost" ball_obj.reset() bat_obj.reset() ball_dir_x = randint(-10, 10) ball_dir_y = 10 else: state = "GameOver" if bat_obj.bat_shape_rect.top - 2 <= ball_obj.ball_rect.bottom <= bat_obj.bat_shape_rect.bottom - 10 and \ ball_obj.ball_rect.right >= bat_obj.bat_shape_rect.left and \ ball_obj.ball_rect.left <= bat_obj.bat_shape_rect.right: ball_dir_y = -10 tick_bat.play() offset = ball_obj.ball_rect.center[ 0] - bat_obj.bat_shape_rect.center[0] if offset > 30: ball_dir_x = 8 + randint(-1, 1) elif offset > 20: ball_dir_x = 7 + randint(-1, 1) elif offset > 10: ball_dir_x = 2 + randint(-1, 1) elif offset < -30: ball_dir_x = -8 + randint(-1, 1) elif offset < -20: ball_dir_x = -7 + randint(-1, 1) elif offset < -10: ball_dir_x = -2 + randint(-1, 1) else: ball_dir_x = ball_dir_x + randint(-1, 1) index = ball_obj.ball_rect.collidelist(blocks_obj.blocks) if index != -1: block_out = blocks_obj.blocks[index] blocks_obj.blocks[index] = (-1, -1, -1, -1) if ball_obj.ball_rect.bottom >= pygame.Rect(block_out).top: ball_dir_y = 1 * abs(ball_dir_y) elif ball_obj.ball_rect.top <= pygame.Rect(block_out).bottom: ball_dir_y = -1 * abs(ball_dir_y) block_out_left = block_out[0] - blocks_obj.block_rect[0][0] block_out_top = block_out[1] - blocks_obj.block_rect[0][1] block_out_pos = (block_out_left, block_out_top, blocks_obj.block[0], blocks_obj.block[1]) block_in = blocks_obj.true_img.subsurface(block_out_pos) blocks_obj.false_img.blit(block_in, block_out_pos) self.Score += 100 if blocks_obj.blocks.count( (-1, -1, -1, -1)) == len(blocks_obj.blocks): state = "Win" blocks_state = "Hitting" blocks_explosion_slide = 0 tick_blocks.play() blocks_obj.draw() bat_obj.drive(0) if blocks_state == "Hitting": surface.blit(blocks_explosion_img, block_out, (40 * blocks_explosion_slide, 0, 40, 20)) blocks_explosion_slide += 1 if blocks_explosion_slide == 11: blocks_state = "Normal" if state == "Play": ball_obj.draw((ball_dir_x, ball_dir_y)) else: ball_obj.draw((0, 0)) if state == "Start": surface.blit(text_enter, (250, 320)) elif state == "Pause": surface.blit(text_pause, (280, 300)) surface.blit(text_enter, (250, 320)) elif state == "Lost": surface.blit(text_lost, (280, 300)) surface.blit(text_enter, (250, 320)) elif state == "GameOver": surface.blit(text_game_over, (280, 300)) elif state == "Win": surface.blit(text_win, (280, 300)) clock.tick(self.frame) pygame.display.flip()
my_table = table.Table(window) # Ball 공장으로부터 볼을 주문합니다 my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, colour="red", x_start=288, y_start=188) # Bat 공장으로부터 왼쪽과 오른쪽 배트를 주문합니다 my_bat = bat.Bat(table=my_table, width=100, height=15, x_posn=250, y_posn=350, colour="blue") #### 함수: def game_flow(): # 배트에서 공을 받아치는지 확인: my_bat.detect_collision(my_ball) my_ball.move_next() window.after(50, game_flow) # 배트를 제어하기 위해 키보드의 키에 연결 window.bind("<Left>", my_bat.move_left)
def __init__(self): #adicionando as formas(obstaculos) self.Circulo_0 = obstaculos.Circulo(385, 583, 39, collision_types) self.Circulo_1 = obstaculos.Circulo(257, 302, 39, collision_types) self.space.add(self.Circulo_0.circulo_body, self.Circulo_1.circulo_body) self.space.add(self.Circulo_0.circulo, self.Circulo_1.circulo) self.Triangulo1_0 = obstaculos.Triangulo1(270, 444, 42, collision_types) self.Triangulo1_1 = obstaculos.Triangulo1(181, 560, 42, collision_types) self.Triangulo1_2 = obstaculos.Triangulo1(413, 385, 42, collision_types) self.space.add(self.Triangulo1_0.triangulo1_body, self.Triangulo1_1.triangulo1_body, self.Triangulo1_2.triangulo1_body) self.space.add(self.Triangulo1_0.triangulo1, self.Triangulo1_1.triangulo1, self.Triangulo1_2.triangulo1) self.Triangulo2_0 = obstaculos.Triangulo2(210, 121, 40, 90, -40, collision_types) self.Triangulo2_1 = obstaculos.Triangulo2(385, 121, -40, 90, 40, collision_types) self.space.add(self.Triangulo2_0.triangulo2_body, self.Triangulo2_1.triangulo2_body) self.space.add(self.Triangulo2_0.triangulo2, self.Triangulo2_1.triangulo2) self.Criaremov() #Criando os bastoes aux = func.ancorar(pyglet.image.load('resources/images/bastao1.png'), 'esq') self.batE = bat.Bat(-1, aux, xE, yE) self.space.add( self.batE.body, self.batE.shape ) #adicionando os elementos a simulação fisica do pymunk self.space.add(self.batE.j, self.batE.s) self.physicalObjects.append(self.batE) aux = func.ancorar(pyglet.image.load('resources/images/bastao-1.png'), 'dir') self.batD = bat.Bat(1, aux, xD, yD) self.space.add( self.batD.body, self.batD.shape ) #adicionando os elementos a simulação fisica do pymunk self.space.add(self.batD.j, self.batD.s) self.physicalObjects.append(self.batD) first = 0 for line in self.borders: line.elasticity = 0.7 line.group = 1 if first == 0: line.collision_type = collision_types["mola"] first += 1 line.elasticity = 0 else: line.collision_type = collision_types["Parede"] self.space.add(line) self.status = 'BEGINING' h = self.space.add_collision_handler(collision_types["mola"], collision_types["ball"]) h.begin = self.iniciando hobj = self.space.add_collision_handler(collision_types["ball"], collision_types["objects"]) hobj.post_solve = self.col_post
first_serve = True # tkinter 클래스으로부터 윈도우 호출 window = Tk(mixer.music.play(-1,0.0)) window.title("MiniminiPong") # Table 클래스으로부터 table 호출 my_table = table.Table(window, net_colour="red", vertical_net=True) # Ball 클래스으로부터 볼을 호출합니다 my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=30, height=30, colour="red", x_start=288, y_start=188) # Bat 클래스으로부터 배트를 호출합니다 bat_L = bat.Bat(table=my_table, width=15, height=100, x_posn=20, y_posn=150, colour="green") bat_R = bat.Bat(table=my_table, width=15, height=100, x_posn=575, y_posn=150, colour="green") def on_close(): mixer.music.stop() window.destroy() window.protocol("WM_DELETE_WINDOW", on_close) #### 함수: def game_flow(): global first_serve global score_left global score_right # 첫번째 서브를 기다림
score_left = 0 score_right = 0 first_serve = True my_invaders_missle = Invaders_missle.Invaders_missle(table=my_table, x_speed=x_velocity, y_speed=y_velocity, width=24, height=24, colour="red", x_start=288, y_start=188) bat_B = bat.Bat(table=my_table, height=15, width=8, x_posn=250, y_posn=350, colour="black") #### functions: def game_flow(): global first_serve # wait for first serve: if (first_serve == True): my_invaders_missle.stop_ball() first_serve = False # detect if ball has hit the bats: ## bat_L.detect_collision(my_invaders_missle)