Quote: "Okay, I managed to get your code running. I had to add in a virtual resolution at the start and declare an array for arrtower[]."
Like I said, I didn't include all my code. I didn't even mean to include the arrtower arrays because they're not part of what I'm trying to figure out.
Quote: "
I'm not entirely sure what the code is supposed to do but I'm seeing is some white squares falling and another square that I believe the player is supposed to control."
Sorry, I guess I wasn't very clear on what I'm trying to do. The white squares are simply placeholders for the art that will come later. I made them 100x100, and yes, they are supposed to "fall" down the screen. They're part of a scrolling background.
The goal is to get the player sprite to collide with the squares during a certain animation frame. If it doesn't, it activates the plpfalls function that plays a death animation.
The player is a fish trying to jump from pool to pool on a scrolling background. At the point when the animation shows the fish coming back down and hitting the water, the player should be overlapping one of the pools or else he's killed.
It's important that the collision occurs during that final frame of animation.
Quote: "
Looking at the various ray cast you're doing, you're ray casting diagonally 100 pixels down and to the right."
I'm attempting to make a raycast the same size as the squares, so that should be right as long as it's 100x100. I'm going by the example given in the AppGameKit help section. the raycasts should also stay with the squares, which I just realized I don't think I coded for. I don't even know if that's possible.
Quote: "
If none of the ray cast collides with a pool(?) then the code goes to the plpfalls() function where the player, for want of a better phrase, "flips out", i.e. starts spinning and bouncing around."
The ray cast is supposed to be part of the pool, and if the player doesn't collide with the raycast, then the plpfalls function plays. And, yes, that's how the player behaves. It's a spinning, dazed fish that will fly off the screen once I fix the collide bits so it doesn't react to any other sprites. I haven't included that code yet so that's why it bounces all over the place. I'm trying to get the hard stuff out of the way.
Quote: "
I'm guessing you tried the GetSpriteCollision command, which will return a 1 as long as the sprites are overlapping. There might something with the way you're using this command that's causing the behaviour you're seeing."
I've tried GetSpriteCollision, GetPhysicsCollision, making the pools sensors, and now ray casting.
The first two commands only worked when the edges of the sprites touched. If I was in the middle of a sprite (and I made the pool sprite stretch across the screen just to test it) it doesn't detect the collision and goes straight to plpfalls.
Quote: "
To be honest, you're code is a bit of a mess* so this wouldn't surprise me."
Could you please explain? Most of the main loop is full of code taken directly from code given to me by BatVink (the increased speed in scrolling), so I assume you're referring to the rest of the code, but I don't see what the mess is you're speaking of.
As far as I can tell, I'm coding each command the way I've read it in the help guides, but I wouldn't doubt that while each command may be sound, they may not work together. Then again, I could be coding each command wrong.
Quote: "
I would also advise against creating a sprite during the game loop, as this can slow the game down, but rather create it before the start of the main loop and then just hide it until it's needed."
The only place I see that I created a sprite other than before the loop is in the plpfalls function, and I did that because it wouldn't recognize it if I created the sprite before the loop. It gave me the error that I hadn't initialized it and such.
In the main loop itself, I positioned sprites, but didn't create them, unless I have some code in there I'm not seeing.
I'll look into your code, thanks.
I might have been naive to think you wouldn't need to see all my code to see what's causing problems, so here it is.
// set window properties
SetWindowTitle( "Plp Splash New" )
SetWindowSize( 768, 1024, 0 )
// set display properties
SetVirtualResolution( 768, 1024 )
SetOrientationAllowed( 1, 1, 0, 0 )
EnableClearColor ( 0 )
SetSortDepth (1)
// set physics
SetPhysicsGravity( 0, 300 )
//SetPhysicsGravity(0,0)
SetPhysicsWallBottom ( 0 )
SetPhysicsWallLeft ( 1 )
SetPhysicsWallRight ( 1 )
SetPhysicsDebugOn ()
// Load Music
LoadMusic ( 1, "wwq2.wav" )
SetMusicFileVolume( 1, 25 )
LoadMusic ( 2, "wwq3.wav" )
SetMusicFileVolume( 2, 25 )
// play and loop the music
PlayMusic ( 1, 1 )
// load sound files
LoadSound (1, "explode1.wav" )
// Create Background
background1 = CreateSprite ( LoadImage ( "bg1.png" ) )
SetSpritePosition ( background1, 0, 0 )
SetSpriteDepth (background1, 10)
// Create Tower
GLOBAL arrTower as integer[2]
arrTower[1] = createSprite(LoadImage ("tower.png"))
setSpriteSize(arrTower[1],610,3143)
setSpritePosition(arrTower[1],100,-2119)
arrTower[2] = createSprite(LoadImage ("tower2.png"))
setSpriteSize(arrTower[2],610,3143)
setSpritePosition(arrTower[2],100,-5262)
// Create Plp
GLOBAL fishspriteg as integer[1]
speed = 1
fishspriteg[1] = CreateSprite (LoadImage ("fishspriteg.png"))
SetSpritePosition(fishspriteg[1], 300, 500)
SetSpriteCategoryBit(fishspriteg[1], 3, 1)
SetSpriteCollideBit (fishspriteg[1], 3, 1)
SetSpritePhysicsOn(fishspriteg[1],1)
SetSpriteDepth(fishspriteg[1],3)
SetSpritePhysicsCanRotate (fishspriteg[1],0)
SetSpriteShapeBox ( fishspriteg[1], -1*(GetSpriteWidth(fishspriteg[1])/20), -1*(GetSpriteHeight(fishspriteg[1])/4), GetSpriteWidth(fishspriteg[1])/20, GetSpriteHeight(fishspriteg[1])/4, 0 )
SetSpriteAnimation ( fishspriteg[1], 56, 75, 8 )
PlaySprite (fishspriteg[1],speed,1,8,1)
// Create Pools
GLOBAL pool as integer[7]
pool[1] = CreateSprite (0)
pool[2] = CreateSprite (0)
pool[3] = CreateSprite (0)
pool[4] = CreateSprite (0)
pool[5] = CreateSprite (0)
pool[6] = CreateSprite (0)
SetSpriteSize (pool[1], 100, 100)
SetSpriteSize (pool[2], 100, 100)
SetSpriteSize (pool[3], 100, 100)
SetSpriteSize (pool[4], 100, 100)
SetSpriteSize (pool[5], 100, 100)
SetSpriteSize (pool[6], 100, 100)
SetSpritePosition (pool[1], Random (0, 718), -512)
SetSpritePosition (pool[2], Random (0, 718), -256)
SetSpritePosition (pool[3], Random (0, 718), 0)
SetSpritePosition (pool[4], Random (0, 718), 256)
SetSpritePosition (pool[5], Random (0, 718), 512)
SetSpritePosition (pool[6], Random (0, 718), 768)
SetSpriteShape (pool[1], 2)
SetSpriteShape (pool[2], 2)
SetSpriteShape (pool[3], 2)
SetSpriteShape (pool[4], 2)
SetSpriteShape (pool[5], 2)
SetSpriteShape (pool[6], 2)
SetSpriteCategoryBit (pool[1], 3, 1)
SetSpriteCategoryBit (pool[2], 3, 1)
SetSpriteCategoryBit (pool[3], 3, 1)
SetSpriteCategoryBit (pool[4], 3, 1)
SetSpriteCategoryBit (pool[5], 3, 1)
SetSpriteCategoryBit (pool[6], 3, 1)
SetSpritePhysicsOn (pool[1], 1)
SetSpritePhysicsOn (pool[2], 1)
SetSpritePhysicsOn (pool[3], 1)
SetSpritePhysicsOn (pool[4], 1)
SetSpritePhysicsOn (pool[5], 1)
SetSpritePhysicsOn (pool[6], 1)
// Create Scrolling
initialScroll# = 45
initialScroll# = 45
defaultScroll# = 45
increment = 0
gameStart# = timer()
// run functions
CreateSpray ()
do
CheckPlpFrame ()
// Increase scrolling speed
y# = defaultScroll# * getFrameTime()
gameTime# = timer() - gameStart#
elapsedTime = gameTime# / 10
if elapsedTime > increment
increment = elapsedTime
defaultScroll# = initialScroll# + ((initialScroll# / 3) * increment)
endif
SetSpritePosition (arrTower[1], getSpritex(arrTower[1]), GetSpriteY (arrTower[1]) + y#)
if getSpriteY(arrTower[1]) > GetVirtualHeight()
SetSpritePosition (arrTower[1], getSpritex(arrTower[1]), GetSpriteY (arrTower[1]) - 6286)
endif
SetSpritePosition (arrTower[2], getSpritex(arrTower[2]), GetSpriteY (arrTower[2]) + y#)
if getSpriteY(arrTower[2]) > GetVirtualHeight()
SetSpritePosition (arrTower[2], getSpritex(arrTower[2]), GetSpriteY (arrTower[2]) - 6286)
endif
for n = 1 to 6
SetSpritePosition (pool[n], getSpritex(pool[n]), GetSpriteY (pool[n]) + y#)
if getSpriteY(pool[n]) > GetVirtualHeight()
SetSpritePosition (pool[n], Random (0, 718), -512)
endif
next n
SetSpriteSpeed (fishspriteg [1], speed + y#)
// Move player left, right, and down using buttons
if GetRawKeyState (39) = 1
SetSpritePosition (fishspriteg[1], GetSpriteX (fishspriteg[1]) + 10, GetSpriteY (fishspriteg[1]))
endif
if GetRawKeyState (37) = 1
SetSpritePosition (fishspriteg[1], GetSpriteX (fishspriteg[1]) - 10, GetSpriteY (fishspriteg[1]))
endif
Sync()
loop
function CreateSpray ()
LoadImage ( 20, "spot.png" )
CreateParticles ( 1, 0.0, 0.0 )
SetParticlesImage ( 1, 20 )
SetParticlesStartZone ( 1, 0, -1024, 768, 1024 )
SetParticlesDirection ( 1, 0.0, 15.0 )
SetParticlesLife ( 1, 200 )
SetParticlesSize ( 1, 3)
SetParticlesAngle ( 1, 45 )
SetParticlesFrequency ( 1, 10000 )
SetParticlesVelocityRange ( 1, 4.0, 25.0 )
SetParticlesDepth (1, 0)
FixParticlesToScreen ( 1, 1 )
endfunction
function CheckPlpFrame ()
if GetSpriteCurrentFrame (fishspriteg[1]) = 1
CheckPlpAgainstPool1 ()
endif
endfunction
// Set the RayCast for pools
function CheckPlpAgainstPool1 ()
If (SpriteRayCast (GetSpriteX (pool[1]), GetSpriteY (pool[1]), GetSpriteX (pool[1]) + 100, GetSpriteY (pool[1]) + 100) = 1)
Print ("Collision!")
else
CheckPlpAgainstPool2 ()
endif
endfunction
function CheckPlpAgainstPool2 ()
if (SpriteRayCast (GetSpriteX (pool[2]), GetSpriteY (pool[2]), GetSpriteX (pool[2]) + 100, GetSpriteY (pool[2]) + 100) = 1)
Print ("Collision!")
else
CheckPlpAgainstPool3 ()
endif
endfunction
function CheckPlpAgainstPool3 ()
if (SpriteRayCast (GetSpriteX (pool[3]), GetSpriteY (pool[3]), GetSpriteX (pool[3]) + 100, GetSpriteY (pool[3]) + 100) = 1)
Print ("Collision!")
else
CheckPlpAgainstPool4 ()
endif
endfunction
function CheckPlpAgainstPool4 ()
if (SpriteRayCast (GetSpriteX (pool[4]), GetSpriteY (pool[4]), GetSpriteX (pool[4]) + 100, GetSpriteY (pool[4]) + 100) = 1)
Print ("Collision!")
else
CheckPlpAgainstPool5 ()
endif
endfunction
function CheckPlpAgainstPool5 ()
if (SpriteRayCast (GetSpriteX (pool[5]), GetSpriteY (pool[5]), GetSpriteX (pool[5]) + 100, GetSpriteY (pool[5]) + 100) = 1)
Print ("Collision!")
else
CheckPlpAgainstPool6 ()
endif
endfunction
function CheckPlpAgainstPool6 ()
if (SpriteRayCast (GetSpriteX (pool[6]), GetSpriteY (pool[6]), GetSpriteX (pool[6]) + 100, GetSpriteY (pool[6]) + 100) = 1)
Print ("Collision!")
else
plpfalls ()
endif
endfunction
function plpfalls ()
PlaySound ( 1 )
StopMusic ()
LoadMusic (2,"wwq3.wav")
SetMusicFileVolume( 2, 100 )
PlayMusic (2)
plpfall = CreateSprite (LoadImage ("plpfall.png"))
SetSpriteCategoryBit (plpfall,1,1)
SetSpriteCollideBit (plpfall, 3, 0 )
SetSpritePhysicsOn (plpfall,2)
SetSpriteDepth (plpfall,0)
SetSpriteVisible (plpfall, 1 )
SetSpritePosition (plpfall, GetSpriteX ( fishspriteg[1] ), GetSpriteY ( fishspriteg[1] ) )
SetSpritePhysicsCanRotate( plpfall, 1 )
SetSpritePhysicsVelocity(plpfall,GetSpritePhysicsVelocityX(plpfall),-200)
SetSpritePhysicsVelocity(plpfall,GetSpritePhysicsVelocityY(plpfall),-50)
SetSpritePhysicsAngularVelocity( plpfall, -20 )
DeleteSprite (fishspriteg[1])
endfunction
Thank you for all your help.