Python+Pygame實現海洋之神大冒險遊戲

利用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

以上就是Python+Pygame實現海洋之神大冒險遊戲的詳細內容,更多關於Python Pygame遊戲的資料請關註WalkonNet其它相關文章!

推薦閱讀: