File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ export default class DOMRenderer extends Renderer {
64
64
<span class="red">red</span> area into the
65
65
<span class="blue">blue</span> area.`
66
66
: model . condition === "WIN"
67
- ? `You win! Congratulations! `
67
+ ? `<span class="blue"> You win! Congrats!</span> `
68
68
: `<span class="red">You lost! Oh no!</span>` ;
69
69
}
70
70
/**
Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
/*----- Imports --------------------------------------------------------------*/
8
+ import Area from "./Area.js" ;
8
9
import Celestial from "./Celestial.js" ;
9
10
import GameData from "./GameData.js" ;
10
11
import Physics from "./Physics.js" ;
@@ -112,15 +113,30 @@ export default class Game {
112
113
// Loss conditions
113
114
model . condition === "PLAY" &&
114
115
model . health <= 0 &&
116
+ // Last played Celestial older than 30s
115
117
new Date ( ) - 30e3 >
116
118
model . scene
117
119
. slice ( )
118
120
. reverse ( )
119
- . find (
120
- ( obj ) =>
121
- obj instanceof Celestial && obj . name . toLowerCase ( ) === "played"
122
- ) . birth &&
121
+ . find ( ( obj ) => obj instanceof Celestial && obj . name === "played" )
122
+ . birth &&
123
123
( model . condition = "LOSS" ) ;
124
+ // Win conditions
125
+ model . condition === "PLAY" &&
126
+ model . scene . reduce (
127
+ ( acc , obj ) =>
128
+ // Check played Celestial
129
+ obj instanceof Celestial && obj . name === "played"
130
+ ? obj . collisions . find (
131
+ ( hit ) =>
132
+ // Check if hit target
133
+ hit . who instanceof Area &&
134
+ hit . who . name . toLowerCase ( ) === "target"
135
+ ) || acc
136
+ : acc ,
137
+ false
138
+ ) &&
139
+ ( model . condition = "WIN" ) ;
124
140
requestAnimationFrame ( this . loop . bind ( this ) ) ;
125
141
}
126
142
}
You can’t perform that action at this time.
0 commit comments