'=========================================================================== ' Subject: SPRITES USING PEEK & POKE Date: 06-26-97 (11:54) ' Author: Jay Cook Code: QB, QBasic, PDS ' Origin: jay.cook@sandh.com Packet: GRAPHICS.ABC '=========================================================================== 'Qsprite.bas _ Jay Cook _ 6-25-97 _ http://members.tripod.com/~jaycook/QB.HTM ' I needed to write some sprite routines for the game in QB I was programming 'and I was currently "borrowing" some routines from someone else's program. 'I found out how to POKE it up. How it works is 1-64000 and color. 1=(1,1) '64000=(320,200) using the formula (y * 320 + x). What I did was build an array 'of a 16x16(256) sprite and the value represented the sprite color. If the color 'was 0 then it would skip the plot and leave the background. I also desided to 'make a reverse sprite by having the x plot in reverse(instead of adding it 'would subtract) and just move the X value of the sprite over 15 pixels. I didn't 'add Y-flip, but that could easily be done. I also added PSET plotting so it 'can be run in Qbasic without overflowing. If you use poke, you will have to 'compile because when it POKEs beyond 32000, it crashes. It is pretty fast and 'sure beats the hell outa PSET. Not bad for 3 am programming? ' - Jay 'jay.cook@sandh.com DEFINT A-Z DECLARE SUB gets (x111%, y111%, s11%()) DECLARE SUB puts (x111%, y111%, s11%()) DECLARE SUB putr (x111%, y111%, s11%()) COMMON SHARED x111%, y111%, s11%, xz2, xz, yz2, yz, xz3, px, px2 CLS DEF SEG = &HA000 SCREEN 13 px = 256: 'Amount of data for a single sprite array xz3 = 15: 'X width of sprite DIM SHARED gfx(px) '(\/ Sprite) LINE (0, 0)-(15, 15), 12 LINE (0, 0)-(15, 15), 9, B '(/\ Sprite) '\/ Gets sprite in array(Upper left X,Y) gets 0, 0, gfx() CLS LINE (1, 1)-(100, 27), 1, BF '\/ Puts down regular sprite puts 20, 20, gfx() '\/ Puts down reversed sprite putr 40, 20, gfx() SUB gets (x111%, y111%, s11%()) xz3 = 15 xz = x111%: yz = y111% xz2 = xz: yz2 = yz FOR b = 1 TO px IF xz > xz2 + xz3 THEN xz = xz2: yz = yz + 1 px2 = yz * 320 + xz s11%(b) = PEEK(px2) xz = xz + 1 NEXT END SUB SUB putr (x111%, y111%, s11%()) xz = x111% + 15: yz = y111% xz2 = xz - 15: yz2 = yz FOR b = 1 TO px IF xz < xz2 THEN xz = xz2 + xz3: yz = yz + 1 IF s11%(b) = 0 THEN sc = 1 IF sc = 0 THEN : px2 = yz * 320 + xz: POKE (px2), s11%(b) '| use this line instead of above to run in Qbasic, otherwise compile '\/ using the line above(faster) 'IF sc = 0 THEN : PSET (xz, yz), s11%(B) xz = xz - 1: sc = 0 NEXT 'yz = yz - xz3 END SUB SUB puts (x111%, y111%, s11%()) xz = x111%: yz = y111% xz2 = xz: yz2 = yz FOR b = 1 TO px IF xz > xz2 + xz3 THEN xz = xz2: yz = yz + 1 IF s11%(b) = 0 THEN sc = 1 IF sc = 0 THEN : px2 = yz * 320 + xz: POKE (px2), s11%(b) '| use this line instead of above to run in Qbasic, otherwise compile '\/ using the line above(faster) 'IF sc = 0 THEN : PSET (xz, yz), s11%(b) xz = xz + 1: sc = 0 NEXT END SUB