
-----------------------------------
Conrad13
Thu Dec 15, 2011 8:07 pm

Helicopter Game Help
-----------------------------------
 I'm sure everyone here has played the infamous Helicopter game where you simply click the screen to increase elevation and let go to decrease.
Okay, so I am trying to make a helicopter game, I have the intro done but i need a lot of help making the environment that is passes through and so on. I also am looking to making a separate page for controls which you can view before selecting to play the game.
Keeping in mind i will want it to be as realistic as possible like I want the distance to be counting in the corner of the screen and so on.
I need to make it so that when the colours of the helicopter contact the colours of the environment, then it ends the game and says replay, I am not new to Turing so I will for the better part know what you guys are trying to say however don't make it to complex. 

This is what I have so far.







var icolor : int
var icolor2 : int
var iXposition : int
var iYposition : int
var xdirection : int
var ydirection : int
var font : int
var font1 : int
var font2 : int
font := Font.New ("serif:50")
font1 := Font.New ("serif:20")
font2 := Font.New ("serif:20")

icolor2 := 21
icolor := 1
iXposition := 0
iYposition := 80
xdirection := 1
ydirection := 1
View.Set ("graphics,offscreenonly")
loop
    Draw.Cls


    % Background
    drawfillbox (0, 0, maxx, maxy, 100)


    % Cloud 1
    drawfilloval (90, 350, 130, 80, white)
    drawfilloval (70, 280, 80, 40, white)
    drawfilloval (200, 310, 60, 50, white)
    drawfilloval (230, 380, 60, 50, white)

    % Cloud 2
    drawfilloval (400, 150, 130, 80, white)
    drawfilloval (380, 80, 80, 40, white)
    drawfilloval (410, 220, 80, 40, white)
    drawfilloval (520, 110, 70, 50, white)
    drawfilloval (520, 190, 80, 50, white)
    drawfilloval (300, 180, 60, 50, white)
    drawfilloval (300, 120, 40, 30, white)


    % Helicopter
    drawfillbox (iXposition + 85, iYposition + 5, iXposition + 155, iYposition + 10, black) % Base (legs)
    drawfillbox (iXposition + 100, iYposition + 10, iXposition + 105, iYposition + 20, black) % Base 1
    drawfillbox (iXposition + 135, iYposition + 10, iXposition + 140, iYposition + 20, black) % Base 2
    drawfillbox (iXposition + 118, iYposition + 80, iXposition + 123, iYposition + 65, black) % Main Rotor
    drawfillbox (iXposition + 25, iYposition + 40, iXposition + 130, iYposition + 50, black) % Rotor rectangle
    drawfilloval (iXposition + 120, iYposition + 85, 70, 5, icolor2) % Rotor Blades
    drawfilloval (iXposition + 120, iYposition + 45, 40, 30, black) % Cockpit
    drawfillbox (iXposition + 10, iYposition + 40, iXposition + 15, iYposition + 70, black) % Rotor rectangle
    drawfilloval (iXposition + 15, iYposition + 48, 15, 15, icolor2) % Rear Rotor
    drawfilloval (iXposition + 85, iYposition + 45, 20, 15, black) % Smaller circle from main body of helicopter




    Draw.Text ("Super-Heli", 190, 25, font, icolor - 1)
    Draw.Text ("Play", 300, 240, font1, icolor - 1)
    Draw.Text ("Controls", 280, 200, font2, icolor - 1)
    icolor := icolor + 1
    if icolor = 62 then
        icolor := 1
    end if
    icolor2 := icolor2 + 1
    if icolor2 = 31 then
        icolor2 := 21
    end if
    iXposition := iXposition + xdirection
    iYposition := iYposition + ydirection

    if iXposition > 445 or iXposition < 0 then
        xdirection := -xdirection
    end if

    if iYposition > 305 or iYposition < 80 then
        ydirection := -ydirection
    end if

    delay (1)
    View.Update
end loop


Using Turing 4.1.1

-----------------------------------
Aange10
Thu Dec 15, 2011 8:48 pm

RE:Helicopter Game Help
-----------------------------------
I can't even read your post, my eyes hurt. Don't post in all bold!!

I'm not sure I can infer your problem, considering I could barley comprehend your giant wall of dark text. If you did state your problem, I missed it. 

Where do you need help? Specifically? and what have YOU tried to fix it?


EDIT: I think in a lucky glance at that cannon up there, I have found your problem (?).


I need to make it so that when the colours of the helicopter contact the colours of the environment, then it ends the game 


[code]
loop
if helicopter.color = helicopter.contractColor then
  endGame := true
end if
exit when endGame = true
end loop
[/code]

-----------------------------------
Conrad13
Thu Dec 15, 2011 9:42 pm

Re: Helicopter Game Help
-----------------------------------
Well, I have more then a simple problem, and sorry for the text as this is my first post I didnt know what to do. But anyways basically these are my problems:
- Creating a Menu where you click on the Controls or the Play and it takes you to either controls or play.( I created that intro part seen above however i do not know how to get it so that when you click it brings you to the controls or enters the game.
- Then I need to basically create the game (Helicopter controls (arrow keys or mouse click), environment to which it must dodge something i do not know what yet(hopefully more then shapes).
- Then the part where it measures (in the corner of the screen) the distance and after you crash it pops up and says the distance that you traveled.
- Then basically a key input that brings you back to the main Home screen

-----------------------------------
Aange10
Thu Dec 15, 2011 10:29 pm

RE:Helicopter Game Help
-----------------------------------
In the Turing Walkthrough, you can find answers to most of your questions. I expect you to go through there and read things like Keyboard Input, Mouse detection, etc. The tutorials are there for a reason.

I will help you with a basic algorithm to achieve your aspirations.

- When you read a tutorial on how to track clicking, you'll already be half done. Now just see if the user clicked on the play, and if it did then continue on. (etc)

- Collision detections is also in the walkthrough. The biggest hint I can give you is that there is no 'camera' in Turing. The way you have a camera is your draw things closer/farther to yourself.

- if I start a 0 and my x is now 500 then I've travled 500. SHould be simple.

-You know how to get input, so figure out how to loop to the main menu

-----------------------------------
Conrad13
Thu Dec 15, 2011 10:48 pm

Re: Helicopter Game Help
-----------------------------------
Thanks for the reply, it did help however still not 100% sure i am capable of like looping back to the main menu, am i supposed to name the loop so it knows what to loop back to or am i supposed to use if, then, input statements?
Also how will i create the flight course? do i need to make like 1000 shapes at which the helicopter must fly through that continuously loop through each other, or do i set it to the the y2 value of a drawfillbox to a random variable?

-----------------------------------
Aange10
Fri Dec 16, 2011 1:15 am

RE:Helicopter Game Help
-----------------------------------
Easiest thing to do would be to learn about Records and Arrays. From there you can just randomly place obsticles on your path.

There are tons of ways to do one thing, but I'll show you two of the most common.

Here's the easiest one, but it can make a mess sometimes.


loop
      % Main menu
      loop
            % Game
            exit when they click menu
      end loop
end loop


However, a better way to go about this, if you know procedures, could be something like this:


var gotoMainMenu : boolean := false

proc MainMenu
    var choseOption : boolean := false
    % Draw the main menu, options, etc.
    loop
        % Loop here untill they choose an option
        exit when choseOption = true
    end loop
    gotoMainMenu := false
end MainMenu

loop
    % Run the Game, somewhere in here you will check for the 'exit' key to be pressed
    % When pressed you can toggle the main menu, and reset variables 


Study up on records and arrays for your second question. You will need to have a firm grasp on for loops as well.

A general gist of what you'll be doing:


% Make a Record
type OData :
    record
        x, y, x2, y2, Color : int
    end record

% Make an array of the record
var obsticles : array 0 .. 30 of OData

% Initialize the array

for i : 0 .. upper (obsticles)
    % There'll be a bit of math here. Try and see whats happening.
    % This way will keep our boxes from just being in a straight line, or
    % on top of each other.
    obsticles (i).x := 150 + (i * 200) % (the 200 is the spacing)
    obsticles (i).y := 100 + (25 * Rand.Int (1, 15)) % This will vary where the y cords of the block are
    obsticles (i).x2 := obsticles (i).x + 20 % 20 is the width
    obsticles (i).y2 := obsticles (i).y + 20 % 20 is the height
    obsticles (i).Color := Rand.Int (7, 14)
end for


% For a visual on how this works;

loop
    cls
    % Move all the blocks over by 20
    for i : 0 .. upper (obsticles)
        obsticles (i).x += -20
        obsticles (i).x2 += -20
    end for
    % Draw them all
    for i : 0 .. upper (obsticles)
        drawfillbox (obsticles (i).x, obsticles (i).y, obsticles (i).x2, obsticles (i).y2, obsticles (i).Color)
    end for
    % My little exit statement to stop when all the obsticles have passed
    if obsticles (upper (obsticles)).x < 0 then
        exit
    end if
    Time.DelaySinceLast (50)
end loop



There are many ways to make this better, and to customize it and optimize it. Hopefully that teaches you the concept a bit, but still read the tutorials.

Nothings set in stone

-----------------------------------
Conrad13
Fri Dec 16, 2011 1:25 pm

Re: Helicopter Game Help
-----------------------------------
Ok so i managed to update the menu a few.. i only had a few minutes at school but now atleast when the play or controls is selected, the function happens!
This is what i have so far:

var icolor : int
var icolor2 : int
var iXposition : int
var iYposition : int
var xdirection : int
var ydirection : int
var font : int
var font1 : int
var font2 : int
var xmouse, ymouse, button : int
font := Font.New ("serif:50")
font1 := Font.New ("serif:25")
font2 := Font.New ("serif:25")

icolor2 := 21
icolor := 1
iXposition := 0
iYposition := 80
xdirection := 1
ydirection := 1
View.Set ("graphics,offscreenonly")
loop
Mouse.Where(xmouse,ymouse,button)

    Draw.Cls
    
    drawfillbox (300,240,350,260,41)


    % Background
    drawfillbox (0, 0, maxx, maxy, 100)


    % Cloud 1
    drawfilloval (90, 350, 130, 80, white)
    drawfilloval (70, 280, 80, 40, white)
    drawfilloval (200, 310, 60, 50, white)
    drawfilloval (230, 380, 60, 50, white)

    % Cloud 2
    drawfilloval (400, 150, 130, 80, white)
    drawfilloval (380, 80, 80, 40, white)
    drawfilloval (410, 220, 80, 40, white)
    drawfilloval (520, 110, 70, 50, white)
    drawfilloval (520, 190, 80, 50, white)
    drawfilloval (300, 180, 60, 50, white)
    drawfilloval (300, 120, 40, 30, white)


    % Helicopter
    drawfillbox (iXposition + 85, iYposition + 5, iXposition + 155, iYposition + 10, black) % Base Connected to Legs
    drawfillbox (iXposition + 100, iYposition + 10, iXposition + 105, iYposition + 20, black) % Base leg 1
    drawfillbox (iXposition + 135, iYposition + 10, iXposition + 140, iYposition + 20, black) % Base leg 2
    drawfillbox (iXposition + 118, iYposition + 80, iXposition + 123, iYposition + 65, black) % Main Rotor
    drawfillbox (iXposition + 25, iYposition + 40, iXposition + 130, iYposition + 50, black) % Rotor rectangle
    drawfilloval (iXposition + 120, iYposition + 85, 70, 5, icolor2) % Rotor Blades
    drawfilloval (iXposition + 120, iYposition + 45, 40, 30, black) % Cockpit
    drawfillbox (iXposition + 10, iYposition + 40, iXposition + 15, iYposition + 70, black) % Rotor rectangle
    drawfilloval (iXposition + 15, iYposition + 48, 15, 15, icolor2) % Rear Rotor
    drawfilloval (iXposition + 85, iYposition + 45, 20, 15, black) % Smaller circle from main body of helicopter




    Draw.Text ("Super-Heli", 190, 25, font, icolor - 1)
    Draw.Text ("Play", 300, 240, font1, icolor - 1)
    Draw.Text ("Controls", 275, 150, font2, icolor - 1)
    
    if xmouse>290 and xmouse230 and ymouse270 and xmouse140 and ymouse 445 or iXposition < 0 then
        xdirection := -xdirection
    end if

    if iYposition > 305 or iYposition < 80 then
        ydirection := -ydirection
    end if

    delay (10)
    View.Update
end loop

-----------------------------------
Aange10
Fri Dec 16, 2011 3:36 pm

RE:Helicopter Game Help
-----------------------------------
contrats! And I suggest wrapping your code in

[ syntax = "turing"]
and
[ /syntax ]

-----------------------------------
Conrad13
Fri Dec 16, 2011 10:40 pm

Re: Helicopter Game Help
-----------------------------------
Thanks Man Helped Me out a lot!! The biggest problem was knowing where to put the separate screens and if i have to loop them separately but I think i have it figured out thanks again! If i need further assistance keep me posted please thank you!

-----------------------------------
Conrad13
Mon Dec 19, 2011 4:48 pm

Re: Helicopter Game Help
-----------------------------------
Ok, so this is my code so far i know i do not have the game going yet however I feel the need to update my post :)
[ syntax = "turing"]
var icolor : int
var icolor2 : int
var iXposition : int
var iYposition : int
var xdirection : int
var ydirection : int
var font : int
var font1 : int
var font2 : int
var font3 : int
var xmouse, ymouse, button : int
var ch : string (1)
 
font := Font.New ("serif:50")
font1 := Font.New ("serif:25")
font2 := Font.New ("serif:15")
font3 := Font.New ("serif:9")

icolor2 := 21
icolor := 1
iXposition := 0
iYposition := 0
xdirection := 1
ydirection := 1
View.Set ("graphics,offscreenonly,nocursor")
loop
Mouse.Where(xmouse,ymouse,button)

    Draw.Cls
    
    drawfillbox (300,240,350,260,41)


    % Background
    drawfillbox (0, 0, maxx, maxy, 100)


    % Cloud 1
    drawfilloval (90, 350, 130, 80, white)
    drawfilloval (70, 280, 80, 40, white)
    drawfilloval (200, 310, 60, 50, white)
    drawfilloval (230, 380, 60, 50, white)

    % Cloud 2
    drawfilloval (400, 150, 130, 80, white)
    drawfilloval (380, 80, 80, 40, white)
    drawfilloval (410, 220, 80, 40, white)
    drawfilloval (520, 110, 70, 50, white)
    drawfilloval (520, 190, 80, 50, white)
    drawfilloval (300, 180, 60, 50, white)
    drawfilloval (300, 120, 40, 30, white)


    % Helicopter
    drawfillbox (iXposition + 85, iYposition + 5, iXposition + 155, iYposition + 10, black) % Base Connected to Legs
    drawfillbox (iXposition + 100, iYposition + 10, iXposition + 105, iYposition + 20, black) % Base leg 1
    drawfillbox (iXposition + 135, iYposition + 10, iXposition + 140, iYposition + 20, black) % Base leg 2
    drawfillbox (iXposition + 118, iYposition + 80, iXposition + 123, iYposition + 65, black) % Main Rotor
    drawfillbox (iXposition + 25, iYposition + 40, iXposition + 130, iYposition + 50, black) % Rotor rectangle
    drawfilloval (iXposition + 120, iYposition + 85, 70, 5, icolor2) % Rotor Blades
    drawfilloval (iXposition + 120, iYposition + 45, 40, 30, black) % Cockpit
    drawfillbox (iXposition + 10, iYposition + 40, iXposition + 15, iYposition + 70, black) % Rotor rectangle
    drawfilloval (iXposition + 15, iYposition + 48, 15, 15, icolor2) % Rear Rotor
    drawfilloval (iXposition + 85, iYposition + 45, 20, 15, black) % Smaller circle from main body of helicopter




    Draw.Text ("Super-Heli", 190, 325, font, icolor - 1)
    Draw.Text ("Play", 300, 180, font1, icolor - 1)
    Draw.Text ("Controls", 275, 120, font1, icolor - 1)
    
    % Play
    if xmouse>290 and xmouse170 and ymouse270 and xmouse100 and ymouse 455 or iXposition < 0 then
        xdirection := -xdirection
    end if

    if iYposition > 215 or iYposition < 0 then
        ydirection := -ydirection
    end if
   

    delay (0)
    View.Update
end loop

[ /syntax ]
I could use some help as to where to start my game :(.
Like i do no know where to start, i feel if i get a start i can move from there any ideas?
Thanks to all contributor(s) 290 and xmouse170 and ymouse 10 then
            chary := chary - 1
        end if
        if num (KEY_LEFT_ARROW) and charx > 10 then
            charx := charx - 1
        end if
        if num (KEY_RIGHT_ARROW) and charx < 630 then
            charx := charx + 1
        end if
        
        % Draw everything
        Draw.FillOval (targetx, targety, 20, 20, black)
        Draw.Oval (charx, chary, 5, 5, brightred)
        colourback (0) put "targetx:", targetx
        colourback (0) put "targety:", targety
        
        % ONE line of collision
        exit when whatdotcolor (charx, chary) = black
        View.Update
        delay (5)
        cls
    end loop
    cls
end loop 

% Taken from the Whatdotcolor tutorial




-----------------------------------
Conrad13
Thu Dec 22, 2011 5:46 pm

RE:Helicopter Game Help
-----------------------------------
: / still dont get this

-----------------------------------
Aange10
Thu Dec 22, 2011 6:39 pm

RE:Helicopter Game Help
-----------------------------------
What part do you not get?

-----------------------------------
Conrad13
Thu Dec 22, 2011 7:12 pm

RE:Helicopter Game Help
-----------------------------------
thanks, but never mind ill try and figure it out

-----------------------------------
Conrad13
Thu Dec 22, 2011 9:02 pm

Re: Helicopter Game Help
-----------------------------------
Can anyone help me with color collision detection?!! Please out of all the people on the forum how do i only have one person trying to help?!!? :(

-----------------------------------
chipanpriest
Thu Dec 22, 2011 9:27 pm

Re: Helicopter Game Help
-----------------------------------
if whatdotcolor (x,y) = col then
exit
end if

Think that would work?

-----------------------------------
Aange10
Thu Dec 22, 2011 9:46 pm

RE:Helicopter Game Help
-----------------------------------
Indeed, whatdotcolor is very simple. you put in the x cord, and the y cord, and it tells you what color that dot is. Simple.


So you could look at the edge of your helicopter, and say "if this dot turns white, exit". To do that you'd say whatdotcolor (theDotsXposition, theDotsYposition). That'd give you the color of that dot, then you'd take it and compare it and see if its white.


if whatdotcolor (theDotsXposition, theDotsYposition) = white then
exit
end if


-----------------------------------
chipanpriest
Thu Dec 22, 2011 9:59 pm

Re: Helicopter Game Help
-----------------------------------
for the ceiling and floor you could put
if helicoptery >= maxy then
exit
elsif helicoptery 