feat(champions): use champions sent from server (#54)
This commit is contained in:
1 parent
710d3ec041
commit
bf6abfb2fa
6 files changed
+47
-25
No files matched your search
@@ -1,9 +1,15 @@
|
||||
import random
|
||||
|
||||
from autobeerpong.types.raw import MessageRaw_T
|
||||
|
||||
champions = ["berset", "lucas"]
|
||||
|
||||
def randomChampion() -> str:
|
||||
return random.choice(champions)
|
||||
|
||||
class Team:
|
||||
def __init__(self) -> None:
|
||||
self.formation = [1, 2, 3]
|
||||
self.formation = [randomChampion(), randomChampion(), randomChampion()]
|
||||
self.cups = [True, True, True]
|
||||
|
||||
def rotate(self) -> None:
|
||||
|
||||
@@ -4,15 +4,16 @@ import { randomInteger } from "../utils/randomUtils";
|
||||
import { getImage } from "../imageLoader";
|
||||
import { Clock } from "../Timers/Clock";
|
||||
import { BaseActor } from "./BaseActor";
|
||||
import { ChampionName, champions } from "./champions";
|
||||
import { champions } from "./champions";
|
||||
import { ChampionId } from "../jsonTypes";
|
||||
|
||||
type Facing = "left" | "right";
|
||||
|
||||
export class Champion extends BaseActor {
|
||||
facing: Facing;
|
||||
championName: ChampionName;
|
||||
championName: ChampionId;
|
||||
|
||||
constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionName) {
|
||||
constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionId) {
|
||||
super(actorArgs);
|
||||
this.facing = facing;
|
||||
this.championName = name;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type ChampionName = "lucas" | "berset";
|
||||
import { ChampionId } from "../jsonTypes";
|
||||
|
||||
export interface ChampionConfig {
|
||||
name: ChampionName;
|
||||
name: ChampionId;
|
||||
height: number;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const berset: ChampionConfig = {
|
||||
height: 1.5,
|
||||
};
|
||||
|
||||
export const champions: Record<ChampionName, ChampionConfig> = {
|
||||
export const champions: Record<ChampionId, ChampionConfig> = {
|
||||
lucas,
|
||||
berset,
|
||||
};
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { Action, Table } from "../jsonTypes";
|
||||
import { assertNotNull, assertNull } from "../utils/assertUtils";
|
||||
import { colorDistance } from "../utils/colorUtils";
|
||||
import { randomColor, randomInteger } from "../utils/randomUtils";
|
||||
import { randomColor } from "../utils/randomUtils";
|
||||
import { BaseScene } from "./BaseScene";
|
||||
import { Parabola } from "../GameElements/Parabola";
|
||||
import { Engine, vec, Color } from "excalibur";
|
||||
@@ -83,20 +83,6 @@ export class MatchScene extends BaseScene {
|
||||
this._cups.push(cup);
|
||||
});
|
||||
|
||||
championPositions.forEach((offsetX, index) => {
|
||||
const facing = index < 3 ? "right" : "left";
|
||||
const champion = new Champion(
|
||||
{
|
||||
color: randomNonGroundColor(),
|
||||
pos: vec(offsetX, groundHeight),
|
||||
},
|
||||
facing,
|
||||
randomInteger(0, 2) === 0 ? "berset" : "lucas",
|
||||
);
|
||||
this.add(champion);
|
||||
this._champions.push(champion);
|
||||
});
|
||||
|
||||
this._ball = new Ball({}, defaultBallConfiguration);
|
||||
}
|
||||
|
||||
@@ -150,6 +136,30 @@ export class MatchScene extends BaseScene {
|
||||
assertNotNull(cup);
|
||||
this.updateActorVisibility(cup, visible);
|
||||
});
|
||||
|
||||
this._updateChampions(table);
|
||||
}
|
||||
|
||||
private _updateChampions(table: Table): void {
|
||||
this._champions.forEach((champion) => this.remove(champion));
|
||||
this._champions = [];
|
||||
|
||||
championPositions.forEach((offsetX, index) => {
|
||||
const facing = index < 3 ? "right" : "left";
|
||||
const championName =
|
||||
index < 3 ? table.teamA[index] : table.teamB[index - 3];
|
||||
|
||||
const champion = new Champion(
|
||||
{
|
||||
color: randomNonGroundColor(),
|
||||
pos: vec(offsetX, groundHeight),
|
||||
},
|
||||
facing,
|
||||
championName,
|
||||
);
|
||||
this.add(champion);
|
||||
this._champions.push(champion);
|
||||
});
|
||||
}
|
||||
|
||||
private _updateFromActionState(action: Action): void {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type Id = number;
|
||||
export type ChampionId = "lucas" | "berset";
|
||||
|
||||
export type MessageRaw = LobbyStateRaw | MatchStateRaw;
|
||||
|
||||
@@ -32,8 +33,8 @@ export interface MatchStateRaw {
|
||||
export interface Table {
|
||||
cupsA: [boolean, boolean, boolean];
|
||||
cupsB: [boolean, boolean, boolean];
|
||||
teamA: [Id, Id, Id];
|
||||
teamB: [Id, Id, Id];
|
||||
teamA: [ChampionId, ChampionId, ChampionId];
|
||||
teamB: [ChampionId, ChampionId, ChampionId];
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
|
||||
@@ -35,7 +35,11 @@
|
||||
"team": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "number"
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"berset",
|
||||
"lucas"
|
||||
]
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
|
||||
Reference in new issue
Block a user