当前位置: 首页 > news >正文

做网站价格差异很大/百度推广客户端怎么登陆

做网站价格差异很大,百度推广客户端怎么登陆,bae安装wordpress,企业站seo价格1、歼灭敌机(1)增加敌机:设置敌机,随机从窗口顶部出现,往底部移动,随机从窗口顶部出现只需要设置初始纵坐标为顶部的一个固定值:#敌机初始化k 0enemy_x1 0enemy_y1 0(2)敌机移动敌机随机出现设定敌机速度敌机随机出…

1、歼灭敌机

(1)增加敌机:设置敌机,随机从窗口顶部出现,往底部移动,随机从窗口顶部出现只需要设置初始纵坐标为顶部的一个固定值:

#敌机初始化

k = 0

enemy_x1 = 0

enemy_y1 = 0

(2)敌机移动

敌机随机出现

设定敌机速度

敌机随机出现,可以将初始位置设定在y = -24的位置(稍高于窗口顶部y = 0位置)

设定敌机速度,要确定速度就要设定时间t和路程s,时间设定为每执行一次程序t0,时间参数k,设定每执行一次程序移动的像素为5,根据实际效果调整参数,飞机从上到下运行总时间为(1000 + 90)/10 = 109*t0,总路程s = (109*t0)*5:

#随机出现敌人

#敌人1

if k == 0:

enemy_x1 = random.randint(-24, 426)

enemy_y1 = -24

elif k == 90:

k = -1000

k += 10

enemy_y1 += 5

同理,可以再增加一个敌机,但是飞机初始出现的位置需要和前一个区别:

#敌人2

if l == 80:

enemy_x2 = random.randint(-24, 426)

enemy_y2 = -24

elif l == 170:

l = -1170

l += 10

enemy_y2 += 5

2、碰撞检测

只要检测到子弹“左边缘”横坐标在敌机“左边缘”和“右边缘”之间且子弹“顶部”纵坐标在敌机“底部坐标之上”,或者子弹“右边缘”横坐标在敌机“左边缘”和“右边缘”之间且子弹“顶部”纵坐标在敌机“底部坐标之上”,则判定子弹会和敌机发生碰撞:(由于设定的子弹速度很快,暂时没有判断子弹“顶部”纵坐标在敌机“底部坐标之上”)

9f2c63f39b9c9dde98b48b3c6eedd578.png

5fb69e4ace23e292f3de26402b77ad92.png

#检测碰撞

def collide(button_x1, enemy_x1, enemy_y1, score_count): # x1子弹中心横坐标,X2敌机中心横坐标

collide_x1 = enemy_x1

collide_y1 = enemy_y1

if ((enemy_x1 - 15) <= (button_x1 - 4) <= (enemy_x1 + 15)) or ((enemy_x1 - 15) <= (button_x1 + 4) <= (enemy_x1 + 15)):

collide_x1 = random.randint(-24, 426)

collide_y1 = -65

score_count +=1

print(score_count)

return collide_x1, collide_y1, score_count

3、增加声音

初始化及加载:

#音乐初始化及加载

pygame.mixer.init()

pygame.mixer_music.load('button.wav')

显示子弹声音:

#显示子弹声音

pygame.mixer_music.play()

4、计算分数

计算分数比较简单,这里只选择了三位数,即最大为999,但是提前需要准备好1-9的数字图片:

#计算并显示分数

units = score_count//1%10

tens = score_count//10%10

hundreds = score_count//100%10

units_picture = score_picture_list[units]

tens_picture = score_picture_list[tens]

hundreds_picture = score_picture_list[hundreds]

5、完整代码

#参数初始化

background_image_filename = 'background.png'

mouse_image_filename = 'airplane.png'

button_image_filename = 'button1.png'

enemy1_image_filename = 'enemy.png'

enemy2_image_filename = 'enemy.png'

score_board = 'score_board.png'

number_0 = 'zero.png'

number_1 = 'one.png'

number_2 = 'two.png'

number_3 = 'three.png'

number_4 = 'four.png'

number_5 = 'five.png'

number_6 = 'six.png'

number_7 = 'seven.png'

number_8 = 'eight.png'

number_9 = 'nine.png'

#导入函数

import pygame

from pygame.locals import *

from sys import exit

import random

#音乐初始化及加载

pygame.mixer.init()

pygame.mixer_music.load('button.wav')

#加载并转换图像

background = pygame.image.load(background_image_filename)

mouse_cursor = pygame.image.load(mouse_image_filename)

button_picture1 = pygame.image.load(button_image_filename)

button_picture2 = pygame.image.load(button_image_filename)

enemy_picture1 = pygame.image.load(enemy1_image_filename)

enemy_picture2 = pygame.image.load(enemy2_image_filename)

score_board_picture = pygame.image.load(score_board)

score_zero_picture = pygame.image.load(number_0)

score_one_picture = pygame.image.load(number_1)

score_two_picture = pygame.image.load(number_2)

score_three_picture = pygame.image.load(number_3)

score_four_picture = pygame.image.load(number_4)

score_five_picture = pygame.image.load(number_5)

score_six_picture = pygame.image.load(number_6)

score_seven_picture = pygame.image.load(number_7)

score_eight_picture = pygame.image.load(number_8)

score_nine_picture = pygame.image.load(number_9)

score_picture_list = [score_zero_picture, score_one_picture, score_two_picture, score_three_picture, score_four_picture,

score_five_picture, score_six_picture, score_seven_picture, score_eight_picture, score_nine_picture]

#创建窗口及标题

screen = pygame.display.set_mode((450, 550), 0, 32)

pygame.display.set_caption("hello world")

#初始化pygame,为硬件使用作准备

pygame.init()

x1 = 225

y1 = 275

#子弹坐标初始化

button_x1 = 0

button_y1 = 0

button_x2 = 0

button_y2 = 0

v = 4

i = 0

j = 0

#敌机初始化

k = 0

enemy_x1 = 0

enemy_y1 = 0

#分数初始化

score_count = 0

board_x = 280

board_y = 20

number_x = list(range(10))

l = 0

enemy_x2 = 0

enemy_y2 = 0

units_x1 = 60

units_y1 = 0

tens_x1 = 30

tens_y1 = 0

hundreds_x1 = 0

hundreds_y1 = 0

# 检测边缘

def judge(potx, poty):

if potx >= 426:

potx = 426

elif potx <= -24:

potx = -24

elif poty >= 526:

poty = 526

elif poty <= -24:

poty = -24

return potx, poty

#检测碰撞

def collide(button_x1, enemy_x1, enemy_y1, score_count): # x1子弹中心横坐标,X2敌机中心横坐标

collide_x1 = enemy_x1

collide_y1 = enemy_y1

if ((enemy_x1 - 15) <= (button_x1 - 4) <= (enemy_x1 + 15)) or ((enemy_x1 - 15) <= (button_x1 + 4) <= (enemy_x1 + 15)):

collide_x1 = random.randint(-24, 426)

collide_y1 = -65

score_count +=1

print(score_count)

return collide_x1, collide_y1, score_count

#游戏主循环

while True:

# 检测退出事件,判断是否执行退出

for event in pygame.event.get():

if event.type == QUIT:

exit()

#将背景画上去

screen.blit(background, (0, 0))

#获取按键状态并完成移动

press = pygame.key.get_pressed()

if press[K_LEFT] == True:

if press[K_UP] == True:

x1 = x1 - v

y1 = y1 - v

elif press[K_DOWN] == True:

x1 = x1 - v

y1 = y1 + v

else:

x1 = x1 - v

elif press[K_RIGHT] == True:

if press[K_UP] == True:

x1 = x1 + v

y1 = y1 - v

elif press[K_DOWN] == True:

x1 = x1 + v

y1 = y1 + v

else:

x1 = x1 + v

elif press[K_UP] == True:

y1 = y1 - v

elif press[K_DOWN] == True:

y1 = y1 + 4

# 获取鼠标位置

#x, y = pygame.mouse.get_pos()

#计算光标在左上角的位置

#x -= mouse_cursor.get_width() / 2

#y -= mouse_cursor.get_height() / 2

#子弹移动

#子弹1移动

if i == 0:

button_x1 = x1 + 3

button_y1 = y1 + 60

elif i == 90:

i = -10

i += 10

button_y1 -= 65

#子弹2移动

if j == 0:

button_x2 = x1 + 27

button_y2 = y1 + 60

elif j == 90:

j = -10

j += 10

button_y2 -= 65

#判断边缘

x1, y1 = judge(potx = x1, poty = y1)

#随机出现敌人

#敌人1

if k == 0:

enemy_x1 = random.randint(-24, 426)

enemy_y1 = -24

elif k == 90:

k = -1000

k += 10

enemy_y1 += 5

#敌人2

if l == 80:

enemy_x2 = random.randint(-24, 426)

enemy_y2 = -24

elif l == 170:

l = -1170

l += 10

enemy_y2 += 5

#子弹击中

enemy_x1, enemy_y1, score_count = collide(button_x1, enemy_x1, enemy_y1, score_count)

enemy_x2, enemy_y2, score_count = collide(button_x2, enemy_x2, enemy_y2,score_count)

#显示子弹声音

pygame.mixer_music.play()

#计算并显示分数

units = score_count//1%10

tens = score_count//10%10

hundreds = score_count//100%10

units_picture = score_picture_list[units]

tens_picture = score_picture_list[tens]

hundreds_picture = score_picture_list[hundreds]

#将光标画上去

screen.blit(mouse_cursor, (x1, y1))

screen.blit(button_picture1, (button_x1, button_y1))

screen.blit(button_picture2, (button_x2, button_y2))

screen.blit(enemy_picture1, (enemy_x1, enemy_y1))

screen.blit(enemy_picture2, (enemy_x2, enemy_y2))

screen.blit(units_picture, (units_x1, units_y1))

screen.blit(tens_picture, (tens_x1, tens_y1))

screen.blit(hundreds_picture, (hundreds_x1, hundreds_y1))

# 在新的位置上画图

pygame.display.update()

PS:可以看出,这样的写法代码量很大,下一步会基于“面向对象”和“程序提炼”来优化一遍上述的程序。

原文链接:https://blog.csdn.net/F_MILK_/article/details/109030183

http://www.lbrq.cn/news/1077391.html

相关文章:

  • 腾讯做电脑吃鸡网站/注册网站流程和费用
  • 人才网站/西地那非片的功能主治
  • 怎么把在EXCEL做的查询系统做到网站上/百度提交入口网址
  • 宁波网站建设 熊掌号/长沙网站建设
  • 网页美工设计公司/排名优化服务
  • 正规接单赚佣金的app/win7优化大师官网
  • wp网站开发/上海今天最新发布会
  • 天猫购物商城/徐州seo推广
  • asp网站建设实录pdf/百度站内搜索代码
  • 什么是大型门户网站/免费网站制作教程
  • 织梦的cms哪些网站/合肥seo优化公司
  • window2008 网站建设/seo网站营销推广公司
  • 多少钱翻译/北京排名seo
  • 企业网站改版seo/潮州网络推广
  • 在线教育网站建设方案/刷关键词怎么刷
  • 网站建设 风险/百度seo排名在线点击器
  • 网站申请名称/品牌策划公司排行榜
  • ui做网站实例/什么是搜索关键词
  • 政府网站 定制/搜索引擎优化的办法有哪些
  • 企业网站设计策划/做百度seo
  • php网站空间购买/品牌推广的意义
  • 电销系统开发/seo整站优化费用
  • 北海做网站哪家好/网址
  • 营销型网站策划 建设的考试题/百度推广电话销售好做吗
  • 建一个网站难不难/重庆网站seo技术
  • 韩国网站never/天天seo百度点击器
  • 网站切图是指什么/seo咨询邵阳
  • wordpress主题安装报错/关键词怎么优化
  • 怎么做网站排名优化/网站如何注册
  • 做网站去哪里做/外链查询
  • html5+css3+canvas长文转长图工具支持换行
  • sqli-labs:65个关卡的文章汇总
  • Flutter镜像替换
  • 大模型结构比较
  • 李宏毅深度学习教程 第4-5章 CNN卷积神经网络+RNN循环神经网络
  • 【PHP】接入百度AI开放平台人脸识别API,实现人脸对比