Computer Science Canada

RPG 360* shooting (trig)

Author:  rownale [ Wed Sep 06, 2006 6:52 pm ]
Post subject:  RPG 360* shooting (trig)

shooting arrows...
Ive made a couple RPG games in the past but ive always wanted to implement arrows or projectiles that can be shot wherever the mouse points. (I had this in chasegame but the bullets were "invisible" lol)
Another game of mine i decided to just use button/turn based combat sort of thing ( http://www.compsci.ca/v2/viewtopic.php?t=12771&highlight= )

Anyways, I'd like to try to make a game where you can just click on the screen and a projectile will emerge from the players character (a circle lol) and i dont even care if it looks dumb because it starts in the center of the player and moves outwards (although that can be fixed with colour).

The game will be played in a top down view. The person will move around if that makes a difference. And I only have some programming done (engine parts). And the bullets can be continuous or just one click=one bullet thing it doesnt matter.

So basically I need help with the trig stuff and ive done gr11 math but i still dont understand how to program it and implement it.

Plz help thanks

Author:  BenLi [ Wed Sep 06, 2006 7:06 pm ]
Post subject: 

actually, you don't need trig. assuming the arrows travels in a constant rate, you only have to wrry about direction. You don't need to break it down into angles. This is code from the beginnings of my FP last year, it actually tells you the angle






code:

setscreen ("graphics:800;600,offscreenonly")
%const detail := 10
var speed : int := 0
const startx := 0
const starty := 0
var shotx, shoty : real
var mx, my, mb : int
var deltax, deltay : real
var b : real
var ang : real


loop %main loop
    shotx := startx
    shoty := starty
    loop %gives player initial angle
        mousewhere (mx, my, mb)
        b := Math.Distance (startx, starty, mx, my)
        deltay := my - starty
        deltax := mx - startx

        ang := arcsind (deltay / b)
        if mx < startx then
            ang := 180 - ang
        end if
        locate (1, 1)
        put "Angle is: ", ang
        View.Update
        exit when mb = 1
    end loop


    deltay := my - starty
    deltax := mx - startx


    b := Math.Distance (startx, starty, mx, my) %trig
    ang := arcsind (deltay / b)
    if mx < startx then
        ang := 180 - ang
    end if

    loop
        mousewhere (mx, my, mb) %detects when shot is initialed

        exit when mb = 1
    end loop
    speed := 15
    loop %tracks shots
        shotx := shotx + (deltax / ((Math.Distance (startx, starty, mx, my)) / speed))
        shoty := shoty + (deltay / ((Math.Distance (startx, starty, mx, my)) / speed))

        drawfilloval (round (shotx), round (shoty), 10, 10, red)
        View.Update
        cls
        put "Angle is: ", ang
        locate (2, 1)

        exit when shotx > 800 or shoty > 600
    end loop
end loop

Author:  rownale [ Thu Sep 07, 2006 7:19 am ]
Post subject: 

ok thanks
i couldnt get ur program to work because i didnt have mathdistance but i just found it here lol http://www.compsci.ca/v2/viewtopic.php?t=13177 thanks for the help

Author:  Clayton [ Thu Sep 07, 2006 2:31 pm ]
Post subject: 

if you dont have the Math.Distance function, make one Very Happy all it is is the distance formula with the parameters being the two points ordered pairs


: