国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

跑酷游戲源代碼

這篇具有很好參考價(jià)值的文章主要介紹了跑酷游戲源代碼。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

import pygame, sys
import random

class Person(): ?# 人物
? ? def __init__(self, surf=None, y=None):
? ? ? ? self.surface = surf
? ? ? ? self.y = y ?# y坐標(biāo)
? ? ? ? self.w = (surf.get_width()) / 12 ?# 寬度
? ? ? ? self.h = surf.get_height() / 2 ?# 高度
? ? ? ? self.cur_frame = -1 ?# 當(dāng)前的運(yùn)動(dòng)狀態(tài)幀
? ? ? ? self.state = 0 ?# 0代表跑步狀態(tài),1代表跳躍狀態(tài),2代表連續(xù)跳躍
? ? ? ? self.gravity = 1 ?# 重力加速度
? ? ? ? self.velocity_y = 0 ?# y方向的速度
? ? ? ? self.vy_start = -20 ?# 起跳開(kāi)始速度

? ? def getPos(self): ? # 獲取當(dāng)前的位置信息,用于碰撞檢測(cè)
? ? ? ? return (0, self.y + 12, self.w, self.h)


class Obstacle(object): ?# 障礙物
? ? def __init__(self, surf, x=0, y=0):
? ? ? ? self.surface = surf
? ? ? ? self.x = x
? ? ? ? self.y = y
? ? ? ? self.w = surf.get_width()
? ? ? ? self.h = surf.get_height()
? ? ? ? self.cur_frame = random.randint(0, 6) ?# 隨機(jī)獲取一種障礙物的類型
? ? ? ? self.w = 100
? ? ? ? self.h = 100

? ? def getPos(self): ?# 當(dāng)前的坐標(biāo)信息
? ? ? ? return (self.x, self.y, self.w, self.h)

? ? def judgeCollision(self, rect1, rect2): ?# 碰撞檢測(cè)
? ? ? ? if (rect2[0] >= rect1[2] - 20) or (rect1[0] + 40 >= rect2[2]) or (rect1[1] + rect1[3] < rect2[1] + 20) or (
? ? ? ? ? ? ? ? rect2[1] + rect2[3] < rect1[1] + 20):
? ? ? ? ? ? return False
? ? ? ? return True


class BackGround(object): ?# 背景
? ? def __init__(self, surf):
? ? ? ? self.surface = surf ?# 初始化一個(gè)Surface 對(duì)象
? ? ? ? self.dx = -10
? ? ? ? self.w = surf.get_width() ? ?# 返回 Surface 對(duì)象的寬度,以像素為單位。
? ? ? ? self.rect = surf.get_rect() ?# 獲取 Surface 對(duì)象的矩形區(qū)域


class PaoKu(object):
? ? def __init__(self):
? ? ? ? pygame.init()
? ? ? ? pygame.mixer.init()

? ? ? ? self.width = 1200 ?# 窗口寬度
? ? ? ? self.height = 500 ?# 窗口高度
? ? ? ? self.size = (self.width, self.height)
? ? ? ? self.screen = pygame.display.set_mode(self.size)
? ? ? ? pygame.display.set_caption('跑酷運(yùn)動(dòng)')
? ? ? ? self.score = 0 ?# 分?jǐn)?shù)
? ? ? ? self.font1 = pygame.font.Font("resource/simkai.ttf", 32)
? ? ? ? self.font2 = pygame.font.Font("resource/simkai.ttf", 64) ?# 字體
? ? ? ? self.obstacle_pic = pygame.image.load("resource/obstacles.png").convert_alpha() ?# 障礙物圖片
? ? ? ? self.game_over = pygame.image.load("resource/gameover.bmp").convert_alpha() ?# 游戲結(jié)束圖片
? ? ? ? self.bg = BackGround(pygame.image.load("resource/bg.png").convert_alpha()) ?# 背景對(duì)象
? ? ? ? self.person = Person(pygame.image.load("resource/person.png").convert_alpha(), 500 - 85) ?# 人物對(duì)象
? ? ? ? self.screen.blit(self.bg.surface, [0, 0]) ?# 初始化游戲背景

? ? ? ? self.obstacle_list = [] ?# 障礙物對(duì)象數(shù)組
? ? ? ? self.game_state = 0 ?# 游戲狀態(tài),0表示游戲中,1表示游戲結(jié)束
? ? ? ? self.life = 3 ? ? ? ?# 初始的生命值
? ? ? ? self.clock = pygame.time.Clock() ?# 時(shí)鐘
? ? ? ? self.bg_music = pygame.mixer.Sound(r"resource\bgm.wav").play(-1, 0) ?# 循環(huán)播放北京音樂(lè)

? ? def startGame(self, screen): ? # 開(kāi)始游戲界面
? ? ? ? gameStart = pygame.image.load("resource/start1new.png")
? ? ? ? screen.blit(gameStart, (0, 0))
? ? ? ? font = pygame.font.SysFont("resource/simkai.ttf", 70)
? ? ? ? tip = font.render("Press Any Key To Start!, Press Esc To Quit", True, (65, 105, 225))
? ? ? ? screen.blit(tip, (self.width / 2 - 550, self.height / 2 + 150))
? ? ? ? pygame.display.update()
? ? ? ? while True:
? ? ? ? ? ? for event in pygame.event.get(): ?# 關(guān)閉窗口
? ? ? ? ? ? ? ? if event.type == pygame.QUIT:
? ? ? ? ? ? ? ? ? ? self.terminate()
? ? ? ? ? ? ? ? elif event.type == pygame.KEYDOWN:
? ? ? ? ? ? ? ? ? ? if (event.key == pygame.K_ESCAPE): ?# 按下ESC鍵
? ? ? ? ? ? ? ? ? ? ? ? self.terminate()
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? return
? ? def addObstacle(self): ? # 添加障礙物
? ? ? ? rate = 4
? ? ? ? # 是否生成障礙物
? ? ? ? if not random.randint(0, 300) < rate:
? ? ? ? ? ? return
? ? ? ? y = random.choice([self.height - 100, self.height - 200, self.height - 300, self.height - 400])
? ? ? ? obstacle = Obstacle(self.obstacle_pic, self.width + 40, y)
? ? ? ? self.obstacle_list.append(obstacle)
? ? # 監(jiān)聽(tīng)鍵盤事件,并做處理
? ? def ListenKeyBoard(self): ?# 鍵盤事件處理

? ? ? ? for event in pygame.event.get():
? ? ? ? ? ? if event.type == pygame.QUIT:
? ? ? ? ? ? ? ? sys.exit()
? ? ? ? ? ? elif event.type == pygame.KEYDOWN:
? ? ? ? ? ? ? ? # 空格鍵跳躍
? ? ? ? ? ? ? ? if self.game_state == 0:
? ? ? ? ? ? ? ? ? ? if event.key == pygame.K_SPACE:
? ? ? ? ? ? ? ? ? ? ? ? pygame.mixer.Sound(r"resource\jump.wav").play()
? ? ? ? ? ? ? ? ? ? ? ? if self.person.state == 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.person.state = 1
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.person.velocity_y = self.person.vy_start
? ? ? ? ? ? ? ? ? ? ? ? elif self.person.state == 1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.person.state = 2
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.person.velocity_y = self.person.vy_start
? ? ? ? ? ? ? ? elif self.game_state == 1:
? ? ? ? ? ? ? ? ? ? if event.key == pygame.K_RETURN: ? # 重新開(kāi)始游戲
? ? ? ? ? ? ? ? ? ? ? ? self.bg_music.stop()
? ? ? ? ? ? ? ? ? ? ? ? self.__init__()

? ? ? ? if self.game_state == 0:
? ? ? ? ? ? # BackGorund的運(yùn)動(dòng)
? ? ? ? ? ? self.bg.dx += 10
? ? ? ? ? ? if self.bg.dx == 1200:
? ? ? ? ? ? ? ? self.bg.dx = 0

? ? ? ? ? ? ? ? # Person的移動(dòng)
? ? ? ? ? ? if self.person.state == 0:
? ? ? ? ? ? ? ? self.person.cur_frame += 1
? ? ? ? ? ? ? ? if self.person.cur_frame == 12:
? ? ? ? ? ? ? ? ? ? self.person.cur_frame = 0
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.person.y += self.person.velocity_y
? ? ? ? ? ? ? ? self.person.velocity_y += self.person.gravity
? ? ? ? ? ? ? ? if self.person.y >= 500 - 85:
? ? ? ? ? ? ? ? ? ? self.person.y = 500 - 85
? ? ? ? ? ? ? ? ? ? self.person.state = 0
? ? ? ? ? ? # bstacle的操作
? ? ? ? ? ? self.addObstacle()

? ? ? ? ? ? for obstacle in self.obstacle_list:
? ? ? ? ? ? ? ? obstacle.x -= 10# obstacle向左移動(dòng)十個(gè)像素

? ? ? ? ? ? ? ? if obstacle.x + obstacle.w <= 0: ?# 當(dāng)obstacle離開(kāi)界面時(shí)
? ? ? ? ? ? ? ? ? ? self.obstacle_list.remove(obstacle)
? ? ? ? ? ? ? ? ? ? self.score += 10 ?# 避開(kāi)obstacle,加10分
? ? ? ? ? ? ? ? if obstacle.judgeCollision(self.person.getPos(), obstacle.getPos()): ?# 碰撞檢測(cè)
? ? ? ? ? ? ? ? ? ? if obstacle.cur_frame == 6:
? ? ? ? ? ? ? ? ? ? ? ? self.obstacle_list.remove(obstacle)
? ? ? ? ? ? ? ? ? ? ? ? self.score += 100 ?# 吃金幣加100分
? ? ? ? ? ? ? ? ? ? ? ? coin_sound = pygame.mixer.Sound(
? ? ? ? ? ? ? ? ? ? ? ? ? ? r"resource/coin.wav")
? ? ? ? ? ? ? ? ? ? ? ? coin_sound.play()
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ?self.life -= 1
? ? ? ? ? ? ? ? ? ? ? ?self.obstacle_list.remove(obstacle)
? ? ? ? ? ? ? ? ? ? ? ?if self.life <= 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.game_state = 1 ?# 游戲失敗
? ? ? ? ? ? ? ? ? ? ? ?die_sound = pygame.mixer.Sound(
? ? ? ? ? ? ? ? ? ? ? ? ? ?r"resource\die.wav") ?# 添加碰撞之后產(chǎn)生的音效
? ? ? ? ? ? ? ? ? ? ? ?die_sound.play()
? ? # 更新顯示界面
? ? def updateScreen(self, screen):
? ? ? ? ? ? screen.blit(self.bg.surface, [-self.bg.dx, 0]) ?# 背景的貼圖
? ? ? ? ? ? screen.blit(self.bg.surface, [1200 - self.bg.dx, 0])
? ? ? ? ? ? text = self.font1.render("score:%d" % self.score, True, (128, 128, 128)) ?# 分?jǐn)?shù)的貼圖
? ? ? ? ? ? screen.blit(text, (500, 20))
? ? ? ? ? ? del text
? ? ? ? ? ? rest_life = self.font1.render("life:%d" % self.life, True, (128, 128, 128)) ?# 剩余生命
? ? ? ? ? ? screen.blit(rest_life, (400, 20))
? ? ? ? ? ? del rest_life
? ? ? ? ? ? screen.blit(self.person.surface, [0, self.person.y], [int(self.person.cur_frame) * self.person.w, 0, self.person.w, self.person.h]) ?# 人物的貼圖
? ? ? ? ? ? for obstacle in self.obstacle_list: ?# 障礙物的貼圖
? ? ? ? ? ? ? ? screen.blit(obstacle.surface, [obstacle.x, obstacle.y],
? ? ? ? ? ? ? ? ? ? ? ? ? ? [int(obstacle.cur_frame) * obstacle.w, 0, obstacle.w, obstacle.h])
? ? # 判斷游戲的狀態(tài)
? ? def judgeState(self, screen):
? ? ? ? if self.game_state == 0:
? ? ? ? ? ? self.updateScreen(screen)
? ? ? ? ? ? return
? ? ? ? elif self.game_state == 1:
? ? ? ? ? ? screen.blit(self.game_over, [0, 0])
? ? ? ? ? ? text = self.font1.render("GameOver Score:%d ?Press Enter to restart" % self.score, True, (255, 0, 0))
? ? ? ? ? ? screen.blit(text, (self.width / 2 - 350, self.height / 2 + 150))
? ? # 游戲結(jié)束
? ? def terminate(self):
? ? ? ? pygame.quit()
? ? ? ? sys.exit()

? ? # 游戲主入口函數(shù)
? ? def main(self):
? ? ? ? self.startGame(self.screen)
? ? ? ? while True:
? ? ? ? ? ? self.clock.tick(40) ?# 設(shè)置時(shí)鐘頻率
? ? ? ? ? ? self.judgeState(self.screen)
? ? ? ? ? ? self.ListenKeyBoard()
? ? ? ? ? ? pygame.display.flip()

if __name__ == '__main__':
? ? paoku = PaoKu()
? ? paoku.main()

素材包:跑酷游戲源代碼

person

跑酷游戲源代碼?start1new

跑酷游戲源代碼startgame1?

跑酷游戲源代碼?

?startgame2

跑酷游戲源代碼
bg

跑酷游戲源代碼?gameover

跑酷游戲源代碼?

?obstacles文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-471457.html

到了這里,關(guān)于跑酷游戲源代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • python簡(jiǎn)單小游戲代碼教程,python小游戲程序源代碼

    python簡(jiǎn)單小游戲代碼教程,python小游戲程序源代碼

    大家好,小編來(lái)為大家解答以下問(wèn)題,python簡(jiǎn)單小游戲代碼教程,python小游戲程序源代碼,今天讓我們一起來(lái)看看吧! 哈嘍鐵子們 表弟最近在學(xué)Python,總是跟我抱怨很枯燥無(wú)味,其實(shí),他有沒(méi)有認(rèn)真想過(guò),可能是自己學(xué)習(xí)姿勢(shì)不對(duì)? 比方說(shuō),可以通過(guò)打游戲來(lái)學(xué)編程! 今天

    2024年02月02日
    瀏覽(97)
  • Python背單詞記單詞小程序源代碼,背單詞記單詞小游戲源代碼

    Python背單詞記單詞小程序源代碼,背單詞記單詞小游戲源代碼

    背單詞小游戲,要有多界面交互,界面整潔、美觀,可調(diào)節(jié)游戲等級(jí)難度,可配置游戲信息。 有游戲分?jǐn)?shù),游戲時(shí)間,動(dòng)畫特效,背景音樂(lè),不同游戲等級(jí)的歷史最高分記錄。 拼寫成功的英文單詞顯示中文意思。支持長(zhǎng)按回刪鍵[backspace],快速刪除單詞字母。 多種游戲困難

    2024年02月15日
    瀏覽(95)
  • python簡(jiǎn)單小游戲代碼100行,python小游戲程序源代碼

    python簡(jiǎn)單小游戲代碼100行,python小游戲程序源代碼

    大家好,本文將圍繞python簡(jiǎn)單小游戲代碼100行展開(kāi)說(shuō)明,python小游戲代碼能用的是一個(gè)很多人都想弄明白的事情,想搞清楚python小游戲程序源代碼需要先了解以下幾個(gè)事情。 這次用Python實(shí)現(xiàn)的是一個(gè)接球打磚塊的小游戲,需要導(dǎo)入pygame模塊,有以下兩條經(jīng)驗(yàn)總結(jié): 1.多父類的

    2024年02月06日
    瀏覽(98)
  • python簡(jiǎn)單小游戲代碼200行,用python寫小游戲源代碼

    python簡(jiǎn)單小游戲代碼200行,用python寫小游戲源代碼

    大家好,小編來(lái)為大家解答以下問(wèn)題,python簡(jiǎn)單小游戲代碼200行,用python寫小游戲源代碼,現(xiàn)在讓我們一起來(lái)看看吧! Source code download: 本文相關(guān)源碼 大家好,本文將圍繞python簡(jiǎn)單小游戲代碼100行展開(kāi)說(shuō)明,python小游戲代碼能用的是一個(gè)很多人都想弄明白的事情,想搞清楚

    2024年02月21日
    瀏覽(98)
  • Python游戲開(kāi)發(fā)--外星人入侵(源代碼)

    Python游戲開(kāi)發(fā)--外星人入侵(源代碼)

    最近學(xué)習(xí)的python第一個(gè)項(xiàng)目實(shí)戰(zhàn),《外星人入侵》,成功實(shí)現(xiàn)所有功能,給大家提供源代碼 環(huán)境安裝:python 3.7+ pygame 安裝 pygame 或者 先展示效果,消滅外星人,有三條命,按Q是退出全屏,空格鍵是子彈,按下play鍵開(kāi)始游戲,擊敗外星人飛船會(huì)有積分加,三條命之后需要點(diǎn)擊

    2024年02月06日
    瀏覽(96)
  • Python制作的賽車小游戲源代碼,逆行飆車

    Python制作的賽車小游戲源代碼,逆行飆車

    python制作的賽車小游戲,逆行飆車,通過(guò)鍵盤方向鍵控制 程序運(yùn)行截圖: 源代碼 完整賽車小游戲下載:賽車小游戲源代碼 Python代碼大全,海量代碼任你下載

    2024年02月12日
    瀏覽(96)
  • Java基礎(chǔ)階段項(xiàng)目 ---- 拼圖游戲(含講解以及源代碼)

    Java基礎(chǔ)階段項(xiàng)目 ---- 拼圖游戲(含講解以及源代碼)

    此項(xiàng)目為java基礎(chǔ)的階段項(xiàng)目,此項(xiàng)目涉及了基礎(chǔ)語(yǔ)法,面向?qū)ο蟮戎R(shí),具體像語(yǔ)法基礎(chǔ)如判斷,循環(huán),數(shù)組,字符串,集合等…; 面向?qū)ο笕绶庋b,繼承,多態(tài),抽象類,接口,內(nèi)部類等等…都有涉及。此項(xiàng)目涉及的內(nèi)容比較多,作為初學(xué)者可以很好的將前面的知識(shí)串起來(lái)。此項(xiàng)目拿來(lái)練手以

    2024年02月09日
    瀏覽(22)
  • python版大富翁游戲源代碼,自己實(shí)現(xiàn)自己玩~

    python版大富翁游戲源代碼,自己實(shí)現(xiàn)自己玩~

    本文實(shí)例為大家分享了python版大富翁游戲的具體代碼,供大家參考,具體內(nèi)容如下: 關(guān)于Python技術(shù)儲(chǔ)備 學(xué)好 Python 不論是就業(yè)還是做副業(yè)賺錢都不錯(cuò),但要學(xué)會(huì) Python 還是要有一個(gè)學(xué)習(xí)規(guī)劃。最后大家分享一份全套的 Python 學(xué)習(xí)資料,給那些想學(xué)習(xí) Python 的小伙伴們一點(diǎn)幫助!

    2024年01月16日
    瀏覽(14)
  • Java實(shí)現(xiàn)俄羅斯方塊小游戲。(附完整源代碼)

    Java實(shí)現(xiàn)俄羅斯方塊小游戲。(附完整源代碼)

    大家好,我是百思不得小趙。 創(chuàng)作時(shí)間:2022 年 5 月 12 日 博客主頁(yè): ??點(diǎn)此進(jìn)入博客主頁(yè) —— 新時(shí)代的農(nóng)民工 ?? —— 換一種思維邏輯去看待這個(gè)世界 ?? 今天是加入CSDN的第1167天。覺(jué)得有幫助麻煩??點(diǎn)贊、??評(píng)論、??收藏 目錄 一、游戲背景 二、功能實(shí)現(xiàn) 三、效果

    2024年02月03日
    瀏覽(92)
  • ASP.NET猜數(shù)游戲的設(shè)計(jì)與開(kāi)發(fā)(源代碼+論文)

    隨著科學(xué)技術(shù)和精神生活的不斷提高,人們?cè)絹?lái)越多的熱衷于猜數(shù)游戲這類小型休閑益智型游戲。它利用其簡(jiǎn)單的操作方式及邏輯有趣的游戲過(guò)程吸引著眾多玩家。本次課題設(shè)計(jì)的即一款界面簡(jiǎn)潔、大方,休閑有趣的小型猜數(shù)游戲系統(tǒng)。本系統(tǒng)采用Microsoft Visual Studio.NET 2003開(kāi)

    2024年02月07日
    瀏覽(15)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包