Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Layering
#1
Ok, this problem has been haunting me for 2 months now.
I am making a layering system, but I can't seem to understand how I'm supposed to get the characters to draw between layers

I'll provide the code for anyone who thinks they can help.
I've marked out the problem area's, and places where I think could use optimization.


verticalVal% = cam.y
tileX% = cam.x \ 16 'this division is by 16 and 12, always, so it stands to reason that it can be made faster somehow.
tileY% = verticalVal% \ 12
mapElem% = tileY% * 100 + tileX%

spriteX% = cam.x MOD 16 'the MOD command is a bit slow, I'm wondering what I can do here.
spriteY% = cam.y MOD 12
spriteElem% = spriteY% * 16 + spriteX%

FOR screenY% = 0 TO 192
offset& = buffoff% + screenY% * 238& + 4
FOR screenX% = 0 TO 238


SELECT CASE picl2%(mapl2%(mapElem%), spriteElem%)
CASE 0
POKE offset&, pic%(map%(mapElem%), spriteElem%)
CASE IS <> 0


'NPC's and monsters must somehow draw here. I find
the most trouble with this, because they must draw there pixels
with the map scanning pixel.



POKE offset&, picl2%(mapl2%(mapElem%), spriteElem%)
END SELECT

offset& = offset& + 1

spriteElem% = spriteElem% + 1

IF spriteElem% MOD 16 = 0 THEN 'again, the MOD command
spriteElem% = spriteElem% - 16
mapElem% = mapElem% + 1
END IF

NEXT

verticalVal% = verticalVal% + 1
tileY% = verticalVal% \ 12 again a division by an even number
mapElem% = tileY% * 100 + tileX%
spriteY% = spriteY% + 1

IF spriteY% = 12 THEN spriteY% = 0
spriteElem% = spriteY% * 16 + spriteX%
NEXT
Reply
#2
What do you mean by a layering system?
In the beginning, there is darkness – the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Reply
#3
Hmmm... You cold just add an If...Then statement. It's probably faster than dividing and taking the remainder.


Code:
spriteX% = cam.x
If spriteX%>15 Then spriteX% = 0
spriteY% = cam.y
If spriteY%>11 Then spriteY% = 0


Also...
Code:
spriteElem% = spriteElem% + 1

IF spriteElem% >15 THEN
    spriteElem% = 0
    mapElem% = mapElem% + 1
END IF


I don't think you can do binary shifting in QB. I can't really remember, but if it's possible, you could SHR 4, instead of \16. The \12 is probably as fast as it's going to get, since you're already doing integer division.

Those are the only things that come to mind... Someone else can probably help more. It's been a long time since I used QB. Wink
Reply
#4
yeah, integer div and using AND instead of mod are the fastest you can get in QB. too bad you haven't tried fb yet, but really it's ok, we don't need any competition, keep using qb, sucker! *evil laugh*

just kidding.


edit:

12 is the worst choice you'll ever make. make them both 16x16. 16 is a power of 2, that's how computers work.

then instead of MOD 16, do AND 15.
Reply
#5
By layering system, I mean graphical layers:

1 layer is the background.
1 layer is a second back layer for more background stuff.
layer three is for NPC's, you (the hero), and monsters.
1 layer for forground sprites, like tree tops and tall walls. stuff you can walk behind.
Reply
#6
You could use a library, such as RelLib, DirectQB or CosmoX, if you're using QB4.5. If you're using QBasic, you could try that Blast library. Wink

Or, you could switch to FreeBASIC!!!111
Reply
#7
no thanks, I'd rather do it "pure QB"
everything so far has been pure QB, except the key handling, that's ASM. (QB has problems with keys)
BTW it's QB 4.5
Reply
#8
Layered thingos are just drawn from bottom to top, using transparent blits.

In pureQB it will be so slow.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#9
omg, you used asm for the keys though. cheater.


PureQB™ is a sad idealism =[
Reply
#10
Yeah, it's like downgrading your 3 Ghz computer to run a game that runs like those who were available for 12Mhz 286s.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)