import random
import pygame
import sys
import plane
import enemy
def key_control(hero):
# event 事件:电脑监控们对电脑的每一次操作,包括鼠标移动,按键
for shi_jian in pygame.event.get():
# 判断我们有没有点击退出
if shi_jian.type == pygame.QUIT:
sys.exit()
# 判断我们有没有按键 Key
elif shi_jian.type == pygame.KEYDOWN:
print("你按键啦!!!!")
if shi_jian.key == pygame.K_UP:
hero.move_up()
elif shi_jian.key == pygame.K_DOWN:
hero.move_down()
if shi_jian.key == pygame.K_RIGHT:
hero.move_right()
elif shi_jian.key == pygame.K_LEFT:
hero.move_left()
if shi_jian.key == pygame.K_SPACE:
hero.fire()
def main():
# 初始化,加载一些文件进来
pygame.init()
# 游戏需要做一个窗口 dis 分开 play 玩 diaplay展览
chuang_kou = pygame.display.set_mode((400, 700))
# 游戏标题
pygame.display.set_caption("反基督者")
# 新建一个战机对象、
hero = plane.plane(chuang_kou)
# 新建一个敌机对象、
enemy_plane = []
# append
# 设置电脑美过多少毫秒响应一次参数
pygame.key.set_repeat(1, 1)
background = pygame.image.load("图片/background.png")
while True:
key_control(hero)
# 将图片放到窗口上
chuang_kou.blit(background, (0, 0))
zi_dan_x, zi_dan_y = hero.show()
print(zi_dan_x)
# 每次循环的时候产生一个随机数
luck_num = random.randint(1, 50)
if luck_num == 6:
enemy_plane.append(enemy.enemy(chuang_kou, random.randint(1, 400), 0))
for badegg in enemy_plane:
badegg.show()
badegg.move_down()
if hero.x < badegg.x < hero.x+100 and hero.y < badegg.y< hero.y+120:
pygame.quit()
for zidan in range(len(zi_dan_x)):
if badegg.x < zi_dan_x[zidan] < badegg.x + 51 \
and badegg.y < zi_dan_y[zidan] < badegg.y + 39:
try:
enemy_plane.remove(badegg)
except:
pass
# 刷新 up上date日期 update 升级,刷新
pygame.display.update()
if __name__ == '__main__':
main()
import pygame
import bullet
战机图纸
class plane:
# 魔法方法,记录属性
def init(self,ck):
self.x = 200
self.y = 200
self.picture = pygame.image.load(“图片/hero1.png”)
self.chuang_kou = ck
self.zidan = [ ] # 子弹库
def move_up(self):
self.y -= 10
if self.y < -124:
self.y = 700
def move_down(self):
self.y += 10
if self.y > 700:
self.y = -120
def move_right(self):
self.x += 10
if self.x > 350:
self.x = 295
def move_left(self):
self.x -= 10
if self.x < -90:
self.x = 5
def show(self):
self.chuang_kou.blit(self.picture, (self.x, self.y))
zi_dan_x = []
zi_dan_y = []
for dan_ge_bullet in self.zidan:
dan_ge_bullet.show()
dan_ge_bullet.move_up()
zi_dan_x.append(dan_ge_bullet.x)
zi_dan_y.append(dan_ge_bullet.y)
# 返回
return zi_dan_x, zi_dan_y
# 发射字典的方法:
def fire(self):
for y in range(10):
self.zidan.append(bullet.bullet(self.x+y*10, self.y, self.chuang_kou))
“”"
AO3
子弹打到敌机,敌机爆炸
肖战粉丝铭牌,
战机爆炸功能
“”"
python
import pygame
import bullet
战机图纸
class plane:
# 魔法方法,记录属性
def init(self,ck):
self.x = 200
self.y = 200
self.picture = pygame.image.load(“图片/hero1.png”)
self.chuang_kou = ck
self.zidan = [ ] # 子弹库
def move_up(self):
self.y -= 10
if self.y < -124:
self.y = 700
def move_down(self):
self.y += 10
if self.y > 700:
self.y = -120
def move_right(self):
self.x += 10
if self.x > 350:
self.x = 295
def move_left(self):
self.x -= 10
if self.x < -90:
self.x = 5
def show(self):
self.chuang_kou.blit(self.picture, (self.x, self.y))
zi_dan_x = []
zi_dan_y = []
for dan_ge_bullet in self.zidan:
dan_ge_bullet.show()
dan_ge_bullet.move_up()
zi_dan_x.append(dan_ge_bullet.x)
zi_dan_y.append(dan_ge_bullet.y)
# 返回
return zi_dan_x, zi_dan_y
# 发射字典的方法:
def fire(self):
for y in range(10):
self.zidan.append(bullet.bullet(self.x+y*10, self.y, self.chuang_kou))
“”"
AO3
子弹打到敌机,敌机爆炸
肖战粉丝铭牌,
战机爆炸功能
“”"