Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Is there a cleaner way to do this?

Author
Message
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 15th May 2012 21:04
When my player character hits an enemy in-game, I want the enemy to simply fall off the screen. However, my player character gets injured if it touches an enemy sprite.

I do this by doing a check using getSpriteCollision().

So when the player hits an enemy, I "turn on" physics on the enemy sprite, and it begins to topple off the screen - so far, so good.

However, if the player hits it whilst it is falling, my player dies.

Now, I've managed to fix this by using setSpriteGroup and having a "dead" group, and doing an if statement to stop it. However, I wanted to ask, before I put this elsewhere in my code...

Is there a way to turn on physics on an object, but disable all of its collision so it falls through everything else off the screen, AND getSpriteCollision() will always return false if this sprite is one of the arguments?
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 15th May 2012 21:05
Just read that back and it's not clear what I meant.

Player is running along the ground.

Player ATTACKS an enemy.

The attack hits the enemy.

The enemy starts to fall off the screen.

The player sprite makes contact with the enemy whilst it is falling.

currently the player dies because getSpriteCollision returns true. I want it to return false.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th May 2012 21:25
Why dont you use types?

type sEnemy
State as integer
endtype

global dim Enemys[10] as sEnemy

#constant Alive 0
#constant Dead 1

if player collides with enemy and Enemys[10].State = Dead
no action
else
kill enemy
endif

I use things like this all the time!
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 15th May 2012 21:43
Yeah, that's similar to the solution I'm using myself. However, I thought it would be better if there was some way to simply turn off collisions for the object, as it requires fewer statements.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th May 2012 21:58
Maybe something like this:


Naturally, you can use arrays of enemies. But the idea is to initially set the bits so that the two sprites will interact initially.

Once they collide, the collision category is turned off for the enemy. Since it is initially set to the same category as the walls, floors and other objects, it will stay in place. But once it's set so that it won't collide with the other objects in the category, it should fall through them all and collisions with the player won't register.

I could be wrong. I haven't tested this. It is based on reading the descriptions of the commands.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-05-04 15:58:14
Your offset time is: 2024-05-04 15:58:14