Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 My animations keep pausing, and I don't know why?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vdemons




PostPosted: Sat May 21, 2011 10:52 pm   Post subject: 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 <= box_y2 and (x + x1) = maxx - 18 then
x2 := (-1) * x2
end if

if y >= box2_y1 and y <= box2_y2 and (x + x1) = 23 then
x2 := (-1) * x2
end if

if box_y2 + 5 >= maxy then
box_y2 -= 2
box_y1 -= 2
end if
if box_y1 - 5 <= 0 then
box_y2 += 2
box_y1 += 2
end if

if box2_y2 + 5 >= maxy then
box2_y2 -= 2
box2_y1 -= 2
end if
if box2_y1 - 5 <= 0 then
box2_y2 += 2
box2_y1 += 2
end if

if (x - x1) = 0 then
p2_score += 1
x := maxx div 2
y := maxy div 2
delay(1000)
elsif (x + x1) = maxx then
p1_score += 1
x := maxx div 2
y := maxy div 2
delay(1000)
end if

if p1_score = 0 then
Font.Draw ("0", 230, 450, font, red)
elsif p1_score = 1 then
Font.Draw ("1", 230, 450, font, red)
elsif p1_score = 2 then
Font.Draw ("2", 230, 450, font, red)
elsif p1_score = 3 then
Font.Draw ("3", 230, 450, font, red)
elsif p1_score = 4 then
Font.Draw ("4", 230, 450, font, red)
elsif p1_score = 5 then
Font.Draw ("5", 230, 450, font, red)
end if

if p2_score = 0 then
Font.Draw ("0", 610, 450, font, red)
elsif p2_score = 1 then
Font.Draw ("1", 610, 450, font, red)
elsif p2_score = 2 then
Font.Draw ("2", 610, 450, font, red)
elsif p2_score = 3 then
Font.Draw ("3", 610, 450, font, red)
elsif p2_score = 4 then
Font.Draw ("4", 610, 450, font, red)
elsif p2_score = 5 then
Font.Draw ("5", 610, 450, font, red)
end if

if p1_score >= 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)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat May 21, 2011 11:08 pm   Post subject: 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 View.Update?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: Sat May 21, 2011 11:16 pm   Post subject: 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




PostPosted: Sat May 21, 2011 11:32 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: