Skip to content

Commit

Permalink
Added more record tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Sehmisch committed Sep 21, 2020
1 parent 25401b6 commit 4def647
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 15 deletions.
Binary file removed build.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const CONST = {
CAMERA_AGILITY: 1.5, // how fast the camera reacts to changes in direction

// UI settings
RECORD_SHOW_DURATION: 1, // seconds a record stays on screen
RECORD_SHOW_DURATION: 5, // seconds a record stays on screen

// mob properties
MOB_BALLOON_RADIUS: 48, // radius of the collision hitcircle
Expand Down
1 change: 1 addition & 0 deletions entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ExplodeOnImpactBehavior extends Behavior {
// collision detected
state.removeEntity(other)
this.explode(entity, state)
state.player.kills++
return
}
}
Expand Down
1 change: 1 addition & 0 deletions player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Player extends Entity {
public airtime = 0
public falldist = 0
public isGrounded = false
public kills = 0

private rocketlauncher: Rocketlauncher

Expand Down
111 changes: 97 additions & 14 deletions ui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
interface RecordEntry {
pos: Point
kills: number
}

class UI {

private airborneSpan: HTMLSpanElement
Expand All @@ -6,47 +11,125 @@ class UI {
private recordTypeSpan: HTMLSpanElement
private recordValueSpan: HTMLElement

private bestHeight = -CONST.PLAYER_START_ALTITUDE
private bestFall = CONST.PLAYER_START_ALTITUDE
private recordHeight: RecordCategory
private recordFall: RecordCategory
private recordKills: RecordCategory
private recordDistance: RecordCategory
private recordAirtime: RecordCategory
private recordTutorial: RecordCategory
private lastPlayerAirtime = 0

private recordShowTimeLeft = 0

private totalTime = 0
private timeRecorded = 0

private timeLeft = 0
private record: RecordEntry[] = Array()

private tutorialUnderstood = false

constructor() {
this.airborneSpan = document.getElementById("ui_airborne")
this.altitudeSpan = document.getElementById("ui_altitude")
this.recordDiv = document.getElementById("ui_records")
this.recordTypeSpan = document.getElementById("ui_records_type")
this.recordValueSpan = document.getElementById("ui_records_value")

this.recordHeight = new RecordCategory(
"Altitude Record",
(value) => Math.floor(value / CONST.METER).toString() + " meters",
CONST.PLAYER_START_ALTITUDE )
this.recordFall = new RecordCategory(
"Highest Fall",
(value) => Math.floor(value / CONST.METER).toString() + " meters",
CONST.PLAYER_START_ALTITUDE )
this.recordAirtime = new RecordCategory(
"Airtime record",
(value) => value.toFixed(1) + " seconds",
4)
this.recordDistance = new RecordCategory(
"Horizontal Distance per Minute record",
(value) => Math.floor(value / CONST.METER).toString() + " meters",
200)
this.recordKills = new RecordCategory(
"Kill per Minute record",
(value) => value.toString(),
0)

}

update(deltaTime: number, player: Player) {
// basic display
this.altitudeSpan.textContent = Math.floor(player.pos.y / -CONST.METER).toString()
this.airborneSpan.textContent = player.airtime.toFixed(1)


this.timeLeft -= deltaTime
if(this.timeLeft < 0) {
if(this.recordShowTimeLeft < 0) {
this.recordDiv.style.display = "none"
} else {
this.recordDiv.style.display = "block"
}

if (player.pos.y < this.bestHeight) {
this.bestHeight = player.pos.y
this.postRecord("New Altitude Record", Math.floor(player.pos.y / -CONST.METER).toString() + " meters")
// update every-frame records
if (player.isGrounded) {
this.recordFall.checkRecord(player.falldist, this)
this.recordAirtime.checkRecord(this.lastPlayerAirtime, this)
}
this.lastPlayerAirtime = player.airtime
this.recordHeight.checkRecord(-player.pos.y, this)

if (player.isGrounded) {
if (player.falldist > this.bestFall) {
this.bestFall = player.falldist
this.postRecord("New longest fall", Math.floor(player.falldist / CONST.METER).toString() + " meters")
// update time-based records
while(this.timeRecorded < this.totalTime) {
this.record.push({
pos: { x: player.pos.x, y: player.pos.y },
kills: player.kills
})
if (this.record.length > 60) {
let begin = this.record.shift()
let end = this.record[59]
this.recordKills.checkRecord(end.kills - begin.kills, this)
this.recordDistance.checkRecord(Math.abs(end.pos.x - begin.pos.x), this)
}
this.timeRecorded += 1
}

/*
if (player.pos.y < -200 && player.velocity.y < 0) {
this.tutorialUnderstood = true
}
if(this.tutorialUnderstood === false ) {
this.postRecord("Aim&Shoot with mouse", "A&D or left&right for moving while airborne")
}
*/

this.totalTime += deltaTime
this.recordShowTimeLeft -= deltaTime
}

postRecord(type: string, value: string) {
this.timeLeft = CONST.RECORD_SHOW_DURATION
this.recordShowTimeLeft = CONST.RECORD_SHOW_DURATION
this.recordTypeSpan.textContent = type
this.recordValueSpan.textContent = value
}
}

class RecordCategory{
headline: string
toStringFunc: (value:number) => string

private best: number

constructor(headline:string, toString: (value:number) => string, best: number) {
this.headline = headline
this.toStringFunc = toString
this.best = best
}

checkRecord(current: number, ui: UI) {
if (current > this.best) {
this.best = current
ui.postRecord(this.headline, this.toStringFunc(this.best))
}
}

}

0 comments on commit 4def647

Please sign in to comment.