method to NOT portal when arriving ON a portal from
another portal;
discord inquiry.
premise: If WasNotOnPortal and AmNowOnPortal then Portal()
// Project: Portal
// Created: 2022-03-31
// By: Virtual Nomad
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Portal" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
GLOBAL Player, WasPortal, PortalGroup = 100
Player = CreateSprite(0) : SetSpriteSize(Player,32,32) : SetSpritePositionByOffset(Player,300,300)
#CONSTANT PX = GetSpriteXByOffset(Player) : #CONSTANT PY = GetSpriteYByOffset(Player)
Type Portal
ID, ToID
EndType
GLOBAL Portals as Portal [] // [Destination,x,y]
AddPortal(3,200,200) : AddPortal(2,400,200)
AddPortal(1,200,400) : AddPortal(0,400,400)
SortPortals()
Do
If GetRawKeyState(27) then End //[ESC]
Move()
If GetSpriteHitGroup(PortalGroup,PX,PY) > 0
If WasPortal = 0
WasPortal = GetSpriteHitGroup(PortalGroup,PX,PY)
GoPortal(Portals.Find(WasPortal))
EndIf
Else
WasPortal = 0
EndIf
Print("[WASD]")
Sync()
Loop
Function SortPortals()
For x = 0 to 3
Portals[x].ToID = Portals[Portals[x].ToID].ID //Portal Index to Portal Sprite ID for .Find
Next x
Portals.Sort()
EndFunction
Function AddPortal(Destination,x,y)
ThisPortal as Portal
ThisPortal.ID = CreateSprite(0) : SetSpriteSize(ThisPortal.ID,96,96)
SetSpriteGroup(ThisPortal.ID, PortalGroup) : SetSpritePositionByOffset(ThisPortal.ID,x,y)
SetSpriteColor(ThisPortal.ID, 255,128,0,255): SetSpriteDepth(ThisPortal.ID,100)
ThisPortal.ToID = Destination //Will re-assign to destination sprite ID vs Index @ SortPortals()
Portals.Insert(ThisPortal)
EndFunction
Function Move()
SetSpritePositionByOffset(Player,PX+GetJoystickX()*5.0, PY+GetJoystickY()*5.0 )
EndFunction
Function GoPortal(FromIndex)
x = GetSpriteXByOffset(Portals[FromIndex].ToID)
y = GetSpriteYByOffset(Portals[FromIndex].ToID)
SetSpritePositionByOffset(Player,x,y)
EndFunction