前言
🚀 作者 :“程序员梨子”
🚀 **文章简介 **:本篇文章主要讲解基于pyagme写的一款休闲小游戏。
🚀 **文章源码获取 **: 为了感谢每一个关注我的小可爱💓每篇文章的项目源码都是无偿分
享滴💓👇👇👇👇
点这里蓝色这行字体自取,需要什么源码记得说标题名字哈!私信我也可!
🚀 欢迎小伙伴们 点赞👍、收藏⭐、留言💬
正文
《泡泡乐》是一款适合全年龄玩家的游戏,采用非常经典的“泡泡龙”式的消除泡泡的玩法,游戏没
有太多创新玩法,容易上手。当我们一个人独处而无人聊天时可以用它来打发时间。来来来,跟
着小编一起开始玩游戏吧~
一、效果展示
游戏运行界面👆
同色三个即可消除👆
二、代码实现
import math, pygame, sys, os, copy, time, random
import pygame.gfxdraw
from pygame.locals import *
FPS = 120
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
TEXTHEIGHT = 20
BUBBLERADIUS = 20
BUBBLEWIDTH = BUBBLERADIUS * 2
BUBBLELAYERS = 5
BUBBLEYADJUST = 5
STARTX = WINDOWWIDTH / 2
STARTY = WINDOWHEIGHT - 27
ARRAYWIDTH = 16
ARRAYHEIGHT = 14
RIGHT = 'right'
LEFT = 'left'
BLANK = '.'
## COLORS ##
# R G B
GRAY = (100, 100, 100)
NAVYBLUE = ( 60, 60, 100)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
YELLOW = (255, 255, 0)
ORANGE = (255, 128, 0)
PURPLE = (255, 0, 255)
CYAN = ( 0, 255, 255)
BLACK = ( 0, 0, 0)
COMBLUE = (233, 232, 255)
BGCOLOR = WHITE
COLORLIST = [RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, CYAN]
class Bubble(pygame.sprite.Sprite):
def __init__(self, color, row=0, column=0):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(0, 0, 30, 30)
self.rect.centerx = STARTX
self.rect.centery = STARTY
self.speed = 10
self.color = color
self.radius = BUBBLERADIUS
self.angle = 0
self.row = row
self.column = column
def update(self):
if self.angle == 90:
xmove = 0
ymove = self.speed * -1
elif self.angle < 90:
xmove = self.xcalculate(self.angle)
ymove = self.ycalculate(self.angle)
elif self.angle > 90:
xmove = self.xcalculate(180 - self.angle) * -1
ymove = self.ycalculate(180 - self.angle)
self.rect.x += xmove
self.rect.y += ymove
def draw(self):
pygame.gfxdraw.filled_circle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, self.color)
pygame.gfxdraw.aacircle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, GRAY)
def xcalculate(self, angle):
radians = math.radians(angle)
xmove = math.cos(radians)*(self.speed)
return xmove
def ycalculate(self, angle):
radians = math.radians(angle)
ymove = math.sin(radians)*(self.speed) * -1
return ymove
class Arrow(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.angle = 90
arrowImage = pygame.image.load('Arrow.png')
arrowImage.convert_alpha()
arrowRect = arrowImage.get_rect()
self.image = arrowImage
self.transformImage = self.image
self.rect = arrowRect
self.rect.centerx = STARTX
self.rect.centery = STARTY
def update(self, direction):
if direction == LEFT and self.angle < 180:
self.angle += 2
elif direction == RIGHT and self.angle > 0:
self.angle -= 2
self.transformImage = pygame.transform.rotate(self.image, self.angle)
self.rect = self.transformImage.get_rect()
self.rect.centerx = STARTX
self.rect.centery = STARTY
def draw(self):
DISPLAYSURF.blit(self.transformImage, self.rect)
class Scor