Playing with the Tween commands was really funny..
Added a simple Machine State to restart the game, Collisions and enemies respawn, plus a few minor changes.
The case study is done for me, normally can't do more than 14 kills, so it's enough rippy
Enjoy it!
// Project: BattleGround
// Created: 2017-12-18
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "BattleGround" )
SetWindowSize(768, 1024, 0)
SetDisplayAspect(768.0/1024)
// set display properties
SetVirtualResolution( 768.0 , 1024 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
#option_explicit
#constant MAX_ENEMIES = 10
Type Enemy
size as integer
spriteId as integer
tweenId as integer
particleId as integer
EndType
#constant GAME_STARTS 1
#constant GAME_STARTED 2
global kills as integer
global tweenId as integer
global playerSpriteId as integer
global clickPointer as integer
global tailSpriteId as integer
global tailImageId as integer
global spriteAngle as float
global spawner as integer
global spawned as integer = 0
global enemies as Enemy[MAX_ENEMIES]
global gameState as integer = GAME_STARTS
playerSpriteId = CreateSprite(0)
SetSpriteSize(playerSpriteId, 25, 25)
SetSpriteColor(playerSpriteId, 0, 255, 255, 255)
SetSpritePosition(playerSpriteId,25,25)
tweenId = CreateTweenSprite(0.2)
clickPointer = CreateSprite(0)
SetSpriteSize(clickPointer, 25, 25)
//SetSpriteOffset(clickPointer, 0, 0)
SetSpriteVisible(clickPointer, 0)
tailSpriteId = CreateSprite(0)
SetSpriteSize(tailSpriteId, 10, 10)
SetSpriteOffset(tailSpriteId, 0, 0)
spawner = CreateSpawner()
do
select gameState:
case GAME_STARTS:
kills = 0
gameState = GAME_STARTED
endcase
case GAME_STARTED:
i as integer
for i = 1 to MAX_ENEMIES
// Refill the enemies
if enemies[i].spriteId = 0
enemies[i].spriteId = CreateSprite(0)
enemies[i].tweenId = CreateTweenSprite(5.5)
MoveSpawner(spawner, GetDeviceWidth(), GetDeviceHeight())
SetSpritePositionByOffset(enemies[i].spriteId, GetSpriteX(spawner), GetSpriteY(spawner))
enemies[i].size = Random(10,50)
SetSpriteSize(enemies[i].spriteId, enemies[i].size, enemies[i].size)
SetSpriteColor(enemies[i].spriteId, Random(0,255), Random(0,255), Random(0,255), 255)
PlayTweenSprite(enemies[i].tweenId, enemies[i].spriteId, Random(0,3))
endif
next i
if GetPointerPressed()
// Move my player
StopTweenSprite(tweenId, playerSpriteId)
SetSpritePosition(clickPointer, GetPointerX(), GetPointerY())
SetTweenSpriteX(tweenId,GetSpriteX(playerSpriteId),GetPointerX(),TweenSmooth1())
SetTweenSpriteY(tweenId,GetSpriteY(playerSpriteId),GetPointerY(),TweenSmooth1())
SetSpriteColor(tailSpriteId, Random(0,255), Random(0,255), Random(0,255), 100)
SetSpritePosition(tailSpriteId, GetSpriteX(playerSpriteId),GetSpriteY(playerSpriteId))
SetSpriteAngle(tailSpriteId, ATanFull(GetSpriteX(tailSpriteId) - GetSpriteX(clickPointer), GetSpriteY(tailSpriteId) - GetSpriteY(clickPointer)))
SetSpriteSize(tailSpriteId, 10, GetSpriteDistance(playerSpriteId, clickPointer))
PlayTweenSprite(tweenId,playerSpriteId, 0)
// Move the enemies tweening to the player
for i = 1 to MAX_ENEMIES
StopTweenSprite(enemies[i].tweenId, enemies[i].spriteId)
PlayTweenSprite(enemies[i].tweenId, enemies[i].spriteId, Random(0,3))
MoveEnemy(enemies[i].tweenId, enemies[i].spriteId)
UpdateTweenSprite(enemies[i].tweenId, enemies[i].spriteId, Random(0,3))
// Enemy hits the player
if GetSpriteCollision(enemies[i].spriteId, playerSpriteId)
Message("You're died. Resurrect or Go Town? :P")
gameState = GAME_STARTS
exit
endif
// We should be able to kill more than an enemy in a row ^^
if GetSpriteCollision(tailSpriteId, enemies[i].spriteId) || GetSpriteCollision(playerSpriteId, enemies[i].spriteId)
enemies[i] = KillEnemy(enemies[i])
endif
next i
endif
if GetSpriteColorAlpha(tailSpriteId) > 0
SetSpriteColorAlpha(tailSpriteId, GetSpriteColorAlpha(tailSpriteId) - 1)
endif
UpdateAllTweens(GetFrameTime())
Print("Something like enemies killed: " + str(kills))
endcase
endselect
Sync()
loop
Function CreateSpawner()
sprId as integer
sprId = CreateSprite(0)
SetSpriteVisible(sprId, 0)
EndFunction sprId
function MoveSpawner(sprId, w, h)
SetSpritePositionByOffset(sprId, Random2(0, w), Random2(0, h))
endfunction
function MoveEnemy(tid, enemyId)
SetTweenSpriteX(tid,GetSpriteX(enemyId),GetSpriteX(clickPointer),TweenSmooth2())
SetTweenSpriteY(tid,GetSpriteY(enemyId),GetSpriteY(clickPointer),TweenSmooth2())
endfunction
function KillEnemy(enemy as Enemy)
DeleteSprite(enemy.spriteId)
DeleteTween(enemy.tweenId)
enemy.spriteId = 0
enemy.tweenId = 0
inc kills
endfunction enemy