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

Username:   Password: 
 RegisterRegister   
 1st game, helicopter (update again oct 23)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
frank26080115




PostPosted: Sun Oct 22, 2006 3:44 pm   Post subject: 1st game, helicopter (update again oct 23)

I'm sure you are familar with the game called helicopter, the game that you fly a heli in a tunnel and try not to hit anything, i tried to clone it, like it, the tunnel narrows, but unlike it, the speed increases

code:
var winID : int %id of window
var accelrate : int %rate of accel
var accelrate2 : int %memory
var speed : int %speed of movement
var speed2 : int %memory
var ypos : int %where the dot is
var ypos2 : int %memory
var mx : int %mouse x position, useless
var my : int %mouse y position, useless
var mbutton : int %mouse button up or down
const maxspeed1 := 20 %maximum speed
var lose : int := 0 %if you lose, this is 1, the purpose is to stop "process getmousebutton"
var obsposx1 : int %obstacle
var obsposx2 : int := 750 %mem
var obsposx1a : int %obstacle
var obsposx2a : int := 750 + 375 + 50 %mem
var obsposx3 : int %obstacle
var obsposx4 : int := 750 %mem
var obsposx5 : int %obstacle
var obsposx6 : int := 1500 %mem
var obsposx7 : int %obstacle
var obsposx8 : int := 750 + 375 %mem
var obsposx9 : int %obstacle
var obsposx10 : int := 1500 + 375
var obsposx11 : int %obstacle
var obsposx12 : int := 1500 + 375 + 375
var obsposx13 : int %obstacle
var obsposx14 : int := 1500 + 375 + 375
var obsposy : int := Rand.Int (150, 350)
var obsposya : int := Rand.Int (150, 350)
var score1 : int := 0
var score2 : int := 0
var hiscore1 : int := 0
const narrowfactor := 75 %difficulty
const speedfactor := 125 %difficulty
var randomlower : int
var randomhigher : int
var font : int
var endl1 : int := 0
font := Font.New ("serif:25")
winID := Window.Open ("position:center;center,graphics:750;500;nobuttonbar;offscreenonly") %opens the window
%Draw a heli
%Draw.Box (43, 86, 131, 124, black)
%x88
%y38
colorback (black)
color (white)
%Draw.FillBox (50 - maxspeed1 * 2, 86 - maxspeed1 * 2, 138 + maxspeed1 * 2, 124 + maxspeed1 * 2, black)
Draw.FillOval (107, 100, 15, 10, grey)
Draw.FillBox (57, 105, 107, 110, grey)
Draw.FillOval (57, 107, 6, 6, brightblue)
Draw.FillOval (107, 115, 30, 8, brightblue)
Draw.FillBox (88 + 7, 90, 112 + 7, 87, grey)
% Create the picture
var pic := Pic.New (50, 86, 138, 124)
%var pic2 := Pic.New (250, 251, 250, 251)
cls
const xpos := 50 % x always here
%this detects mouse button
% process getmousebutton
%     loop
%         Mouse.Where (mx, my, mbutton)
%         if lose = 1 then
%             exit
%         end if
%     end loop
% end getmousebutton
procedure lowuhigh1
    if randomlower < randomhigher then
        obsposy := Rand.Int (randomlower, randomhigher)
    elsif randomlower >= randomhigher then
        obsposy := Rand.Int (randomhigher, randomlower)
    end if
end lowuhigh1
procedure lowuhigh1a
    if randomlower < randomhigher then
        obsposya := Rand.Int (randomlower, randomhigher)
    elsif randomlower >= randomhigher then
        obsposya := Rand.Int (randomhigher, randomlower)
    end if
end lowuhigh1a
procedure procobs1
    obsposx1 := obsposx2 - (15 + (score2 div (speedfactor)))
    obsposx2 := obsposx1
    Draw.FillOval (obsposx2, obsposy, 47 + Rand.Int( -3, 3), 47 + Rand.Int( -3, 3), brightgreen)
    Draw.FillOval (obsposx2, obsposy, 47 + Rand.Int( -3, 3), 47 + Rand.Int( -3, 3), brightgreen)
    if obsposx2 < -50 then
        obsposx2 := 800
        obsposx2a := 375
        randomlower := 50 + 50 + 50 + (score2 div narrowfactor)
        randomhigher := 450 - 50 - 50 - (score2 div narrowfactor)
        lowuhigh1
    end if
end procobs1
procedure procobs8
    obsposx1 := obsposx2 - (15 + (score2 div (speedfactor)))
    obsposx2 := obsposx1
    Draw.FillOval (obsposx2 + Rand.Int (-2, 2), obsposy + Rand.Int (-2, 2), 20 + Rand.Int (-5, 5), 20 + Rand.Int (-5, 5), brightred)
    Draw.FillOval (obsposx2 + Rand.Int (-2, 2), obsposy + Rand.Int (-2, 2), 20 + Rand.Int (-5, 5), 20 + Rand.Int (-5, 5), brightred)
    if obsposx2 < -50 then
        obsposx2 := 800
        obsposx2a := 375
        randomlower := 50 + 50 + 50 + (score2 div narrowfactor)
        randomhigher := 450 - 50 - 50 - (score2 div narrowfactor)
        lowuhigh1
    end if
end procobs8
procedure procobs9
    obsposx1a := obsposx2a - (15 + (score2 div (speedfactor)))
    obsposx2a := obsposx1a
    Draw.FillOval (obsposx2a, obsposya, 47 + Rand.Int( -3, 3), 47 + Rand.Int( -3, 3), brightgreen)
    Draw.FillOval (obsposx2a, obsposya, 47 + Rand.Int( -3, 3), 47 + Rand.Int( -3, 3), brightgreen)
    if obsposx2a < -50 then
        obsposx2 := 375
        obsposx2a := 800
        randomlower := 50 + 50 + 50 + (score2 div narrowfactor)
        randomhigher := 450 - 50 - 50 - (score2 div narrowfactor)
        lowuhigh1a
    end if
end procobs9
procedure procobs10
    obsposx1a := obsposx2a - (15 + (score2 div (speedfactor)))
    obsposx2a := obsposx1a
    Draw.FillOval (obsposx2a + Rand.Int (-2, 2), obsposya + Rand.Int (-2, 2), 20 + Rand.Int (-5, 5), 20 + Rand.Int (-5, 5), brightred)
    Draw.FillOval (obsposx2a + Rand.Int (-2, 2), obsposya + Rand.Int (-2, 2), 20 + Rand.Int (-5, 5), 20 + Rand.Int (-5, 5), brightred)
    if obsposx2a < -50 then
        obsposx2 := 375
        obsposx2a := 800
        randomlower := 50 + 50 + 50 + (score2 div narrowfactor)
        randomhigher := 450 - 50 - 50 - (score2 div narrowfactor)
        lowuhigh1a
    end if
end procobs10
procedure procobs2
    obsposx3 := obsposx4 - (15 + (score2 div (speedfactor div 2)))
    obsposx4 := obsposx3
    Draw.FillOval (obsposx4, 450 + 25 - (score2 div (narrowfactor - 1)), 750, 50 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx4 < -750 then
        obsposx4 := 750 + 750
    end if
end procobs2
procedure procobs3
    obsposx5 := obsposx6 - (15 + (score2 div (speedfactor div 2)))
    obsposx6 := obsposx5
    Draw.FillOval (obsposx6, 450 + 25 - (score2 div (narrowfactor - 1)), 750, 60 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx6 < -750 then
        obsposx6 := 750 + 750
    end if
end procobs3
procedure procobs4
    obsposx7 := obsposx8 - (15 + (score2 div (speedfactor div 2)))
    obsposx8 := obsposx7
    Draw.FillOval (obsposx8, 50 - 25 + (score2 div (narrowfactor + 1)), 750, 50 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx8 < -750 then
        obsposx8 := 750 + 750
    end if
end procobs4
procedure procobs5
    obsposx9 := obsposx10 - (15 + (score2 div (speedfactor div 2)))
    obsposx10 := obsposx9
    Draw.FillOval (obsposx10, 50 - 25 + (score2 div (narrowfactor + 1)), 750, 50 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx10 < -750 then
        obsposx10 := 750 + 750
    end if
end procobs5
procedure procobs6
    obsposx11 := obsposx12 - (15 + (score2 div (speedfactor div 2)))
    obsposx12 := obsposx11
    Draw.FillOval (obsposx12, 450 + 25 - (score2 div (narrowfactor + 1)), 750, 70 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx12 < -750 then
        obsposx12 := 750 + 750
    end if
end procobs6
procedure procobs7
    obsposx13 := obsposx14 - (15 + (score2 div (speedfactor div 2)))
    obsposx14 := obsposx13
    Draw.FillOval (obsposx14, 50 - 25 + (score2 div (narrowfactor + 1)), 750, 70 + (score2 div (speedfactor div 0.5)), brightgreen)
    if obsposx14 < -750 then
        obsposx14 := 750 + 750
    end if
end procobs7
procedure checkhs
    if score2 > hiscore1 then
        hiscore1 := score2
        score1 := 0
        score2 := 0
        put "high score: ", hiscore1
    else
        put "high score: ", hiscore1
    end if
end checkhs
%this checks if speed is over the limit
procedure checkspeed1
    if speed > maxspeed1 then
        speed := maxspeed1
    end if
end checkspeed1
put "Any Key to Play"
loop
    exit when hasch
end loop
loop
    score1 := 0
    score2 := 0
    %settings
    accelrate := 2
    accelrate2 := accelrate
    speed := 1
    speed2 := speed
    ypos := 250     %start from here
    ypos2 := ypos
    lose := 0
    % fork getmousebutton
    cls
    %level 1
    randomlower := 50 + 50 + 50 + (score2 div narrowfactor)
    randomhigher := 450 - 50 - 50 - (score2 div narrowfactor)
    loop
    Mouse.Where (mx, my, mbutton)
        %checks for direction
        if mbutton = 0 then     %this one is for gravity
            speed := speed2 + accelrate     %speed increase
        elsif mbutton = 1 then     %going up
            speed := speed2 - accelrate     %speed decrease
        end if
        speed2 := speed
        checkspeed1         %checks if speed is over the limit
        ypos := ypos2 - speed         %going down
        ypos2 := ypos
        Pic.Draw (pic, xpos, ypos, picMerge)         %draws the heli
        %obstacle
        Draw.FillBox (0, 0, 1000, 50 + (score2 div narrowfactor), brightgreen)            %bottom border
        Draw.FillBox (0, 450 - (score2 div narrowfactor), 1000, 500, brightgreen)        %top border
        if score2 <= 1500 then
            procobs1
            procobs9
        elsif score2 > 1500 then
            procobs8
            procobs10
        end if
        procobs2
        procobs3
        procobs4
        procobs5
        procobs6
        procobs7
        Draw.Text ("Score: " + intstr (score2), 2, 10, font, brightred)
        if score2 > hiscore1 then
            hiscore1 := score2
        end if
        Draw.Text ("High Score: " + intstr (hiscore1), 300, 10, font, brightred)
        % Draw.Text (intstr (obsposx2a - obsposx2), 300, 150, font, brightred)
        % Draw.Text (intstr (obsposx2 - obsposx2a), 300, 300, font, brightred)
        delay (66)         %delay for speed adjustment
        score1 := score2 + 1
        score2 := score1
        %collision detection using colour detection on edges and corners of heli pic
        if whatdotcolor (xpos + 10, ypos + 5) not= black then
            exit
        elsif whatdotcolor (xpos, ypos + 38) not= black then
            exit
        elsif whatdotcolor (xpos + 88, ypos) not= black then
            exit
        elsif whatdotcolor (xpos + 88, ypos + 38) not= black then
            exit
        elsif whatdotcolor (xpos + 44, ypos) not= black then
            exit
        elsif whatdotcolor (xpos + 44, ypos + 38) not= black then
            exit
        elsif whatdotcolor (xpos, ypos + 19) not= black then
            exit
        elsif whatdotcolor (xpos + 88, ypos + 19) not= black then
            exit
        end if
        View.Update
        cls
    end loop
    setscreen ("nooffscreenonly")
    Pic.Draw (pic, xpos, ypos, picMerge)
    Draw.Oval (xpos + 52, ypos + 19, 5, 5, brightred)
    delay (50)
    Draw.Oval (xpos + 52, ypos + 19, 6, 6, brightred)
    delay (75)
    Draw.Oval (xpos + 52, ypos + 19, 8, 8, brightred)
    delay (100)
    Draw.Oval (xpos + 52, ypos + 19, 11, 11, brightred)
    delay (125)
    Draw.Oval (xpos + 52, ypos + 19, 15, 15, brightred)
    delay (150)
    Draw.Oval (xpos + 52, ypos + 19, 20, 20, brightred)
    delay (175)
    Draw.Oval (xpos + 52, ypos + 19, 26, 26, brightred)
    delay (200)
    Draw.Oval (xpos + 52, ypos + 19, 33, 33, brightred)
    delay (225)
    Draw.Oval (xpos + 52, ypos + 19, 41, 41, brightred)
    delay (250)
    Draw.Oval (xpos + 52, ypos + 19, 50, 50, brightred)
    delay (275)
    Draw.Oval (xpos + 52, ypos + 19, 60, 60, brightred)
    delay (2000)
    obsposx2 := 1000
    obsposx2a := 1000 + 375 + 50
    obsposy := Rand.Int (50 + 50 + 50, 500 - 50 - 50)
    View.Update
    cls
    %cls
    put "try again"
    put "score: ", score2
    checkhs
    delay (3000)
    score2 := 0
    setscreen ("offscreenonly")
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: