Skip to content

Commit

Permalink
Merge pull request #27 from rengert/balancing
Browse files Browse the repository at this point in the history
Balancing
  • Loading branch information
rengert authored Jan 4, 2024
2 parents 3f96679 + 0965b85 commit 2ff82b8
Show file tree
Hide file tree
Showing 29 changed files with 283 additions and 171 deletions.
2 changes: 1 addition & 1 deletion capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'net.bolzplatzarena.solarstriker',
appName: 'Solar Striker',
webDir: 'dist/solar-striker',
webDir: 'dist/solar-striker/browser',
plugins: {
SplashScreen: {
launchShowDuration: 3000,
Expand Down
2 changes: 1 addition & 1 deletion ios/App/App/capacitor.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"appId": "net.bolzplatzarena.solarstriker",
"appName": "Solar Striker",
"webDir": "dist/solar-striker",
"webDir": "dist/solar-striker/browser",
"plugins": {
"SplashScreen": {
"launchShowDuration": 3000,
Expand Down
13 changes: 1 addition & 12 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
def assertDeploymentTarget(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# ensure IPHONEOS_DEPLOYMENT_TARGET is at least 13.0
deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f
should_upgrade = deployment_target < 13.0 && deployment_target != 0.0
if should_upgrade
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
end
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '13.0'
use_frameworks!
Expand Down
12 changes: 6 additions & 6 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- Capacitor (5.3.0):
- Capacitor (5.6.0):
- CapacitorCordova
- CapacitorCordova (5.3.0)
- CapacitorCordova (5.6.0)
- CapacitorSplashScreen (5.0.6):
- Capacitor

Expand All @@ -19,10 +19,10 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/splash-screen"

SPEC CHECKSUMS:
Capacitor: 1ac9165943bc4f2137642d218c5ba05df811de69
CapacitorCordova: b9374d68e63ce29e96ab5db994cf14fbefd722c9
Capacitor: ebfc16cdb8116d04c101686b080342872da42d43
CapacitorCordova: 931b48fcdbc9bc985fc2f16cec9f77c794a27729
CapacitorSplashScreen: 5fa2ab5e46cf5cc530cf16a51c80c7a986579ccd

PODFILE CHECKSUM: 7a859ce68b9d4ff260e7aa4163685f3f2d526323
PODFILE CHECKSUM: f335af037f3993fa7c4aaec9ad935feb22d428fc

COCOAPODS: 1.12.1
COCOAPODS: 1.14.3
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@capacitor/splash-screen": "^5.0.0",
"@pixi/ui": "^0.9.0",
"@types/offscreencanvas": "^2019.6.4",
"dayjs": "^1.11.10",
"gsap": "^3.12.2",
"pixi.js": "^7.1.1",
"rxjs": "^7.5.4",
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { SplashScreen } from '@capacitor/splash-screen';
import { PixijsComponent } from './components/pixijs/pixijs.component';

@Component({
selector: 'app-root',
standalone: true,
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
imports: [PixijsComponent],
})
export class AppComponent implements OnInit {
ngOnInit(): void {
Expand Down
16 changes: 0 additions & 16 deletions src/app/app.module.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/app/components/pixijs/pixijs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GameService } from '../../services/game.service';

@Component({
selector: 'app-pixijs',
standalone: true,
template: '',
providers: [GameService],
})
Expand All @@ -14,7 +15,7 @@ export class PixijsComponent implements OnInit {
) {
}

ngOnInit(): Promise<void> {
return this.ngZone.runOutsideAngular(() => this.pixiGame.init(this.elementRef));
async ngOnInit(): Promise<void> {
await this.ngZone.runOutsideAngular(() => this.pixiGame.init(this.elementRef));
}
}
8 changes: 7 additions & 1 deletion src/app/game-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface GameConfig extends Config {
enemy: {
autoSpawnSpeed: number;
},
meteor: {
autoSpawnSpeed: number;
},
ship: {
shotSpeed: number;
}
Expand All @@ -18,8 +21,11 @@ export const GAME_CONFIG: GameConfig = {
enemy: {
autoSpawnSpeed: 1.35, // per second
},
meteor: {
autoSpawnSpeed: 0.35, // per second
},
ship: {
shotSpeed: 3, // speed in pixel
shotSpeed: 6, // speed in pixel
},
powerUpConfig: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AnimatedSprite, FrameObject, Sprite, Texture } from 'pixi.js';
import { hit } from '../../utils/sprite.util';

export class GameSprite extends AnimatedSprite {
export class AnimatedGameSprite extends AnimatedSprite {
private readonly speed: number = 1;

constructor(
Expand All @@ -19,12 +20,6 @@ export class GameSprite extends AnimatedSprite {
}

hit(object2: Sprite): boolean {
const bounds1 = this.getBounds();
const bounds2 = object2.getBounds();

return bounds1.x < bounds2.x + bounds2.width
&& bounds1.x + bounds1.width > bounds2.x
&& bounds1.y < bounds2.y + bounds2.height
&& bounds1.y + bounds1.height > bounds2.y;
return hit(this, object2);
}
}
4 changes: 2 additions & 2 deletions src/app/models/pixijs/power-up-sprite.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { FrameObject, Texture } from 'pixi.js';
import { PowerUpConfig } from '../power-up-config.model';
import { GameSprite } from './game-sprite';
import { AnimatedGameSprite } from './animated-game-sprite';

export enum PowerUp {
speed,
shotSpeed,
shotPower,
}

export class PowerUpSprite extends GameSprite {
export class PowerUpSprite extends AnimatedGameSprite {
readonly config: PowerUpConfig;

constructor(speed: number, textures: Texture[] | FrameObject[], config: PowerUpConfig) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/models/pixijs/ship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GameSprite } from './game-sprite';
import { AnimatedGameSprite } from './animated-game-sprite';

export class Ship extends GameSprite {
export class Ship extends AnimatedGameSprite {
shotPower = 1;
shotSpeed = 1;

Expand Down
24 changes: 24 additions & 0 deletions src/app/models/pixijs/simple-game-sprite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Sprite, Texture } from 'pixi.js';
import { hit } from '../../utils/sprite.util';

export class GameSprite extends Sprite {
private readonly ySpeed: number;
private readonly xSpeed: number;

constructor(speed: number, texture: Texture) {
super(texture);

this.ySpeed = Math.random() * speed;
this.xSpeed = Math.random() * speed / 2;
}

update(delta: number): void {
this.rotation += 0.015 * delta;
this.y += delta * this.ySpeed;
this.x += delta * this.xSpeed;
}

hit(object2: Sprite): boolean {
return hit(this, object2);
}
}
14 changes: 10 additions & 4 deletions src/app/popups/highscore-popup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dayjs from 'dayjs';
import { GameService } from '../services/game.service';
import { StorageService } from '../services/storage.service';
import { Popup } from './popup';
Expand All @@ -14,13 +15,18 @@ export class HighscorePopup extends Popup {
override async show(): Promise<void> {
const highscore = await this.storage.getHighscore();
highscore.sort((a, b) => b.kills - a.kills);
for (let i = 0; i < Math.min(highscore.length, 5); i++) {

this.addText(this.panel, 'Datum', { size: 12 }, { y: -60, x: -60 });
this.addText(this.panel, 'Kills', { size: 12 }, { y: -60, x: 35 });
this.addText(this.panel, 'Level', { size: 12 }, { y: -60, x: 100 });

for (let i = 1; i <= Math.min(highscore.length, 5); i++) {
const dataSet = highscore[i];
const date = new Date(dataSet.date);
const dateString = `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}`;
const dateString = dayjs(date).format('DD.MM.YYYY HH:mm');
this.addText(this.panel, dateString, { size: 12 }, { y: -60 + i * 20, x: -60 });
this.addText(this.panel, dataSet.kills.toString(), { size: 12 }, { y: -60 + i * 20, x: 25 });
this.addText(this.panel, dataSet.level.toString(), { size: 12 }, { y: -60 + i * 20, x: 75 });
this.addText(this.panel, dataSet.kills.toString(), { size: 12 }, { y: -60 + i * 20, x: 35 });
this.addText(this.panel, dataSet.level.toString(), { size: 12 }, { y: -60 + i * 20, x: 100 });
}

await super.show();
Expand Down
2 changes: 1 addition & 1 deletion src/app/popups/your-are-dead-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class YouAreDeadPopup extends Popup {
this.addText(this.panel, 'Du bist gestorben', { size: 14 }, { y: -60 });
this.addText(this.panel, 'Du bist leider unterlegen\n\t und der Kampf ist vorbei', { size: 12 }, { y: -40 });
this.addText(this.panel, 'Punkte', { size: 14 }, { y: -10 });
this.addText(this.panel, gameService.kills.value.toString(), { size: 12 }, { y: 10 });
this.addText(this.panel, gameService.kills().toString(), { size: 12 }, { y: 10 });

this.addButton('Schließen!', () => gameService.endGame(this), 2, this.panel);
}
Expand Down
34 changes: 34 additions & 0 deletions src/app/services/base.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AnimatedSprite, Application, Assets, Spritesheet, Texture } from 'pixi.js';

export abstract class BaseService {
private explosionSprite!: Spritesheet;

protected constructor(protected readonly app: Application) {
}

protected async init(): Promise<void> {
this.explosionSprite = await Assets.load<Spritesheet>('assets/game/explosion.json');
}

protected explode(
x: number,
y: number,
oncomplete: (explosion: AnimatedSprite) => void = (): void => {
},
): void {
// explode
const animations: Record<string, Texture[]> = this.explosionSprite.animations;
const explosion = new AnimatedSprite(animations['explosion']);
explosion.animationSpeed = Math.min(.3, Math.max(0.1, Math.random()));
explosion.loop = false;
explosion.x = x;
explosion.y = y;
explosion.rotation = Math.random() * 360;
explosion.onComplete = (): void => {
oncomplete(explosion);
explosion.destroy();
};
this.app.stage.addChild(explosion);
explosion.play();
}
}
Loading

0 comments on commit 2ff82b8

Please sign in to comment.