import pygame
import random
import math
from pygame.constants import TIMER_RESOLUTION
pygame.init()
score_value = 0
font = pygame.font.Font(‘freesansbold.ttf’, 32)
textX = 10
textY = 10
def show_score(x, y):
score = font.render(“Score :” + str(score_value), True, (255, 255, 255))
screen.blit(score, (x, y))
屏幕和图片引入
screen = pygame.display.set_mode((1000, 700))
icon = pygame.image.load(“master2.jpg”)
rocket = pygame.image.load(“ship.png”)
bulletImg = pygame.image.load(“bullet.png”)
background = pygame.image.load(“background.jpg”)
pygame.display.set_icon(icon)
pygame.display.set_caption(“油管版外星人大战”)
火箭参数
rocketX = 460
rocketY = 550
player_changex = 0
player_changey = 0
敌人参数
enemy_image = []
enemyX = []
enemyY = []
enemy_changex = []
enemy_changey = []
num_of_enemys = 5
for i in range(num_of_enemys):
enemy_image.append(pygame.image.load(“ufo2.png”))
enemyX.append(random.randint(0, 1000))
enemyY.append(random.randint(0, 300))
enemy_changex.append(0.3)
enemy_changey.append(30)
子弹参数
bulletx = 0
bullety = rocketY
bullet_changex = 0
bullet_changey = 1
bullet_state = “ready”
火箭函数
def rocket_player(x, y):
screen.blit(rocket, (x, y))
敌人函数
def enemy_set(x, y, i):
screen.blit(enemy_image[i], (x, y))
子弹函数
def fire_bullet(x, y):
global bullet_state
bullet_state = “fire”
screen.blit(bulletImg, (x+50, y))
碰撞函数
def boom(enemyX, enemyY, bulletx, bullety):
distance = math.sqrt((math.pow(enemyX-bulletx, 2)) +
(math.pow(enemyY-bullety, 2)))
if distance
Original: https://blog.csdn.net/qq_60695842/article/details/120794225
Author: matcha.title ( )
Title: pygame简单游戏 飞机大战
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/780220/
转载文章受原作者版权保护。转载请注明原作者出处!