import random
import pygame
class
di_ji()
:def
__init__
(self,chuangkou)
: pifu =
[r"\alien_1.png"
, r"\alien_2.png"
, r"\alien_3.png"
, r"\alien_4.png"
, r"\alien_5.png"
] self.x = random.randint(0,
480)
self.y = random.randint(0,
480)
self.clothes = pygame.image.load(pifu[random.randint(0,
4)])
self.chuangkou = chuangkou
self.su_du_x =
100def
show
(self)
: self.chuangkou.blit(self.clothes,
(self.x,self.y)
)def
yi_dong
(self)
: self.x = self.x + self.su_du_x
if self.x >
480:
self.su_du_x =-10
if self.x <0:
self.su_du_x =
10# 飛彈類
# 向前移動
# 判斷有沒有碰撞
# 屬性:x,y,**, 視窗
class
dao_dan()
:def
__init__
(self,chuangkou,x,y,pifu)
: self.x = x
self.y = y
self.clothes = pygame.image.load(pifu)
self.chuangkou = chuangkou
defshow
(self)
: self.chuangkou.blit(self.clothes,
(self.x,self.y)
)def
shang
(self)
: self.y = self.y -
10# 敵機類
# 方法:發射子彈,移動
# 屬性:x,y,膚, 視窗
class
zhan_ji()
:def
__init__
(self, chuangkou)
: self.name =
"戰神號"
self.x =
240 self.y =
390 self.clothes = pygame.image.load(r"\hero1.png"
) self.chuangkou = chuangkou
self.wu_qi =
defshow
(self)
: self.chuangkou.blit(self.clothes,
(self.x,self.y)
)for dao in self.wu_qi:
dao.show(
) dao.shang(
)def
shang
(self)
: self.y = self.y -
10if self.y <0:
self.y =
30def
xia(self)
: self.y = self.y +
10if self.y >
780:
self.y =
750def
zuo(self)
: self.x = self.x -
10if self.x <0:
self.x =
30def
you(self)
: self.x = self.x +
10if self.x >
480:
self.x =
380def
fa_she
(self):)
)def
anjian_kongzhi
(zhan_shen)
:for event in pygame.event.get():
if event.
type
== pygame.quit:
pygame.quit(
)elif event.
type
== pygame.keydown:
if event.key == pygame.k_right:
zhan_shen.you(
)elif event.key == pygame.k_left:
zhan_shen.zuo(
)elif event.key == pygame.k_down:
zhan_shen.xia(
)elif event.key == pygame.k_up:
zhan_shen.shang(
)elif event.key == pygame.k_space:
zhan_shen.fa_she(
)pygame.init(
)screen = pygame.display.set_mode(
(480
,780))
pygame.display.set_caption(
"飛機大戰"
)jiazai_tupian = pygame.image.load(r"\background.png"
)zhan_shen = zhan_ji(screen)
# 讓電腦每隔多少毫秒響應一次按鈕
pygame.key.set_repeat(1,
1)di_fang_zhan_ji = di_ji(screen)
while
1>0:
anjian_kongzhi(zhan_shen )
screen.blit(jiazai_tupian,(0
,0))
di_fang_zhan_ji.show(
) di_fang_zhan_ji.yi_dong(
) zhan_shen.show(
) pygame.display.update(
)
deqin 飛機大戰4。0
製作遊戲 導包 import random import time import pygame import sys import plane import enemy defkey control hero event 事件,我們對電腦的每一次操作都是乙個事件 for shi jian in py...
飛機大戰 3
今天主要是敵方飛機的建立,下落 前面已建飛機的父類call 2 敵方飛機 function enemyplane hp,x,y,sizex,sizey,score,dietime,sudu,bombplane,srcimage 敵方的飛機型別分為大中小,要隨機下落 飛機的隨機下落,大中小飛機出現頻率...
飛機大戰 一
圖1 遊戲開始 圖2 英雄機,子彈,敵機和小蜜蜂 圖4 遊戲結束 圖5 遊戲暫停 由圖2可以看出遊戲中至少有4個類,hero 英雄機 airplane 敵機 bee 小蜜蜂 bullet 子彈 圖6注 圖6中,英雄機,子彈,敵機和小蜜蜂均為矩形,所以會有x座標和y座標 會在程式中有體現 1.建立4個...