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

Username:   Password: 
 RegisterRegister   
 Make bullets fire at a constant speed?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pttptppt




PostPosted: Sun Feb 26, 2017 3:47 pm   Post subject: Make bullets fire at a constant speed?

What is it you are trying to achieve?
As of now, my code will fire a shot and will only allow you to fire again when the bullet reaches past the turing run window.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


%View.Set ("offscreenonly")
View.Set ("graphics:1500;750, offscreenonly")

var chars : array char of boolean
var x, y, bullety, bulletx : int := 100
var shot : int := 0
var mx, my, mb : int

var x1, x2, y1, y2 : int
var run, rise : int
var counter : int := 0
var pastvaluex2, pastvaluey2 : int



forward proc movement

var button : int
var xtemp, ytemp : int := 0

%%%%%%%%%%%%%%%
%Turret Spinning:
var keys : array char of boolean
var tx, ty : real := 0

%Length of Turret:
var realx, realy : real

realx := 60
realy := 60

%%%%%%%%%%%%%%%

proc shoot
    loop
        shot := 1


        %Mouse.Where (x1, y1, button)
        if counter = 0 then
            x2 := mx + round (realx)
            y2 := my + round (realy)

            run := (x2 - mx)
            rise := (y2 - my)


            counter := 1
        end if
        x2 := x2 + (run div 10)
        y2 := y2 + (rise div 10)

        %delay (50)

        %View.Update

        % pastvaluex2 := x2
        % pastvaluey2 := y2
        %drawfilloval (x2, y2, 7, 7, blue)
        if y2 > maxy or y2 < 1 or x2 > maxx or x2 < 1 then
        counter := 0
        exit
        end if
        delay (5)
        movement
    end loop
    shot := 0
end shoot


proc rotate
    const SHORTEN := 4
    if keys (KEY_UP_ARROW) then
        tx := realx
        ty := realy
        realx := cosd (1) * tx + sind (1) * ty
        realy := cosd (1) * ty - sind (1) * tx
    end if
    if keys (KEY_DOWN_ARROW) then
        tx := realx
        ty := realy
        realx := cosd (1) * tx - sind (1) * ty
        realy := sind (1) * tx + cosd (1) * ty
    end if
    if realx > 0 then
        realx -= SHORTEN
    elsif realx < 0 then
        realx += SHORTEN
    end if
    if realy > 0 then
        realy -= SHORTEN
    elsif realy < 0 then
        realy += SHORTEN
    end if
    Draw.ThickLine (x, y, x + round (realx), y + round (realy), 10, red)
    if realx > 0 then
        realx += SHORTEN
    elsif realx < 0 then
        realx -= SHORTEN
    end if
    if realy > 0 then
        realy += SHORTEN
    elsif realy < 0 then
        realy -= SHORTEN
    end if
    delay (1)

end rotate

body proc movement
    %Input.KeyDown (chars)
    % if chars (KEY_UP_ARROW) and y + 64 < maxy then
    %     y := y + 1
    % elsif chars (KEY_DOWN_ARROW) and y > 0 then
    %     y := y - 1
    % elsif chars (KEY_LEFT_ARROW) and x > 0 then
    %     x := x - 1
    % elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
    %     x := x + 1
    % end if
    % if chars (KEY_CTRL) and shot = 0 then
    %     bullety := y
    %     bulletx := x
    %     shoot
    % end if
    % cls
    %  loop
    %Draw.Cls
    Mouse.Where (mx, my, mb)

    x := mx
    y := my

    %draw (x, y)
    if mb > 0 and shot = 0 then
        % bullety := y
        % bulletx := x
        shoot
    end if
    cls
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if shot = 1 then
        %drawoval (bulletx, bullety + 14, 10, 10, black)
        %drawoval (bulletx, bullety + 15, 10, 10, black)
        %drawoval (bulletx, bullety - 1, 10, 10, black)
        %drawoval (bulletx, bullety, 10, 10, black)

        drawfilloval (x2, y2, 7, 7, blue)

    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Draw.FillOval (x, y, 55, 55, black)
    Draw.FillOval (x, y, 50, 50, white)

    %Thick crosshair threads
    Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
    Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
    Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
    Draw.ThickLine (x, y + 50, x, y + 35, 3, black)

    %Thin threads
    Draw.Line (x - 20, y, x + 20, y, red)
    Draw.Line (x, y - 20, x, y + 20, red)

    delay (1)
    Input.KeyDown (keys)
    rotate

    View.Update
    % end loop
end movement

loop
    movement
end loop




Please specify what version of Turing you are using
Latest
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: