How to draw a line like a boss
#1
Posted 16 January 2013 - 09:45 PM
This is for a laser sight I'm building into my players gun. I'm sure this is possible somehow, but I never excelled at math and it seems like a math problem. Something like dividing the X by the Y axis to determine the angle. For instance, it may drop 1 block vertically for every 4 blocks it travels horizontally. I'd need to pixel edit the 4 blocks so a line appears to travel through them diagonally and repaste those 4 blocks along the path of the line until it reaches the destination block. Probably involve sprites somehow. I love using sprites.
Thing is, I have limited characters to work with. I couldn't justify setting aside more than 4 chars at most. Any thoughts? Am I nuts for wanting to do this? Should I settle for a single character with just a simple dot in the middle, so it appears as a dotted line between two locations?
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#2
Posted 16 January 2013 - 10:11 PM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#3
Posted 16 January 2013 - 11:58 PM
. "how many times we're going to subdivide the arc"
set "steps" to 100
set "x1" to 20
set "y1" to 20
set "x2" to 20
set "y2" to 1
. "the destination relative to the origin"
set "x" to "('x2'-'x1')"
set "y" to "('y2'-'y1')"
. "if x is 0, this doesn't work, so fudge it"
inc "x" by "('x'=0)"
. "reciprocal of the slope of the curve, since we can't have decimals"
set "s" to 40
. "solve for the root that will make the arc pass through the destination, and put it in terms of our subdivisions"
set "a" to "('s'*'y'/'x'-'x'*-'steps')"
loop start
. "the x coord of the current position relative to the origin and in terms of subdivisions"
set "!" to "('x'*'LOOPCOUNT')"
. "if we divide out the subdivisions and add the origin x, we get the current x"
set "!x" to "('!'/'steps'+'x1')"
. "solve the quadratic equation for the y coordinate, divide our slope in, divide out steps twice (since we squared '!'), add the origin y to get the current y"
set "!y" to "('!'-'a'*'!'/'s'/'steps'/'steps'+'y1')"
. "draw"
put cff CustomBlock p00 at "!x" "!y"
. "loop for the number of subdivisions"
loop for "steps"
end
EDIT: fixed a bug
EDIT 2: fixed another bug
EDIT 3: just redid it entirely
EDIT 4: comments
For drawing the laser sight line, I'd stongly suggest dotting it. I'll give that a look in a little bit.
xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
#4
Posted 17 January 2013 - 02:07 AM
This post has been edited by CJA: 17 January 2013 - 02:09 AM
#5
Posted 17 January 2013 - 02:43 AM
Most lines will not be possible to draw with 4 repeating chars.

<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
#6
Posted 17 January 2013 - 03:10 AM
You know, like what NES games to get around a small number of sprites that could appear on a line simultaneously.
"The fact that I say I've one of the best, is called honesty." -Akwende
"Megazeux is not ment to be just ASCII, it is ANSI!" - T-bone6
"I hate it when you get all exo on me." - emalkay
Exophase can what Rubi-cant.
exoware is ware ur ware is exoware
ps. not loking 4 new membrs kthx
#7
Posted 17 January 2013 - 03:13 AM
Lachesis, I'll try this code tonight and see if I can make sense of it. :-) I think I can use it in my game, in which case ill credit you for the help.
CJA, that may help me with what I'm trying to do. At least it gives me some avenue to try. Thanks.
Lancer-X, I'm think I'll try and draw the line chars my self. Thanks.
Exophase, I had a similar thought. I'm not sure if I'll like the flicker, but I may give it a try. Thank you.
This post has been edited by Graham: 17 January 2013 - 03:17 AM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#8
Posted 17 January 2013 - 04:05 AM
Exophase, on 17 January 2013 - 01:10 PM, said:
On speed 2 it could be bearable, although I think you'd still want more than 4 chars. 4 chars is really very few.

<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
#9
Posted 17 January 2013 - 05:44 AM
<Cybersilver> "All my sugestions are for FUTER VERSIONS. Say it with me Fu-ter futer. Yep..."
9-21-2009, SFMZX game play video: HERE
Risu2112
#10
Posted 17 January 2013 - 03:20 PM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#11
Posted 20 January 2013 - 06:38 AM
http://www.digitalmz...=1
it's from 2006, which is something like 7 years ago.
I might have it on my PC but it's not plugged in and I can't bother.
Anyhow... the trick is to optimize horizontal lines to draw multiple pixels at a time.
With 4 chars you can't draw within the characters.
The best you can do is have a char that is a single vertical line in the middle, use it for all vertical lines, and have three chars with horizontal lines that are at ~ 1/6, 3/6, 5/6th of the way down the character respectively.
This post has been edited by LogiCow: 20 January 2013 - 06:39 AM
#12
Posted 21 January 2013 - 09:41 PM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#13
Posted 23 January 2013 - 09:17 AM
laser bomb test.zip (4.86K)
Number of downloads: 4
So this is pretty cool. Thanks very much Lachesis, CJA, Exophase, and all the rest of you for the input. I think this is going to work nicely.
It's basically Lachesis's program, for bombing it was as she made it. For shooting, I flattened the slope so it drew in a straight line and reduced the steps to make it appear as though it was going faster. Since I don't understand the math, I just fooled around a bit until I came up with this. I may have been able to do it more efficiently, I don't know. But this works. Hold space to shoot, press control to throw a bomb. In my game, you will be able to move a sight up and down and it will land on either customblocks or sprites. The laser beam follows the sight. Also, its 2d sidescrolling, hence the trajectory for the bomb.
Thanks again for the input. Night all.
P.S. You will be credited in the game too.
This post has been edited by Graham: 23 January 2013 - 09:19 AM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#14
Posted 21 September 2016 - 07:17 PM
Lachesis, on 16 January 2013 - 03:58 PM, said:
. "how many times we're going to subdivide the arc"
set "steps" to 100
set "x1" to 20
set "y1" to 20
set "x2" to 20
set "y2" to 1
. "the destination relative to the origin"
set "x" to "('x2'-'x1')"
set "y" to "('y2'-'y1')"
. "if x is 0, this doesn't work, so fudge it"
inc "x" by "('x'=0)"
. "reciprocal of the slope of the curve, since we can't have decimals"
set "s" to 40
. "solve for the root that will make the arc pass through the destination, and put it in terms of our subdivisions"
set "a" to "('s'*'y'/'x'-'x'*-'steps')"
loop start
. "the x coord of the current position relative to the origin and in terms of subdivisions"
set "!" to "('x'*'LOOPCOUNT')"
. "if we divide out the subdivisions and add the origin x, we get the current x"
set "!x" to "('!'/'steps'+'x1')"
. "solve the quadratic equation for the y coordinate, divide our slope in, divide out steps twice (since we squared '!'), add the origin y to get the current y"
set "!y" to "('!'-'a'*'!'/'s'/'steps'/'steps'+'y1')"
. "draw"
put cff CustomBlock p00 at "!x" "!y"
. "loop for the number of subdivisions"
loop for "steps"
end
EDIT: fixed a bug
EDIT 2: fixed another bug
EDIT 3: just redid it entirely
EDIT 4: comments
For drawing the laser sight line, I'd stongly suggest dotting it. I'll give that a look in a little bit.
Lachesis-this code is very helpful and I've employed it in quite a number of different ways in my game. I'm wondering though if there is a way to draw the entire arc in one cycle? There arent any cycle ending commands in the loop so I don't really understand how it behaves as it takes several cycles to draw the arc across the screen.
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#15
Posted 21 September 2016 - 08:29 PM

<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
#16
Posted 21 September 2016 - 09:13 PM
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#17
Posted 21 September 2016 - 10:35 PM
xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
#18
Posted 22 September 2016 - 12:11 AM
set "COMMANDS" to "(10000)"
. "x0,y0 - board position for the origin (i.e. player position)"
. "x1,y1 - board position RELATIVE to x0,y0 for the midpoint"
. "x2,y2 - board position RELATIVE to x0,y0 for the destination"
. "inputs"
set "x0" to 0
set "y0" to 24
. "x1 = (x0+x2)/2 is implicit"
set "y1" to -22
set "x2" to 79
set "y2" to -10
. "steps - the number of subdivisions to draw"
. "fp - fixed y multiplier to help the curve look less nasty"
. "u1,u2 - adjusted y1,y2"
set "steps" to 100
set "fp" to 10
set "u1" to "('y1'*'fp')"
set "u2" to "('y2'*'fp')"
. "x = pretty straightforward"
. "y = look it just works trust me"
loop start
put cff 'A' overlay to "('x2'*'LOOPCOUNT'/'steps'+'x0')" "(-2*'u1'+'u2'*2*'LOOPCOUNT'/'steps'+'u1'+'u1'+'u1'+'u1'-'u2'*'LOOPCOUNT'/'steps'/'fp'+'y0')"
loop for "steps"
the idea is that instead of some vague "slope" value, you can just define a middle Y value in this version that is actually intuitive. how you determine that Y value is totally up to you (i.e. it could be y1 = y2 - (some constant))
like with last time, you should probably vary steps based on the distance too
xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
#19
Posted 22 September 2016 - 02:15 AM
Lachesis, on 21 September 2016 - 04:11 PM, said:
set "COMMANDS" to "(10000)"
. "x0,y0 - board position for the origin (i.e. player position)"
. "x1,y1 - board position RELATIVE to x0,y0 for the midpoint"
. "x2,y2 - board position RELATIVE to x0,y0 for the destination"
. "inputs"
set "x0" to 0
set "y0" to 24
. "x1 = (x0+x2)/2 is implicit"
set "y1" to -22
set "x2" to 79
set "y2" to -10
. "steps - the number of subdivisions to draw"
. "fp - fixed y multiplier to help the curve look less nasty"
. "u1,u2 - adjusted y1,y2"
set "steps" to 100
set "fp" to 10
set "u1" to "('y1'*'fp')"
set "u2" to "('y2'*'fp')"
. "x = pretty straightforward"
. "y = look it just works trust me"
loop start
put cff 'A' overlay to "('x2'*'LOOPCOUNT'/'steps'+'x0')" "(-2*'u1'+'u2'*2*'LOOPCOUNT'/'steps'+'u1'+'u1'+'u1'+'u1'-'u2'*'LOOPCOUNT'/'steps'/'fp'+'y0')"
loop for "steps"
the idea is that instead of some vague "slope" value, you can just define a middle Y value in this version that is actually intuitive. how you determine that Y value is totally up to you (i.e. it could be y1 = y2 - (some constant))
like with last time, you should probably vary steps based on the distance too
Oh yeah, I can really see the value in that. Being able to define the height of the slope to keep it from being too high when aiming for something a distance away could be very useful. Thank you! I'll see if I can use it.
"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
#20
Posted 22 September 2016 - 02:20 AM
here's a graph of the example curve my code calculates with the points it uses marked
*in many of the situations I think you'd want to use it in, anyway. it's still better than "s", because you can at least make an educated guess and fine tune it to nearby values if your initial y1 doesn't work.
xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository

Help











