I don't know what you are trying to do but it seems like it will be an interesting game. I have been testing your code with out media so all I had to go off of was the X-out boxes.
Here is what I have come up with for you.
Complete source.
// Project: InfiniSerpent
// Created: 2015-10-04
Global _UCFSwipeRightTime as Float
Global _UCFSwipeRightX as Integer
Global _UCFSwipeLeftTime as Float
Global _UCFSwipeLeftX as Integer
Global _UCFSwipeDownTime as Float
Global _UCFSwipeDownY as Integer
Global _UCFSwipeUpTime as Float
Global _UCFSwipeUpY as Integer
Global Dim Sprite[1000]
Global SpriteID = 1
Global RecoverTime#
Global Recover = 0
Global Time#
// set window properties
SetWindowTitle( "InfiniSerpent" )
//SetWindowSize( getdevicewidth(), getdeviceheight(), 0 )
// set display properties
SetDisplayAspect ( -1 )
//setvirtualresolution (getdevicewidth(), getdeviceheight())
SetOrientationAllowed( 0, 0, 1, 1 )
DeviceWidth# = GetDeviceWidth()
DeviceHeight# = GetDeviceHeight()
W# = 100 * GetDeviceWidth()/DeviceWidth#
H# = 100 * GetDeviceHeight()/DeviceHeight#
//Goal:
//Classic Snake/Serpent game that enlarges the play area as the game progresses
loadsound(2,"transport.wav")
loadsound(1,"1up.wav")
setsoundinstancevolume(1,10)
loadmusic(1,"bgm1.wav")
loadmusic(2,"bgm2.wav")
setmusicfilevolume(1,10)
loadimage(1,"SerpentSegment.png")
loadimage(2,"SerpentFood.png")
loadimage(3,"SerpentDeath.png")
createsprite(1,1)
setspritesize(1,1,1.5)
setspriteposition(1,random(5,95),random(5,95))
createsprite(2,2)
setspritesize(2,1,1.5)
setspriteposition(2,random(5,95),random(5,95))
createsprite(3,3)
setspritevisible(3,0)
x=getpointerx()
y=getpointery()
score=0
createtext(1,"0")
settextsize(1,2)
StepDirection$=""
NewDeathBlock=4
playmusic(1,1)
thisMidX = getVirtualWidth() * 0.5
thisMidY = getVirtualHeight() * 0.5
if thisMidX > thisMidY
thisRadius# = thisMidY * 0.8
else
thisRadius# = thisMidX * 0.8
endif
thisLife# = 10
thisEmitter = CreateParticles( thisMidX , thisMidY )
SetParticlesSize( thisEmitter ,0.2)
SetParticlesLife( thisEmitter , thisLife# )
SetParticlesFrequency( thisEmitter , 200 )
SetParticlesDirection( thisEmitter , 1 , 1 )
SetParticlesColorInterpolation( thisEmitter ,1)
AddParticlesColorKeyFrame( thisEmitter , 0 , 255 , 255 , 255 , 125 )
AddParticlesColorKeyFrame( thisEmitter , thisLife# , 0 , 0 , 0 , 0 )
do
Time# = Timer()
drawsprite(1)
drawsprite(2)
x=getspritex(1)
y=getspritey(1)
If GetSwipeRight( 0.1, 20 ) = 1 then stepdirection$="R" //right
If GetSwipeLeft( 0.1, 20 ) = 1 then stepdirection$="L" //left
If GetSwipeDown( 0.1, 20 ) = 1 then stepdirection$="D" //dn
If GetSwipeUp( 0.1, 20 ) = 1 then stepdirection$="U" //up
if stepdirection$="R"
inc x,1
setspriteposition(1,x,y)
endif
if stepdirection$="L"
dec x,1
setspriteposition(1,x,y)
endif
if stepdirection$="D"
inc y,1
setspriteposition(1,x,y)
endif
if stepdirection$="U"
dec y,1
setspriteposition(1,x,y)
endif
For SpriteNum = 1 to SpriteID
If GetSpriteCollision(Sprite[SpriteNum],1) and Recover = 0
dec score,1
settextstring(1,str(Score))
RecoverTime# = Time# + 1
Recover = 1
endif
Next SpriteNum
if getspritecollision(1,2) and Recover = 0
playsound(1,10)
inc score,1
SpriteID = SpriteID + 1
Sprite[SpriteID] = CreateSprite(3)
SetSpritePosition(Sprite[SpriteID],getspritex(2),getspritey(2))
setspriteposition(2,random(5,95),random(5,95))
SetSpriteSize(Sprite[SpriteID],W#/15,-1)
settextstring(1,str(Score))
RecoverTime# = Time# + 1
Recover = 1
endif
If Recover = 1
Recovering()
endif
if getspritex(1)<0
setspritex(1,getvirtualwidth())
playsound(2,20)
endif
if getspritex(1)>getvirtualwidth()
setspritex(1,0)
playsound(2,20)
endif
if getspritey(1)<0
setspritey(1,getvirtualheight())
playsound(2,20)
endif
if getspritey(1)>getvirtualheight()
setspritey(1,0)
playsound(2,20)
endif
thisTime# = timer()
//thisX# = thisMidX + cos( thisTime# * 180 ) * thisRadius#
//thisY# = thisMidY + sin( thisTime# * 180 ) * thisRadius#
thisx# = getspritex(1)
thisy# = getspritey(1)
SetParticlesPosition( thisEmitter , thisX# , thisY# )
Sync()
loop
deleteparticles( thisEmitter )
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////CAROLINA SOUTH'S SWIPE CODE/////////////////////////////////////////////////////////
////////////////https://forum.thegamecreators.com/thread/195049/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
Function GetSwipeRight( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeRightTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeRightX = GetPointerX() + s
If GetPointerState() = 1 and _UCFSwipeRightTime < Timer()
If _UCFSwipeRightX < GetPointerX()
_UCFSwipeRightTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeLeft( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeLeftTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeLeftX = GetPointerX() - s
If GetPointerState() = 1 and _UCFSwipeLeftTime < Timer()
If _UCFSwipeLeftX > GetPointerX()
_UCFSwipeLeftTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeDown( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeDownTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeDownY = GetPointerY() + s
If GetPointerState() = 1 and _UCFSwipeDownTime < Timer()
If _UCFSwipeDownY < GetPointerY()
_UCFSwipeDownTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function GetSwipeUp( t#, s )
Output = 0
If GetPointerState() = 0 then _UCFSwipeUpTime = Timer() + t#
If GetPointerPressed() = 1 then _UCFSwipeUpY = GetPointerY() - s
If GetPointerState() = 1 and _UCFSwipeUpTime < Timer()
If _UCFSwipeUpY > GetPointerY()
_UCFSwipeUpTime = 0
Output = 1
EndIf
EndIf
EndFunction Output
Function Recovering()
If Time# > RecoverTime#
Recover = 0
endif
endfunction
//-Writing programs for years, new to AGK2
What I have changed.
First a few new variables at the top of your code, where you do your defining.
Global RecoverTime#
Global Recover = 0
Global Time#
A timer call at the very top of your loop so we can use a timer function.
TIME# = TIMER()
When the player hits the object that will decrease your score we call a recover function. So that the player can go into recovery mode. Mainly to kill the object collision for 1 second so the score will not decrease rapidly and give the player the chance to catch up.
For SpriteNum = 1 to SpriteID
If GetSpriteCollision(Sprite[SpriteNum],1) and Recover = 0
dec score,1
settextstring(1,str(Score))
RecoverTime# = Time# + 1
Recover = 1
endif
Next SpriteNum
Also I have called the recover time when the player hits object 2. So the newly created sprite can be positioned on top of the player with out detecting collision until 1 second has passed. This give the player just enough time to get away with out decreasing his score.
if getspritecollision(1,2) and Recover = 0
playsound(1,10)
inc score,1
SpriteID = SpriteID + 1
Sprite[SpriteID] = CreateSprite(3)
SetSpritePosition(Sprite[SpriteID],getspritex(2),getspritey(2))
setspriteposition(2,random(5,95),random(5,95))
SetSpriteSize(Sprite[SpriteID],W#/15,-1)
settextstring(1,str(Score))
RecoverTime# = Time# + 1
Recover = 1
endif
I have added a new IF statement to check if the player is in recover mode.
If Recover = 1
Recovering()
endif
And last but not least the recovering function to end the players recovery.
Function Recovering()
If Time# > RecoverTime#
Recover = 0
endif
endfunction
So to break down the timer function.
When the Player either hits object 2, or Sprite[SpriteNum] the recovery function is called for 1 second. Giving the player a short period of recovery mode.
How the timer works is when the player is in contact with either of these 2 sprites
RecoveryTime# = Time# + 1 which adds + 1 to the game time.
When Time# is greater than RecoveryTime# the recovery period is over turning the collision back on.
I hope this is what you need and im sure there is another way of doing it...But this is my only idea for the moment.
Keep up the work, it is looking very interesting.
Edit: I have also changed the size of Sprite[SpriteID] when it is created
Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim