[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.

improve triangleenemy

Florian (Jul 24, 2024, 9:31 AM +0200) d84bc36d 3ef367d6

+49 -17
+4
src/app.ts
··· 249 249 player.takeDamage(projectile.damage); 250 250 projectile.destroy(); 251 251 } 252 + 253 + if (projectile) { 254 + projectile.onHit(); 255 + } 252 256 }); 253 257 } 254 258
+29 -17
src/enemy.ts
··· 286 286 } 287 287 288 288 export class TriangleEnemy extends Enemy { 289 - weapon: Weapon; 290 - 291 289 projectile: Projectile; 292 290 293 291 constructor(game: Game) { 294 292 super(game); 295 293 296 - this.speed = 600; 294 + this.speed = 3000; 297 295 298 - this.weapon = new Weapon(this.game, { 299 - color: this.color, 300 - collisionGroups: 0x00100001, 301 - projectileSpeed: 0.0, 302 - fireRate: 30, 303 - projectileSize: 4, 296 + let position = { x: this.x, y: this.y }; 297 + 298 + this.projectile = new Projectile(this.game, { 299 + position, 300 + enemyPosition: position, 301 + speed: 0.0, 304 302 damage: 10, 305 - lifetime: 30, 306 - sound: false 303 + size: 2, 304 + angleOffset: 0, 305 + hit: () => { 306 + this.destroy(); 307 + }, 308 + collisionGroups: 0x00100001, 309 + color: this.color 307 310 }); 308 311 } 309 312 ··· 335 338 new Vector2(0, -this.size) 336 339 ) 337 340 .setActiveEvents(RAPIER().ActiveEvents.COLLISION_EVENTS) 338 - .setCollisionGroups(0x00020007); 341 + .setCollisionGroups(0x00020007) 342 + .setDensity(5); 339 343 340 344 this.game.world.createCollider(colliderDesc, this.rigidBody); 341 345 ··· 372 376 attack(deltaTime: number, nearestPlayer: Player, dx: number, dy: number, distance: number): void { 373 377 if (this.destroyed) return; 374 378 if (distance < nearestPlayer.viewDistance) { 375 - const x = Math.cos(this.rotation + Math.PI / 2 - 0.0); 376 - const y = Math.sin(this.rotation + Math.PI / 2 - 0.0); 377 - const startPosition = { x: this.x + x * 20 - 2, y: this.y + y * 20 - 2 }; 378 - this.weapon.fire(startPosition, startPosition); 379 + this.projectile.shape.alpha = 1; 380 + const x = Math.cos(this.rotation + Math.PI / 2); 381 + const y = Math.sin(this.rotation + Math.PI / 2); 382 + 383 + this.projectile.setPosition(this.x + x * 20 - 1, this.y + y * 20 - 1); 384 + } else { 385 + this.projectile.shape.alpha = 0; 379 386 } 380 387 381 - this.weapon.update(deltaTime); 388 + // this.weapon.update(deltaTime); 389 + } 390 + 391 + destroy(): void { 392 + this.projectile.destroy(); 393 + super.destroy(); 382 394 } 383 395 } 384 396
+1
src/projectile-manager.ts
··· 12 12 lifetime?: number; 13 13 collisionGroups?: number; 14 14 showParticles?: boolean; 15 + hit?: () => void; 15 16 }; 16 17 17 18 export default class ProjectileManager {
+15
src/projectile.ts
··· 21 21 22 22 showParticles: boolean = true; 23 23 24 + hit?: () => void; 25 + 24 26 constructor( 25 27 game: Game, 26 28 data: ProjectileData ··· 71 73 72 74 this.showParticles = data.showParticles ?? true; 73 75 76 + this.hit = data.hit; 77 + 74 78 this.isProjectile = true; 75 79 } 76 80 ··· 91 95 if (this.showParticles) this.game.spawnParticles(this.shape.x, this.shape.y, 4, this.color); 92 96 } 93 97 } 98 + } 99 + 100 + setPosition(x: number, y: number) { 101 + this.shape.x = x; 102 + this.shape.y = y; 103 + 104 + this.rigidBody.setTranslation({ x, y: -y }); 105 + } 106 + 107 + onHit() { 108 + if (this.hit) this.hit(); 94 109 } 95 110 96 111 destroy() {