Zombie: Difference between revisions

5,746 bytes added ,  7 days ago
no edit summary
No edit summary
No edit summary
Line 89:
| $7E || 2 || int16 0-based || freezeTimer || Amount of time to stay [[Fire extinguisher|frozen]]
|}
 
== Pseudocode ==
 
moveAmount = { { 0, 0 },
{ 0, -1 },
{ 1, -1 },
{ 1, 0 },
{ 1, 1 },
{ 0, 1 },
{ -1, 1 },
{ -1, 0 },
{ -1, -1 } }
newPositionIsBlocked() {
return {{ROM name|$80:AE97}}(this.newX, this.newY) ||
{{ROM name|$80:BF67}}(this.sprite, this.newX, this.newY)
}
wanderInRandomDirection() {
this.direction = ({{ROM name|$80:9D39}}() % 4) * 2 + 1
this.setStateToWandering()
}
setStateToWandering() {
this.state = this.wanderingState
this.wanderingState()
}
wanderingState() {
this.newX = this.x + this.moveAmount[this.direction][0]
this.newY = this.y + this.moveAmount[this.direction][1]
if (!{{ROM name|$80:AE97}}(this.newX, this.newY)) {
if (!{{ROM name|$80:BF67}}(this.sprite, this.newX, this.newY)) {
this.x = this.newX
this.sprite.x = this.newX
this.y = this.newY
this.sprite.y = this.newY
}
} else {
this.followWall()
}
}
followWall() {
this.direction = ((this.direction - 1) + 2) % 8 + 1 // Rotate 90 degrees clockwise
this.setStateToFollowingWall()
}
setStateToFollowingWall() {
this.state = this.followingWallState
}
followingWallState() {
this.newDirection = ((this.direction - 1) - 2) % 8 + 1 // Rotate 90 degrees counterclockwise
this.newX = this.x + this.moveAmount[this.newDirection][0]
this.newY = this.y + this.moveAmount[this.newDirection][1]
if (!this.newPositionIsBlocked()) {
this.direction = this.newDirection
}
this.newX = this.x + this.moveAmount[this.direction][0]
this.newY = this.y + this.moveAmount[this.direction][1]
if (!this.newPositionIsBlocked()) {
this.x = this.newX
this.sprite.x = this.newX
this.y = this.newY
this.sprite.y = this.newY
} else {
this.followWall()
}
}
setStateToTargeting() {
this.state = this.targetingState
}
targetingState() {
distance, this.targetSprite = {{ROM name|$80:B123}}(this.x, this.y)
if (distance >= 70) {
this.wanderInRandomDirection()
return
}
{{ROM name|$80:B3F1}}(this.sprite, this.targetSprite)
this.direction = {{ROM name|$80:B22A}}(this.sprite, this.targetSprite)
if (this.direction == 0) {
this.wanderInRandomDirection()
return
}
this.targetDirection = this.direction
for (i = 0; i < 2; i++) {
this.newX = this.x + this.moveAmount[this.targetDirection][0]
this.newY = this.y + this.moveAmount[this.targetDirection][1]
if (!this.newPositionIsBlocked()) {
this.x = this.newX
this.sprite.x = this.newX
this.y = this.newY
this.sprite.y = this.newY
}
}
}
checkForTarget() {
distance = {{ROM name|$80:B123}}(this.x, this.y)
if (distance < 65) {
this.setStateToTargeting()
return
}
direction = {{ROM name|$80:B2A5}}(208, this.x, this.y)
if (direction == 0) {
this.deathStatus -= 1
}
}
killed() {
{{ROM name|$80:B2A5}}(this.collidedSpriteType & 0x8000, 100)
this.deathStatus = 0xF5F5
}
updateAnimation() {
this.cyclesUntilAnimUpdate -= 1
if (this.cyclesUntilAnimUpdate == 0) {
this.cyclesUntilAnimUpdate = 4
this.animationFrame = (this.animationFrame + 1) % 4
this.sprite.tileData.lowBytes = this.animations[this.direction][this.animationFrame]
this.sprite.tileData.bank = 0x90
if (this.direction < DOWN_LEFT) {
this.sprite.flipX = false
} else {
this.sprite.flipY = true
}
}
}
animations = { { 0xCABC, 0xCADD, 0xCAFE, 0xCB1F },
{ 0xCB40, 0xCB61, 0xCB82, 0xCBA3 },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B },
{ 0xCABC, 0xCADD, 0xCAFE, 0xCB1F },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B },
{ 0xCA28, 0xCA51, 0xCA72, 0xCA9B } }
init() {
{{ROM name|$81:8000}}()
this.animationFrame = 0
this.x = args.x
this.sprite.x = args.x
this.sprite.z = 0
this.y = args.y
this.sprite.y = args.y
this.sprite.tileData = $90:C98A
this.sprite.visible = true
this.sprite.alternatePalette = 6
this.collidedSpriteType = 0
this.freezeTimer = 0
}
mainNormal() {
{{RAM name|$7E:00DE}} += 0x14
this.cyclesUntilAnimUpdate = 7
this.init()
{{ROM name|$81:832C}}(this.spawnAnimation)
this.sprite.type = MONSTER
this.wanderInRandomDirection()
this.health = 0
{{ROM name|$80:8475}}(this.collisionHandler)
this.deathStatus = 0
while (this.deathStatus == 0) {
{{ROM name|$80:8353}}(2)
this.checkForTarget()
this.state()
this.updateAnimation()
}
if (this.deathStatus == 0xF5F5) {
{{RAM name|$7E:1F64}} += 1
{{ROM name|$81:83A3}}(mummy.deathAnimation, this.deathStatus, 0x90)
}
{{RAM name|$7E:00DE}} -= 0x14
while ({{RAM name|$7E:00DE}} < 0) { }
{{ROM name|$80:BE41}}(this.sprite)
}
spawnAnimation = { { 0xC98A, 10 }, { 0xC993, 10 }, { 0xC9A4, 10 }, { 0xC9B5, 10 },
{ 0xC9D6, 10 }, { 0xC9FF, 10 }, { 0, 0 } }
collisionHandler(spriteType) {
if (spriteType < SQUIRT_GUN) {
return false
}
this.collidedSpriteType = spriteType
weaponType = spriteType & 0x7FFF
if (weaponType == MARTIAN_BUBBLE_GUN) {
return {{ROM name|$81:83C6}}()
} else if (weaponType == FIRE_EXTINGUISHER) {
return {{ROM name|$81:847E}}()
} else {
newHealth = this.health - {{ROM name|$81:8561}}[weaponType - SQUIRT_GUN]
if (newHealth < 0) {
this.health = newHealth
this.freezeTimer = 0
this.killed()
return true
} else if (newHealth != this.health) {
this.health = newHealth
return {{ROM name|$81:8506}}()
}
return false
}
}
 
[[Category:Respawning monster]]