A 2d light program I want to show you...

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

A 2d light program I want to show you...

Sorry there are no comments. It computes for every point if there's light at that point. You have to see to understand... Hope you like it, I saw this in a game and tried for some time to code it and I got it working some time ago... I will try multiple lights soon, shouldn't be too hard...

The game I saw it, Gish (free demo & screenshots, but appearently not from the light effect I meant, for those who want: http://www.gishgame.com/)

Code: Select all

``````CLS
SCREEN 13
DEFLNG A-Z
DEF SEG = &HA000
FOR c = 0 TO 5
OUT &H3C8, c
OUT &H3C9, c / 5 * 63
OUT &H3C9, c / 5 * 63
OUT &H3C9, c / 5 * 63
NEXT

CONST pi = 22 / 7
DO UNTIL LEN(INKEY\$)
lx = 260
ly = COS(c / 40) * 50 + 100

c = c + 1

x1 = SIN(c / 20) * 50 + 130
y1 = COS(c / 20) * 50 + 60
xv1 = x1 - lx
yv1 = y1 - ly

x2 = SIN(c / 20 + pi) * 50 + 130
y2 = COS(c / 20 + pi) * 50 + 60
xv2 = x2 - lx
yv2 = y2 - ly

xv3 = x2 - x1
yv3 = y2 - y1

cx = (x1 + x2) \ 2
cy = (y1 + y2) \ 2
c2x = (cx - lx) * 5 + lx
c2y = (cy - ly) * 5 + ly

IF yv1 <> 0 THEN sgn1 = SGN(cx - (lx + (xv1 * (cy - ly)) \ yv1)) ELSE sgn1 = SGN(cx - (lx + xv1 * (cy - ly))): yv1 = 1
IF yv2 <> 0 THEN sgn2 = SGN(cx - (lx + (xv2 * (cy - ly)) \ yv2)) ELSE sgn2 = SGN(cx - (lx + xv2 * (cy - ly))): yv2 = 1
IF yv3 <> 0 THEN sgn3 = SGN(c2x - (x1 + (xv3 * (c2y - y1)) / yv3)) ELSE sgn3 = SGN(c2x - (x1 + xv3 * (c2y - y1))): yv3 = 1

p = 0
FOR y = 0 TO 199
xx1 = lx + xv1 * ((y - ly) / yv1)
xx2 = lx + xv2 * ((y - ly) / yv2)
xx3 = x1 + xv3 * ((y - y1) / yv3)
FOR x = 0 TO 319
IF (SGN(x - xx1) = sgn1) AND (SGN(x - xx2) = sgn2) AND (SGN(x - xx3) = sgn3) THEN POKE p, 0 ELSE POKE p, 5
p = p + 1
NEXT
NEXT
LINE (x1, y1)-(x2, y2), 0
CIRCLE (lx, ly), 10, 0
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
LOOP
END
``````
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL

Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:
*By the way, sorry if it is not allowed to post links to non-qbasic sites... if you're a moderator please only remove the link... please? xD
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL

sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:
Codemss wrote:*By the way, sorry if it is not allowed to post links to non-qbasic sites... if you're a moderator please only remove the link... please? xD
no thats fine it was relative to the issue you were discussing and
NOT Pornography...