亲宝软件园·资讯

展开

Python Pygame游戏

Retr0_Mich 人气:0

利用pygame自制小游戏。

海洋之神在漆黑的海底深处,利用自身的光勇敢前进!在海里收集鱼骨头,有些鱼骨头可以转化为武器,用来攻击敌人。

开始:

游戏开始的界面:

快通关啦!

结尾致敬超级马里奥,碰到小蘑菇就可以去下一关冒险!

海底背景自己画的,按钮图案自己画的,通关蘑菇自己画的。 

特效代码

import pygame
import random
import sys
import time
 
pygame.init()
clock = pygame.time.Clock()
 
win = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Particles")
 
particles = []
colors = [(255, 255,250), (235, 65, 54), (255, 69, 0)]
 
 
class Particle():
    def __init__(self, x, y, xvel, yvel, radius, color, gravity=None):
        self.x = x
        self.y = y
        self.xvel = xvel
        self.yvel = yvel
        self.radius = radius
        self.color = color
        self.gravity = gravity
 
    def render(self, win):
        self.x += self.xvel
        self.y += self.yvel
        if self.gravity != None:
            self.yvel += self.gravity
        self.radius -= 0.1
 
        pygame.draw.circle(win, self.color, (self.x, self.y), self.radius)
 
 
 
def DrawParticles():
    for particle in particles:
        particle.render(win)
        if particle.radius <= 0:
            particles.remove(particle)
 
 
 
while True:
    clock.tick(60)
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
 
    for x in range(random.randint(5, 20)):
        particle = Particle(pos[0], pos[1], random.randint(-100, 0) / 10, random.randint(1, 3), random.randint(2, 5),
                            random.choice(colors))
        particles.append(particle)
 
    win.fill((0, 0, 0))
    DrawParticles()
    pygame.display.update()

Credits:

游戏主角形象 :Cute Girl - Free Sprites | OpenGameArt.org

地图编辑器参考:https://github.com/russs123/LevelEditor

Fish Pack:

Gunner - Animated Character by Secret Hideout

Fantasy Game Music | Soundimage.org

Bullet Whizzing By Sounds | Effects | Sound Bites | Sound Clips from SoundBible.com

加载全部内容

相关教程
猜你喜欢
用户评论