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

Username:   Password: 
 RegisterRegister   
 Some More Advanced Graphics - Skifree Backcountry
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GregLP




PostPosted: Fri Nov 18, 2005 10:10 pm   Post subject: Some More Advanced Graphics - Skifree Backcountry

I'm doing a remake of the classic game Skifree. Problem is that with all the moving objects, it's quite blinky with all the graphics, even with a delay. Any ideas?

code:

% Friday November 18th/2005

% add up command
% tricks - keys?
% backcountry?
% crash detection
% error trapping
% comments
% high score?
% intro
% clock
% finish line
% fix blinking on edge of screen
% fix skating sideways

procedure main
    %-------------------------------------------------

    % Edit Scenery

    const numbersmalltrees := 15
    const numberbigtrees := 13
    const numbercliffs := 4

    %-------------------------------------------------

    % Main Variables

    View.Set ("offscreenonly")
    setscreen ("graphics:max;max,nobuttonbar;nocursor")
    var key : string (1)
    var down : int
    var turnleft : int
    var turnright : int
    var hardturnleft : int
    var hardturnright : int
    var stopleft : int
    var stopright : int
    var skateleft : int
    var skateright : int
    var speedy : int := 17
    var speedx : int := 0
    var position := 0
    var cliff : int
    const locationx := round (maxx / 2)
    const locationy := round (maxy / 2)
    var tree : int
    var bigtree : int

    %-------------------------------------------------

    % Pictures

    down := Pic.FileNew ("down.bmp")                        % regular position
    stopleft := Pic.FileNew ("stop.bmp")          % stopped in left position
    stopright := Pic.FileNew ("stopright.bmp")    % stopped in right position
    turnleft := Pic.FileNew ("left.bmp")                % gentle turn left
    turnright := Pic.FileNew ("right.bmp")              % gentle turn right
    hardturnleft := Pic.FileNew ("lefterturn.bmp")            % sharp turn left
    hardturnright := Pic.FileNew ("righterturn.bmp")          % sharp turn right
    skateleft := Pic.FileNew ("skate.bmp")
    skateright := Pic.FileNew ("skateright.bmp")
    cliff := Pic.FileNew ("cliff.bmp")
    tree := Pic.FileNew ("tree.bmp")
    bigtree := Pic.FileNew ("bigtree.bmp")

    %-------------------------------------------------

    % Arrays for scenery

    var cliffx : array 1 .. numbercliffs of int
    var cliffy : array 1 .. numbercliffs of int
    var treex : array 1 .. numbersmalltrees of int
    var treey : array 1 .. numbersmalltrees of int
    var bigtreex : array 1 .. numberbigtrees of int
    var bigtreey : array 1 .. numberbigtrees of int

    %---------------------------------------------

    % Random Integers for scenery

    for i : 1 .. numbercliffs
        randint (cliffx (i), 1, maxx)
    end for
    for j : 1 .. numbercliffs
        randint (cliffy (j), 1, maxy)
    end for

    for i : 1 .. numbersmalltrees
        randint (treex (i), 1, maxx)
    end for
    for j : 1 .. numbersmalltrees
        randint (treey (j), 1, maxy)
    end for

    for i : 1 .. numberbigtrees
        randint (bigtreex (i), 1, maxx)
    end for
    for j : 1 .. numberbigtrees
        randint (bigtreey (j), 1, maxy)
    end for

    %-------------------------------------------------

    % Draw the guy

    loop
        loop
            cls
            if position = 0 then
                speedy := 10
                speedx := 0
                Pic.Draw (down, locationx, locationy, picUnderMerge)
            elsif position = 1 then
                speedy := 7
                speedx := -4
                Pic.Draw (turnright, locationx, locationy, picUnderMerge)
            elsif position = 2 then
                speedy := 3
                speedx := -5
                Pic.Draw (hardturnright, locationx, locationy, picUnderMerge)
            elsif position = 3 then
                speedy := 0
                speedx := 0
                Pic.Draw (stopright, locationx, locationy, picUnderMerge)
            elsif position = 4 then
                speedy := 0                                                                 % Fix
                speedx := -3
                Pic.Draw (skateright, locationx, locationy, picUnderMerge)
            elsif position = -1 then
                speedy := 7
                speedx := 4
                Pic.Draw (turnleft, locationx, locationy, picUnderMerge)
            elsif position = -2 then
                speedy := 3
                speedx := 5
                Pic.Draw (hardturnleft, locationx, locationy, picUnderMerge)
            elsif position = -3 then
                speedy := 0
                speedx := 0
                Pic.Draw (stopleft, locationx, locationy, picUnderMerge)
            elsif position = -4 then
                speedy := 0                                                                % Fix
                speedx := 3
                Pic.Draw (skateleft, locationx, locationy, picUnderMerge)
            end if

            %----------------------------

            % Draw Scenery

            for j : 1 .. numbercliffs
                if cliffy (j) < 0 or cliffy (j) > maxy then
                    randint (cliffx (j), 1, maxy)
                    cliffy (j) := 0
                elsif cliffx (j) < 1 or cliffx (j) > maxx then
                    randint (cliffy (j), 1, maxx)
                    cliffx (j) := 0
                else
                    cliffy (j) += speedy
                    cliffx (j) += speedx
                end if
                Pic.Draw (cliff, cliffx (j) + speedx, cliffy (j) + speedy, picUnderMerge)
            end for



            for j : 1 .. numberbigtrees
                if bigtreey (j) < 0 or bigtreey (j) > maxy then
                    randint (bigtreex (j), 0, maxx)
                    bigtreey (j) := 0
                elsif bigtreex (j) < 0 or bigtreex (j) > maxx then
                    randint (bigtreey (j), 0, maxy)
                    bigtreex (j) := 0
                else
                    bigtreey (j) += speedy
                    bigtreex (j) += speedx
                end if
                Pic.Draw (bigtree, bigtreex (j) + speedx, bigtreey (j) + speedy, picMerge)
            end for


            for j : 1 .. numbersmalltrees
                if treey (j) < 0 or treey (j) > maxy then
                    randint (treex (j), 1, maxx)
                    treey (j) := 0
                elsif treex (j) < 0 or treex (j) > maxx then
                    randint (treey (j), 0, maxy)
                    treex (j) := 0
                else
                    treey (j) += speedy
                    treex (j) += speedx
                end if
                Pic.Draw (tree, treex (j) + speedx, treey (j) + speedy, picMerge)
            end for
            exit when hasch
            View.Update
            delay (20)
        end loop
        getch (key)

        %----------------------------------------------

        % Determine the position, Controls

        if ord (key) = 208 then             % down
            position := 0
        elsif ord (key) = 205 then          % right
            if position = -4 then
                position += 2
            elsif position = 4 then
                position := 3
            else
                position += 1
            end if
        elsif ord (key) = 203 then          % left
            if position = 4 then
                position -= 2
            elsif position = -4 then
                position := -3
            else
                position -= 1
            end if
        end if
    end loop
end main

main



The particularily troubling area is the draw scenery section. I'm trying to get it so that when the object goes off the screen, another one is redrawn randomly on the opposite side to fll in the map so it is an infinitely large hill.

Don't mind some of the messy programming, I usually clean the stuff up when I'm done anyhow.

G



Skifree.zip
 Description:
All my images

Download
 Filename:  Skifree.zip
 Filesize:  30.13 KB
 Downloaded:  56 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Sun Nov 20, 2005 8:24 pm   Post subject: (No subject)

-> Use the jpegs instead of bmp, jpegs are compressed and will save CPU process and will actually run it faster and smoother.
-> What do you mean by "when the object goes off the screen, another one is redrawn randomly on the opposite side to fll in the map so it is an infinitely large hill"
iker




PostPosted: Sun Nov 20, 2005 9:05 pm   Post subject: (No subject)

What I think he means is that when a tree is far enough behind you, that it will dissapear and reappear infront of you? i guess... anyways, I used a code like that in my LFS game, so i can tell you say the trees are drawn at:

tree(n)x, tree(n)y (n) representing a number
loop the trees going upwards
then when a tree reaches the top of the screen redraw it at the bottom
code:

loop
    tree(n)y+=1
    draw (tree(n)x, tree(n)y, pic.Merge)
    if tree(n)y > maxy then
        randint (tree(n)x, 0, maxx)
    end if
end loop


also, instead of putting a loop, then say when the skier's speed downwards is actualy the trees speed upwards
lets say if you press the down arrow, the guy moves
code:

if key (KEY_DOWN_ARROW) then
    tree(n)y += speed
    draw (tree(n)x, tree(n)y, pic.Merge)
    if tree(n)y > maxy then
        randint (tree(n)x, 0, maxx)
    end if
end if
[Gandalf]




PostPosted: Mon Nov 21, 2005 1:28 am   Post subject: (No subject)

MysticVegeta wrote:
-> Use the jpegs instead of bmp, jpegs are compressed and will save CPU process and will actually run it faster and smoother.

No. You may not have noticed, but jpegs are horrible for when you are using Pic.SetTransparentColor. Too bad Turing doesn't support pngs or gifs...
ZeroPaladn




PostPosted: Mon Nov 21, 2005 10:08 am   Post subject: (No subject)

you say the animation is flickery, maybe because you have about 3 or 4 different loops with animation, but only one of them has View.Update. the only animation loop that has the View.Update will not flciker, but the other ones will. My suggestions is to stuff your code into procedures, and make a main loop and then stick only 1 cls, View.Update, and delay in so the animation will stop flickering. that usually solves my problems.[/code]
MysticVegeta




PostPosted: Mon Nov 21, 2005 2:50 pm   Post subject: (No subject)

[Gandalf] wrote:
MysticVegeta wrote:
-> Use the jpegs instead of bmp, jpegs are compressed and will save CPU process and will actually run it faster and smoother.

No. You may not have noticed, but jpegs are horrible for when you are using Pic.SetTransparentColor. Too bad Turing doesn't support pngs or gifs...


oh I didnt pay attention to transparent color command. Embarassed
GregLP




PostPosted: Mon Nov 21, 2005 11:09 pm   Post subject: (No subject)

I discovered what was wrong!

It was all how I was drawing the pics. It seemed like the left edge of the screen was 'collecting' the pics and that gave me the hint that I should split up the drawscenery if statements into:

code:

if cliffy (j) < 0 then
       randint (cliffx (j), 1, maxy)
       cliffy (j) := maxy
elsif cliffy (j) > maxy then
       randint (cliffx (j), 1, maxy)
       cliffy (j) := 0
 
% and so on


This solved my problem and now it's quite smooth.

I just need to change my blasted pics back to bmp now!!!! Evil or Very Mad

Very Happy

Thanks for the suggestions. I broke my program into messy procedures and tried to improve efficiency. This proggy will prolly be quite CPU intensive after I add all the other stuff and possibly even more scenery Rolling Eyes

g
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  [ 7 Posts ]
Jump to:   


Style:  
Search: