Hiding an Entity you collide with?

Blitz3D Forums/Blitz3D Beginners Area/Hiding an Entity you collide with?

StOrM3(Posted 2004) [#1]
Hello,

Here is my question, I have an array of custom types, items per say. Now the entitycollided function returns the handle to the entity collided with, so say for instance my player runs into one of these items. If I use a variable like tmphandle = entitycollided(p1\bubble,2) then I use tmphandle\points ? Can I use a tmp variable like this to get the props of the returned handle from the collision, and also can I use the tmp variable to hideentity to make that item hide on the screen etc. ? If not I am going to have to figure out how to tell exactly which item in the custom type array I collided with and use that variable directly to get the points field data and to hide it.. Just wondering.. thought they might have it set up to auto assign fields of types to temp variables assigned from a returned handle..

Help me please. ehhehe


big10p(Posted 2004) [#2]
entitycollided() returns a regular entity handle so, yes, you can use hideentity to hide that entity, but no, you can't use tmphandle\points etc. to access it's properties. As I said, tmphandle would be an entity handle, not a pointer to any type instance you may wish to associate with that entity. The docs for entitycollided() talk about 'types' but these refer to collision types (set using entitytype) and not type variables. A bit confusing but the two are completely unrelated.

You may well have an 'entity' field in your type declaration that points to the associated entity but that link only works one way. To get the type instance associated to a given entity, you're going to have to search through your array of types until you get a match with the 'entity' field.

Or, if you're feeling more daring, you can get a type's handle ID with handle() and store it as the entity name. Then you can retrieve this later to find the associated type instance using the object() command.


StOrM3(Posted 2004) [#3]
do you have any example code on how to do this ? I mean using the entities handle to name the entity, then when I collide with that entity and return the handle, checking through all the entities in the array for that handle / entity with that name ? Or do I just use object command to get access to the entity using object and the handle which is also what the entities name is, which would then allow me to grab the points etc.. fields from it ?

I appreciate the help btw.

PS. I can't find any docs on the object command, what it is used for, how it is used etc..


StOrM3(Posted 2004) [#4]
Say for instance we have the following:
type shapes
  field item ;handle for model
  field points ;point value
end type

global myshapes.shapes(8,8)
for x = 1 to 8
  for z = 1 to 8
    myshapes.shapes(x,z) = new shapes
    ; would I do the name here ?
    nameentity(myshapes.shapes(x,z),str(handle(myshapes.shapes(x,z))))
  next
next
; now theoretically all myshapes should be named by their handle ?

; so to access the points after a collision.. something like...
tmpvar = object.myshapes(entitycollided(p1\bubble,2))
;Then is this possible ?
p1\points = p1\points + tmpvar\points
hideentity(tmpvar)

; Tell me where I am wrong,
; or if this is right ?  I am at work currently,
; and will not be able to try it, until this weekend
; when I am off work, and will not have access to
; internet, as I will have my portable out and about 
; coding trying to finish the game up.

Thanks in advance.

Ken


Yan(Posted 2004) [#5]
type shapes
  field item ;handle for model
  field hidden ;so you know if the entity's hidden
  field points ;point value
end type

global myshapes.shapes(8,8)
for x = 1 to 8
  for z = 1 to 8
    myshapes(x,z) = new shapes
    ; would I do the name here ?
    myshapes(x,z)\item = createcube()
    myshapes(x,z)\hidden = 0
    nameentity myshapes(x,z)\item, handle(myshapes(x,z))
  next
next
; now theoretically all myshapes should be named by their handle ?

; so to access the points after a collision.. something like...
tmpvar.shapes = object.shapes(entityname(entitycollided(p1\bubble, 2)))

;Then is this possible ?
p1\points = p1\points + tmpvar\points

hideentity(tmpvar\item)
tmpvar\hidden = 1
YAN


big10p(Posted 2004) [#6]
Thats the basic idea.

BTW, should be 'Dim myshapes.shapes(8,8)' though.


Yan(Posted 2004) [#7]
Hehe...Didn't notice that!

:o)


YAN


StOrM3(Posted 2004) [#8]
Thanks you guys.. you helped me bigtime understand this... Now if I can only figure a way to do chain reaction collisions.. May have to move the actual object ran into, then check the object it collides with to see if it is the same type etc.. until the next item collided with is not same, then remove all previous objects whose objects and handles I use to read the number field are equal. Then return player to previous position. You guys have helped alot, I think I may be able to get at least the first beta done of my game this weekend, with at least one item being removed by the player each time if equal to player number.

I will keep you guys informed, and your names would be great so I can add you to the credits screen, since you played a big part in my being able to finish it this weekend on time. It would have taken me forever to figure it out on my own playing with it, trial and error, trying all kinds of wierd stuff that wouldn't work like to for next loops through all the objects every time player shoots seeing if one of the objects is colliding with player which would have greatly slowed down game play, this way is way more elegant, and will improve overall game speed.

Thank you.. Please post your names you would like in the credits etc..

Thanks,

Ken


big10p(Posted 2004) [#9]
No credit needed, really... *cough* but if you really insist, my name's in my user profile. :P


Yan(Posted 2004) [#10]
Sorry, didn't notice this...Erm...Ditto ;o)


YAN


StOrM3(Posted 2004) [#11]
Guess what... the beta is done.. although I am not happy with some of the coding, and there is a wierd bug, where most of the time if not the whole time everything functions as planned, it returns the player to where it was before shooting the bubble/fruit at a piece of fruit to take it off the screen. Then at other times, there is a wierd bug, where when you hit a piece of fruit to take it off the screen, instead of positioning you back where you were before shooting at it, it puts you to close to the fruit, and you get stuck on the fruit item...?... I believe this is because of how slow it was running on my laptop with its little ati 16mb videocard, and maybe also the fact that when it is moving the player back to its position, you move the mouse or something, actually I'm not sure what is causing it, since it is so wierdly intermittant. Is there a way to disable the mouse during this time frame ? So no matter what the player does while the bubble is traveling to hit the fruit item, or on the return trip, the mouse stays where it was, and player input as no affect on the location it is returning to ? I have tried to store the location you start from, and the mouse position, and then resetting these values upon returning from the playershoot function, but it still happens every now and then. So disabling the mouse all together for this time frame would be the best solution if it is possible ?

Any ideas, suggestions, things to check would be greatly appreciated. I can supply the code to the player shoot function, and the maingameloop function from which the player shoot function is called if necessary.

Thanks you guys, and yes I am serious about putting your names in there, because of you guys I was able to get my game to beta stage.

Thanks very very much.. I love this blitz3d community, always been very helpful to me.

Ken


big10p(Posted 2004) [#12]
If I understand what you're saying correctly, it sounds like your collisions are still in play when manually positioning your player. You may want to look at this thread:

http://www.blitzbasic.com/Community/posts.php?topic=32141


StOrM3(Posted 2004) [#13]
I changed the MovePlayer code back to the older somewhat less elegant code that would move the player around the outside of the items at grid size increments, jumping between fruit rows perfectly. This improved game play, by speeding up movement, and also, got rid of the wierd player movement bug. It no longer is a problem... Everything works great! Thanks you guys for everything. Now I am going to write an inhouse tool to help with bmp fonts, to jazz it up a little bit.

Thanks again.. if anyone knows somewhere to get cheap/free webhosting that I can use to host my website that has code in it to allow purchase through pay pal, please let me know either in here, or email me at storm3@... thank you again.

Ken