[READ-ONLY] Mirror of https://github.com/flo-bit/shadow-shmup. Fun and casual top-down, roguelike shoot 'em up browsergame with shadow elements and colorful neon effects flo-bit.dev/shadow-shmup/
browsergame pixijs rapier2d roguelike shoot-em-up typescript webgame
0

Configure Feed

Select the types of activity you want to include in your feed.

some coop improvements

Florian (Jul 24, 2024, 12:10 PM +0200) fa002e6d d84bc36d

+67 -11
+2
index.html
··· 18 18 <body class="m-0 bg-black overflow-hidden overscroll-none select-none"> 19 19 <script src="src/app.ts" type="module"></script> 20 20 21 + <div id="timer" class="absolute top-1 right-1 text-white font-bold">0</div> 22 + 21 23 <!-- ui: title, play button --> 22 24 <div 23 25 id="ui"
+15 -4
src/app.ts
··· 50 50 51 51 invincible = false; 52 52 53 + playingTime = 0; 54 + 53 55 constructor() { 54 56 this.setup(); 55 57 ··· 183 185 this.playerManager?.resetPlayers(1); 184 186 185 187 this.startMusic(); 188 + 189 + this.playingTime = 0; 186 190 }); 187 191 188 192 const playCoopButton = document.getElementById('play-coop'); ··· 195 199 this.playerManager?.resetPlayers(2); 196 200 197 201 this.startMusic(); 202 + 203 + this.playingTime = 0; 198 204 }); 199 205 } 200 206 ··· 280 286 this.playerManager?.update(deltaTime, this.keys); 281 287 if (!this.playing) return; 282 288 289 + this.playingTime += deltaTime; 290 + if (Math.floor(this.playingTime / 1000) !== Math.floor((this.playingTime - deltaTime) / 1000)) { 291 + let timer = document.getElementById('timer'); 292 + if (timer) timer.innerText = Math.floor(this.playingTime / 1000).toString(); 293 + } 294 + 283 295 this.obstacleManager.update(deltaTime); 284 296 285 297 this.enemyManager?.update(deltaTime); 286 298 287 299 if (this.invincible) { 288 - this.playerManager!.players[0].health = 100; 300 + this.playerManager!.players[1].health = 100; 289 301 } 290 302 291 303 let playerManager = this.playerManager; ··· 293 305 if (playerManager) { 294 306 let timeSinceLastDamage = playerManager.smallestTimeSinceLastDamage(); 295 307 if (timeSinceLastDamage < 150) { 296 - this.container.alpha = playerManager.players[0].timeSinceLastDamage / 300; 308 + this.container.alpha = timeSinceLastDamage / 300; 297 309 } else { 298 310 this.container.alpha = 1; 299 311 } ··· 305 317 306 318 this.projectileManager?.update(deltaTime); 307 319 308 - let player = this.playerManager?.players[0]; 309 - if (player && player.health <= 0) { 320 + if (this.playerManager?.allDead()) { 310 321 this.enemyManager?.killAll(); 311 322 this.projectileManager?.clearAllProjectiles(); 312 323
-1
src/obstacle-manager.ts
··· 31 31 32 32 const currentCell = this.getCellCoord(position.x, position.y); 33 33 34 - console.log(currentCell); 35 34 if (this.lastActiveCell === currentCell) return; 36 35 37 36 this.lastActiveCell = currentCell;
+17 -3
src/player-manager.ts
··· 40 40 let x = 0, 41 41 y = 0; 42 42 43 + let count = 0; 44 + 43 45 for (let player of this.players) { 46 + if (player.dead) continue; 47 + 44 48 x += player.x; 45 49 y += player.y; 50 + 51 + count++; 46 52 } 47 53 48 - return { x: x / this.players.length, y: y / this.players.length }; 54 + return { x: x / count, y: y / count }; 49 55 } 50 56 51 57 smallestTimeSinceLastDamage() { 52 58 let min = Infinity; 53 59 54 60 for (let player of this.players) { 55 - min = Math.min(min, player.timeSinceLastDamage); 61 + if (!player.dead) min = Math.min(min, player.timeSinceLastDamage); 56 62 } 57 63 58 64 return min; 65 + } 66 + 67 + allDead() { 68 + for (let player of this.players) { 69 + if (!player.dead) return false; 70 + } 71 + 72 + return true; 59 73 } 60 74 61 75 getClosestPlayer( ··· 69 83 for (let player of this.players) { 70 84 const dist = (player.x - position.x) ** 2 + (player.y - position.y) ** 2; 71 85 72 - if (dist < closestDist) { 86 + if (dist < closestDist && !player.dead) { 73 87 closestDist = dist; 74 88 closestPlayer = player; 75 89 }
+33 -3
src/player.ts
··· 49 49 50 50 timeSinceLastDamage: number = 0; 51 51 52 + dead: boolean = false; 53 + 54 + respawnTime: number = 0; 55 + 52 56 constructor(game: Game, num: number) { 53 57 this.game = game; 54 58 this.num = num; ··· 169 173 170 174 update(deltaTime: number, keys: Record<string, boolean>) { 171 175 // move the player, wasd 172 - if (this.game.playing) { 176 + if (this.game.playing && !this.dead) { 173 177 let dx = 0, 174 178 dy = 0; 175 179 if (this.game.controls.up(this.num)) dy -= 1; ··· 184 188 } 185 189 if (dx || dy) this.rigidBody?.applyImpulse({ x: dx * this.speed, y: -dy * this.speed }, true); 186 190 } 191 + 192 + console.log(this.num, this.dead); 193 + 194 + if (this.dead && this.respawnTime > 0) { 195 + this.playerContainer.alpha = 0.1; 196 + if (this.light) this.light.alpha = 0.0; 197 + 198 + this.respawnTime -= deltaTime; 199 + if (this.respawnTime <= 0 && this.game.playing) { 200 + // get closest player 201 + const closestPlayer = this.game.playerManager?.getClosestPlayer(this.position); 202 + this.x = (closestPlayer?.x ?? 0) + 50; 203 + this.y = closestPlayer?.y ?? 0; 204 + 205 + this.dead = false; 206 + this.health = this.maxHealth; 207 + 208 + this.playerContainer.alpha = 1; 209 + } 210 + 211 + return; 212 + } 213 + 214 + console.log(this); 187 215 188 216 this.timeSinceLastDamage += deltaTime; 189 217 ··· 211 239 this.rightEye.move(angle); 212 240 } 213 241 214 - this.weapon.update(deltaTime); 215 - 216 242 this.drawShadow(); 243 + 244 + this.weapon.update(deltaTime); 217 245 218 246 this.playerContainer.position.set(this.x, this.y); 219 247 } ··· 264 292 this.health -= amount; 265 293 if (this.health < 0) { 266 294 this.health = 0; 295 + this.dead = true; 296 + this.respawnTime = 5000; 267 297 } 268 298 if (this.healthBar) this.healthBar.width = this.size * (this.health / this.maxHealth); 269 299