async def game(): player.physics.x_speed = 0 player.physics.y_speed = 0 if play.key_is_pressed('w', 'up'): player.y = player.y + 5 if play.key_is_pressed('s', 'down'): player.y = player.y - 5 if play.key_is_pressed('a', 'left'): player.x = player.x - 5 if play.key_is_pressed('d', 'right'): player.x = player.x + 5 if player.is_touching(finish): wall1.hide() wall2.hide() wall3.hide() wall4.hide() wall5.hide() wall6.hide() wall7.hide() wall8.hide() wall9.hide() wall10.hide() wall11.hide() wall12.hide() wall13.hide() wall14.hide() wall15.hide() finish.hide() q1.show() await play.timer(seconds=1 / frames)
def do(): spaceship.physics.y_speed = 0 spaceship.physics.x_speed = 0 if play.key_is_pressed('w'): spaceship.physics.y_speed = 15 if play.key_is_pressed('s'): spaceship.physics.y_speed = -15 if play.key_is_pressed('a'): spaceship.physics.x_speed = -15 if play.key_is_pressed('d'): spaceship.physics.x_speed = 15 if spaceship.is_touching(finish): asteroid1.hide() asteroid2.hide() asteroid3.hide() spaceship.hide() finish.hide() win = play.new_text(words="WIN", x=0, y=0, font_size=200, color="green") if spaceship.is_touching(asteroid1) or spaceship.is_touching( asteroid2) or spaceship.is_touching(asteroid3): asteroid1.hide() asteroid2.hide() asteroid3.hide() spaceship.hide() finish.hide() lose = play.new_text(words="LOSE", x=0, y=0, font_size=200, color="red")
async def game(): # перемещение платформы if play.key_is_pressed('a'): platform.physics.x_speed = -20 elif play.key_is_pressed('d'): platform.physics.x_speed = 20 else: platform.physics.x_speed = 0 # удаление блоков for b in blocks: if b.is_touching(ball): # ball.x_speed=-ball.x_speed # ball.y_speed=-ball.y_speed ball.physics.x_speed = -1 * ball.physics.x_speed ball.physics.y_speed = -1 * ball.physics.y_speed b.hide() blocks.remove(b) # проигрыш if ball.y <= platform.y: for b in blocks: blocks.remove(b) play.set_backdrop('light blue') platform.hide() ball.hide() lose.show() # выигрыш if len(blocks) == 0: play.set_backdrop('light yellow') win.show() await play.timer(seconds=1 / frames ) # частота смены кадров (пауза раз в несколько кадров)
def do(): ball.physics.y_speed = 0 ball.physics.x_speed = 0 if play.key_is_pressed('w'): ball.physics.y_speed = 10 if play.key_is_pressed('s'): ball.physics.y_speed = -10 if play.key_is_pressed('a'): ball.physics.x_speed = -10 if play.key_is_pressed('d'): ball.physics.x_speed = 10 if ball.is_touching(finish): wall1.hide() wall2.hide() wall3.hide() wall4.hide() wall5.hide() wall6.hide() wall7.hide() wall8.hide() wall9.hide() wall10.hide() wall11.hide() wall12.hide() finish.hide() ball.hide() play.new_text(words="YOU WIN", x=0, y=0, font=None, font_size=100, color="red")
async def move_box(): old_x, old_y = box.x, box.y if play.key_is_pressed('up', 'w'): box.y += 5 # y = y + 15 y += 15 elif play.key_is_pressed('down', 's'): box.y -= 5 if play.key_is_pressed('right', 'd'): box.x += 5 elif play.key_is_pressed('left', 'a'): box.x -= 5 # Делаем непроходимыми стены проверяем условие касания стен и делаем возврат на исходную точку if box.x != old_x or box.y != old_y: for line in lines: if box.is_touching(line): box.x, box.y = old_x, old_y # условие Победы if box.is_touching(key): winner.show() await play.timer(seconds=3) sys.exit(0) await play.timer(seconds=0.001)
async def keys_control(): if play.key_is_pressed('up', 'w'): had.angle = 90 if play.key_is_pressed('down', 's'): had.angle = -90 if play.key_is_pressed('right', 'd'): had.angle = 0 if play.key_is_pressed('left', 'a'): had.angle = 180 await play.timer(seconds=0.001)
async def do(): if play.key_is_pressed('w', 'ц'): l_racket.y += 15 if play.key_is_pressed('s', "ы"): l_racket.y -= 15 if play.key_is_pressed('o', "щ"): r_racket.y += 15 if play.key_is_pressed('l', "д"): r_racket.y -= 15 if ball.x > RIGHT - 2 * B_SIZE: # что происходит здесь? point_l() # и здесь? if ball.x < LEFT + 2 * B_SIZE: point_r() await play.timer(seconds=1 / frames ) # частота смены кадров (пауза раз в несколько кадров)
async def fly_image(): if status == 1: if play.key_is_pressed("W", "w", "Ц", "ц", "up", "space"): bird.image = "./img/bird2.png" await play.timer(0.5) else: bird.image = "./img/bird1.png"
async def jump(): if play.key_is_pressed ('space'): bird.y+=50 elif bird.y<-300: po.show() else: bird.y-=20 await play.timer(1/40)
def keypads(): global number_k, x, direction, sprite if play.key_is_pressed('space'): for wall in wall_list: if sprite_box.is_touching(wall) and sprite_box.y > wall.y: sprite_box.physics.y_speed = 50 if play.key_is_pressed("d"): direction = 'right' number_k += 1 if x >= 0: sprite_box.physics.x_speed = 0 for wall in wall_list: wall.physics.x_speed = -10 else: sprite_box.physics.x_speed = 10 for wall in wall_list: wall.physics.x_speed = 0 x += 5 elif play.key_is_pressed("a"): direction = 'left' number_k += 1 if x == 0: for wall in wall_list: wall.physics.x_speed = 10 else: sprite_box.physics.x_speed = -10 for wall in wall_list: wall.physics.x_speed = 0 x -= 5 else: number_k = 0 sprite_box.physics.x_speed = 0 for wall in wall_list: wall.physics.x_speed = 0
def do(): if play.key_is_pressed('e'): photo.image = "1.jpg" text.words = "Happy" text.color = "Yellow" if play.key_is_pressed('w'): photo.image = "2.jpg" text.words = "Sad" text.color = "Blue" if play.key_is_pressed('a'): photo.image = "3.png" text.words = "Angry" text.color = "REd" if play.key_is_pressed('s'): photo.image = "4.png" text.words = "Neutral" text.color = "White" if play.key_is_pressed('d'): photo.image = "5.png" text.words = "Sleepy" text.color = "Green"
async def game(): global score global score_num if sprite.is_touching(sea): sea_sound.play() gameover_text.show() retry_button.show() if sprite.is_touching(finish): for c in coins: c.hide() for plat in platforms: plat.hide() finish.hide() sprite.hide() sea.hide() text.hide() score.hide() score_txt.hide() await play.timer(seconds=2) quit() for c in coins: if c.is_touching(sprite): coin_sound.play() sprite.physics.y_speed = -1 *sprite.physics.y_speed c.hide() coins.remove(c) score.words = str(int(score.words) + 1) if play.key_is_pressed('d'): sprite.physics.x_speed = 10 elif play.key_is_pressed('a'): sprite.physics.x_speed = -10 elif play.key_is_pressed('space'): sprite.physics.y_speed = 50 await play.timer(seconds=1) sprite.physics.y_speed = 0 await play.timer(seconds=1/60)
async def keypads(): global status for truba in truby: if play.key_is_pressed('Ц', 'ц', 'W', 'w', 'space', 'up'): bird.physics.y_speed = 50 if bird.is_touching(truba[1]) or bird.is_touching(truba[0]): for g in truby: g[1].hide() g[0].hide() truby.remove(truba) bird.stop_physics() bird.hide() u_lose.show() exit_demon.show() status = 0 await play.timer(1 / 60)
async def vois_bird () : global status if status == 1 : if play.key_is_pressed ('space') : sound_jump.play () await play.timer (2)
def go_bird (): if play.key_is_pressed ('space') : bird.y = bird.y + 3 else: bird.y -= 3
def game(): # перемещение платформы # if play.key_is_pressed('a'): # platform.physics.x_speed = -20 # elif play.key_is_pressed('d'): # platform.physics.x_speed = 20 # elif play.key_is_pressed('w'): # platform.physics.y_speed = 20 # elif play.key_is_pressed('s'): # platform.physics.y_speed = -20 # else: # platform.physics.x_speed = 0 # platform.physics.y_speed = 0 platform2.turn(0.1) i=0 i+=1 print(i) if play.key_is_pressed('w'): if platform.velocity.x < 0: platform.acceleration = platform.brake_deceleration else: platform.acceleration += 30 * dt elif play.key_is_pressed('s'): if platform.velocity.x > 0: platform.acceleration = -platform.brake_deceleration else: platform.acceleration -= 30 * dt else: if abs(platform.velocity.x) > dt * platform.free_deceleration: platform.acceleration = -copysign(platform.free_deceleration, platform.velocity.x) else: if dt != 0: platform.acceleration = -platform.velocity.x / dt if play.key_is_pressed('d'): platform.steering -= 30 * dt elif play.key_is_pressed('a'): platform.steering += 30 * dt else: platform.steering = 0 # pressed = pygame.key.get_pressed() # # if pressed[pygame.K_UP]: # if platform.physics.x_speed < 0: # platform.acceleration = platform.brake_deceleration # else: # platform.acceleration += 100 * dt # elif pressed[pygame.K_DOWN]: # if platform.physics.x_speed > 0: # platform.acceleration = -platform.brake_deceleration # else: # platform.acceleration -= 100 * dt # elif pressed[pygame.K_SPACE]: # if abs(platform.physics.x_speed) > dt * platform.brake_deceleration: # platform.acceleration = -copysign(platform.brake_deceleration, platform.physics.x_speed) # else: # platform.acceleration = -platform.physics.x_speed / dt # else: # if abs(platform.physics.x_speed) > dt * platform.free_deceleration: # platform.acceleration = -copysign(platform.free_deceleration, platform.physics.x_speed) # else: # if dt != 0: # platform.acceleration = -platform.physics.x_speed / dt # platform.acceleration = max(-platform.max_acceleration, min(platform.acceleration, platform.max_acceleration)) # if pressed[pygame.K_RIGHT]: # platform.steering -= 80 * dt # elif pressed[pygame.K_LEFT]: # platform.steering += 80 * dt # else: # platform.steering = 0 # platform.steering = max(-platform.max_steering, min(platform.steering, platform.max_steering)) platform.update() if platform.ball.is_touching(platform2): print('touch')
async def do(): if play.key_is_pressed('space'): bird.physics.y_speed = 30 await play.timer(0.1)
def start_program(): global status if status == 4: if play.key_is_pressed('space'): podzkazka_dlia_ne_ochen_umnih.hide() status = 2 bird_kub = play.new_box(color='black', transparency=0, width=32, height=25) bird = play.new_image(image='bird_1.png', size=140, x=0) bird_kub.start_physics(can_move=True, obeys_gravity=True, stable=True, y_speed=0) bird_kub.y += 10 if status == 2: global n n = 0 status = 1 chet = play.new_text(str(n), y=-30) chet.hide() # trubi_img(-200,100) trubi_list = [] lose = play.new_text('YOU LOSE', color='red') lose.hide() @play.repeat_forever def keypads(): if play.key_is_pressed('space'): bird_kub.y += 10 @play.repeat_forever async def do(): global status if status == 1: a = trubi_img(randint(-500, -200), 150) trubi_list.append(a) await play.timer(3) else: for tum in trubi_list: tum[1].remove() tum[0].remove() trubi_list.remove(tum) @play.repeat_forever async def run(): for i in trubi_list: i[0].x -= 5 i[1].x -= 5 if i[0].x < -500: i[0].remove() i[1].remove() trubi_list.remove(i) await play.timer(1 / 40) @play.repeat_forever def touch(): global status if status == 1: if bird_kub.y < -280: bird_kub.stop_physics() bird_kub.hide() bird.remove() lose.show() chet.show() restart_knopka.show() restart_kub.show() status = 0 elif status == 1: for truba in trubi_list: if truba[0].is_touching( bird_kub) or truba[1].is_touching(bird_kub): bird_kub.stop_physics() bird_kub.hide() bird.remove() lose.show() chet.show() restart_knopka.show() restart_kub.show() status = 0 bird.y = bird_kub.y @play.repeat_forever def chets(): global n global status if status == 1: for tr in trubi_list: if bird_kub.x > tr[1].x and tr[0].status == 1: tr[0].status = 0 n = n + 1 chet.words = str(n) @restart_kub.when_clicked def restart(): global status restart_kub.hide() restart_knopka.hide() status = 5 start_knopka.show() start_kub.show() lose.hide() chet.words.hide() for tumka in trubi_list: tumka[0].remove() tuka[1].remove() trubi_list.remove(tumka)
def keypads(): if play.key_is_pressed('space'): bird_kub.y += 10
async def fly(): if status == 1: if play.key_is_pressed("W", "w", "Ц", "ц", "up", "space"): bird.physics.y_speed = 30 await play.timer(0.1)
async def suits(): if play.key_is_pressed('Ц', 'ц', 'W', 'w', 'space', 'up'): bird.image = bird_suits[1] await play.timer(0.5) else: bird.image = bird_suits[0]
def jumb(): if STATUS==1: if play.key_is_pressed("space"): bird.physics.y_speed = 50 else: bird.physics.y_speed = -20