摘要:嗷大喵和他的小伙伴們快樂的生活在一起,他們總是能給大家?guī)須g樂。大家都說嗷大喵真棒。大家要做的就是解救嗷大喵遠(yuǎn)離惡龍。
哈嘍~大家好,我是木子,首先今天木子先給大家講個(gè)小故事:
在喵界有這樣一只網(wǎng)紅——混跡于二次元、表情包界,賤萌活潑,調(diào)皮機(jī)靈,白色的大圓臉,脖子
上系了個(gè)鈴鐺,年齡不詳,傳說可于兒童、少年、青年間隨意切換。
他的歡樂日常帶給了很多人溫暖和爆笑,他的樂觀積極也是很多人治療傷心難過空虛寂寞冷綜合癥
的良方,他就是——嗷大喵!
?
嗷大喵資料:是一位開朗、樂觀、熱情奔放、溫暖人心的喵星人。他靜如癱瘓,動(dòng)如癲癇,喜歡的
事情是吃和睡,他的直率和可愛還經(jīng)常被人誤以為是神經(jīng)病呢。
嗷大喵和他的小伙伴們快樂的生活在一起,他們總是能給大家?guī)須g樂。大家都說:“嗷大喵真
棒!”。?
...........................................................................................................................................................
介紹到這里就差不多了哈,今天要寫的小游戲也跟嗷大喵有關(guān)的呢~
利用這個(gè)“網(wǎng)紅”ip打造出一個(gè)獨(dú)一無二的嗷大喵表情包小游戲給大家解解乏哦~上班摸魚也可以.jpg
...........................................................................................................................................................
背景音樂:(可修改)
圖片素材:(可修改)
嗷大喵遇險(xiǎn)記:嗷大喵即玩家,遭遇飛機(jī)失聯(lián),一貓?獨(dú)自掉落到無人居住的荒島,好在荒島上
資源充足,嗷大喵一個(gè)貓生存了下來,某一天嗷大喵追趕一只奇奇怪怪的生物,跑到了一個(gè)很高的
洞口,好奇心驅(qū)使嗷大喵緊張的走進(jìn)了洞穴,不料想一進(jìn)洞就遇到了一只傳說中的惡龍,嗷大喵嚇
得只好趕緊跑出洞外——自此一直被惡龍追趕......
Over ,咳咳咳......兒童故事就聽到這里吧。大家要做的就是解救嗷大喵~遠(yuǎn)離惡龍。
玩法:按住空格躲避惡龍的火焰,擊中的話會(huì)減速,然后被惡龍吃掉。
環(huán)境:Python3、Pycharm、Pygame以及一些自帶模塊。
這里模塊安裝命令:
pip install +模塊名 或者豆瓣鏡像源 pip install -i https://pypi.douban.com/simple/ +模塊名
# -*- coding: utf-8 -*-import pygamefrom sys import exitfrom pygame.locals import *pygame.init()screen = pygame.display.set_mode((300,200),0,32)upImageFilename = "game_start_up.png"downImageFilename = "game_start_down.png"class Button(object): def __init__(self, upimage, downimage,position): self.imageUp = pygame.image.load(upimage).convert_alpha() self.imageDown = pygame.image.load(downimage).convert_alpha() self.position = position def isOver(self): point_x,point_y = pygame.mouse.get_pos() x, y = self. position w, h = self.imageUp.get_size() in_x = x - w/2 < point_x < x + w/2 in_y = y - h/2 < point_y < y + h/2 return in_x and in_y def render(self): w, h = self.imageUp.get_size() x, y = self.position if self.isOver(): screen.blit(self.imageDown, (x-w/2,y-h/2)) else: screen.blit(self.imageUp, (x-w/2, y-h/2)) def is_start(self): b1,b2,b3 = pygame.mouse.get_pressed() if b1 == 1: return Truebutton = Button(upImageFilename,downImageFilename, (150,100)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() screen.fill((200, 200, 200)) button.render() if button.is_start(): print ("start") pygame.display.update()
3.11 附效果截圖
# -*- coding: utf-8 -*-import sys, time, random, math, pygame,localefrom pygame.locals import *from MyLibrary import *#重置火箭函數(shù)def reset_arrow(): y = random.randint(270,350) arrow.position = 800,y bullent_sound.play_sound()#定義一個(gè)滾動(dòng)地圖類class MyMap(pygame.sprite.Sprite): def __init__(self,x,y): self.x = x self.y = y self.bg = pygame.image.load("background.png").convert_alpha() def map_rolling(self): if self.x < -600: self.x = 600 else: self.x -=5 def map_update(self): screen.blit(self.bg, (self.x,self.y)) def set_pos(x,y): self.x =x self.y =y#定義一個(gè)按鈕類class Button(object): def __init__(self, upimage, downimage,position): self.imageUp = pygame.image.load(upimage).convert_alpha() self.imageDown = pygame.image.load(downimage).convert_alpha() self.position = position self.game_start = False def isOver(self): point_x,point_y = pygame.mouse.get_pos() x, y = self. position w, h = self.imageUp.get_size() in_x = x - w/2 < point_x < x + w/2 in_y = y - h/2 < point_y < y + h/2 return in_x and in_y def render(self): w, h = self.imageUp.get_size() x, y = self.position if self.isOver(): screen.blit(self.imageDown, (x-w/2,y-h/2)) else: screen.blit(self.imageUp, (x-w/2, y-h/2)) def is_start(self): if self.isOver(): b1,b2,b3 = pygame.mouse.get_pressed() if b1 == 1: self.game_start = True bg_sound.play_pause() btn_sound.play_sound() bg_sound.play_sound()def replay_music(): bg_sound.play_pause() bg_sound.play_sound()#定義一個(gè)數(shù)據(jù)IO的方法def data_read(): fd_1 = open("data.txt","r") best_score = fd_1.read() fd_1.close() return best_score #定義一個(gè)控制聲音的類和初始音頻的方法def audio_init(): global hit_au,btn_au,bg_au,bullent_au pygame.mixer.init() hit_au = pygame.mixer.Sound("exlposion.wav") btn_au = pygame.mixer.Sound("button.wav") bg_au = pygame.mixer.Sound("background.ogg") bullent_au = pygame.mixer.Sound("bullet.wav")class Music(): def __init__(self,sound): self.channel = None self.sound = sound def play_sound(self): self.channel = pygame.mixer.find_channel(True) self.channel.set_volume(0.5) self.channel.play(self.sound) def play_pause(self): self.channel.set_volume(0.0) self.channel.play(self.sound) #主程序部分pygame.init()audio_init()screen = pygame.display.set_mode((800,600),0,32)pygame.display.set_caption("嗷大喵快跑!")font = pygame.font.Font(None, 22)font1 = pygame.font.Font(None, 40)framerate = pygame.time.Clock()upImageFilename = "game_start_up.png"downImageFilename = "game_start_down.png"#創(chuàng)建按鈕對(duì)象button = Button(upImageFilename,downImageFilename, (400,500))interface = pygame.image.load("interface.png")#創(chuàng)建地圖對(duì)象bg1 = MyMap(0,0)bg2 = MyMap(600,0)#創(chuàng)建一個(gè)精靈組group = pygame.sprite.Group()group_exp = pygame.sprite.Group()group_fruit = pygame.sprite.Group()#創(chuàng)建怪物精靈dragon = MySprite()dragon.load("dragon.png", 260, 150, 3)dragon.position = 100, 230group.add(dragon)#創(chuàng)建爆炸動(dòng)畫explosion = MySprite()explosion.load("explosion.png",128,128,6)#創(chuàng)建玩家精靈player = MySprite()player.load("sprite.png", 100, 100, 4)player.position = 400, 270group.add(player)#創(chuàng)建子彈精靈arrow = MySprite()arrow.load("flame.png", 40, 16, 1)arrow.position = 800,320group.add(arrow)#定義一些變量arrow_vel = 10.0game_over = Falseyou_win = Falseplayer_jumping = Falsejump_vel = 0.0player_start_y = player.Yplayer_hit = Falsemonster_hit = Falsep_first = Truem_first = Truebest_score = 0global bg_sound,hit_sound,btn_sound,bullent_soundbg_sound=Music(bg_au)hit_sound=Music(hit_au)btn_sound=Music(btn_au)bullent_sound =Music(bullent_au)game_round = {1:"ROUND ONE",2:"ROUND TWO",3:"ROUND THREE",4:"ROUND FOUR",5:"ROUND FIVE"}game_pause = Trueindex =0current_time = 0start_time = 0music_time = 0score =0replay_flag = True#循環(huán)bg_sound.play_sound()best_score = data_read()while True: framerate.tick(60) ticks = pygame.time.get_ticks() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() keys = pygame.key.get_pressed() if keys[K_ESCAPE]: pygame.quit() sys.exit() elif keys[K_SPACE]: if not player_jumping: player_jumping = True jump_vel = -12.0 screen.blit(interface,(0,0)) button.render() button.is_start() if button.game_start == True: if game_pause : index +=1 tmp_x =0 if score >int (best_score): best_score = score fd_2 = open("data.txt","w+") fd_2.write(str(best_score)) fd_2.close() #判斷游戲是否通關(guān) if index == 6: you_win = True if you_win: start_time = time.clock() current_time =time.clock()-start_time while current_time<5: screen.fill((200, 200, 200)) print_text(font1, 270, 150,"YOU WIN THE GAME!",(240,20,20)) current_time =time.clock()-start_time print_text(font1, 320, 250, "Best Score:",(120,224,22)) print_text(font1, 370, 290, str(best_score),(255,0,0)) print_text(font1, 270, 330, "This Game Score:",(120,224,22)) print_text(font1, 385, 380, str(score),(255,0,0)) pygame.display.update() pygame.quit() sys.exit() for i in range(0,100): element = MySprite() element.load("fruit.bmp", 75, 20, 1) tmp_x +=random.randint(50,120) element.X = tmp_x+300 element.Y = random.randint(80,200) group_fruit.add(element) start_time = time.clock() current_time =time.clock()-start_time while current_time<3: screen.fill((200, 200, 200)) print_text(font1, 320, 250,game_round[index],(240,20,20)) pygame.display.update() game_pause = False current_time =time.clock()-start_time else: #更新子彈 if not game_over: arrow.X -= arrow_vel if arrow.X < -40: reset_arrow() #碰撞檢測,子彈是否擊中玩家 if pygame.sprite.collide_rect(arrow, player): reset_arrow() explosion.position =player.X,player.Y player_hit = True hit_sound.play_sound() if p_first: group_exp.add(explosion) p_first = False player.X -= 10 #碰撞檢測,子彈是否擊中怪物 if pygame.sprite.collide_rect(arrow, dragon): reset_arrow() explosion.position =dragon.X+50,dragon.Y+50 monster_hit = True hit_sound.play_sound() if m_first: group_exp.add(explosion) m_first = False dragon.X -= 10 #碰撞檢測,玩家是否被怪物追上 if pygame.sprite.collide_rect(player, dragon): game_over = True #遍歷果實(shí),使果實(shí)移動(dòng) for e in group_fruit: e.X -=5 collide_list = pygame.sprite.spritecollide(player,group_fruit,False) score +=len(collide_list) #是否通過關(guān)卡 if dragon.X < -100: game_pause = True reset_arrow() player.X = 400 dragon.X = 100 #檢測玩家是否處于跳躍狀態(tài) if player_jumping: if jump_vel <0: jump_vel += 0.6 elif jump_vel >= 0: jump_vel += 0.8 player.Y += jump_vel if player.Y > player_start_y: player_jumping = False player.Y = player_start_y jump_vel = 0.0 #繪制背景 bg1.map_update() bg2.map_update() bg1.map_rolling() bg2.map_rolling() #更新精靈組 if not game_over: group.update(ticks, 60) group_exp.update(ticks,60) group_fruit.update(ticks,60) #循環(huán)播放背景音樂 music_time = time.clock() if music_time > 150 and replay_flag: replay_music() replay_flag =False #繪制精靈組 group.draw(screen) group_fruit.draw(screen) if player_hit or monster_hit: group_exp.draw(screen) print_text(font, 330, 560, "press SPACE to jump up!") print_text(font, 200, 20, "You have get Score:",(219,224,22)) print_text(font1, 380, 10, str(score),(255,0,0)) if game_over: start_time = time.clock() current_time =time.clock()-start_time while current_time<5: screen.fill((200, 200, 200)) print_text(font1, 300, 150,"GAME OVER!",(240,20,20)) current_time =time.clock()-start_time print_text(font1, 320, 250, "Best Score:",(120,224,22)) if score >int (best_score): best_score = score print_text(font1, 370, 290, str(best_score),(255,0,0)) print_text(font1, 270, 330, "This Game Score:",(120,224,22)) print_text(font1, 370, 380, str(score),(255,0,0)) pygame.display.update() fd_2 = open("data.txt","w+") fd_2.write(str(best_score)) fd_2.close() pygame.quit() sys.exit() pygame.display.update()
嗷大喵歷險(xiǎn)記~
?
?
萌萌的嗷大喵能不能逃離惡龍的追擊,就看你們了哈~
噗~哈哈哈 咋感覺我最近的畫風(fēng)有點(diǎn)兒不對(duì),都是一些奇奇怪怪可可愛愛的兒童畫風(fēng)!
如需完整的項(xiàng)目源碼+素材源碼基地見:#私信小編06#或者點(diǎn)擊藍(lán)色文字添加即可獲取免費(fèi)的福利!
你們的支持是我最大的動(dòng)力!!記得三連哦~mua?歡迎大家閱讀往期的文章哦~
項(xiàng)目1.8? 人機(jī)五子棋游戲?
Pygame實(shí)戰(zhàn):利用Python實(shí)現(xiàn)智能五子棋,實(shí)現(xiàn)之后發(fā)現(xiàn)我玩不贏它。
項(xiàng)目4.2? 我的世界游戲
Pygame實(shí)戰(zhàn):方塊連接世界,云游大好河山—《我的世界》已上線,確定不進(jìn)來康康嘛?
項(xiàng)目4.4? 劇情版游戲
【Python劇情版游戲】優(yōu)美精致的畫風(fēng)甜甜的劇情、很難不讓人上頭啊?你get到了嘛
項(xiàng)目1.1? ?掃雷
?Pygame實(shí)戰(zhàn):據(jù)說這是史上最難掃雷游戲,沒有之一,你們感受下......
項(xiàng)目1.2? ?魂斗羅
Pygame實(shí)戰(zhàn):多年后“魂斗羅”像素風(fēng)歸來 不止是經(jīng)典與情懷@全體成員
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/124496.html
摘要:時(shí)間永遠(yuǎn)都過得那么快,一晃從年注冊(cè),到現(xiàn)在已經(jīng)過去了年那些被我藏在收藏夾吃灰的文章,已經(jīng)太多了,是時(shí)候把他們整理一下了。那是因?yàn)槭詹貖A太亂,橡皮擦給設(shè)置私密了,不收拾不好看呀。 ...
摘要:大多數(shù)待遇豐厚的開發(fā)職位都要求開發(fā)者精通多線程技術(shù)并且有豐富的程序開發(fā)調(diào)試優(yōu)化經(jīng)驗(yàn),所以線程相關(guān)的問題在面試中經(jīng)常會(huì)被提到。將對(duì)象編碼為字節(jié)流稱之為序列化,反之將字節(jié)流重建成對(duì)象稱之為反序列化。 JVM 內(nèi)存溢出實(shí)例 - 實(shí)戰(zhàn) JVM(二) 介紹 JVM 內(nèi)存溢出產(chǎn)生情況分析 Java - 注解詳解 詳細(xì)介紹 Java 注解的使用,有利于學(xué)習(xí)編譯時(shí)注解 Java 程序員快速上手 Kot...
摘要:大家好,我是冰河有句話叫做投資啥都不如投資自己的回報(bào)率高。馬上就十一國慶假期了,給小伙伴們分享下,從小白程序員到大廠高級(jí)技術(shù)專家我看過哪些技術(shù)類書籍。 大家好,我是...
閱讀 976·2023-04-26 02:56
閱讀 9532·2021-11-23 09:51
閱讀 1883·2021-09-26 10:14
閱讀 2988·2019-08-29 13:09
閱讀 2159·2019-08-26 13:29
閱讀 576·2019-08-26 12:02
閱讀 3569·2019-08-26 10:42
閱讀 3009·2019-08-23 18:18