
-----------------------------------
vdemons
Sat May 21, 2011 10:52 pm

My animations keep pausing, and I don't know why?
-----------------------------------
In my game, my animations keep pausing then continuing can someone please tell me why?
It didn't use to be like this before it worked fine and all of a sudden it does this and I don't know why, i think i may have done something accidentally before but I don't know what.
Can someone please help?

My Code:


import GUI

var winID : int
winID := Window.Open ("graphics:700;500:top;right,nobuttonbar")
View.Set ("title: Two Player Pong - By: Vishnu Kumarkulasingam")

var x, y : int %coordinates
x := maxx div 2
y := maxy div 2
var x1, y1 : int := 5 %size of ball
var x2, y2 : int := 1 %speed and direction
var chars : array char of boolean
var xmouse, ymouse, button : int
Input.KeyDown (chars)
var p1_score, p2_score : int := 0

var picID : int
var p1wins : int
var p2wins : int

var font, font2 : int
font := Font.New ("elephant:20")
font2 := Font.New ("serif:15")

var box_x1 : int := maxx - 15
var box_x2 : int := maxx - 5
var box_y1 : int := 218
var box_y2 : int := 293

var box2_x1 : int := 5
var box2_x2 : int := 15
var box2_y1 : int := 218
var box2_y2 : int := 293

picID := Pic.FileNew ("43818.jpg")
p1wins := Pic.FileNew ("Player 1 Wins.jpg")
p2wins := Pic.FileNew ("Player 2 Wins.jpg")
Pic.Draw (picID, -190, -134, picCopy)
Font.Draw ("This is Pong!", 25, 250, font, red)
Font.Draw ("Player 1 moves up and down using the, W and S keys.", 25, 200, font2, black)
Font.Draw ("Player 2 moves up and down using the, up arrow and down arrow keys.", 25, 150, font2, black)
Font.Draw ("First one to 5 points WINS!", 25, 100, font2, black)



procedure game
    loop
        Input.KeyDown (chars)
        setscreen ("offscreenonly")
        View.Update
        Draw.FillBox (0, 0, maxx, maxy, 255)
        drawfillbox (box_x1, box_y1, box_x2, box_y2, 8)
        drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, 8)
        drawfillbox (345, 0,355, 500, 0)
        Font.Draw ("Player 1:", 90, 450, font, 0)
        Font.Draw ("Player 2:", 460, 450, font, 0) 
        drawfilloval (x, y, x1, y1, 10)

        if chars ('w') then
            box2_y1 := box2_y1 + 2
            box2_y2 := box2_y2 + 2
        elsif chars ('s') then
            box2_y1 := box2_y1 - 2
            box2_y2 := box2_y2 - 2
        end if

        if chars (KEY_UP_ARROW) then
            box_y1 := box_y1 + 2
            box_y2 := box_y2 + 2
        elsif chars (KEY_DOWN_ARROW) then
            box_y1 := box_y1 - 2
            box_y2 := box_y2 - 2
        end if

        x := x + x2 %causes the ball to move around the screen
        y := y + y2

        if (x - x1) = 0 or (x + x1) = maxx then %makes the ball bounce on any wall border that is left or right
            x2 := (-1) * x2
        elsif (y - y1) = 0 or (y + y1) = maxy then %makes the ball bounce on any wall border that is top or bottom
            y2 := (-1) * y2
        end if

        if y >= box_y1 and y = box2_y1 and y = maxy then
            box_y2 -= 2
            box_y1 -= 2
        end if
        if box_y1 - 5 = maxy then
            box2_y2 -= 2
            box2_y1 -= 2
        end if
        if box2_y1 - 5 = 5 then
            cls
            colourback(black)cls
            Pic.Draw (p1wins, 200, 100, picCopy)
            var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit)
            exit when GUI.ProcessEvent
        elsif p2_score >= 5 then
            cls
            colourback(black)cls
            Pic.Draw (p2wins, 200, 100, picCopy)
            var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit)
            exit when GUI.ProcessEvent
        end if
        delay (4)
    end loop
end game



var b : int := GUI.CreateButton (maxx div 2, maxy div 2, 0, "Start Game", game)
var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit)

%% Finishes the program when quit button is pressed
loop
    exit when GUI.ProcessEvent
end loop

% Closes the window when the program is finished
Window.Close (winID)


-----------------------------------
Tony
Sat May 21, 2011 11:08 pm

RE:My animations keep pausing, and I don\'t know why?
-----------------------------------
This is an excellent lesson in the benefits of http://en.wikipedia.org/wiki/Revision_control

To be fair, revision control isn't ever (as far as I'm aware, there might be some select exceptions) mentioned at a high school level, and only briefly covered in University. You don't really need to understand the complexities of the wikipedia article beyond the "can go back in history to any save ever made, and see what the differences are"

I don't actually know what your code does or how the problem looks, but if I had to guess -- maybe something that has to do with [tdoc]View.Update[/tdoc]?

-----------------------------------
vdemons
Sat May 21, 2011 11:16 pm

RE:My animations keep pausing, and I don\'t know why?
-----------------------------------
How do you access all of your save files? Can you access them even if they were over written, in Turing I mean?

-----------------------------------
Tony
Sat May 21, 2011 11:32 pm

RE:My animations keep pausing, and I don\'t know why?
-----------------------------------
No, you need to setup a revision control system, such as Git http://en.wikipedia.org/wiki/Git_(software)

it's more of an advice-for-the-future sort of thing. It _will_ save you, if you ever decide to take on a large enough project. And it should be mandatory for professional work.
