Crocodile - numberZero/CrocoLogic GitHub Wiki
Class name is self-describing =)
On each logical step, methods should be called for all crocodiles on the map in order:
update()
think()
go()
Each method must be called for all crocodiles before next method is called.
And each animation step only step()
should be called. It may never be called if animation is not needed.
Properties
State-describing properties
integer id
Crocodile ID. Currently almost not meaningful.Cell field
Field the crocodile is in.Cell target
Field the crocodile moves to.integer sleep
Count of logic steps the crocodile will sleep.integer dir
Current direction.boolean omnicroc
Describes can the crocodile change its direction.integer ate
Count of Meats ate.
Visual-only properties:
HTMLImageElement img
Crocodile image.string[] images
Crocodile images paths; depends on initial value of theomnicroc
property.float sleepiness
Same as sleep, but changes every animation stepfloat x, y
Image coordinates (changes every animation step)float vx, vy
Image speed
Related properties:
Crocodile field.content
Refers to the crocodile.Crocodile img.object
Refers to the crocodile.
Methods
constructor
new Crocodile(Cell cell, integer dir)
Creates new crocodile on given cell with given direction, if possible, and throws exception otherwise.
If dir
is equal to dirAuto
, omnicroc is created with initial direction set to 0.
die
void this.die(void)
Deletes the crocodile. Should not be used.
See _Die()
.
updateImageParams
void this.updateImageParams(void)
Updates image position and opaticy according to the crocodile properties.
updateImage
void this.updateImage(void)
Updates image according to the crocodile properties.
step
void this.step(void)
Does one animation step.
update
void this.update(void)
Updates crocodile properties according to its moving. Updates references to and from map.
think
void this.think(void)
Searches where the crocodile wants to go. Uses checkForMeat()
.
go
void this.go(void)
Starts walking to choosed by think()
cell, if possible.
walk
void this.walk(void)
Starts walking animation in current direction.
checkForMeat
integer this.checkForMeat(integer dir)
Check is there reachable meat in given direction. Returns distance to it, or Number.POSITIVE_INFINITY
otherwise.