I want to write a little Pong game, but the RAM of the following game keeps increasing and slowing down the longer I run it.
Note, it's not completed yet, it has terrible design, etc.
I just want to know why the performance of the game get worse and worse the longer I run it.
I've also attached the following code as .agc file
// Project: Demo
// Created: 2015-07-21
// set window properties
SetWindowTitle( "Demo" )
SetWindowSize( 1920, 1080, 1 )
// set display properties
SetVirtualResolution( 1920, 1080 )
SetOrientationAllowed( 1, 1, 1, 1 )
#constant BoxY 28.75
#constant Box1X 50
#constant Box1Width 233
#constant Box2X 1610
#constant Box2Width 260
#constant Box3X 333
#constant Box3Width 233
#constant PlayerHeight 126.875
#constant PlayerWidth 30
#constant MoveStep 4
global signalToPlay = 0
global BallX# = 960
global BallY# = 468.125
global Player1#
Player1# = 468.125 - PlayerHeight/2
global Player2#
Player2# = 468.125 - PlayerHeight/2
function MouseOverStartButton()
MouseX# = GetRawMouseX()
MouseY# = GetRawMouseY()
value = 0
if ((MouseX# > Box1X AND MouseX# < Box1X + Box1Width) AND (MouseY# > BoxY AND MouseY# < 3*BoxY)) then value = 1
endfunction value
function MouseOverExitButton()
MouseX# = GetRawMouseX()
MouseY# = GetRawMouseY()
value = 0
if (MouseX# > Box2X AND MouseX# < Box2X + Box2Width) AND (MouseY# > BoxY AND MouseY# < 3*BoxY) then value = 1
endfunction value
function MouseOverEndButton()
MouseX# = GetRawMouseX()
MouseY# = GetRawMouseY()
value = 0
if (MouseX# > Box3X AND MouseX# < Box3X + Box3Width) AND (MouseY# > BoxY AND MouseY# < 3*BoxY) then value = 1
endfunction value
function DrawBoxes()
DrawBox(Box1X, BoxY, Box1X + Box1Width, 3*BoxY, MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), 0 )
newGameString = CreateText("New Game")
DrawBox(Box2X, BoxY, Box2X + Box2Width, 3*BoxY, MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), 0 )
exitGameString = CreateText("Exit Game")
DrawBox(Box3X, BoxY, Box3X + Box3Width, 3*BoxY, MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), MakeColor(255,255,255), 0 )
endGameString = CreateText("End Game")
SetTextSize(newGameString, 45)
SetTextSize(exitGameString, 45)
SetTextSize(endGameString, 45)
SetTextX(newGameString, Box1X+3)
SetTextY(newGameString, 3/2*BoxY+7)
SetTextX(exitGameString, Box2X+3)
SetTextY(exitGameString, 3/2*BoxY+7)
SetTextX(endGameString, Box3X+3)
SetTextY(endGameString, 3/2*BoxY+7)
if MouseOverStartButton()
SetTextColor(newGameString, 200, 255, 0, 255)
DrawBox(Box1X, BoxY, Box1X + Box1Width, 3*BoxY, MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), 0 )
if GetRawMouseLeftPressed() then signalToPlay = 1
endif
if MouseOverEndButton()
SetTextColor(endGameString, 200, 255, 0, 255)
DrawBox(Box3X, BoxY, Box3X + Box3Width, 3*BoxY, MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), 0 )
if GetRawMouseLeftPressed() then signalToPlay = 0
endif
if MouseOverExitButton()
SetTextColor(exitGameString, 200, 255, 0, 255)
DrawBox(Box2X, BoxY, Box2X + Box2Width, 3*BoxY, MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), 0 )
if GetRawMouseLeftPressed() then end
endif
endfunction
function DrawGameSurface() // Game size 1920*936.25
DrawLine(0, 4*BoxY , 1920, 4*BoxY , 255,255,255)
DrawLine(0, 1080 - BoxY , 1920, 1080 - BoxY , 255,255,255)
for i = 0 to 31
if (Mod(i, 2) = 1) then continue
DrawLine(960, 4*BoxY + i*BoxY, 960, 5*BoxY + i*BoxY, 255,255,255 )
next
DrawLine(960, 4*BoxY + 32*BoxY, 960, 1080 - BoxY, 255,255,255 )
endfunction
function DrawBall(x, y)
y = y + 4*BoxY + 1
DrawBox(x - PlayerWidth/2, y - PlayerWidth/2, x + PlayerWidth/2, y + PlayerWidth/2, MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), MakeColor(200, 255, 0), 1)
endfunction
function DrawPlayer(playerNumber, y)
y = y + 4*BoxY + 1
if playerNumber = 1
DrawBox(Box1X, y , Box1X + PlayerWidth, y + PlayerHeight, MakeColor(250, 2, 16), MakeColor(250, 2, 16), MakeColor(250, 2, 16), MakeColor(250, 2, 16), 1)
elseif playerNumber = 2
DrawBox(1920-50-PlayerWidth, y, 1920-50, y + PlayerHeight, MakeColor(36,55,194), MakeColor(36,55,194), MakeColor(36,55,194), MakeColor(36,55,194), 1)
endif
endfunction
do
DrawBoxes()
if (signalToPlay = 1)
DrawGameSurface()
DrawPlayer(1, Player1#)
DrawPlayer(2, Player2#)
DrawBall(BallX#, BallY#)
// Player1 Controls
if GetRawKeyState(87)
Player1# = Player1# - MoveStep
if Player1# <= 0 then Player1# = 2
DrawPlayer(1, Player1#)
endif
if GetRawKeyState(83)
Player1# = Player1# + MoveStep
if ((Player1# + PlayerHeight) >= 936.25) then Player1# = 936.25 - 2 - PlayerHeight
DrawPlayer(1, Player1#)
endif
//Player2 Controls
if GetRawKeyState(38)
Player2# = Player2# - MoveStep
if Player2# <= 0 then Player2# = 2
DrawPlayer(2, Player2#)
endif
if GetRawKeyState(40)
Player2# = Player2# + MoveStep
if ((Player2# + PlayerHeight) >= 936.25) then Player2# = 936.25 - 2 - PlayerHeight
DrawPlayer(2, Player2#)
endif
endif
Sync()
loop