Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A layer problem
#1
mine problem:
i've got 3 layers, the engine put the characters above all layers,
but it checks if the npcY(n) is on or one above a layer 3 tile.
Then the layer 3 tile is put above the character. The problem is how to calculate the position to put the layer 3 tiles above the character. Currently it correctly put it above the main character but thats because i made some routines which are dependent on cameraX and cameraY which is calculated from the npc(pc) axis values, but the tiles are moving to the left and right above the other npcs when i walk with my character.

Anywayz could someone help me with calculating the right position to put the layer 3 tiles above the chars.



Code:
SUB drawcharobj

FOR i = 0 TO npcs
   SnpcY(i) = npcY(i)
   Inpc(i) = i
NEXT i

FOR i = npcs + 1 TO npcs + nmys
   SnpcY(i) = nmyY(i - npcs)
   Inpc(i) = i
NEXT i

FOR d = 0 TO npcs + nmys
   FOR i = 0 TO npcs + nmys
      IF SnpcY(i) > SnpcY(i + 1) THEN SWAP t, SnpcY(i + 1): SWAP tt, Inpc(i + 1): SWAP SnpcY(i + 1), SnpcY(i): SWAP Inpc(i + 1), Inpc(i): SWAP SnpcY(i), t: SWAP Inpc(i), tt
   NEXT i
NEXT d

FOR i = 0 TO npcs + nmys
n = Inpc(i)
  
IF n <= npcs THEN
   IF npcIngame(n) = 1 THEN
   xpos = npcX(n) - cameraX
   ypos = npcY(n) - cameraY
  IF npcSpr(n) <= 3 THEN DQBput 1, xpos - 10, ypos, VARSEG(shadow1%(0)), VARPTR(shadow1%(0))
  IF npcSpr(n) = 4 THEN DQBput 1, xpos - 10, ypos, VARSEG(shadow2%(0)), VARPTR(shadow2%(0))
  IF npcSpr(n) = 0 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(hero%((nframe(n) + nadd(n)) * 352)), VARPTR(hero%((nframe(n) + nadd(n)) * 352))
  IF npcSpr(n) = 1 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(npc1%((nframe(n) + nadd(n)) * 352)), VARPTR(npc1%((nframe(n) + nadd(n)) * 352))
  IF npcSpr(n) = 2 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(npc2%((nframe(n) + nadd(n)) * 352)), VARPTR(npc2%((nframe(n) + nadd(n)) * 352))
  IF npcSpr(n) = 3 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(npc3%((nframe(n) + nadd(n)) * 352)), VARPTR(npc3%((nframe(n) + nadd(n)) * 352))
  IF npcSpr(n) = 4 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(orb%((nframe(oc) + nadd(oc)) * 202)), VARPTR(orb%((nframe(oc) + nadd(oc)) * 202))
  IF npcSpr(n) = 5 THEN DQBput 1, xpos - 25, ypos - 25, VARSEG(vec1%(vadd * 677)), VARPTR(vec1%(vadd * 677))
  IF numb = 1 THEN DQBprint 1, STR$(n), xpos - 20, ypos - 30, 32

xtile = INT(npcX(n) / 20)
ytile = INT(npcY(n) / 20)

IF xtile < 1 THEN xtile = 1
IF xtile > mapx THEN xtile = mapx - 1
IF ytile < 1 THEN ytile = 1
IF ytile > mapy THEN ytile = mapy - 1

xpos = cameraX MOD 20 'i guess this has to be make dependent from the char cordinates instead of the camera
ypos = cameraY MOD 20
  
x = npcX(n) - cameraX
y = npcY(n) - cameraY
x = INT(x / 20)
y = INT(y / 20)

'here begins the putting of the tiles from layer 3 with the calculated positions

      IF mapc(xtile, ytile) > 0 THEN
        DQBput 1, x * 20 - xpos, y * 20 - ypos, VARSEG(tile%(mapc(xtile, ytile) * 202)), VARPTR(tile%(mapc(xtile, ytile) * 202))
        IF mapc(xtile - 1, ytile) > 0 THEN DQBput 1, x * 20 - xpos - 20, y * 20 - ypos, VARSEG(tile%(mapc(xtile - 1, ytile) * 202)), VARPTR(tile%(mapc(xtile - 1, ytile) * 202))
        IF mapc(xtile + 1, ytile) > 0 THEN DQBput 1, x * 20 - xpos + 20, y * 20 - ypos, VARSEG(tile%(mapc(xtile + 1, ytile) * 202)), VARPTR(tile%(mapc(xtile + 1, ytile) * 202))
      END IF
      IF mapc(xtile, ytile + 1) > 0 THEN
        DQBput 1, x * 20 - xpos, y * 20 - ypos + 20, VARSEG(tile%(mapc(xtile, ytile + 1) * 202)), VARPTR(tile%(mapc(xtile, ytile + 1) * 202))
        IF mapc(xtile - 1, ytile + 1) > 0 THEN DQBput 1, x * 20 - xpos - 20, y * 20 - ypos + 20, VARSEG(tile%(mapc(xtile - 1, ytile + 1) * 202)), VARPTR(tile%(mapc(xtile - 1, ytile + 1) * 202))
        IF mapc(xtile + 1, ytile + 1) > 0 THEN DQBput 1, x * 20 - xpos + 20, y * 20 - ypos + 20, VARSEG(tile%(mapc(xtile + 1, ytile + 1) * 202)), VARPTR(tile%(mapc(xtile + 1, ytile + 1) * 202))
      END IF
   END IF
END IF

IF n > npcs THEN
  IF nmyingame(n - npcs) = 1 THEN
   xpos = nmyX(n - npcs) - cameraX
   ypos = nmyY(n - npcs) - cameraY
     DQBput 1, xpos - 10, ypos, VARSEG(shadow1%(0)), VARPTR(shadow1%(0))
     IF nmySpr(n - npcs) = 1 THEN DQBput 1, xpos - 16, ypos - 24, VARSEG(enemy1%((nmyframe(n - npcs) + nmyadd(n - npcs)) * 514)), VARPTR(enemy1%((nmyframe(n - npcs) + nmyadd(n - npcs)) * 514))
  END IF
END IF
  
NEXT i

END SUB
Reply
#2
You're crazy.

Place the tiles first in a grid and the characters second.

PS: Use clean code.

Code:
IF n <= npcs THEN
IF npcIngame(n) = 1 THEN
xpos = npcX(n) - cameraX
ypos = npcY(n) - cameraY
IF npcSpr(n) <= 3 THEN DQBput 1, xpos - 10, ypos, VARSEG(shadow1%(0)), VARPTR(shadow1%(0))
IF npcSpr(n) = 4 THEN DQBput 1, xpos - 10, ypos, VARSEG(shadow2%(0)), VARPTR(shadow2%(0))

SELECT CASE npcSpr
CASE 0: DQBput 1, xpos - 10, ypos - 30, VARSEG(hero%((nframe(n) + nadd(n)) * 352)), VARPTR(hero%((nframe(n) + nadd(n)) * 352))
CASE 1: IF npcSpr(n) = 1 THEN DQBput 1, xpos - 10, ypos - 30, VARSEG(npc1%((nframe(n) + nadd(n)) * 352)), VARPTR(npc1%((nframe(n) + nadd(n)) * 352))
CASE 2: DQBput 1, xpos - 10, ypos - 30, VARSEG(npc2%((nframe(n) + nadd(n)) * 352)), VARPTR(npc2%((nframe(n) + nadd(n)) * 352))
CASE 3: DQBput 1, xpos - 10, ypos - 30, VARSEG(npc3%((nframe(n) + nadd(n)) * 352)), VARPTR(npc3%((nframe(n) + nadd(n)) * 352))
CASE 4: DQBput 1, xpos - 10, ypos - 30, VARSEG(orb%((nframe(oc) + nadd(oc)) * 202)), VARPTR(orb%((nframe(oc) + nadd(oc)) * 202))
CASE 5: DQBput 1, xpos - 25, ypos - 25, VARSEG(vec1%(vadd * 677)), VARPTR(vec1%(vadd * 677))
END SELECT

PPS: Convert to int division by just doing this:

A = A \ 100
Same as:
A = INT(A / 100)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
Quote:PS: Use clean code.
This coming from Captain GOTO...
Reply
#4
I'm going to fight you to the end, Captain Space Pirate Alien!
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
i'm not completely following you (yeah on the clean part maybe ;-))
but howz is putting the tiles 1st in a grid and the characters second going to help me? could you explain it a little more, cause i don't think i really understand you...

thnx
Reply
#6
Thing "A" will appear in front of thing "B" only when thing "A" is drawn before thing "B" in each frame.

Tho get proper layered graphics for a RPG you can do this:

1. Draw a base tiled map.
2. Z-order all your characters: You have to have an array specifying the order in which they will be rendered. In each frame, you have to sort that array attending the Y position of every sprite, and draw them following that order. That way, someone whose Y = 24 will be drawn before someone whose Y = 32, and it will look like the first one is behind the second one. When the first one walks down and Y = 40 the reordering will cause that it comes to first plane and the second one is behind.
3. Draw another tiled map on top which may be useful for house roofs, tree tops and more stuff that may cover the players.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
yeah that's exactly what i have, but the problem lies within part 3 you say, 1st i put the the 3rd layer as last but then i had problems with standing 1 under a layer 3 tile (roof layer etc.) and the top of my character would be under the layer 3 tile which is plot above all.

so my new way of doing it is checking if there's a layer 3 tile is next to and under the character and only then put it above the player, and in default the layer 3 tiles are plot under the chars, this works for my main char (coz the calculations of the cordinates of where to put the covering layer 3 tiles are based on camera-X and -Y) but not for the other npc's.

So i need help with a proper way of calculating the position where to put the layer 3 tiles (which are near the chars)
Reply
#8
here's the demo of it:

http://www.ngemu.com/forums/attachment.p...ntid=54628

EDIT: i've put in a delay-er, it brings the fps down from 450 on my AMD 2000 XP
to 35 fps, if you need more speed tell me =)
Reply
#9
anyone willing to reply? plz help me with this problem...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)