mirror of
https://github.com/klmp200/sarl-fireworks.git
synced 2024-11-22 14:53:19 +00:00
82 lines
1.9 KiB
Plaintext
82 lines
1.9 KiB
Plaintext
|
package io.sarl.demos.fireworks
|
||
|
|
||
|
import io.sarl.core.Behaviors
|
||
|
import io.sarl.core.DefaultContextInteractions
|
||
|
import io.sarl.core.ExternalContextAccess
|
||
|
import io.sarl.core.Initialize
|
||
|
import io.sarl.core.InnerContextAccess
|
||
|
import io.sarl.core.Lifecycle
|
||
|
import io.sarl.core.Logging
|
||
|
import io.sarl.core.MemberJoined
|
||
|
import io.sarl.util.OpenEventSpaceSpecification
|
||
|
import java.util.Random
|
||
|
import java.util.UUID
|
||
|
|
||
|
agent LaunchingArea {
|
||
|
uses DefaultContextInteractions, Lifecycle, Behaviors, Logging, InnerContextAccess, ExternalContextAccess
|
||
|
|
||
|
var rocketsQuantity: Integer
|
||
|
var fireQuantity: Integer
|
||
|
var gravity: Double
|
||
|
var grid: Positions = new Positions
|
||
|
var maxWidth = 10.0
|
||
|
var exited = false
|
||
|
|
||
|
on SetupSettings {
|
||
|
this.rocketsQuantity = occurrence.rocketsQuantity
|
||
|
this.fireQuantity = occurrence.fireQuatity
|
||
|
this.gravity = occurrence.gravity
|
||
|
this.maxWidth = occurrence.maxWidth
|
||
|
}
|
||
|
|
||
|
on Exit [!hasMemberAgent]{
|
||
|
killMe
|
||
|
}
|
||
|
|
||
|
on Exit [hasMemberAgent && !exited] {
|
||
|
exited = true
|
||
|
innerContext.defaultSpace.emit(new Exit)
|
||
|
}
|
||
|
|
||
|
on Initialize [ occurrence.parameters.empty ] {
|
||
|
rocketsQuantity = 20
|
||
|
fireQuantity = 30
|
||
|
gravity = 0.5
|
||
|
|
||
|
info("Setup Area")
|
||
|
|
||
|
}
|
||
|
|
||
|
on Initialize [ !occurrence.parameters.empty ]{
|
||
|
var ctrl = occurrence.parameters.get(0) as FXMLViewerController
|
||
|
var ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID)
|
||
|
ctrl.setGUISpace(^space)
|
||
|
^space.register(asEventListener)
|
||
|
|
||
|
ctrl.listenAndDraw(grid)
|
||
|
|
||
|
info("Setup Area")
|
||
|
|
||
|
}
|
||
|
|
||
|
on CreateArea {
|
||
|
var x: Double
|
||
|
var i=0
|
||
|
var rnd = new Random()
|
||
|
while (i<rocketsQuantity){
|
||
|
x = rnd.nextDouble() * maxWidth
|
||
|
spawnInContext(RocketLauncher, getInnerContext, x, 0.0, fireQuantity, gravity, grid)
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
on Freeze[!isFromMe(occurrence)] {
|
||
|
innerContext.defaultSpace.emit(occurrence)
|
||
|
}
|
||
|
|
||
|
on MemberJoined [ occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity]{
|
||
|
info("Area Ready")
|
||
|
innerContext.defaultSpace.emit(new Launch)
|
||
|
}
|
||
|
|
||
|
}
|