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

做H5哪个网站字体漂亮一些seo排名关键词搜索结果

做H5哪个网站字体漂亮一些,seo排名关键词搜索结果,58桐城网站做装修推广是真的吗,网站建设选择4 绘制防御塔 从图2中可以看出,防御塔实际上是图4中第2行第1列的图像与第7行第1列图像的组合,绘制防御塔的代码只需要将图5中绘制完整坦克代码中相应的行列坐标改为防御塔所需的行列坐标即可,在render()方法中。代码如图7所示。 图7 绘制防御…

4 绘制防御塔

从图2中可以看出,防御塔实际上是图4中第2行第1列的图像与第7行第1列图像的组合,绘制防御塔的代码只需要将图5中绘制完整坦克代码中相应的行列坐标改为防御塔所需的行列坐标即可,在render()方法中。代码如图7所示。

图7 绘制防御塔的代码

其中,第82行和90行代码中的gameState.tower1Pos以及gameState.tower2Pos指定了防御塔的位置;第83行、第86行、第91行和第94行指定了绘制防御塔所需的图片。

5 碰撞处理

从图1中可以看出,玩家控制的坦克无法放在防御塔所在的方框中,以上功能通过GameState类的update()方法实现。

《从零开始学Python游戏编程38-精灵5》中提到的GameState类的update()方法中,根据控制指令修改玩家坦克的位置,还要对玩家坦克的位置超出游戏屏幕范围的情况进行处理。而加入碰撞处理的update()方法代码如图8所示。

图8 加入碰撞处理的update()方法代码

第22行代码创建newTankPos变量,其值为之前坦克的位置加上控制指令。newTankPos可以看作是坦克“理论上”的新位置,“理论上”的新位置指的是只有某些条件满足时,坦克才会出现在新位置上,第24-26行就指定了这些条件,包括坦克的位置必须在游戏窗口范围内,并且新位置不能在两个防御塔的位置上,满足以上条件,第27行才会将坦克的位置设置为新位置,否则坦克的位置不会改变。通过以上代码,完成了碰撞处理。

6 完整代码

碰撞处理的完整代码如下所示。

import os
import pygame
from pygame import Rect
from pygame.math import Vector2class GameState():def __init__(self):self.worldSize = Vector2(16,10)self.tankPos = Vector2(0,0)self.tower1Pos = Vector2(10, 3)self.tower2Pos = Vector2(10, 5)def update(self,moveTankCommand):newTankPos = self.tankPos + moveTankCommandif  newTankPos.x >= 0 and newTankPos.x < self.worldSize.x \and newTankPos.y >= 0 and newTankPos.y < self.worldSize.y \and newTankPos != self.tower1Pos and newTankPos != self.tower2Pos:self.tankPos = newTankPosclass UserInterface():def __init__(self):pygame.init()self.gameState = GameState()self.unitsTexture = pygame.image.load("units.png")self.cellSize = Vector2(64,64)windowSize = self.gameState.worldSize.elementwise() * self.cellSizeself.window = pygame.display.set_mode((int(windowSize.x),int(windowSize.y)))pygame.display.set_caption("移动坦克")self.moveTankCommand = Vector2(0,0)self.clock = pygame.time.Clock()self.running = Truedef processInput(self):self.moveTankCommand = Vector2(0,0)for event in pygame.event.get():if event.type == pygame.QUIT:self.running = Falsebreakelif event.type == pygame.KEYDOWN:if event.key == pygame.K_ESCAPE:self.running = Falsebreakelif event.key == pygame.K_RIGHT:self.moveTankCommand.x = 1elif event.key == pygame.K_LEFT:self.moveTankCommand.x = -1elif event.key == pygame.K_DOWN:self.moveTankCommand.y = 1elif event.key == pygame.K_UP:self.moveTankCommand.y = -1def update(self):self.gameState.update(self.moveTankCommand)def render(self):self.window.fill((0,0,0))spritePoint = self.gameState.tankPos.elementwise()*self.cellSizetexturePoint = Vector2(1,0).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y),int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)texturePoint = Vector2(0,6).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y),int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)spritePoint = self.gameState.tower1Pos.elementwise()*self.cellSizetexturePoint = Vector2(0,1).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y), int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)texturePoint = Vector2(0,6).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y), int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)spritePoint = self.gameState.tower2Pos.elementwise()*self.cellSizetexturePoint = Vector2(0,1).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y), int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)texturePoint = Vector2(0,6).elementwise()*self.cellSizetextureRect = Rect(int(texturePoint.x), int(texturePoint.y), int(self.cellSize.x),int(self.cellSize.y))self.window.blit(self.unitsTexture,spritePoint,textureRect)pygame.display.update()    def run(self):while self.running:self.processInput()self.update()self.render()self.clock.tick(60)userInterface = UserInterface()
userInterface.run()pygame.quit()

http://www.dtcms.com/wzjs/236276.html

相关文章:

  • wordpress打开速度慢 插件合肥网站优化软件
  • 石家庄哪家网站做的好爱网站关键词查询工具
  • 衡阳靠谱seo优化揭阳新站seo方案
  • 网站发布与推广淘宝推广怎么做
  • 淘宝营销网站建设营销策略有哪些方面
  • 微信网站链接怎么做网站移动端优化工具
  • 慈溪网站开发手机优化
  • 吴亦凡经纪公司seo内部优化方式包括
  • 林壑地板北京网站建设百度竞价广告
  • 网站优化含义学大教育培训机构电话
  • 手机壳图案设计网站磁力蜘蛛搜索引擎
  • 盘点2013网络自制剧:视频网站的"招牌菜"接下来怎么做?百度ai人工智能
  • 租服务器百度seo优化服务项目
  • 哪里做网站最好重庆百度推广关键词优化
  • 设计网站的步骤南昌seo外包公司
  • 厦门网站推广步骤机构最佳的资源磁力搜索引擎
  • 网站建设捌金手指专业7培训心得体会范文大全2000字
  • 做电影收费网站怎样做好销售和客户交流
  • 学校网站建设方案模板精准客源推广引流
  • 做报告的网站适合40岁女人的培训班
  • 地方网站建站平台全媒体广告加盟
  • 丰台网站制作公司web网页制作成品免费
  • foxmail企业邮箱入口河南seo技术教程
  • 最简单的编程语言临沂seo代理商
  • 如何做网站经营性备案最好的优化公司
  • 用wordpress建站之后如何优化最新全国疫情实时大数据
  • 营销型企业网站建设大学生网络营销策划书
  • 网站改版需求怎么制作网站
  • 可以免费做商业网站的cmswindows优化大师官方免费下载
  • 网站做视频怎么赚钱的镇江网站