BASIC

Author Topic: Z-DEPTH ? if you can, I will very happy  (Read 4270 times)

Offline equinox

  • Mc. Print
  • *
  • Posts: 19
    • View Profile
Hi,
is an example of how a character goes behind a rock and is covered. As in games rpg?
« Last Edit: 2009-Feb-12 by equinox »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1772
    • View Profile
    • Homepage
Re: Z-DEPTH ?
« Reply #1 on: 2009-Feb-08 »
Look at Mappyloader on my homepage, gamecorner.110mb.com. If you set a stone or a tree on layer 1, the player will be in front of the stone/tree when he is lower down, if he goes up he will be covered behind the stone/tree.

Or if you just want it a bit easier, if you want something to cover something else, draw the sprite you want on top, last.

eg:
Code: GLBasic [Select]
DRAWSPRITE player, 50, 50
DRAWSPRITE stone, 50, 50
 

For this you need to sort your objects on Y coordinate. Look for the example SORTARRAY in the help.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Z-DEPTH ?
« Reply #2 on: 2009-Feb-09 »
hehe

Use layers:

Code: GLBasic [Select]
// L = Layer ( 3 layers or something more :D )
Level[L][X][Y]

FOR L = 0 TO 2 // 3 layers
    FOR X = 0 TO 99 // 100 X-Tiles
        FOR Y = 0 TO 99 // 100 Y-Tiles

            SELECT L
                CASE 0 // behind the Player layer
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
                CASE 1 // Player and collision layer
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
                    CheckCollision()
                    Player() // Your player drawing and movement
                CASE 2 // the "coverlayer"
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
            ENDSELECT

        NEXT
    NEXT
NEXT

I can make a little example, if you want?
« Last Edit: 2009-Feb-09 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1772
    • View Profile
    • Homepage
Re: Z-DEPTH ?
« Reply #3 on: 2009-Feb-09 »
Schranzor, if you use layers you can't stand in front of a stone, the stone will still cover the player. The example picture from the mappy loader below shows what I mean.

[attachment deleted by admin]

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10689
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Z-DEPTH ?
« Reply #4 on: 2009-Feb-09 »
No!! You sort by the bottom line of a sprite :P

Offline equinox

  • Mc. Print
  • *
  • Posts: 19
    • View Profile
hehe

Use layers:

Code: GLBasic [Select]
// L = Layer ( 3 layers or something more :D )
Level[L][X][Y]

FOR L = 0 TO 2 // 3 layers
    FOR X = 0 TO 99 // 100 X-Tiles
        FOR Y = 0 TO 99 // 100 Y-Tiles

            SELECT L
                CASE 0 // behind the Player layer
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
                CASE 1 // Player and collision layer
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
                    CheckCollision()
                    Player() // Your player drawing and movement
                CASE 2 // the "coverlayer"
                    DRAWSPRITE Level[L][X][Y], X*Tilesize, Y*Tilesize
            ENDSELECT

        NEXT
    NEXT
NEXT

I can make a little example, if you want?

Yes,tnk1000. If yuo can,if you can, I will very happy!!!

Offline equinox

  • Mc. Print
  • *
  • Posts: 19
    • View Profile
Re: Z-DEPTH ?
« Reply #6 on: 2009-Feb-12 »
In yoUr exemple, I dont FIND guy.png.

Look at Mappyloader on my homepage, gamecorner.110mb.com. If you set a stone or a tree on layer 1, the player will be in front of the stone/tree when he is lower down, if he goes up he will be covered behind the stone/tree.

Or if you just want it a bit easier, if you want something to cover something else, draw the sprite you want on top, last.

eg:
Code: GLBasic [Select]
DRAWSPRITE player, 50, 50
DRAWSPRITE stone, 50, 50
 

For this you need to sort your objects on Y coordinate. Look for the example SORTARRAY in the help.

« Last Edit: 2009-Feb-12 by equinox »