aboutsummaryrefslogtreecommitdiff
path: root/src/paperflight/static/update.js
blob: 0b44089965d9760346c897556e6b467e9a56161d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * Update functions
 */
function update() {
    t++
    score++
    if (startLevel) {
        plane.x += plane.vx * plane.dir
        plane.y += plane.vy
    }
    if (!isPlaneInBox({ x: plane.width, y: plane.height, width: width - (2*plane.width), height: height - (2*plane.height) })) {
        gameOver()
    }
    currLevel.items.forEach(item => {
        item.update()
    })
    if (atExit()) {
        setLevel(currLevelIndex + 1)
    }
    if(gameIsOver){
        window.clearInterval(gameInterval)
    }
}
function updateVent() {
    // Custom box since vent height is upwards
    if (isPlaneInBox({
        x: this.x,
        y: this.y - this.height,
        width: this.width,
        height: this.height
    })) {
        plane.y -= 2
    }
}
function updateBlock() {
    if (isPlaneInBox(this)) {
        gameOver()
    }
}
function updateRamp() {
    if (isPointInRamp(plane.x, plane.y, this) ||
        isPointInRamp(plane.x + plane.width, plane.y, this) ||
        isPointInRamp(plane.x + plane.width, plane.y + plane.height, this) ||
        isPointInRamp(plane.x, plane.y + plane.height, this)) {
        gameOver()
    }
}
function updateCoin() {
    if (!this.collected && isPlaneInCircle(this)) {
        this.collected = true
        collected++
    }
}
function updateSwitch() {
    if (isPlaneInBox(this)) {
        if (!this.inBox) {
            this.inBox = true
            switchState = (switchState + 1) % this.stateCount
        }
    } else {
        this.inBox = false
    }
}
function updateSwitchRect() {
    if (isPlaneInBox(this) && switchState == this.state) {
        gameOver()
    }
}