Qbasicnews.com
May 26, 2020, 04:22:38 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: EMS Question  (Read 4194 times)
Anonymous
Guest
« on: April 08, 2004, 08:02:15 AM »

Hello everyone

I have a question for you. You would have to know CosmoX lib, though. Hopefully someone does... anyways Tongue

My question is... How do you map multiple layers in EMS? I've read the doc, followed it to the letter. But I just can NOT figure out how to have it so you could write to say layer 1, with sprites, and layer 2 with bg... the way the doc puts it, its like you can only have one on at a time or something. is there something im missing that you know?? HELP!
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: April 08, 2004, 08:12:15 AM »

WHy do you want several layer? That takes more memory and makes your program slower. If you have to draw in each layer, and then blend the layers together, you are wasting time. You just need one layer: just draw things from bottom to top (first background, then sprites, etc etc)
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Anonymous
Guest
« Reply #2 on: April 08, 2004, 08:23:45 AM »

yeah, thats usually how i do it... the only reason ( i know its cheap) is so that i could use cosmox collision detection. *sigh*



adds coll detection to list of things to learn today Tongue
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #3 on: April 08, 2004, 08:26:30 AM »

In such case you just need 1 extra layer where you place the collision info. Normally this is made drawing the sprites and the colliding parts of the background in a solid colour. Can't help further, sorry, I never used that. I know how it works but never used it.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #4 on: April 08, 2004, 01:36:51 PM »

You can have multiple layers in EMS, but you can only map one layer at a time, because the pageframe is only 64k.
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #5 on: April 08, 2004, 06:48:05 PM »

It would be faster to make four separate collision checks with the individual tiles making up the region the sprite is in then the entire layer.

Not only that, it would save memory.  Butt loads of memory.
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #6 on: April 08, 2004, 07:05:26 PM »

That won't work if the sprite is substantially larger than the tiles. And then what about collisions with other sprites?
Logged
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #7 on: April 08, 2004, 07:45:49 PM »

Well, I don't use layers for collision detection. I do a bounding box and then pixel perfect, if bounding box is true..

Here's an example of how to use a backgroud EMS layer in CosmoX though...

Code:
DEFINT A-Z
'$DYNAMIC
'$INCLUDE: 'C:/QB45/Cosmox.bi'

COMMON SHARED TotalPages, Handle, Layer
CONST Buffer1 = 0, Buffer2 = 4


IF CSDetectEMS = 0 THEN
 PRINT "EMS not detected... ABORTING"
 SLEEP 2
 END
END IF
 TotalPages = CSFreeEMSPages
  Handle = CSAllocateEMS(TotalPages)
   Layer = CSGetEMSFrame
    CSInitVGA
     CSInstallKeyBoard
      IsMMX = CSDetectMMX%

'Map and draw on background layer
CSMapEMSLayer Handle, Buffer2
 FOR Y = 0 TO 199
  CSLine Layer, 0, Y, 319, Y, 16 + (Y * .075)
 NEXT
  CSPrint Layer, CENTERED, 95, "Background Layer", 14


DO
'Copy background layer over sprite layer
 CSMoveEMS Handle, Buffer2, 0, Handle, Buffer1, 0, 64000

'Map sprite layer so we can draw on it
 CSMapEMSLayer Handle, Buffer1

Text$ = "Sprite Layer"
 X = X + X1
  IF X <= 0 THEN X1 = 1
  IF X + (LEN(Text$) * 8) >= 319 THEN X1 = -1

 Y = Y + Y1
  IF Y <= 0 THEN Y1 = 1
  IF Y + 8 >= 199 THEN Y1 = -1

 CSPrint Layer, X, Y, Text$, 32
  CSWaitRetrace
   CSPcopyMMX Layer, VIDEO
LOOP UNTIL CSKey(KEYESC)



CSDeallocateEMS Handle
CSRemoveKeyBoard
CSClose
SYSTEM
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #8 on: April 08, 2004, 08:31:58 PM »

Quote from: "Plasma"
That won't work if the sprite is substantially larger than the tiles. And then what about collisions with other sprites?


That's true enough (sprite > tile).  But how often is a sprite more then twice as large as a tile?

As to collisions with other sprites...just make a check with it ;P

Sometimes you have to sacrifice speed (Oh no!  I have a P100, what ever shall I do with 100,000,000 cycles???) to save lots of space (10% of the usable memory space to your application is a lot).
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Anonymous
Guest
« Reply #9 on: April 09, 2004, 01:42:13 AM »

thanks, plasma, your remark about the pageframe only being 64k is what i needed. i should have been able to figure that out Tongue geez.


davenstein, thanks for the routine. unfortunately, i dont think thats how im gonna do it... it seems slow...

69, what do you  mean by running a 'check'? its not pixel perfect, right? cause i mean i could do like

Code:
IF ABS(ENEMYX - X) < TILESIZE AND ABS(ENEMYY - Y) < TILESIZE THEN COLLISION


i wouldnt actually use abs, but you know what i mean. i want pixel perfect ;p ive been reading about true bitmaps (1's and 0's), but it seems hard to do. does anyone know about that?


EDIT: that code wont work. im not going to make it lol you know what i mean
Logged
Piptol
Ancient QBer
****
Posts: 422



WWW
« Reply #10 on: April 09, 2004, 02:21:05 AM »

Last time I did this with Cosmo X, I just had 1 EMS layer I used for both the screen buffer and collisions. Worked like this: Clear the layer, solidPUT collidable objects and then test for collisions using whatever method you want (bounding box/pix perfect). Then just draw over everything and use it as the screen buffer. Rinse and repeat Smiley
Logged

In a world without walls and doors, who needs Windows and Gates?
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #11 on: April 09, 2004, 06:03:35 AM »

Quote from: "Cha0s"
69, what do you  mean by running a 'check'?


Check, analyze, ascertain, audit, compare, confirm, enquire about, find out, investigate, probe, quiz, review, scrutinize, study, test, try, verify, check.

And how do you do any one of the previous pseudonyms in BASIC?

IF...THEN
SELECT CASE...END SELECT

Didn't think the word 'check' was that confusing.  I see your American so English is a bit of a grasp, but come on ;P
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Anonymous
Guest
« Reply #12 on: April 09, 2004, 07:58:19 AM »

piptol: hey thanks, thats actually what i decided to do, i just have to learn how to actually do coll detection. ;P


and you. 69:

fun with prepositions.

"I have half a mind to track you down and smack you up."

when i asked i was wondering what method you used when you were running the check. you really are an a-hole arent you? i mean really, am i guilty of stupidity before being proven innocent just because i have unique spiritual beliefs? grow up. you were civil before that thread got where it is. now youre just being a prick.

here's a couple you should look up.

arrogant, priggish, immature, prejudiced, ignorant


ill have a special place for you in the game i am making.
Logged
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #13 on: April 09, 2004, 01:58:35 PM »

If you comment out the CsWaitRetrace line, it's only a little bit slower than using the method Piptol mentioned. Smiley
Logged
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #14 on: April 09, 2004, 08:19:59 PM »

Quote from: "Cha0s"
and you. 69:

fun with prepositions.

"I have half a mind to track you down and smack you up."

when i asked i was wondering what method you used when you were running the check. you really are an a-hole arent you? i mean really, am i guilty of stupidity before being proven innocent just because i have unique spiritual beliefs? grow up. you were civil before that thread got where it is. now youre just being a prick.

here's a couple you should look up.

arrogant, priggish, immature, prejudiced, ignorant


ill have a special place for you in the game i am making.


Oh come on now.  I was being silly (hence the ;P at the end of the reply).  And this has nothing to do with the other thread.  I judge each act of stupidity on it's own merit.  But, yes, I am an a-hole. ;P

I just didn't understand what you meant by 'what do you mean, do a check?' so, I thought I might have to clarify the word 'check'.

Besides, don't take it too seriously, we Canadians like to poke fun at the American education system and it's quality or lack there-of.

Ok, as to the method, here is some basic pseudo-code...

Assuming the sprite is less then 2x the dimensions of the tiles, and assuming that you are using pixel-perfect movement...

Code:
'' Tile Collision:
   HitQuad = 0
   If PPColide(Tile.Graphic(Map(Player.X \ Tile.X, Player.Y \ Tile.Y)), Player.Graphic, Tile.X, Tile.Y, Player.X, Player.Y) Then HitQuad = 2
   If PPColide(Tile.Graphic(Map(Player.X \ (Tile.X + Tile.Width), Player.Y \ Tile.Y)), Player.Graphic, (Tile.X + Tile.Width), Tile.Y, Player.X, Player.Y) Then HitQuad = 1
   If PPColide(Tile.Graphic(Map(Player.X \ Tile.X, Player.Y \ (Tile.Y + Tile.Height))), Player.Graphic, Tile.X, Tile.Y, Player.X, Player.Y) Then HitQuad = 3
   If PPColide(Tile.Graphic(Map(Player.X \ (Tile.X + Tile.Width), Player.Y \ (Tile.Y + Tile.Height))), Player.Graphic, (Tile.X + Tile.Width), Tile.Y, Player.X, Player.Y) Then HitQuad = 4
   If HitQuad > 0 Then
      '' Do Stuff
   End If


As to sprites...

Code:
''Sprite Collision:
   For Current = 1 To TotalSprites
      If Bound(Sprite(Current).X, Sprite(Current).Y, Sprite(Current).Width, Sprite(Current).Height, Player.X, Player.Y, Player.Width, Player.Height) Then
         If PPColide(Sprite(Current).Graphic, Player.Graphic, Sprite(Current).X, Sprite(Current).Y, Player.X, Player.Y) Then
            '' Do Stuff
            Current = TotalSprites + 1
         End If
      End If
   Next Current


Similar to your code, I'm sure, is that it loops through all the sprites.  But that is where it ends ;P

This first checks the bounding box of the sprite against the player, if they overlap, then it would check for pixel perfect collision.  If they do collide, you would do your regular stuff about it.  Then, it sets the current sprite counter to after the last sprite so that it will exit to loop.  Not much sense in checking more sprites if we already fail on one.
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!