Skip to content

Commit

Permalink
Add respawn times
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Apr 5, 2021
1 parent 5231bca commit c5c32c1
Show file tree
Hide file tree
Showing 36 changed files with 919 additions and 371 deletions.
10 changes: 7 additions & 3 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class GameClient {
public roomparams: RoomParameters = {
id: -1,
name: "Name",
map: { name: "custom", layout: [], objects: undefined },
map: { name: "custom", layout: "", objects: undefined },
max_players: 16,
};

Expand Down Expand Up @@ -389,9 +389,12 @@ export class GameClient {
id: object.controlID
};
}
if (object.name !== undefined) {
if (object.name !== undefined && object.controlType != EntityType.Respawner) {
this.playerInfo.name = object.name;
}
else {
this.playerInfo.name = "";
}
if (this.followObject.type == EntityType.Plane) {
this.audio.playEngine(true);
} else {
Expand Down Expand Up @@ -419,7 +422,8 @@ export class GameClient {
if (type == this.followObject.type && this.followObject.id == id) {
const { x, y } = object;
if (x !== undefined && y !== undefined) {
this.renderer.centerCamera(x, y);
this.renderer.followObject(type, id);
//this.renderer.centerCamera(x, y);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion client/src/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
>settings</i
>
</a>
</a>
</div>
</template>

Expand Down
1 change: 1 addition & 0 deletions client/src/render/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export enum DrawLayer {
Bullet = LAYER.LAYER11,
Player = LAYER.LAYER12,
Clock = LAYER.LAYER07,
Respawner = LAYER.LAYER08,
}

export enum GameScreen {
Expand Down
13 changes: 13 additions & 0 deletions client/src/render/entities/killarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import { Team } from "../../../../dogfight/src/constants";
import { TeamChooserUI } from "./teamChooserUI";
import { TeamColor } from "../constants";

/*
public static final int CHAT_PLANE_KILL_SELF = 1;
public static final int CHAT_PLANE_KILL_TEAM = 2;
public static final int CHAT_PLANE_KILL_OPPONENT = 3;
public static final int CHAT_MAN_KILL_SELF = 4;
public static final int CHAT_MAN_KILL_TEAM = 5;
public static final int CHAT_MAN_KILL_OPPONENT = 6;
public static final int CHAT_CONTROL_END = 1;
public static final int CHAT_CONTROL_START = 2;
public static final int CHAT_KILL_TYPE_PLANE = 1;
public static final int CHAT_KILL_TYPE_MAN = 2;
*/

export class KillArea {
public container: PIXI.Container;
Expand Down
3 changes: 3 additions & 0 deletions client/src/render/entities/playerInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class PlayerInfos {
} else if (playerInfo.controlType == EntityType.Trooper) {
text.position.set(x, (y + 48) * 1);
}
else {
text.text = "";
}

text.style.fill = color;
}
Expand Down
17 changes: 15 additions & 2 deletions client/src/render/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TeamChooserUI } from "./entities/teamChooserUI";
import { ClientMode } from "../types";
import { TakeoffSelectUI } from "./entities/takeoffSelectUI";
import { PlaneSprite } from "./sprites/plane";
import { RespawnerSprite } from "./sprites/respawner";
import { PlayerInfos } from "./entities/playerInfos";
import { ExplosionSprite } from "./sprites/explosion";
import { BulletSprite } from "./sprites/bullet";
Expand All @@ -31,6 +32,8 @@ import { ClockSprite } from "./sprites/clock";
import { Clock } from "./entities/clock";
import { ChatArea } from "./entities/chatarea";
import { ChatField } from "./entities/chatfield";
import { NoneSprite } from "./sprites/none";
import { Followable, isFollowable } from "../../../dogfight/src/entities/Followable";

PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;

Expand All @@ -42,7 +45,7 @@ export class GameRenderer {
private spriteSheet: PIXI.Spritesheet;

/** A JS container of all Game Objects and their Srite Objects */
private sprites = {};
public sprites = {};

private pixiApp: PIXI.Application;

Expand Down Expand Up @@ -235,8 +238,10 @@ export class GameRenderer {
return new BombSprite(this.spriteSheet);
case EntityType.Plane:
return new PlaneSprite(this.spriteSheet);
case EntityType.Respawner:
return new RespawnerSprite(this.spriteSheet);
case EntityType.Clock:
return new ClockSprite(this.spriteSheet);
return new NoneSprite(this.spriteSheet);
default:
console.log(
"ERROR: Failed to create undefined object sprite:",
Expand Down Expand Up @@ -304,6 +309,14 @@ export class GameRenderer {
this.setCamera(newX, newY);
}

public followObject(type, id) {
let f = this.sprites[type][id].entity
if (isFollowable(f)) {
this.centerCamera(f.getCenterX(), f.getCenterY())
f.followed = true;
}
}

/**
* Center the camera view on a specific (x, y) location
* Coordinates must be in game world space.
Expand Down
23 changes: 23 additions & 0 deletions client/src/render/sprites/none.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as PIXI from "pixi.js";
import { GameSprite } from "../sprite";
import { DrawLayer } from "../constants";
import { EntityType } from "../../../../dogfight/src/entity";
import { TeamInfo } from "../../../../dogfight/src/entities/TeamInfo";
import { spriteSheet } from "../textures";
import { Clock } from "../../../../dogfight/src/entities/Clock";
import { None } from "../../../../dogfight/src/entities/None";

export class NoneSprite extends GameSprite<None> {

public constructor(spritesheet: PIXI.Spritesheet) {
super(spriteSheet, None);
}

public redraw(): void {
//
}

public destroy(): void {
//
}
}
122 changes: 122 additions & 0 deletions client/src/render/sprites/respawner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import * as PIXI from "pixi.js";
import { GameSprite } from "../sprite";
import { DrawLayer } from "../constants";
import { Terrain, FacingDirection } from "../../../../dogfight/src/constants";
import { BackgroundItem } from "../../../../dogfight/src/entities/BackgroundItem";
import { spriteSheet } from "../textures";
import { Respawner, RespawnType, WAIT_TIMES } from "../../../../dogfight/src/entities/Respawner";

export enum RespawnColor {
FG = 0xafaf5a,
BG = 0x32325a,
}



export class RespawnerSprite extends GameSprite<Respawner> {
//public x: number;
//public y: number;
//public subType: number;

//private spritesheet: PIXI.Spritesheet;

private container: PIXI.Container;

private time: PIXI.Text;
private penalty: PIXI.Text;
private info: PIXI.Text;
private interval;



public constructor(spritesheet: PIXI.Spritesheet) {
super(spriteSheet, Respawner);

//this.x = 0;
//this.y = 0;
//this.subType = 0;

this.spritesheet = spritesheet;

this.container = new PIXI.Container();


this.info = new PIXI.Text("", {
font: "arial",
fontSize: 20,
fill: RespawnColor.FG,
//stroke: RespawnColor.BG,
//strokeThickness: 1,
fontWeight: "bold"
}
);
this.time = new PIXI.Text("", {
font: "arial",
fontSize: 255,
fill: RespawnColor.FG,
//stroke: RespawnColor.BG,
//strokeThickness: 1,
fontWeight: "bold"
}
);
this.penalty = new PIXI.Text("", {
font: "arial",
fontSize: 20,
fill: RespawnColor.FG,
stroke: RespawnColor.BG,
strokeThickness: 1,
//fontWeight: "bold"
}
);


this.container.addChild(this.info);
this.container.addChild(this.time);
this.container.addChild(this.penalty);
this.container.zIndex = DrawLayer.Respawner;

this.renderables.push(this.container);
this.interval = setInterval(() => { this.redraw() }, 500);
console.log("created respawner");
}

public redraw(): void {
// update tex
if (this.entity.followed) {
this.info.text = "respawning in ";
let i: number = Math.round((WAIT_TIMES[this.entity.respawnType] - (Date.now() - this.entity.startTime)) / 1000);
this.time.text = "" + i;

switch (this.entity.respawnType) {
case RespawnType.Normal:
this.penalty.text = "";
break;
case RespawnType.Suicide:
//this.penalty.y = 70;
this.penalty.text = "suicide penalty";
break;
case RespawnType.TeamKill:
//this.penalty.y = 70;
this.penalty.text = "teamkill penalty";
break;
}

this.time.y = -this.time.height / 2;
this.time.x = - this.time.width / 2;
this.info.y = -this.time.height / 2 - this.info.height / 2;
this.info.x = - this.info.width / 2;
this.penalty.x = - this.penalty.width / 2;
this.penalty.y = this.time.height / 2
this.container.x = this.entity.x;
this.container.y = this.entity.y;
console.log(this.entity.respawnType + " 2 " + this.entity.startTime);
console.log(this.time.text);
console.log(this.entity.x + " / " + this.entity.y);
}
}

public destroy(): void {
clearInterval(this.interval);
//
}
}
42 changes: 26 additions & 16 deletions dogfight/src/entities/BackgroundItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import { GameWorld } from "../world/world";

//TODO
export class BackgroundItem extends Entity {
public type = EntityType.BackgroundItem;
public static type = EntityType.BackgroundItem;

public x: number;
public y: number;
public subType: FacingDirection;

public constructor(world: GameWorld, t_x = 0, t_y = 0, t_subType = 0,type = EntityType.BackgroundItem,id: number = world.nextID(type), cache: Cache =world.cache, ) {
super(id, world);
this.type = type;
this.setData(cache, {
public constructor(world: GameWorld, t_x = 0, t_y = 0, t_subType = 0) {
super(world, BackgroundItem);
this.setData(world.cache, {
x: t_x,
y: t_y,
subType: t_subType
Expand All @@ -24,19 +23,30 @@ export class BackgroundItem extends Entity {

public getState(): CacheEntry {
return {
type: this.type,
type: this.getType(),
x: this.x,
y: this.y,
subType: this.subType
};
}
}
export const backgroundItemSchema: GameObjectSchema = {
numbers: [
{ name: "x", intType: IntType.Int16 },
{ name: "y", intType: IntType.Int16 },
{ name: "subType", intType: IntType.Uint8 },
],
booleans: [],
strings: []
};
/*
public static schema2: GameObjectSchema = {
numbers: [
{ name: "x", intType: IntType.Int16 },
{ name: "y", intType: IntType.Int16 },
{ name: "subType", intType: IntType.Uint8 },
],
booleans: [],
strings: []
};
*/
public static schema: GameObjectSchema = {
numbers: [
{ name: "x", intType: IntType.Int16 },
{ name: "y", intType: IntType.Int16 },
{ name: "subType", intType: IntType.Uint8 },
],
booleans: [],
strings: []
};
}
Loading

0 comments on commit c5c32c1

Please sign in to comment.