Chooser AI
This commit is contained in:
1 parent
fb94f90326
commit
f98bba041f
2 files changed
+28
-14
No files matched your search
@@ -4,11 +4,23 @@ import {randomInt} from './math.js';
|
|||||||
export const AI_TYPES = {
|
export const AI_TYPES = {
|
||||||
|
|
||||||
moron: {
|
moron: {
|
||||||
decide() {
|
decide(player) {
|
||||||
return {
|
return {
|
||||||
a: randomInt(0, 180),
|
a: randomInt(0, 180),
|
||||||
p: randomInt(PLAYER_INITIAL_POWER, PLAYER_MAX_ENERGY*PLAYER_ENERGY_POWER_MULTIPLIER)}
|
p: randomInt(PLAYER_INITIAL_POWER, PLAYER_MAX_ENERGY*PLAYER_ENERGY_POWER_MULTIPLIER),
|
||||||
}
|
currentWeapon: player.currentWeapon,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
chooser: {
|
||||||
|
decide(player) {
|
||||||
|
return {
|
||||||
|
a: randomInt(0, 180),
|
||||||
|
p: randomInt(PLAYER_INITIAL_POWER, PLAYER_MAX_ENERGY*PLAYER_ENERGY_POWER_MULTIPLIER),
|
||||||
|
currentWeapon: randomInt(0, player.weapons.length-1),
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
+13
-11
@@ -47,7 +47,7 @@ for (let [color, borderColor] of PLAYER_COLORS) {
|
|||||||
weapons: [...PLAYER_STARTING_WEAPONS],
|
weapons: [...PLAYER_STARTING_WEAPONS],
|
||||||
currentWeapon: 0,
|
currentWeapon: 0,
|
||||||
energy: PLAYER_MAX_ENERGY,
|
energy: PLAYER_MAX_ENERGY,
|
||||||
ai: i !== 0 ? 'moron' : undefined,
|
ai: i !== 0 ? sample(Object.keys(AI_TYPES)) : undefined,
|
||||||
fallHeight: 0,
|
fallHeight: 0,
|
||||||
dead: false,
|
dead: false,
|
||||||
});
|
});
|
||||||
@@ -71,7 +71,7 @@ function update() {
|
|||||||
|
|
||||||
else if (state === 'aim') {
|
else if (state === 'aim') {
|
||||||
const player = players[currentPlayer];
|
const player = players[currentPlayer];
|
||||||
const {x, y, a, p, energy} = player;
|
const {x, y, a, p, weapons, energy} = player;
|
||||||
const maxPower = energy * PLAYER_ENERGY_POWER_MULTIPLIER;
|
const maxPower = energy * PLAYER_ENERGY_POWER_MULTIPLIER;
|
||||||
const isPrecise = key('Alt');
|
const isPrecise = key('Alt');
|
||||||
const isFast = key('Shift');
|
const isFast = key('Shift');
|
||||||
@@ -80,10 +80,11 @@ function update() {
|
|||||||
|
|
||||||
if (player.ai) {
|
if (player.ai) {
|
||||||
let ai = AI_TYPES[player.ai];
|
let ai = AI_TYPES[player.ai];
|
||||||
const plan = ai.decide();
|
const plan = ai.decide(player);
|
||||||
const a = player.a = wrap(0, plan.a, 180);
|
player.a = wrap(0, plan.a, 180);
|
||||||
const p = player.p = clamp(0, plan.p, maxPower);
|
player.p = clamp(0, plan.p, maxPower);
|
||||||
shoot = {a, p};
|
player.currentWeapon = clamp(0, plan.currentWeapon, weapons.length-1);
|
||||||
|
shoot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (key('ArrowLeft')) {
|
else if (key('ArrowLeft')) {
|
||||||
@@ -125,19 +126,20 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shoot) {
|
if (shoot) {
|
||||||
const {a, p} = shoot;
|
const {a, p, c, weapons, currentWeapon} = player;
|
||||||
const [px, py] = vec(x, y-3, a+180, 5);
|
const [px, py] = vec(x, y-3, a+180, 5);
|
||||||
|
|
||||||
const weaponType = player.weapons[player.currentWeapon];
|
const weaponType = weapons[currentWeapon];
|
||||||
weaponType.ammo -= 1;
|
weaponType.ammo -= 1;
|
||||||
|
|
||||||
projectile = {
|
projectile = {
|
||||||
osc: createOsc('sine'),
|
osc: createOsc('sine'),
|
||||||
player: player,
|
player: player,
|
||||||
weaponTypeId: weaponType.type,
|
weaponTypeId: weaponType.type,
|
||||||
ox:px, oy:py, a, p,
|
ox: px, oy: py,
|
||||||
x:px, y:py, t: 0,
|
x: px, y: py,
|
||||||
c: player.c
|
a, p, c,
|
||||||
|
t: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
projectile.osc.start();
|
projectile.osc.start();
|
||||||
|
|||||||
Reference in new issue
Block a user