Browse Source

Fixed bugs on Windows and made AI smarter

tags/crossplatform
Madiwka 4 years ago
parent
commit
41de955c90
4 changed files with 55 additions and 59 deletions
  1. +1
    -0
      debuggame.sh
  2. +2
    -2
      paddle.lua
  3. +50
    -55
      src/AI.lua
  4. +2
    -2
      src/baseGame.lua

+ 1
- 0
debuggame.sh View File

@@ -3,3 +3,4 @@ rm game.zip
zip -r game *
mv game.zip game.love
love game.love
rm game.love

+ 2
- 2
paddle.lua View File

@@ -60,9 +60,9 @@ function paddle:update(dt)
self.yx = self.y
end
if (self.yx < self.y) then
self.yx = self.yx + math.abs(paddle_SPEED/1.7) * dt
self.yx = self.yx + math.abs(paddle_SPEED/1.7) * 7 * dt
elseif (self.yx > self.y) then
self.yx = self.yx - math.abs(paddle_SPEED/1.7) * dt
self.yx = self.yx - math.abs(paddle_SPEED/1.7) * 7 * dt
end
end


+ 50
- 55
src/AI.lua View File

@@ -88,64 +88,59 @@ function predictBall(target, px)
end
end
function recursiveCalculations(px, ex, ey, edx, edy, ifspecial)
if VIRTUAL_WIDTH - ex < AI_SPEED then
local time = (VIRTUAL_WIDTH - ex)/(ballSpeed*edx)
local distance = (ballSpeed * edy) * time
love.window.setTitle(ey + (distance*edy))
return ey + (distance*edy)
else
if (edy > 0) then
--print ("normal" .. ex .." " .. ey .. " " .. edx .. " " .. edy)
local time = (VIRTUAL_HEIGHT-40-ey) / (ballSpeed * edy)
local distance = (ballSpeed * edx) * time
--print(distance .. " " .. edx .. " " .. time .. " " .. (px-ex))
if distance > (px - ex) then
local anstime = (px - ex) / (ballSpeed * edx)
local bonus = (ballSpeed * edy) * anstime
--print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (px-ex))
-- if (ifspecial == 0) then
local answer = ey + bonus
love.window.setTitle(tostring(answer) .. "Basiccalc")
return ey + bonus
-- else
-- return -1
--end
else
local emulatedx = ex + distance
local emulatedy = VIRTUAL_HEIGHT-40
local answer = recursiveCalculations(px, emulatedx, emulatedy, edx, -edy, 0)
love.window.setTitle(tostring(answer) .. "recursive calc bottom")
return answer
end
elseif edy == 0 then
return ey
else
--print ("inverse" .. ex .." " .. ey .. " " .. edx .. " " .. edy)
local time = (ey) / math.abs((ballSpeed * edy))
local distance = (ballSpeed * edx) * time
--print(distance .. " " .. edx .. " " .. time .. " " .. (px-ex))

if (edy > 0) then
--print ("normal" .. ex .." " .. ey .. " " .. edx .. " " .. edy)
local time = (VIRTUAL_HEIGHT-ey) / (ballSpeed * edy)
local distance = (ballSpeed * edx) * time
--print(distance .. " " .. edx .. " " .. time .. " " .. (px-ex))
if distance > (px - ex) then
local anstime = (px - ex) / (ballSpeed * edx)
local bonus = (ballSpeed * edy) * anstime
--print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (px-ex))
-- if (ifspecial == 0) then
return ey + bonus
-- else
-- return -1
--end
else
local emulatedx = ex + distance
local emulatedy = VIRTUAL_HEIGHT
local answer = recursiveCalculations(px, emulatedx, emulatedy, edx, -edy, 0)
love.window.setTitle(answer)
return answer
end
elseif edy == 0 then
return ey
else
--print ("inverse" .. ex .." " .. ey .. " " .. edx .. " " .. edy)
local time = (ey) / math.abs((ballSpeed * edy))
local distance = (ballSpeed * edx) * time
--print(distance .. " " .. edx .. " " .. time .. " " .. (px-ex))

--print("Why th efuck ")
--print("Why th efuck ")

if distance > (px - ex) then
local anstime = (px - ex) / (ballSpeed * edx)
local bonus = (ballSpeed * edy) * anstime
--print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (px-ex))
-- if (ifspecial == 0) then
local answer = ey + bonus
love.window.setTitle(answer)
return answer
-- else
-- return -1
-- end
else
local emulatedx = ex + distance
local emulatedy = 0
----print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (VIRTUAL_WIDTH-ex))
local answer = recursiveCalculations(px, emulatedx, emulatedy, edx, -edy, 0)
love.window.setTitle(answer)
if distance > (px - ex) then
local anstime = (px - ex) / (ballSpeed * edx)
local bonus = (ballSpeed * edy) * anstime
--print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (px-ex))
-- if (ifspecial == 0) then
local answer = ey + bonus
love.window.setTitle(tostring(answer) .. "Basiccalc")
return answer
end
-- else
-- return -1
-- end
else
local emulatedx = ex + distance
local emulatedy = 0
----print("results: " .. bonus .. " " .. edx .. " " .. anstime .. " " .. (VIRTUAL_WIDTH-ex))
local answer = recursiveCalculations(px, emulatedx, emulatedy, edx, -edy, 0)
love.window.setTitle(tostring(answer) .. "recursivecalc")
return answer
end
end
end

+ 2
- 2
src/baseGame.lua View File

@@ -467,7 +467,7 @@ function powerAvailability()
player1reverbav = 0
end
end
if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false then
if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false and (maxBalls > 1 or (ball[1].dx < 0 and ball[1].x < VIRTUAL_WIDTH/2))then
player1reverbav = 1
if ((globalState == "clienttest" and lastSentKeyP1 == p1control.counter) or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.counter))) then
powerControl(1, "special")
@@ -510,7 +510,7 @@ function powerAvailability()
end
end
end
if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false then
if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false and (maxBalls > 1 or (ball[1].dx > 0 and ball[1].x < VIRTUAL_WIDTH/2)) then
player2reverbav = 1
if (globalState ~= "nettest" and love.keyboard.isDown(p2control.counter)) or lastSentKeyClient == p2control.counter then
sounds["time"]:play()


Loading…
Cancel
Save