Binding
Sprites to Sinewaves
Sinewaves?
|
Sinewaves bound to sprites present
a variety of artistic effects. Here are some examples.
Acid Trip
Trippin' like it's 1996. Don't do it to all the tiles, or you might
leave some addicts quivering on the floor!
Teleportation
Whoah! That dude just did this whoosh thing, then he was GONE! GONE! It
was cool!
Really painful spell
Yikes! That guy just got all torn up! That evil mage there rolled his
body up like an old matress! HOLY SHIT!
In other words, use your imagination.
|
In C games, it's a trick used quite often to map a bitmap to a
sinewave to give it a waving effect. Here's how to get the same effect
in QB in a tile-based engine. If you run this program, you'll see that
the effect is in fact, quite watery.
DEFINT A-Z
CONST WAVEHEIGHT = 2
CONST WAVESPEED = 1
CONST WAVEMOVE = 5
'here we dimension the memory we'll need.
'in an established tile engine, you'd still need the
'buffer tile. The original bitmap is stored there.
'Bitmap is where the altered tile is sent.
DIM bitmap(1 TO 20, 1 TO 20) AS INTEGER
DIM buffer(1 TO 20, 1 TO 20) AS INTEGER
'generates a random "water" bitmap.
FOR b = 1 TO 20
FOR c = 1 TO 20
bitmap(b, c) = (c * 10) AND 255
buffer(b, c) = bitmap(b, c)
NEXT c
NEXT b
DIM sinlookup(0 TO 381 + 400) AS INTEGER
FOR a = 0 TO 381 + 400
sinlookup(a) = SIN((a) * 3.14159 / 180) * WAVEHEIGHT
NEXT a
a = 0
SCREEN 13
'labelling everything.
LOCATE 2, 4: PRINT "QBXL Tech Demo Number 1: Sinewaves"
LOCATE 10, 2: PRINT "Sinewave"
LOCATE 6, 23: PRINT "Result"
LOCATE 6, 13: PRINT "Original"
LOCATE 24, 1: PRINT "Press 'Q' to quit."
'drawing the stationary original
FOR b = 1 TO 20
FOR c = 1 TO 20
PSET (b + 105, c + 50), buffer(b, c)
PSET (b + 125, c + 50), buffer(b, c)
PSET (b + 105, c + 70), buffer(b, c)
PSET (b + 125, c + 70), buffer(b, c)
NEXT c
NEXT b
DO
h = h + 1
IF h = WAVESPEED THEN g = g + WAVEMOVE: h = 0
IF g > 360 THEN g = 1
LINE (a / 5, 100 - 20)-(a / 5, 100 + 20), 0
PSET (a / 5, 100 + sinlookup(a)), 1
IF a > (360) THEN a = 0
a = a + 1
'just for the hell of it, we draw a sinewave.
LINE (a / 5, 100 - 20)-(a / 5, 100 + 20), 2
PSET (a / 5, 100 + sinlookup(a)), 1
'this is where we do the movement.
FOR b = 1 TO 20
WHILE e > 20: e = e - 20: WEND
WHILE e < 1: e = e + 20: WEND
e = b
FOR c = 1 TO 20
'part of drawing the line through the sinewave.
'IF c MOD 4 = 0 THEN a = a + 1
d = c + sinlookup((g) + (b * 20))'+ e) * 2
WHILE d > 20: d = d - 20: WEND
WHILE d < 0: d = d + 20: WEND
IF d <> 0 THEN bitmap(b, c) = buffer(e, d)
NEXT c
NEXT b
'This renders the various tiles on the screen.
'You don't have to understand this if you have a
'working renderer.
FOR b = 1 TO 20
FOR c = 1 TO 20
PSET (b + 175, c + 50), bitmap(b, c)
PSET (b + 175, c + 70), bitmap(b, c)
PSET (b + 195, c + 50), bitmap(b, c)
PSET (b + 195, c + 70), bitmap(b, c)
NEXT c
NEXT b
'wait for vsync.
WAIT &H3DA, 8
'quitting. Why is it here, rather than at the top?
'no friggin' clue.
key$ = INKEY$
IF key$ = "q" THEN SCREEN 0: WIDTH 80: END
LOOP
-SJ Zero is on LSD. Why do you think he wrote
this?.
|
|