
-----------------------------------
TheOneTrueGod
Fri Mar 03, 2006 4:01 pm

Advice
-----------------------------------
Allright, i'm programming an RPG type thing, with real time battles, and I want to make it entirely in turing (I.E. no outside graphics, meaning the game won't look too great but itll play well function Angle (x1, y1, x2, y2 : real) : real
    var theta : real
    if x1 = x2 then
        if y2 > y1 then
            theta := 90
        else
            theta := 270
        end if
    else
        theta := arctand ((y1 - y2) / (x1 - x2))
        if x2 > x1 then
            if y2 > y1 then
            else
                theta := 360 + theta
            end if
        else
            theta := 180 + theta
        end if
    end if
    result theta
end Angle

function Dist (x1, y1, x2, y2 : real) : real
    result sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)
end Dist

procedure DrawLightning (x, y, tx, ty : real, numforks : int)
    var lx, ly, oldlx, oldly : real := x
    var tempcx, tempcy : real
    var angle : real := Angle (x, y, tx, ty)
    var r : int
    ly := y
    oldly := y
    var c : int := 0
    loop
        c += 1
        lx += cosd (angle) * Dist (x, y, tx, ty) / numforks
        ly += sind (angle) * Dist (x, y, tx, ty) / numforks
        tempcx := lx
        tempcy := ly
        r := Rand.Int (-1, 1)
        tempcx += cosd (angle + r * 90) * Dist (x, y, tx, ty) / numforks
        tempcy += sind (angle + r * 90) * Dist (x, y, tx, ty) / numforks
        exit when c > numforks

        Draw.ThickLine (round (oldlx), round (oldly), round (tempcx), round (tempcy), 3, yellow)
        oldlx := tempcx
        oldly := tempcy

    end loop
end DrawLightning
View.Set ('offscreenonly')
loop
    for i : -1 .. 1
        for j : -1 .. 1
            DrawLightning (maxx div 2, maxy div 2, maxx div 2 + 200 * i, maxy div 2 + 200 * j, 70)
        end for
    end for
    View.Update
    delay (30)
    cls
end loop



This will just draw several lightning bolts originating from the centre.  I need to know some ways to improve it, because while it looks okay, it could still use some improvement. 

The algorithm works basically by dividing it up into "NumForks" different sections, and just randomizing if it goes up or down on that section.  Any ideas on how to make it look better, without sacrificing too much efficiency?  (Also, a bit of efficiency help may be nice, but the main thing i'm looking for is graphical improvement.  I know I should have made it a for loop, for example.)

-----------------------------------
batman
Fri Mar 03, 2006 4:43 pm

Program
-----------------------------------
Cool program!
One thing you could do to make your code better is using arrays, it will make your code shorter. You could also add music to your program! Maybe a lightningnoice, that be cool. IF you need help doing that then send me a message.

-----------------------------------
Delos
Fri Mar 03, 2006 6:05 pm

Re: Program
-----------------------------------
Cool program!
One thing you could do to make your code better is using arrays, it will make your code shorter. You could also add music to your program! Maybe a lightningnoice, that be cool. IF you need help doing that then send me a message.

Intersting concept.  Now where exactly would he be using said arrays?  Perhaps in lx, ly...but that would just be pushing it.

As for improvement:
I like the look of it when few forks are used.  To make things a little more interesting, use a couple of other 'think lines' drawn with a larger radius behind the main one.  This will add a border, and you can achieve some enticing effects.
My own intuition tells me that your parameter setup:

DrawLightning (x, y, tx, ty : real, numforks : int)

would translate as positionX, positionY, sizeX, sizeY, forks.  This is apparently not true though :D.  But that's just me.  Perhaps having a variable size would be advantageous?

Now, the most important critique:
[url=http://www.compsci.ca/v2/viewtopic.php?t=9581]Go here!.  zylum's tut on recursion will open up a whole new level of leetness for you.  You'll want to focus on fractal generation, since this will allow you to create more realistic lightning.

Good work so far, and keep us updated.

-----------------------------------
Clayton
Fri Mar 03, 2006 8:14 pm


-----------------------------------
very nice, how long did that take you to figure out, your obviously a math genius, however, whenever you finish your RPG post it, id like to give it a try, if this is a good sample of it, keep up the good work

-----------------------------------
md
Fri Mar 03, 2006 9:59 pm


-----------------------------------
The math looks interesting; but as I don't have turing someone want to post a screenshot?

Batman: Arrays? I can't see any use for arrays at all...
SuperFreak82: Good with math yes, math genius perhaps not. This code just demonstrates an ability to use math (one which to be fair many people seem to lack...) but I don't think it qualifies for genius level code.

One thing that might be cool; and uses recursion in psudo (Pascal/C) code:

Function Lightening(s, d:point; fork_length, fork_chance, fork_angle:real; fork_count:integer)
{
    if( Distance(s, d) 