
-----------------------------------
anna12345
Mon Apr 14, 2008 10:42 am

Animation problem
-----------------------------------
How to make my bug move I mean like just the wings . I lost 2 marks just because my bug is not moving. So I need my bug to do something besides going around the screen

here's the code


%code for animation
procedure drawhills ()
    drawfilloval (90, 20, 100, 200, 49)
    drawfilloval (270, 20, 100, 100, 49)
    drawfilloval (440, 20, 100, 200, 49)
    drawfilloval (610, 20, 100, 300, 49)
end drawhills

procedure drawBackground (curcolor : int)
    drawfillbox (0, 0, maxx, maxy, curcolor)
end drawBackground

procedure drawStar (x1, y1, x2, y2, col, nDelay : int)
    drawfillstar (x1, y1, x2, y2, col)
    if (nDelay > 0) then
        View.Update
        delay (nDelay)
    end if
end drawStar


procedure drawStars (nDelay : int)
    drawStar (100, 300, 115, 315, 14, nDelay)
    drawStar (200, 200, 215, 215, 14, nDelay)
    drawStar (300, 200, 315, 215, 14, nDelay)
    drawStar (200, 350, 215, 365, 14, nDelay)
    drawStar (350, 280, 365, 295, 14, nDelay)
    drawStar (10, 200, 25, 215, 14, nDelay)
    drawStar (10, 350, 25, 365, 14, nDelay)
    drawStar (500, 350, 515, 365, 14, nDelay)
    drawStar (500, 450, 515, 465, 14, nDelay)
end drawStars

var x1, y1 : int := 0 
var key : array char of boolean 

procedure drawMyObject(x1,y1:int)
     Draw.FillBox (x1, y1, x1 + 50, y1 + 50, blue) 
end drawMyObject

procedure drawBug(x1,y1:int)
    drawfilloval( x1+20,y1+20, 20, 20, red)
    drawfilloval( x1+30,y1+30, 4, 4, yellow)
    drawfilloval( x1+10,y1+30, 4, 4, yellow)
    drawline( x1+20,y1, x1+20, y1+40, black)
    drawfilloval( x1+20,y1+42, 2, 2, black)
end drawBug

procedure drawMovableObject
    
    drawBug(x1,y1)
    Input.KeyDown (key) 
    if key (KEY_RIGHT_ARROW) and x1 + 50 not= maxx then 
        x1 += 1 
    elsif key (KEY_LEFT_ARROW) and x1 not= 0 then 
        x1 -= 1 
    elsif key (KEY_UP_ARROW) and y1 + 50 not= maxy then 
        y1 += 1 
    elsif key (KEY_DOWN_ARROW) and y1 not= 0 then 
        y1 -= 1 
    end if 


end drawMovableObject 


setscreen ("graphics: 600,600")
View.Set ('noecho, nocursor,offscreenonly')



var color1 : int := black
var color2 : int := 151
var color3 : int := 57
var color4 : int := 83
var color5 : int := 103
var color6 : int := 102
var color7 : int := 11
var curcolor : int := color1
var sunDelay : int := 10
var starDelay : int := 300
var loopDelay : int := 3000

loop

% Sun is moving up
    for x : 50 .. 500
        if x = 50 then
            curcolor := color1
        elsif x = 70 then
            curcolor := color2
        elsif x = 100 then
            curcolor := color3
        elsif x = 150 then
            curcolor := color4
        elsif x = 200 then
            curcolor := color5
        elsif x = 250 then
            curcolor := color6
        elsif x > 300 then
            curcolor := color7
        end if
        drawBackground (curcolor)
      
     
        drawfilloval (450, x, 50, 50, yellow)
        if (x < 150) then
            drawStars (0)
        end if
        drawhills ()
        drawMovableObject()
        View.Update
        delay (sunDelay)
        drawfilloval (450, x, 50, 50, curcolor)
    end for

% Sun is moving to the left
    for decreasing y : 450 .. 100
        drawBackground (curcolor)
        drawhills ()
        drawfilloval (y, 500, 50, 50, yellow)
        drawMovableObject()
        View.Update
        delay (sunDelay)
        drawfilloval (y, 500, 50, 50, color7)
    end for
    
% Sun is moving down    
    for decreasing i : 500 .. 10
        if i = 500 then
            curcolor := color7
        elsif i = 480 then
            curcolor := color6
        elsif i = 350 then
            curcolor := color5
        elsif i = 250 then
            curcolor := color4
        elsif i = 150 then
            curcolor := color3
        elsif i = 50 then
            curcolor := color2
        elsif i < 30 then
            curcolor := color1
        end if
        drawBackground (curcolor)
        drawfilloval (100, i, 50, 50, yellow)

        if (i = 150) then
            drawhills ()
            drawMovableObject()
            drawStars (starDelay)
        elsif (i < 150) then
            drawStars (0)
        end if
        drawhills ()
        drawMovableObject()
        View.Update
        delay (sunDelay)
        drawfilloval (100, i, 50, 50, curcolor)
        drawhills ()
    end for
    
    delay (loopDelay)
end loop

-----------------------------------
Tony
Mon Apr 14, 2008 11:30 am

RE:Animation problem
-----------------------------------
in your procedure to draw a bug, add another argument for a frame

procedure drawBug(x1,y1, frame:int) 

Where frame increments each time through the loop. This creates a loop internal to the bug, and you can draw it in different steps.
