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
for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\
doodad edit-doodad -q --option "No A.I.=bool" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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