
-----------------------------------
pttptppt
Fri Feb 24, 2017 8:04 pm

Real/Int problems (to do with Math.Distance)
-----------------------------------
What is it you are trying to achieve?
I'm making a game similar to Diep.io. Basically as the user moves, depending on the direction of movement, little bullets will shoot. Now my program still requires work but I have a big problem.


What is the problem you are having?
The only methods Ive found for achieving the goal of "shooting" is using "Math.Distance" from this thread: Describe what you have tried to solve this problem
I've tried using the Round command but after rounding and whatnot, it tells me that it has no value. So either the "Assigned values are the wrong type" or "It has no value"


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
The problematic code is highlighted with a lot of percent signs.



import GUI
setscreen ("graphics:1500;1500")

var x, y, button : int
var xtemp, ytemp : int := 0

procedure draw (x, y : int)
    View.Set ("offscreenonly")
    %Scope casing
    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)

    %Adds slight delay. Optional
    delay (100)

    View.Update
end draw

procedure undraw

    %Scope casing
    Draw.FillOval (x, y, 55, 55, white)
    Draw.FillOval (x, y, 50, 50, white)

    %Thick crosshair threads
    Draw.ThickLine (x - 50, y, x - 35, y, 3, white)
    Draw.ThickLine (x + 50, y, x + 35, y, 3, white)
    Draw.ThickLine (x, y - 50, x, y - 35, 3, white)
    Draw.ThickLine (x, y + 50, x, y + 35, 3, white)

    %Thin threads
    Draw.Line (x - 20, y, x + 20, y, white)
    Draw.Line (x, y - 20, x, y + 20, white)

end undraw

var speed : int := 2
var xfinal, yfinal : int
var xv, yv : int

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc shoot
xv := (x - xtemp) / (Math.Distance (xtemp, ytemp, x, y) / speed) 
yv := (y - ytemp) / (Math.Distance (xtemp, ytemp, x, y) / speed)
    x := xtemp
    y := ytemp
end shoot
shoot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
    Mouse.Where (x, y, button)  %button is a variable that checks if mouse is clicked
    draw (x, y)
    undraw
    delay (5)
    if button = 1 then
        x += xv                                              % uses velocities to determine the new x and y values
        y -= yv
        if Math.Distance (x, y, xtemp, ytemp) 