Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Real/Int problems (to do with Math.Distance)
Author Message
pttptppt

Posted: Fri Feb 24, 2017 8:04 pm   Post subject: 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: http://compsci.ca/v3/viewtopic.php?t=30017. The problem is that if the values are not real, then Math.Distance doesn't work.

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.

 Turing: 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) <= 9 then             delay (100)             shoot         end if         drawfilloval (round (xtemp), round (ytemp), 10, 10, blue)         drawfilloval (round (x), round (y), 10, 10, black)         drawfilloval (round (x), round (y), 2, 2, brightred)         delay (75)         View.Update     end if     xtemp := x     ytemp := y end loop

Please specify what version of Turing you are using
Latest
[url][/url]

Insectoid

Posted: Sat Feb 25, 2017 1:42 pm   Post subject: RE:Real/Int problems (to do with Math.Distance)

Math.Distance works with integers. Any function that takes reals as input will also accept integers.

Even if you couldn't do that, the Math.Distance function is nothing more than a^2 + b^2 = c^2. You could write your own version in one line of code.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: