
-----------------------------------
adrianr2z
Tue Jun 04, 2013 2:34 pm

Turing slows down
-----------------------------------
What is it you are trying to achieve?
Keep turing at the same speed. Basically to do so, I Have the overwrite on the arrays or get rid of them as the "bricks" roll off the screen.

What is the problem you are having?
Turing slows down over time when you play my game on the hard and medium level. The reason that this is caused by is because i have made an array of 1..999999.


Describe what you have tried to solve this problem
Nothing. Unsure of what to do. Read about flexible arrays and removing elements but don't quite understand. I have read the arrays tutorial many times and specifically about removing elements but I just can't seem to understand how to imply it in my code.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




View.Set ("graphics:max;max,nobuttonbar, offscreenonly")
%Introducing variables
% Add powerups
% add red bricks
% speed up as game goes on

var ballx, bally, font, font1, ballradius, numBlocks, ballspeed, box1X, box1Y, boxWidth, boxHeight, box2X, box2Y, box3X, box3Y, buttonnumber, buttonupdown : int
var x, y, rand1, value2, xvaluerand, speedofball, blockdivision : int
var xvalue, width, score, scorex, scorey, speed : int := 0
var score1 : string
ballradius := 20
ballx := maxx div 2
bally := maxy div 2
scorex := -60
scorey := maxy - 30
font1 := Font.New ("serif:15:bold")
font := Font.New ("serif:30:bold")
ballspeed := speed * 2
rand1 := 300
value2 := 20
xvaluerand := Rand.Int (0,250)
speedofball := 0
blockdivision := 0
box1X := 100
box1Y := maxy div 2
box2X := maxx div 2 - 130
box2Y := maxy div 2
box3X := maxx div 2 + 300
box3Y := maxy div 2
boxWidth := 200
boxHeight := 100
numBlocks := 1
var chars : array char of boolean
var blocks : array 1 .. 999999, 1 .. 2 of int
var newblock : boolean := false


blocks (numBlocks, 1) := Rand.Int (0, xvaluerand)

loop

    width := Rand.Int (ballradius * 2 + 1, rand1)  % sets the x location
    xvalue := xvalue + value2 + width
    blocks (numBlocks, 2) := 0
    blocks (numBlocks + 1, 1) := xvalue

    exit when xvalue >= maxx
    numBlocks := numBlocks + 1
end loop

procedure game



    loop

        Draw.FillOval (ballx, bally, ballradius, ballradius, brightgreen)
        bally := bally - speedofball


        if (bally - ballradius) - speedofball = maxx
            end loop
            newblock := false
        end if

        for i : 1 .. numBlocks

            if bally - ballradius >= blocks (i, 2) and bally - ballradius  maxy


    end loop

    Font.Draw ("Score: ", scorex + 70, scorey, font, brightgreen)

    Font.Draw (score1, scorex + 120, scorey, font, brightblue)

end game


procedure reset
    ballx := maxx div 2
    bally := maxy div 2
    score := 0
    xvalue := Rand.Int (0, xvaluerand)
    numBlocks := 0

    loop
        numBlocks := numBlocks + 1

        randint (width, ballradius * 2 + 1, rand1)         % sets the x location

        blocks (numBlocks, 1) := xvalue

        xvalue := xvalue + value2 + width

        blocks (numBlocks, 2) := 0

        blocks (numBlocks + 1, 1) := xvalue

        exit when xvalue >= maxx

    end loop
end reset



loop

    Draw.FillBox (box1X, box1Y, (box1X + boxWidth), (box1Y + boxHeight), brightred)
    % this is the box to change the color to red
    Draw.FillBox (box2X, box2Y, box2X + boxWidth, box1Y + boxHeight, blue)
    Draw.FillBox (box3X, box3Y, box3X + boxWidth, box1Y + boxHeight, brightgreen)
    Font.Draw ("Easy", box1X + 50, box1Y + 40, font, brightblue)
    Font.Draw ("Medium", box2X + 40, box2Y + 40, font, yellow)
    Font.Draw ("Hard", box3X + 50, box3Y + 40, font, brightred)
    Font.Draw ("Instructions:", maxx div 10, maxy - 100, font, purple)
    Font.Draw ("Welcome to my game young padawan and let me (Hossein) teach you the ways of mastering the game controls.", maxx div 8, maxy - 130, font1, brightblue)
    Font.Draw ("It is pretty simple to master them, simply use the left () arrow keys to move the ball side to side.", maxx div 8, maxy - 150, font1, brightgreen)
    Font.Draw ("The objective of the game is to keep the ball from going off the top of the screen", maxx div 8, maxy - 170, font1, 21)
    Font.Draw ("Good luck young padawan on your journey.", maxx div 8, maxy - 190, font1, 33)
    if Mouse.ButtonMoved ("down") then

        Mouse.ButtonWait ("down", x, y, buttonnumber, buttonupdown)

        cls

        % check if they are clicking inside the grey box
        if x > box1X and x < box1X + boxWidth and y > box1Y and y < box1Y + boxHeight then
            speedofball := 1
            blockdivision := maxx div 20
            speed := 1
            ballspeed := 2
            game
            reset
        end if

        % check if they are clicking inside the red box
        if x > box2X and x < box2X + boxWidth and y > box2Y and y < box2Y + boxHeight then
            speedofball := 2
            blockdivision := maxx div 15
            speed := 2
            ballspeed := 4
            game
            reset
        end if

        if x > box3X and x < box3X + boxWidth and y > box3Y and y < box3Y + boxHeight then
            speedofball := 3
            blockdivision := maxx div 10
            speed := 3
            ballspeed := 6
            game
            reset
        end if
    end if

    View.Update

end loop



Please specify what version of Turing you are using
Latest

-----------------------------------
Raknarg
Tue Jun 04, 2013 3:00 pm

RE:Turing slows down
-----------------------------------
Why do you need an array that size? Why don't you have a certain amount of blocks and just reuse them? I remember when I made a sidescrolling shooter, I had a maximum enemy count of 30 enemies. There would never be that many on the screen, so I wouldn't have to worry about an upper limit.

I don't know what a good number is for yours, but maybe you could have a maximum of 100 blocks or something, and just kill off blocks once they reach the top of the screen. That way you don't have to have rediculous arrays. here's an example:


setscreen ("offscreenonly")

type blockData :
    record
        x, y : int
        live : boolean
    end record

var block : array 1 .. 10 of blockData
var blockNum : int := 0
var spawnDelay : int := 100

for i : 1 .. 10
    block (i).live := false
end for

loop
    for i : 1 .. 10
        if block (i).live = true then
            block (i).x -= 2
            if block (i).x 