| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 183 人关注过本帖
标题:python -- 游戏项目 --- 战斗精英 // www.python.org
只看楼主 加入收藏
th257513971
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-4-11
收藏
 问题点数:0 回复次数:3 
python -- 游戏项目 --- 战斗精英 // www.python.org
战斗精英 python环境开放 第三方软件开放pycharm 是一个自主类开放游戏,此项目是给大家提供环境资源, 源码如下:

import pygame
import random

class Player1(pygame.sprite.Sprite):
    def __init__(self,screen,speed = 8):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/player1.png")
        self.rect = self.image.get_rect()
        self.speed = speed
        self.rect.topleft = [0, 428]
        self.screen = screen
        self.bullets = pygame.sprite.Group()
    def display(self):
        self.screen.blit(self.image, self.rect)
    def move(self):
        key = pygame.key.get_pressed()
        if key[pygame.K_a]:
            if self.rect.left <= 0:
                self.rect.left = 0
            else:
                self.rect.left -= self.speed
        if key[pygame.K_d]:
            if self.rect.right >= 1177:
                self.rect.right = 1177
            else:
                self.rect.right += self.speed
        if key[pygame.K_j]:
            bullet = Bullet2(self.screen, self.rect.right - 10, self.rect.top + 60)
            self.bullets.add(bullet)

    def update(self):
        self.display()
        self.move()
        self.bullets.update()
        self.bullets.draw(self.screen)
class Player2(pygame.sprite.Sprite):
    def __init__(self,screen,speed = 8):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/player2.png")
        self.rect = self.image.get_rect()
        self.speed = speed
        self.rect.topleft = [1089, 428]
        self.screen = screen
        self.bullets = pygame.sprite.Group()
    def display(self):
        self.screen.blit(self.image, self.rect)
    def move(self):
        key = pygame.key.get_pressed()
        pygame.key.get_repeat()
        if key[pygame.K_LEFT]:
            if self.rect.left <= 0:
                self.rect.left = 0
            else:
                self.rect.left -= self.speed
        if key[pygame.K_RIGHT]:
            if self.rect.right >= 1177:
                self.rect.right = 1177
            else:
                self.rect.right += self.speed
        if key[pygame.K_KP0]:
            bullet = Bullet1(self.screen, self.rect.left - 10, self.rect.top + 60)
            self.bullets.add(bullet)
    def update(self):
        self.display()
        self.move()
        self.bullets.update()
        self.bullets.draw(self.screen)
class Bullet1(pygame.sprite.Sprite):
    def __init__(self,screen,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/bullet.png")
        self.rect = self.image.get_rect()
        self.rect.topleft = [x, y]
        self.screen = screen
        self.speed = 10
    def display(self):
        self.screen.blit(self.image, self.rect)
    def move(self):
        if self.rect.left <= 0:
            self.kill()
        else:
            self.rect.left -= self.speed
    def update(self):
        self.display()
        self.move()
class Bullet2(pygame.sprite.Sprite):
    def __init__(self,screen,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/bullet.png")
        self.rect = self.image.get_rect()
        self.rect.topleft = [x, y]
        self.screen = screen
        self.speed = 10
    def display(self):
        self.screen.blit(self.image, self.rect)
    def move(self):
        if self.rect.right >= 1177:
            self.kill()
        else:
            self.rect.right += self.speed
    def update(self):
        self.display()
        self.move()
class Orint(pygame.sprite.Sprite):
    def __init__(self,screen):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/orint.png")
        self.rect = self.image.get_rect()
        self.rect.top = 8000
        self.screen = screen
        self.life = 200
    def update(self):
        self.screen.blit(self.image, self.rect)
def main():
    pygame.init()
    pygame.mixer.init()
    bg_music = pygame.mixer.Sound("./Sound/bg_music.mp3")
    bg_music.play(-1)
    bg_music.set_volume(0.3)
    RECT = x, y = 1177, 571
    bg_RECT = x, y = 0, 0
    background = pygame.image.load("./images/background.png")
    screen = pygame.display.set_mode(RECT)
    player1 = Player1(screen)
    player2 = Player2(screen)
    orint1 = Orint(screen)
    orint2 = Orint(screen)
    orint1_life = 200
    orint2_life = 200
    life_player1 = 500
    life_player2 = 500
    victory_player1 = 0
    victory_player2 = 0
    Fonts = pygame.font.Font("./Font/msyh.ttf", 24)
    clock = pygame.time.Clock()
    pygame.display.set_caption("战斗精英 --- GaMeGame官方独家推出 --- 官方www. 目标_pygame_")
    run = True
    while run:
        player1_font = Fonts.render("红方生命数 :%s"%life_player1, True, (255, 0, 0), (0, 0 ,255))
        player2_font = Fonts.render("蓝方得分数 :%s"%life_player2, True, (0, 255, 255), (0, 0, 255))
        player1_good = Fonts.render("红方胜利数 :%s"%victory_player1, True, (255, 0, 0), (0, 0 , 255))
        player2_good = Fonts.render("红方胜利数 :%s"%victory_player2, True, (0, 255, 255), (0, 0, 255))
        orint1_font = Fonts.render("红方防御盾指数 :%s"%orint1_life, True, (255, 0, 0), (0, 0, 255))
        orint2_font = Fonts.render("蓝方防御盾指数 :%s"%orint2_life, True, (0, 255, 255), (0, 0, 255))
        TiShi = Fonts.render("按下 -- 空格键 -- 重新开始游戏", True, (0, 255, 0), (0, 0, 255))
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_k:
                    orint1.rect.right = player1.rect.right + 76
                    orint1.rect.top = 428
                if event.key == pygame.K_KP1:
                    orint2.rect.right = player2.rect.left - 10
                    orint2.rect.top = 428
                if event.key == pygame.K_SPACE:
                    player1.bullets.remove(player1.bullets.spritedict)
                    player2.bullets.remove(player2.bullets.spritedict)
                    player1.rect.top = 428
                    player1.rect.left = 0
                    player2.rect.top = 428
                    player2.rect.left = 1089
                    orint1.rect.top = 8000
                    orint2.rect.top = 8000
                    life_player1 = 500
                    life_player2 = 500

        if pygame.sprite.spritecollide(orint1, player2.bullets, True):
            print(orint1_life)
            orint1_life -= 1

        if pygame.sprite.spritecollide(orint2, player1.bullets, True):
            print(orint2_life)
            orint2_life -= 1

        if pygame.sprite.spritecollide(player1, player2.bullets, True):
            print(life_player1)
            life_player1 -= 1
            if life_player1 <= 0:
                player1.bullets.remove(player1.bullets.spritedict)
                player2.bullets.remove(player2.bullets.spritedict)
                player1.rect.top = 428
                player1.rect.left = 0
                player2.rect.top = 428
                player2.rect.left = 1089
                orint1.rect.top = 8000
                orint2.rect.top = 8000
                life_player1 = 500
                life_player2 = 500
                victory_player2 += 1

        if pygame.sprite.spritecollide(player2, player1.bullets, True):
            print(life_player2)
            life_player2 -= 1
            if life_player2 <= 0:
                player1.bullets.remove(player1.bullets.spritedict)
                player2.bullets.remove(player2.bullets.spritedict)
                player1.rect.top = 428
                player1.rect.left = 0
                player2.rect.top = 428
                player2.rect.left = 1089
                orint1.rect.top = 8000
                orint2.rect.top = 8000
                life_player1 = 500
                life_player2 = 500
                victory_player1 += 1

        if orint1_life <= 0:
            orint1.rect.top = 8000
            orint1_life += 0.5
            print(orint1_life)
        if orint1_life >= 0:
            if orint1_life < 200:
                orint1_life += 0.5
                print(orint1_life)
            elif orint1_life >= 200:
                orint1_life = 200

        if orint2_life <= 0:
            orint2.rect.top = 8000
            orint2_life += 0.5
            print(orint2_life)
        if orint2_life >= 0:
            if orint2_life < 200:
                orint2_life += 0.5
                print(orint2_life)
            elif orint2_life >= 200:
                orint2_life = 200

        screen.blit(background, (bg_RECT))
        player1.update()
        player2.update()
        screen.blit(player1_font, (0, 0))
        screen.blit(player2_font, (1005, 0))
        screen.blit(player1_good, (0, 50))
        screen.blit(player2_good, (1005, 50))
        screen.blit(orint1_font, (0, 85))
        screen.blit(orint2_font, (950, 85))
        screen.blit(TiShi, (450, 0))
        orint1.update()
        orint2.update()
        pygame.display.update()



if __name__ == '__main__':
    main()

------

素材暂时无法公布,但以上源码可能会帮助你做游戏开发的
搜索更多相关主题的帖子: top screen image pygame if 
2021-04-11 21:03
th257513971
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-4-11
收藏
得分:0 
需要帮助请请在周6或周日来询问我
2021-04-11 21:06
Simple凯
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-4-24
收藏
得分:0 
2021-04-24 14:16
sssooosss
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:238
专家分:594
注 册:2019-8-27
收藏
得分:0 
这是。。。
2021-04-27 10:31
快速回复:python -- 游戏项目 --- 战斗精英 // www.python.org
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.347531 second(s), 8 queries.
Copyright©2004-2021, BCCN.NET, All Rights Reserved