前言
《愤怒的小鸟》其实活得还不错,尽管我们一直在嘲笑它的IP帝国梦做得太大。
但要知道,把休闲益智游戏的生意做到这个份上的,恐怕也就独此一家了。尤其还是这样的一
款古早、过时、难让人相信还能翻出什么花样的游戏。继前两期的效果来看,大家还是依旧挺
喜欢这款游戏的啦~嘿!我是栗子,今天终于迎来了最终版本啦~
这一期给大家写完《愤怒的小鸟最终版》三期完结撒花!
后续再想想给大家更新一些什么内容,爬虫的内容一般过不了,这就没办法!还有其他的游
戏、opencv方面的可以给大家继续更新研究一下啦!大家如果有想学的也可以评论区评论,或
许下一次更新的内容就是你的评论哦~
正文
一)运行环境
本文用到的环境:Python3.6、Pycharm社区版、Pygame游戏模块、pymunk模块自带的就不展示。
pip install -i https://pypi.douban.com/simple/ +模块名
图片素材:
(还有很多素材音频、字体、图片等就不展示啦,比较多,啊随机展示了一点点)
二)代码展示
代码分为四大块,内容有很多代码,这里直接展示主程序,其他的直接找我拿,就直接给你们
看下效果展示一下哈!
主程序:
import os
import sys
import math
import time
import pygame
current_path = os.getcwd()
import pymunk as pm
from characters import Bird
from level import Level
pygame.init()
screen = pygame.display.set_mode((1200, 650))
redbird = pygame.image.load(
"../resources/images/red-bird3.png").convert_alpha()
background2 = pygame.image.load(
"../resources/images/background3.png").convert_alpha()
sling_image = pygame.image.load(
"../resources/images/sling-3.png").convert_alpha()
full_sprite = pygame.image.load(
"../resources/images/full-sprite.png").convert_alpha()
rect = pygame.Rect(181, 1050, 50, 50)
cropped = full_sprite.subsurface(rect).copy()
pig_image = pygame.transform.scale(cropped, (30, 30))
buttons = pygame.image.load(
"../resources/images/selected-buttons.png").convert_alpha()
pig_happy = pygame.image.load(
"../resources/images/pig_failed.png").convert_alpha()
stars = pygame.image.load(
"../resources/images/stars-edited.png").convert_alpha()
rect = pygame.Rect(0, 0, 200, 200)
star1 = stars.subsurface(rect).copy()
rect = pygame.Rect(204, 0, 200, 200)
star2 = stars.subsurface(rect).copy()
rect = pygame.Rect(426, 0, 200, 200)
star3 = stars.subsurface(rect).copy()
rect = pygame.Rect(164, 10, 60, 60)
pause_button = buttons.subsurface(rect).copy()
rect = pygame.Rect(24, 4, 100, 100)
replay_button = buttons.subsurface(rect).copy()
rect = pygame.Rect(142, 365, 130, 100)
next_button = buttons.subsurface(rect).copy()
clock = pygame.time.Clock()
rect = pygame.Rect(18, 212, 100, 100)
play_button = buttons.subsurface(rect).copy()
clock = pygame.time.Clock()
running = True
# the base of the physics
space = pm.Space()
space.gravity = (0.0, -700.0)
pigs = []
birds = []
balls = []
polys = []
beams = []
columns = []
poly_points = []
ball_number = 0
polys_dict = {}
mouse_distance = 0
rope_lenght = 90
angle = 0
x_mouse = 0
y_mouse = 0
count = 0
mouse_pressed = False
t1 = 0
tick_to_next_circle = 10
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
sling_x, sling_y = 135, 450
sling2_x, sling2_y = 160, 450
score = 0
game_state = 0
bird_path = []
counter = 0
restart_counter = False
bonus_score_once = True
bold_font = pygame.font.SysFont("arial", 30, bold=True)
bold_font2 = pygame.font.SysFont("arial", 40, bold=True)
bold_font3 = pygame.font.SysFont("arial", 50, bold=True)
wall = False
# Static floor
static_body = pm.Body(body_type=pm.Body.STATIC)
static_lines = [pm.Segment(static_body, (0.0, 060.0), (1200.0, 060.0), 0.0)]
static_lines1 = [pm.Segment(static_body, (1200.0, 060.0), (1200.0, 800.0), 0.0)]
for line in static_lines:
line.elasticity = 0.95
line.friction = 1
line.collision_type = 3
for line in static_lines1:
line.elasticity = 0.