Computer Science Canada

A question on shooting...

Author:  Remm [ Mon May 08, 2006 6:46 pm ]
Post subject:  A question on shooting...

Alright. After much trouble with account activation, i can finally ask about this. First, my program - in - the - works. Im not too good at turing, and prolly have high hopes to make this game. Anyone remember that old game where you were the little turret shooting down choppers and paratroopers, trying to stop them from touching the ground? I'm trying to re-create that game. However, im having troubles making the shots work.
I shoot, and only bullet is fired, and it lazily follows the cannon around. Anyone know how i can fix it so the shot fires, and more than one can be fired at a time?
Thanks again
Remm
code:


var win1 : int
var num1, num2 : int
num1 := 380
num2 := 73
%Open window

win1 := Window.Open("nocursor;title;Gunner;graphics:800;600;position:center;top")
Draw.FillBox (360, 3, 400, 33, black)
Draw.FillOval (380, 33, 20, 23, black)
Draw.Oval (380, 33, 19, 22, brightred)
Draw.FillBox (360, 3, 400, 33, black)
Draw.FillBox (370, 3, 390, 13, brown)
Draw.Line (380, 3, 380, 13, black)
Draw.Dot (382, 8, black)
Draw.Dot (378, 8, black)
Draw.FillBox (365, 23, 395, 18, brightblue)
Draw.Line (400, 34, 360, 34, red)
Draw.FillOval (380, 35, 5, 5, gray)
Draw.Line (385, 40, 375, 30, black)
Draw.ThickLine (0, 0, maxx, 0, 5, green)

View.Set ("offscreenonly")


% Create cannon & movement process
%====================================================================

process tower
    var move : array char of boolean
    loop
        Draw.ThickLine (380, 35, num1, num2, 7, white)
        if (num1 > 380) then
            Input.KeyDown (move)
            if move (KEY_RIGHT_ARROW) then
                num1 := num1 + 1
                num2 := num2 - 1

            elsif move (KEY_LEFT_ARROW) then
                num1 := num1 - 1
                num2 := num2 + 1
            end if
        elsif (num1 < 380) then
            Input.KeyDown (move)
            if move (KEY_RIGHT_ARROW) then
                num1 := num1 + 1
                num2 := num2 + 1

            elsif move (KEY_LEFT_ARROW) then
                num1 := num1 - 1
                num2 := num2 - 1
            end if
        elsif (num1 = 380) then
            Input.KeyDown (move)
            if move (KEY_RIGHT_ARROW) then
                num1 := num1 + 1
                num2 := num2 - 1
            elsif move (KEY_LEFT_ARROW) then
                num1 := num1 - 1
                num2 := num2 - 1
            end if
        end if

        if (num1 = 420) then
            num1 := num1 - 1
            num2 := num2 + 1
        end if
        if (num1 = 340) then
            num1 := num1 + 1
            num2 := num2 + 1
        end if
        Draw.ThickLine (380, 35, num1, num2, 7, brightred)
        Draw.FillOval (380, 33, 20, 23, black)
        Draw.FillBox (360, 3, 400, 33, black)
        Draw.FillBox (370, 3, 390, 13, brown)
        Draw.Line (380, 3, 380, 13, black)
        Draw.FillBox (365, 23, 395, 18, brightblue)
        Draw.ThickLine (400, 34, 360, 34, 2, red)
        Draw.FillOval (380, 35, 5, 5, gray)
        Draw.Line (385, 40, 375, 30, black)
        Draw.Dot (382, 8, black)
        Draw.Dot (378, 8, black)
        View.Update
        delay (30)
    end loop
end tower

%=========================================================================


%Create the firing mechanism
var gun1 : int
gun1 := 0
%=========================================================================

process shoot
    loop
        var fire : array char of boolean
        Input.KeyDown (fire)
        if fire (KEY_SHIFT) then
            loop
                gun1 := gun1 + 1
                Draw.FillBox (num1 + gun1, num2 + gun1, num1 + 4 + gun1, num2 + 4 + gun1, black)
                delay (100)
                Draw.FillBox (num1 + gun1, num2 + gun1, num1 + 4 + gun1, num2 + 4 + gun1, white)
            end loop
        end if
    end loop
end shoot

%==========================================================================


fork tower
fork shoot


Its really early in, i know, but at least its a start. if anyone has any ideas for things that should be in the game, its all welcome. Thanks again.

Author:  Remm [ Mon May 08, 2006 7:05 pm ]
Post subject: 

Oh, erm, and it also seems to be only moving to the top right. i could do a small fix so that at certian angles when shot, it goes in that direction ( i . e. when pointing strait up, cannon shoots bullet for x=0 and y= 1) but i cant think of any way to make the shots go accurately when its on a random angle... ideas?
Thanks
Remm

Author:  Cervantes [ Mon May 08, 2006 7:09 pm ]
Post subject: 

Welcome to CompSci.ca!

First, I suggest you read Why You Should Avoid Processes.

Second, you'll need to know about Arrays and Flexible Arrays. Consult the Turing Walkthrough for links to tutorials on these subjects.

The Flexible Array tutorial has an example of shooting bullets - probably fairly similar to what you're trying to do here.

Author:  HellblazerX [ Mon May 08, 2006 7:12 pm ]
Post subject: 

It would also be useful to learn about records. There's a nice tut for records here.

Also, for the angles of firing, you'll need to know some trig. And welcome to CompSci.ca!

Author:  Remm [ Mon May 08, 2006 7:17 pm ]
Post subject: 

Thanks guys, i'll start looking through it after i finish posting other things ive been meaning to get to. I'll post the finished product in a while, if it ever gets finished. Thanks again.
(no ones ever played the real thing of this!? Confused it rocked)

Remm


: