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.

Newcomers AppGameKit Corner / Problem with collisions

Author
Message
Humildadever
13
Years of Service
User Offline
Joined: 17th Aug 2010
Location:
Posted: 15th May 2016 23:36 Edited at: 15th May 2016 23:37
Hi!

I need some help! when i try collision with for example coin nothing happens, what i m doing wrong?

This is the code

[rem
rem AppGameKit Application
rem

rem Landscape App
SetDisplayAspect( 4.0/3.0 )
rem variaveis
score=0

keyboard = getKeyboardExists()
if keyboard=0

rem create a virtual joystick
AddVirtualJoystick(1,10,88,12)

rem create a jump button
AddVirtualButton(1,90,88,8)

endif
goodguy=1
LoadImage (1,"goodguy.png")
rem create a character
spr = createSprite(1)
SetSpriteShape ( 1, 1 )
setSpriteSize(spr,8,16)
setSpriteOffset(spr,2,4)
setSpritePositionByOffset(spr,54,96)
setSpritePhysicsOn(spr,2)
setSpritePhysicsCanRotate(spr,0)
SetObjectCollisionMode( 1, 1 )
boxman = spr



loadimage (2, "barreira.png")
barreira=2
rem create static platforms
spr = createSprite(2)
setSpriteSize(spr,20,8)
setSpriteOffset(spr,15,1)
setSpritePositionByOffset(spr,15,75)
setSpritePhysicsOn(spr,2)

LoadImage (6, "coin.png")
coin=6
spr = createSprite(6)
SetSpriteShape ( 6, 1 )
setSpriteSize(spr,8,8)
setSpriteOffset(spr,15,1)
setSpritePositionByOffset(spr,85,50)
setSpritePhysicsOn(spr,2)
SetObjectCollisionMode( 6, 1 )
kinematic = spr
direction = 10


spr = createSprite(2)
setSpriteSize(spr,20,8)
setSpriteOffset(spr,15,1)
setSpritePositionByOffset(spr,40,100)
setSpritePhysicsOn(spr,2)



LoadImage (5, "monstro.png")
monstro=5
spr = createSprite(5)
setSpriteSize(spr,15,15)
setSpriteOffset(spr,15,1)
setSpritePositionByOffset(spr,20,15)
setSpritePhysicsOn(spr,2)





rem create a kinematic platform
spr = createSprite(2)
setSpriteSize(spr,20,8)
setSpriteOffset(spr,15,1)
setSpritePositionByOffset(spr,50,15)
setSpritePhysicsOn(spr,3)
kinematic = spr
direction = 10

SetPhysicsDebugOn ( )

rem A Wizard Did It!
do
gosub coincollector
print ("SCORE: " +str(score))
rem update kinematic platform
setSpritePhysicsVelocity(kinematic,0,direction)
if getSpriteYbyOffset(kinematic)>85
direction=-10
else
if getSpriteYbyOffset(kinematic)<15
direction=10
endif
endif


rem add keyboard control here!
rem jump
jump = GetRawKeyPressed(38)
if jump>0

setSpritePhysicsVelocity(boxman,getSpritePhysicsVelocityX(boxman),-jump*60)
endif

rem move boxman
setSpritePhysicsVelocity(boxman,(GetRawKeyState(39)-GetRawKeyState(37))*30,getSpritePhysicsVelocityY(boxman))

SetPrintColor (255,0,0)

Print( ScreenFPS())
Printc("min->")
Print ((timer()/60))
Sync()
loop
coincollector:
if GetPhysicsCollision (boxman,6 )=1
DeleteSprite (6)
print ("tocou")
score=score+1
playsound (13)
endif
Return/code]
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th May 2016 11:27
SetObjectCollisionMode( 1, 1 ) is used on a sprite, but is only for 3d objects.

[/url]
Humildadever
13
Years of Service
User Offline
Joined: 17th Aug 2010
Location:
Posted: 16th May 2016 13:59
But in Phisics what i can do to detect collision?
Please i need help...

Thestroyer
7
Years of Service
User Offline
Joined: 14th May 2016
Location:
Posted: 26th May 2016 21:16 Edited at: 26th May 2016 21:18
You can do it with maths yourself. If you have the center of the coin and the corner of the cube you can do something with squareroot and look in a for loop if one of the pixels of the guy are within a certain range of the coin (if the coin is round and the guy is a square). If you want an example please ask. I don't know if there is an AKG command for it.
EDIT: There is a command for it: GetSpriteFirstContact

Login to post a reply

Server time is: 2024-04-20 08:36:33
Your offset time is: 2024-04-20 08:36:33