在main.lua
我有这个:
function love.load()
LoadBasic()
LoadSprites()
LoadPlayer()
LoadZombies()
end
function love.update(dt)
PlayerMovement(dt)
ZombieMovement(dt)
BulletMovement(dt)
BulletHitZombie()
EnemySpawning(dt)
end
function love.draw()
DrawBackground()
DrawPlayer()
DrawMenu()
DrawGrunts()
DrawBullets()
DrawTimer()
end
EnemySpawning()
看起来像这样:
function EnemySpawning(dt)
if gameActive == 1 then
GruntSpawning(dt)
RunnerSpawning(dt)
end
end
GruntSpawning(dt)
看起来像这样:
function GruntSpawning(dt)
gruntTimer = gruntTimer - dt
if gruntTimer <= 0 then --timer hits 0, spawn zombie
SpawnGrunt()
if gruntCD >= gruntMinCD then
gruntCD = gruntCD * gruntTimerDecr --zombies spawn faster over time
gruntTimer = gruntCD
else
gruntTimer = gruntMinCD -- faster to a certain degree
end
end
end
最后,SpawnGrunt()
看起来像这样:
function SpawnGrunt()
local side = math.random(1, 4)
if side == 1 then
grunt.x = -30
grunt.y = math.random(0, scrHeight)
elseif side == 2 then
grunt.x = math.random(0, scrWidth)
grunt.y = -30
elseif side == 3 then
grunt.x = scrWidth + 30
grunt.y = math.random(0, scrHeight)
else
grunt.x = math.random( 0, scrWidth )
grunt.y = scrHeight + 30
end
table.insert( zombies, grunt )
end
根据我的理解,love.update(dt)
每秒被调用60次(或者无论FPS是什么)。由于我EnemySpawning(dt)
下love.update()
,因此该函数每秒调用60次。然而,gruntTimer
,每秒应减少1,不会改变。我做错了什么?
编辑:问题到底是gameState == 1
没有实现,因为它应该是gameState == true
。