No A.I. update for Azulians, Crusher, Snake, Thief

master
Noah 2024-02-11 16:51:12 -08:00
parent 79a6056834
commit c77b7b0034
8 changed files with 95 additions and 72 deletions

View File

@ -22,6 +22,7 @@ build:
# Tag the category for these doodads # Tag the category for these doodads
for i in *.doodad; do\ for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\ doodad edit-doodad --tag "category=creatures" $${i};\
doodad edit-doodad -q --option "No A.I.=bool" $${i};\
done done
cp *.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/

View File

@ -5,7 +5,7 @@ var playerSpeed = color === 'blue' ? 2 : 4,
swimSpeed = playerSpeed * 0.4, swimSpeed = playerSpeed * 0.4,
aggroX = 250, // X/Y distance sensitivity from player aggroX = 250, // X/Y distance sensitivity from player
aggroY = color === 'blue' ? 100 : 200, aggroY = color === 'blue' ? 100 : 200,
jumpSpeed = color === 'blue' ? 14 : 18, jumpSpeed = color === 'blue' ? 10 : 11,
swimJumpSpeed = jumpSpeed * 0.4, swimJumpSpeed = jumpSpeed * 0.4,
animating = false, animating = false,
direction = "right", direction = "right",
@ -15,9 +15,9 @@ var playerSpeed = color === 'blue' ? 2 : 4,
if (color === 'white') { if (color === 'white') {
aggroX = 1000; aggroX = 1000;
aggroY = 400; aggroY = 400;
playerSpeed = 8; playerSpeed = 5;
swimSpeed = playerSpeed * 0.4; swimSpeed = playerSpeed * 0.4;
jumpSpeed = 20; jumpSpeed = 12;
swimJumpSpeed = jumpSpeed * 0.4; swimJumpSpeed = jumpSpeed * 0.4;
} }
@ -32,8 +32,6 @@ function setupAnimations(color) {
} }
function main() { function main() {
playerSpeed = color === 'blue' ? 2 : 4;
let swimJumpCooldownTick = 0, // minimum Game Tick before we can jump while swimming let swimJumpCooldownTick = 0, // minimum Game Tick before we can jump while swimming
swimJumpCooldown = 10; // CONFIG: delta of ticks between jumps while swimming swimJumpCooldown = 10; // CONFIG: delta of ticks between jumps while swimming
@ -47,6 +45,11 @@ function main() {
return playerControls(); return playerControls();
} }
// No A.I.?
if (Self.GetOption("No A.I.") === true) {
return;
}
// A.I. pattern: walks back and forth, turning around // A.I. pattern: walks back and forth, turning around
// when it meets resistance. // when it meets resistance.

View File

@ -9,6 +9,7 @@ build:
# Tag the category for these doodads # Tag the category for these doodads
for i in *.doodad; do\ for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\ doodad edit-doodad --tag "category=creatures" $${i};\
doodad edit-doodad -q --option "No A.I.=bool" $${i};\
done done
cp *.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/

View File

@ -17,8 +17,8 @@ let direction = "left",
fallRadius = 120, // player distance before it drops fallRadius = 120, // player distance before it drops
helmetThickness = 48, // safe solid hitbox height helmetThickness = 48, // safe solid hitbox height
fireThickness = 12, // dangerous bottom thickness fireThickness = 12, // dangerous bottom thickness
targetAltitude = Self.Position() targetAltitude = Self.Position(),
lastAltitude = targetAltitude.Y lastAltitude = targetAltitude.Y,
size = Self.Size(); size = Self.Size();
const states = { const states = {
@ -32,25 +32,30 @@ const states = {
let state = states.idle; let state = states.idle;
function main() { function main() {
Self.SetMobile(true); Self.SetMobile(true);
Self.SetGravity(false); Self.SetGravity(false);
Self.SetInvulnerable(true); Self.SetInvulnerable(true);
Self.SetHitbox(5, 2, 90, 73); Self.SetHitbox(5, 2, 90, 73);
Self.AddAnimation("hit", 50, Self.AddAnimation("hit", 50,
["angry", "ouch", "angry", "angry", "angry", "angry", ["angry", "ouch", "angry", "angry", "angry", "angry",
"sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep",
"sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep", "sleep",
"sleep", "sleep", "sleep", "sleep", "sleep", "sleep"], "sleep", "sleep", "sleep", "sleep", "sleep", "sleep"],
) )
// Player Character controls? // Player Character controls?
if (Self.IsPlayer()) { if (Self.IsPlayer()) {
return player(); return player();
} }
// No A.I.?
if (Self.GetOption("No A.I.") === true) {
return;
}
let hitbox = Self.Hitbox(); let hitbox = Self.Hitbox();
Events.OnCollide((e) => { Events.OnCollide((e) => {
// The bottom is deadly if falling. // The bottom is deadly if falling.
if (state === states.falling || state === states.hit && e.Settled) { if (state === states.falling || state === states.hit && e.Settled) {
if (e.Actor.IsMobile() && e.InHitbox && !e.Actor.Invulnerable()) { if (e.Actor.IsMobile() && e.InHitbox && !e.Actor.Invulnerable()) {
@ -85,10 +90,10 @@ function main() {
return false; return false;
} }
} }
}); });
setInterval(() => { setInterval(() => {
// Find the player. // Find the player.
let player = Actors.FindPlayer(), let player = Actors.FindPlayer(),
playerPoint = player.Position(), playerPoint = player.Position(),
point = Self.Position(), point = Self.Position(),
@ -99,11 +104,11 @@ function main() {
// Face the player. // Face the player.
if (playerPoint.X < point.X + (size.W / 2)) { if (playerPoint.X < point.X + (size.W / 2)) {
direction = "left"; direction = "left";
delta = Math.abs(playerPoint.X - (point.X + (size.W/2))); delta = Math.abs(playerPoint.X - (point.X + (size.W / 2)));
} }
else if (playerPoint.X > point.X + (size.W / 2)) { else if (playerPoint.X > point.X + (size.W / 2)) {
direction = "right"; direction = "right";
delta = Math.abs(playerPoint.X - (point.X + (size.W/2))); delta = Math.abs(playerPoint.X - (point.X + (size.W / 2)));
} }
if (delta < watchRadius) { if (delta < watchRadius) {
@ -119,7 +124,7 @@ function main() {
switch (state) { switch (state) {
case states.idle: case states.idle:
if (nearby) { if (nearby) {
Self.ShowLayerNamed("peek-"+direction); Self.ShowLayerNamed("peek-" + direction);
} else { } else {
Self.ShowLayerNamed("sleep"); Self.ShowLayerNamed("sleep");
} }
@ -133,7 +138,7 @@ function main() {
break; break;
case states.peeking: case states.peeking:
if (nearby) { if (nearby) {
Self.ShowLayerNamed("peek-"+direction); Self.ShowLayerNamed("peek-" + direction);
} else { } else {
state = states.idle; state = states.idle;
break; break;
@ -172,7 +177,7 @@ function main() {
Self.SetVelocity(Vector(0, -riseSpeed)); Self.SetVelocity(Vector(0, -riseSpeed));
point = Self.Position(); point = Self.Position();
if (point.Y <= targetAltitude.Y+4 || point.Y === lastAltitude.Y) { if (point.Y <= targetAltitude.Y + 4 || point.Y === lastAltitude.Y) {
Self.MoveTo(targetAltitude); Self.MoveTo(targetAltitude);
Self.SetVelocity(Vector(0, 0)) Self.SetVelocity(Vector(0, 0))
state = states.idle; state = states.idle;
@ -180,17 +185,17 @@ function main() {
} }
lastAltitude = point.Y; lastAltitude = point.Y;
}, 100); }, 100);
} }
// If under control of the player character. // If under control of the player character.
function player() { function player() {
Events.OnKeypress((ev) => { Events.OnKeypress((ev) => {
if (ev.Right) { if (ev.Right) {
direction = "right"; direction = "right";
} else if (ev.Left) { } else if (ev.Left) {
direction = "left"; direction = "left";
} }
// Jump! // Jump!
if (ev.Down) { if (ev.Down) {
@ -199,9 +204,9 @@ function player() {
} else if (ev.Right && ev.Left) { } else if (ev.Right && ev.Left) {
Self.ShowLayerNamed("ouch"); Self.ShowLayerNamed("ouch");
} else if (ev.Right || ev.Left) { } else if (ev.Right || ev.Left) {
Self.ShowLayerNamed("peek-"+direction); Self.ShowLayerNamed("peek-" + direction);
} else { } else {
Self.ShowLayerNamed("sleep"); Self.ShowLayerNamed("sleep");
} }
}); });
} }

View File

@ -10,6 +10,7 @@ build:
# Tag the category for these doodads # Tag the category for these doodads
for i in *.doodad; do\ for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\ doodad edit-doodad --tag "category=creatures" $${i};\
doodad edit-doodad -q --option "No A.I.=bool" $${i};\
done done
cp *.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/

View File

@ -21,34 +21,39 @@ const states = {
let state = states.idle; let state = states.idle;
function main() { function main() {
Self.SetMobile(true); Self.SetMobile(true);
Self.SetGravity(true); Self.SetGravity(true);
Self.SetHitbox(20, 0, 28, 58); Self.SetHitbox(20, 0, 28, 58);
Self.AddAnimation("idle-left", 100, ["left-1", "left-2", "left-3", "left-2"]); Self.AddAnimation("idle-left", 100, ["left-1", "left-2", "left-3", "left-2"]);
Self.AddAnimation("idle-right", 100, ["right-1", "right-2", "right-3", "right-2"]); Self.AddAnimation("idle-right", 100, ["right-1", "right-2", "right-3", "right-2"]);
Self.AddAnimation("attack-left", 100, ["attack-left-1", "attack-left-2", "attack-left-3"]) Self.AddAnimation("attack-left", 100, ["attack-left-1", "attack-left-2", "attack-left-3"])
Self.AddAnimation("attack-right", 100, ["attack-right-1", "attack-right-2", "attack-right-3"]) Self.AddAnimation("attack-right", 100, ["attack-right-1", "attack-right-2", "attack-right-3"])
// Player Character controls? // Player Character controls?
if (Self.IsPlayer()) { if (Self.IsPlayer()) {
return player(); return player();
} }
Events.OnCollide((e) => { // No A.I.?
// The snake is deadly to the touch. if (Self.GetOption("No A.I.") === true) {
if (e.Settled && e.Actor.IsPlayer() && e.InHitbox) { return;
}
Events.OnCollide((e) => {
// The snake is deadly to the touch.
if (e.Settled && e.Actor.IsPlayer() && e.InHitbox) {
// Friendly to fellow snakes. // Friendly to fellow snakes.
if (e.Actor.Doodad().Filename.indexOf("snake") > -1) { if (e.Actor.Doodad().Filename.indexOf("snake") > -1) {
return; return;
} }
FailLevel("Watch out for snakes!"); FailLevel("Watch out for snakes!");
return; return;
} }
}); });
setInterval(() => { setInterval(() => {
// Find the player. // Find the player.
let player = Actors.FindPlayer(), let player = Actors.FindPlayer(),
playerPoint = player.Position(), playerPoint = player.Position(),
point = Self.Position(), point = Self.Position(),
@ -58,11 +63,11 @@ function main() {
// Face the player. // Face the player.
if (playerPoint.X < point.X + (size.W / 2)) { if (playerPoint.X < point.X + (size.W / 2)) {
direction = "left"; direction = "left";
delta = Math.abs(playerPoint.X - (point.X + (size.W/2))); delta = Math.abs(playerPoint.X - (point.X + (size.W / 2)));
} }
else if (playerPoint.X > point.X + (size.W / 2)) { else if (playerPoint.X > point.X + (size.W / 2)) {
direction = "right"; direction = "right";
delta = Math.abs(playerPoint.X - (point.X + (size.W/2))); delta = Math.abs(playerPoint.X - (point.X + (size.W / 2)));
} }
if (delta < watchRadius) { if (delta < watchRadius) {
@ -71,13 +76,13 @@ function main() {
// If we are idle and the player is jumping nearby... // If we are idle and the player is jumping nearby...
if (state == states.idle && nearby && Self.Grounded()) { if (state == states.idle && nearby && Self.Grounded()) {
if (playerPoint.Y - point.Y+(size.H/2) < 20) { if (playerPoint.Y - point.Y + (size.H / 2) < 20) {
// Enter attack state. // Enter attack state.
if (time.Since(jumpCooldownStart) > 500 * time.Millisecond) { if (time.Since(jumpCooldownStart) > 500 * time.Millisecond) {
state = states.attacking; state = states.attacking;
Self.SetVelocity(Vector(0, -jumpSpeed)); Self.SetVelocity(Vector(0, -jumpSpeed));
Self.StopAnimation(); Self.StopAnimation();
Self.PlayAnimation("attack-"+direction, null); Self.PlayAnimation("attack-" + direction, null);
return; return;
} }
} }
@ -90,42 +95,42 @@ function main() {
Self.StopAnimation(); Self.StopAnimation();
} }
// Ensure that the animations are always rolling. // Ensure that the animations are always rolling.
if (state === states.idle && !Self.IsAnimating()) { if (state === states.idle && !Self.IsAnimating()) {
Self.PlayAnimation("idle-"+direction, null); Self.PlayAnimation("idle-" + direction, null);
} }
}, 100); }, 100);
} }
// If under control of the player character. // If under control of the player character.
function player() { function player() {
let jumping = false; let jumping = false;
Events.OnKeypress((ev) => { Events.OnKeypress((ev) => {
Vx = 0; Vx = 0;
Vy = 0; Vy = 0;
if (ev.Right) { if (ev.Right) {
direction = "right"; direction = "right";
} else if (ev.Left) { } else if (ev.Left) {
direction = "left"; direction = "left";
} }
// Jump! // Jump!
if (ev.Up && !jumping) { if (ev.Up && !jumping) {
Self.StopAnimation(); Self.StopAnimation();
Self.PlayAnimation("attack-"+direction, null); Self.PlayAnimation("attack-" + direction, null);
jumping = true; jumping = true;
return; return;
} }
if (jumping && Self.Grounded()) { if (jumping && Self.Grounded()) {
Self.StopAnimation(); Self.StopAnimation();
jumping = false; jumping = false;
} }
if (!jumping && !Self.IsAnimating()) { if (!jumping && !Self.IsAnimating()) {
Self.PlayAnimation("idle-"+direction, null); Self.PlayAnimation("idle-" + direction, null);
} }
}); });
} }

View File

@ -10,5 +10,6 @@ build:
doodad install-script thief.js thief.doodad doodad install-script thief.js thief.doodad
doodad edit-doodad --tag "category=creatures" thief.doodad doodad edit-doodad --tag "category=creatures" thief.doodad
doodad edit-doodad -q --option "No A.I.=bool" thief.doodad
cp *.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/

View File

@ -15,6 +15,12 @@ function main() {
if (Self.IsPlayer()) { if (Self.IsPlayer()) {
return playable(); return playable();
} }
// No A.I.?
if (Self.GetOption("No A.I.") === true) {
return;
}
return ai(); return ai();
} }