Laser pointer... ish. help please
Author |
Message |
Mayb123
|
Posted: Tue Oct 02, 2007 5:01 pm Post subject: Laser pointer... ish. help please |
|
|
i'm trying to make a 2d sidescroller shooter, and i am trying to make a line appear every time you click the mouse which will (so far) extend from coordinates 0 and 0 all the way across the window intercepting with the mouse cursor. so far i can only make it extend to the cursor. help please. here's the code:
var key : array char of boolean
var reticle : int
var mx, my, button, linebasex, linebasey : int
var reticlenum : string
var weapons :array 1..5 of int
setscreen ("graphics:640;480")
View.Set ("nomouse")
% put "would you like to use reticle one or two?"
% get reticlenum
% if reticlenum = "one" then
% reticle := Pic.FileNew ("Reticle.bmp")
% elsif reticlenum = "two" then
% reticle := Pic.FileNew ("Reticle2.bmp")
% end if
loop
View.Set ("offscreenonly")
Input.KeyDown (key)
View.Set ("nomouse")
Mouse.Where (mx, my, button)
drawfillbox (0, 0, maxx, maxy, 7)
% Pic.Draw (reticle, mx - 12, my - 12, picMerge)
if button = 1 then
drawline (0, 0, mx, my, 12)
end if
delay (1)
View.Update
cls
end loop |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Tue Oct 02, 2007 5:10 pm Post subject: RE:Laser pointer... ish. help please |
|
|
You can take the angle between the mouse and the player, and use some basic trig to extend the line. |
|
|
|
|
![](images/spacer.gif) |
Mayb123
|
Posted: Tue Oct 02, 2007 5:21 pm Post subject: Re: Laser pointer... ish. help please |
|
|
and how does one incorporate trig into this? |
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Tue Oct 02, 2007 5:35 pm Post subject: RE:Laser pointer... ish. help please |
|
|
Tan=opposite/adjacent
opposite=delta Y
adjacent=delta X
tan inverse give you the angle if you have opposite/adjacent |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Tue Oct 02, 2007 5:48 pm Post subject: RE:Laser pointer... ish. help please |
|
|
Why use trig at all? Why not just use your general equation for a line? y = mx + b? You know your y-intercept is going to be zero, and you can figure out slope, and then solve for x. |
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Tue Oct 02, 2007 6:00 pm Post subject: RE:Laser pointer... ish. help please |
|
|
Or you could do that.
But the advantage with trig is that you can detect obstacles efficiently (ie if there is a ceiling above you, stop the laser). |
|
|
|
|
![](images/spacer.gif) |
Mayb123
|
Posted: Tue Oct 02, 2007 6:34 pm Post subject: RE:Laser pointer... ish. help please |
|
|
well, my reasoning for this is that i'm going to have a character from which the line will be emitted and that character will be able to run and jump all around the screen (platformer game) and i'm using the mouse as a targeting reticle. so the line will start from the character to the mouse, as i said before |
|
|
|
|
![](images/spacer.gif) |
Mayb123
|
Posted: Tue Oct 02, 2007 6:39 pm Post subject: RE:Laser pointer... ish. help please |
|
|
oh, and CodeMonkey, thanks for the advice, the only issue is that i don't know where to put that in my code. we were basically given a school project where we have to make a game and learn all the stuff on our own |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Tue Oct 02, 2007 9:23 pm Post subject: RE:Laser pointer... ish. help please |
|
|
I think Clayton's method might be better for what you are doing. |
|
|
|
|
![](images/spacer.gif) |
|
|