这是我到目前为止的代码:
from JMSSGraphics import *
import math
import random
class Zombie:
# attributes:
# x
# y
# infected
# image
# we need to define a special function
# that lets us 'construct' an object from this class
# this special function is called a constructor
def __init__(self):
# creating my attributes
# and assigning them to initial values
self.x = 0
self.y = 0
self.img = None
self.speed = 0
self.rotation = 0
# Must use self so that variables
# do not lose values after function returns
class Player:
def __init__(self):
self.x = 0
self.y = 0
self.img = None
self.speed = 0
self.rotation = 0
self.fireSpeed = 0
class Bullet:
def __init__(self):
self.x = 0
self.y = 0
self.speed = 0
self.img = None
self.rotation = 0
self.locationVector = []
def __del__(self):
pass
class Wall:
def __init__(self):
self.x1 = 0
self.y1 = 0
self.x2 = 0
self.y2 = 0
jmss = Graphics(width = 800, height = 600, title = "city", fps = 120)
#Zombie ratio
zombieHeightFactor = 1.205
zombieWidth = 50
zombieHeight = zombieWidth * zombieHeightFactor
#Player ratio
playerHeightFactor = 0.66
playerWidth = 50
playerHeight = playerWidth * playerHeightFactor
#Bullet ratio
bulletHeightFactor = 0.28
bulletWidth = 35
bulletHeight = bulletWidth * bulletHeightFactor
zombiesList = []
n = 0
while n < 7:
newZombie = Zombie()
newZombie.img = jmss.loadImage("zombieImage.png")
newZombie.x = random.randint(10,790)
newZombie.y = random.randint(10,590)
newZombie.speed = random.uniform(1,3)
print(newZombie.speed)
zombiesList.append(newZombie)
n+=1
#Creating player object
player = Player()
player.img = jmss.loadImage("PlayerSprite.png")
player.x = 400
player.y = 300
player.speed = 10
player.fireSpeed = 20
bulletList = []
cooldown = 0
@jmss.mainloop
def Game():
global cooldown
####################PLAYER LOOK###################################
mouseX = jmss.mouseCoordinate()[0]
mouseY = jmss.mouseCoordinate()[1]
if mouseX-player.x > 0:
angle = 360 - math.degrees(math.atan((mouseY-player.y)/(mouseX-player.x))) #Calculates angle between player and mouse in degrees
player.rotation = angle
if mouseX - player.x < 0:
angle = 360 - math.degrees(math.atan((mouseY-player.y)/(mouseX-player.x))) #Calculates angle between player and mouse in degrees
player.rotation = angle + 180
####################PLAYER MOVEMENT#################################
jmss.clear(1,1,1,1)
if jmss.isKeyDown(KEY_W):
player.y += player.speed
if jmss.isKeyDown(KEY_A):
player.x -= player.speed
if jmss.isKeyDown(KEY_D):
player.x += player.speed
if jmss.isKeyDown(KEY_S):
player.y -= player.speed
if player.x > 800: ##ADDING BORDERS
player.x = 800
if player.x < 0:
player.x = 0
if player.y > 600:
player.y = 600
if player.y < 0:
player.y = 0
jmss.drawImage(player.img,player.x,player.y,width = playerWidth,height = playerHeight,rotation = player.rotation)
####################PLAYER SHOOT####################################
if jmss.isKeyDown(KEY_SPACE) and cooldown > player.fireSpeed:
cooldown = 0
bullet = Bullet()
bullet.img = jmss.loadImage("bullet.png")
bullet.x = player.x
bullet.y = player.y
bullet.speed = 20
bullet.locationx = mouseX
bullet.locationy = mouseY
bullet.rotation = player.rotation
bulletList.append(bullet)
n = 0
while n < len(bulletList):
bullet = bulletList[n]
bullet.locationVector = [math.cos(math.radians(bullet.rotation)),math.sin(math.radians(bullet.rotation))]
bullet.x += bullet.locationVector[0]*bullet.speed
bullet.y += -bullet.locationVector[1]*bullet.speed
jmss.drawImage(bullet.img,bullet.x,bullet.y,width = bulletWidth,height = bulletHeight,rotation = bullet.rotation)
if bullet.x > 800:
del bulletList[n]
elif bullet.y > 600:
del bulletList[n]
n += 1
cooldown += 1
############################ZOMBIE AI#########################################
n = 0
while n < len(zombiesList):
currentZombie = zombiesList[n]
if player.x-currentZombie.x > 0:
angle = 360 - math.degrees(math.atan((player.y-currentZombie.y)/(player.x-currentZombie.x))) #Calculates angle between player and mouse in degrees
currentZombie.rotation = angle
if player.x - currentZombie.x < 0:
angle = 360 - math.degrees(math.atan((player.y-currentZombie.y)/(player.x-currentZombie.x))) #Calculates angle between player and mouse in degrees
currentZombie.rotation = angle + 180
if currentZombie.x < player.x:
currentZombie.x += currentZombie.speed
if currentZombie.x > player.x:
currentZombie.x -= currentZombie.speed
if currentZombie.y < player.y:
currentZombie.y += currentZombie.speed
if currentZombie.y > player.y:
currentZombie.y -= currentZombie.speed
jmss.drawImage(currentZombie.img,currentZombie.x,currentZombie.y,zombieWidth,zombieHeight,currentZombie.rotation)
currentZombie.speed += 0.001
n += 1
######################POWER UP################################################
spawnChance = random.randint(0,10000)
if spawnChance == 5000:
print("SPAWN POWERUP")
##########################CREATING ENVIRONMENT###############################
jmss.run()
我想要改进僵尸人工智能,这样它就不再那么无聊和可预测。任何帮助将不胜感激:)
到目前为止,我在 AI 上所做的只是简单地调整敌人对象的 x 和 y 坐标,具体取决于它们是否小于或大于玩家的坐标。它仅适用于 x 或 y 的二维水平,但不能同时适用于两者。
OP中的僵尸AI充当跟踪控制器。这意味着,僵尸正在跟随人类玩家。可以通过在不同的抽象级别上进行跟踪来改进这个想法。在源代码中,跟踪仅适用于欧几里德空间,即玩家和僵尸之间的二维坐标之差。更抽象的衡量标准是与自然语言有关的一切。例如,人类玩家可以处于一种称为“攻击性”的模式,该模式相当于在两点之间快速移动,而僵尸也可以以攻击性行为对该模式做出反应。对动作进行分类的第二个机会是定义几何区域。人类玩家可以在 A、B 或 C 区,而僵尸可以有一个规则,只攻击处于同一区域的玩家。对于休闲游戏玩家来说,这将使他的行为变得难以预测。
为了创建更复杂的角色,专用的任务模型是有意义的。从头开始创建此类模型的一种简单方法是一种称为思维导图的创造性技术。在论文的中心,问题被写下来,然后程序员确定人工智能可能采取的行动。这些操作被排序为子操作(称为层)。如果思维导图成长为一个巨大的网络,那么就该用可执行源代码来实现该系统了。这可以通过版本控制系统手动完成。
实现复杂的人工智能系统始终与自然语言有关。这个想法不是像
diff=pos.x-pos.y
那样以数学方式描述问题,而是在语言层面上描述问题。僵尸游戏的领域必须用故事、思维导图、角色、动作和概念图来描述。这导致了对问题的抽象看法。如果不清楚思维导图应该是什么样子,那么良好的灵感来源可以是来自相同背景的其他游戏、电影和著名著作。对源代码进行编程本身就是在电脑游戏的媒介上讲述故事。
如果您想使用人工智能驱动的应用程序改善旧的模糊和低质量图像,那么您可以转到remini mod apk来改善您的图像。
我想帮助人们访问 [remini apk](https://reminimodsapk.info/) 并改善他们的形象。这个应用程序拥有所有高级功能。