赞
踩
Python版儿童识字游戏源代码,结合植物大战僵尸和儿童识字的小游戏,含学习模式和娱乐模式。
娱乐模式下,僵尸会头顶不同的汉字,此时屏幕会提示要消灭的汉字,移动豌豆消灭对应汉字的僵尸,如果攻击非提示汉字的僵尸会反弹伤害到自己。
完整代码下载地址:Python版儿童识字游戏源代码
核心代码
import pygame import sys from pygame.locals import * from db import * from setting import * from Player import Player, create_new_zombies from Bullet import Bullet, ReturnBullet from Button import menu_mode_buttons, game_over_buttons, all_pass_buttons, play_mode_menu from Study import StudyModeEngine from PlayShowCC import ShowCCGroup from GameLevel import GameLevelShow, GameLevelProcess from util import * pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) game_play_mode_bgm = get_bg_music() SPEAKER_TIP_EVENT = pygame.USEREVENT + 1 pygame.time.set_timer(SPEAKER_TIP_EVENT, 1000) clock = pygame.time.Clock() stage = GAME_MENU_MODE game_level_process = GameLevelProcess() game_level = game_level_process.get_max_game_level() while True: for event in pygame.event.get(): if event.type == QUIT: game_level_process.update_game_level() sys.exit() elif event.type == MOUSEBUTTONDOWN: if stage == GAME_STUDY_MODE: x, y = event.pos study_controller.do_buttons_click(x, y, "DOWN") elif event.type == MOUSEBUTTONUP: x, y = event.pos if stage == GAME_STUDY_MODE: if study_controller.do_buttons_click(x, y, "UP"): stage = GAME_MENU_MODE elif stage == GAME_MENU_MODE: for button in menu_mode_buttons: if button.rect.collidepoint(x, y): if button.name == "study_mode": stage = GAME_STUDY_MODE study_controller = StudyModeEngine() elif button.name == "play_mode": stage = GAME_LEVEL_MODE game_play_mode_bgm.play(-1) elif button.name == "game_exit": game_level_process.update_game_level() sys.exit() elif stage == GAME_LEVEL_MODE: x, y = event.pos # 是否和rect碰撞 is_collide, game_level = game_level_process.choose_game_level(x, y) if is_collide: player = Player() bullets = pygame.sprite.Group() zombies = pygame.sprite.Group() return_bullets = pygame.sprite.Group() game_level_process.set_playing_level(game_level) show_cc_group = ShowCCGroup(screen, game_level) current_text_index = game_level_process.get_current_text_index() show_cc_group.set_speak_cc(current_text_index) zombies = create_new_zombies(current_text_index) stage = GAME_PLAY_MODE elif stage == GAME_PLAY_MODE: if play_mode_menu.rect.collidepoint(x, y): stage = GAME_MENU_MODE game_play_mode_bgm.stop() elif stage == GAME_OVER_FAIL_MODE: for button in game_over_buttons: if button.rect.collidepoint(x, y): if button.name == "play_again": player = Player() bullets = pygame.sprite.Group() zombies = pygame.sprite.Group() return_bullets = pygame.sprite.Group() game_level_process.set_playing_level(game_level) show_cc_group = ShowCCGroup(screen, game_level) current_text_index = game_level_process.get_current_text_index() show_cc_group.set_speak_cc(current_text_index) zombies = create_new_zombies(current_text_index) stage = GAME_PLAY_MODE elif button.name == "game_over_menu": stage = GAME_MENU_MODE game_play_mode_bgm.stop() elif stage == GAME_PASS_ALL_MODE: for button in all_pass_buttons: if button.rect.collidepoint(x, y): if button.name == "pass_return": stage = GAME_MENU_MODE game_play_mode_bgm.stop() elif button.name == "pass_exit": game_level_process.update_game_level() sys.exit() elif event.type == MOUSEMOTION: x, y = event.pos if stage == GAME_MENU_MODE: for menu_choice in menu_mode_buttons: menu_choice.do_mouse_on(x, y) elif stage == GAME_PLAY_MODE: play_mode_menu.do_mouse_on(x, y) elif stage == GAME_OVER_FAIL_MODE: for choice_button in game_over_buttons: choice_button.do_mouse_on(x, y) elif stage == GAME_PASS_ALL_MODE: for choice_button in all_pass_buttons: choice_button.do_mouse_on(x, y) elif event.type == KEYDOWN: if event.key == K_DOWN: player.update_pos("DOWN") elif event.key == K_UP: player.update_pos("UP") elif event.key == K_SPACE: bullet = Bullet(screen, player.get_pos_index()) bullets.add(bullet) elif event.type == SPEAKER_TIP_EVENT: if stage == GAME_PLAY_MODE: show_cc_group.do_text_sound_play() # update and draw if stage == GAME_MENU_MODE: screen.blit(menu_mode_bg, (0, 0)) menu_mode_buttons.update() menu_mode_buttons.draw(screen) elif stage == GAME_STUDY_MODE: screen.blit(study_mode_bg, (0, 0)) study_controller.update() study_controller.draw(screen) elif stage == GAME_LEVEL_MODE: screen.blit(level_choose_mode_bg, (0, 0)) game_level_process.draw_game_level(screen) elif stage == GAME_PLAY_MODE: screen.blit(play_mode_bg, (0, 0)) play_mode_menu.update() play_mode_menu.draw(screen) op_code, pos_x, pos_y = zombies_hit_by_bullets(zombies, bullets, current_text_index) if op_code == ZOMBIE_DIE: kill_sprites(zombies) # 答对了,翻牌 show_cc_group.change_question_to_cc() stage = game_level_process.go_next() current_text_index = game_level_process.get_current_text_index() show_cc_group.set_speak_cc(current_text_index) zombies = create_new_zombies(current_text_index) elif op_code == ZOMBIE_WRONG: return_bullet = ReturnBullet(pos_x, pos_y) return_bullets.add(return_bullet) player_die = player.is_collide_with_them(zombies, return_bullets) if player_die: stage = GAME_OVER_FAIL_MODE player.update() player.draw(screen) bullets.update() bullets.draw(screen) for zombie in zombies: zombie.update() zombie.draw(screen) return_bullets.update() return_bullets.draw(screen) show_cc_group.update() elif stage == GAME_OVER_FAIL_MODE: screen.blit(game_over_bg, (0, 0)) screen.blit(game_fail_widget, (443, 151)) game_over_buttons.update() game_over_buttons.draw(screen) elif stage == GAME_PASS_ALL_MODE: screen.blit(game_pass_all_bg, (0, 0)) print_pass_all_info(screen, total_cc_count) all_pass_buttons.update() all_pass_buttons.draw(screen) pygame.display.update() clock.tick(FPS)
完整代码下载地址:Python版儿童识字游戏源代码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。