├── src ├── assets │ ├── .gitkeep │ ├── hit.wav │ ├── bird.png │ ├── empty.png │ ├── enemy.png │ ├── fire.jpg │ ├── pong.png │ ├── pong2.jpg │ ├── colision.wav │ ├── explode.wav │ ├── fighter.png │ ├── fire_icon.png │ └── pong2_small.png ├── app │ ├── games │ │ ├── fire │ │ │ ├── fire.component.css │ │ │ ├── fire.component.html │ │ │ ├── model │ │ │ │ ├── Ship.ts │ │ │ │ ├── Shot.ts │ │ │ │ ├── Alien.ts │ │ │ │ ├── Dot.ts │ │ │ │ └── Health.ts │ │ │ └── fire.component.ts │ │ ├── pong │ │ │ ├── pong.component.css │ │ │ ├── pong.component.html │ │ │ ├── model │ │ │ │ ├── Paddle.ts │ │ │ │ ├── Brick.ts │ │ │ │ └── Ball.ts │ │ │ └── pong.component.ts │ │ ├── pong2 │ │ │ ├── pong2.component.css │ │ │ ├── pong2.component.html │ │ │ ├── model │ │ │ │ ├── Paddle.ts │ │ │ │ ├── Brick.ts │ │ │ │ └── Ball.ts │ │ │ └── pong2.component.ts │ │ ├── freestyle │ │ │ ├── freestyle.component.css │ │ │ ├── freestyle.component.html │ │ │ ├── model │ │ │ │ ├── Ship.ts │ │ │ │ ├── Shot.ts │ │ │ │ ├── Alien.ts │ │ │ │ ├── Dot.ts │ │ │ │ └── Health.ts │ │ │ └── freestyle.component.ts │ │ ├── games.component.css │ │ ├── games.component.ts │ │ ├── games.component.html │ │ └── games.ts │ ├── app.component.html │ ├── app.component.ts │ ├── app.component.css │ └── app.module.ts ├── styles.css ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── typings.d.ts ├── tsconfig.app.json ├── index.html ├── tsconfig.spec.json ├── main.ts └── polyfills.ts ├── _config.yml ├── .editorconfig ├── README.md ├── tsconfig.json ├── .gitignore ├── protractor.conf.js ├── karma.conf.js ├── .angular-cli.json ├── package.json └── tslint.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /src/app/games/fire/fire.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/games/pong/pong.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/games/pong2/pong2.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/games/freestyle/freestyle.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | }; 4 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/assets/hit.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/hit.wav -------------------------------------------------------------------------------- /src/assets/bird.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/bird.png -------------------------------------------------------------------------------- /src/assets/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/empty.png -------------------------------------------------------------------------------- /src/assets/enemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/enemy.png -------------------------------------------------------------------------------- /src/assets/fire.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/fire.jpg -------------------------------------------------------------------------------- /src/assets/pong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/pong.png -------------------------------------------------------------------------------- /src/assets/pong2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/pong2.jpg -------------------------------------------------------------------------------- /src/assets/colision.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/colision.wav -------------------------------------------------------------------------------- /src/assets/explode.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/explode.wav -------------------------------------------------------------------------------- /src/assets/fighter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/fighter.png -------------------------------------------------------------------------------- /src/assets/fire_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/fire_icon.png -------------------------------------------------------------------------------- /src/assets/pong2_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avraampiperidis/excaliburJsAngular4/HEAD/src/assets/pong2_small.png -------------------------------------------------------------------------------- /src/app/games/fire/fire.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/games/pong/pong.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/games/pong2/pong2.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/app/games/freestyle/freestyle.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/app/games/games.component.css: -------------------------------------------------------------------------------- 1 | .example-card { 2 | width: 185px; 3 | } 4 | 5 | .example-header-image { 6 | background-size: cover; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/app/games/pong/model/Paddle.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as ex from "excalibur/dist/excalibur"; 4 | 5 | export class Paddle extends ex.Actor { 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/app/games/fire/model/Ship.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Ship extends ex.Actor { 5 | description:string; 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | } -------------------------------------------------------------------------------- /src/app/games/fire/model/Shot.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Shot extends ex.Actor { 5 | description:string; 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | } -------------------------------------------------------------------------------- /src/app/games/pong2/model/Paddle.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as ex from "excalibur/dist/excalibur"; 4 | 5 | export class Paddle extends ex.Actor { 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/app/games/freestyle/model/Ship.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Ship extends ex.Actor { 5 | description:string; 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | } -------------------------------------------------------------------------------- /src/app/games/freestyle/model/Shot.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Shot extends ex.Actor { 5 | description:string; 6 | 7 | constructor(x:number,y:number,width?:number,height?:number) { 8 | super(x,y,width,height); 9 | } 10 | } -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/app/games/pong/model/Brick.ts: -------------------------------------------------------------------------------- 1 | 2 | import * as ex from "excalibur/dist/excalibur"; 3 | 4 | export class Brick extends ex.Actor { 5 | 6 | constructor(x:number,y:number,width?:number,height?:number,color?:ex.Color) { 7 | super(x,y,width,height,color); 8 | } 9 | 10 | 11 | } -------------------------------------------------------------------------------- /src/app/games/pong2/model/Brick.ts: -------------------------------------------------------------------------------- 1 | 2 | import * as ex from "excalibur/dist/excalibur"; 3 | 4 | export class Brick extends ex.Actor { 5 | 6 | constructor(x:number,y:number,width?:number,height?:number,color?:ex.Color) { 7 | super(x,y,width,height,color); 8 | } 9 | 10 | 11 | } -------------------------------------------------------------------------------- /src/app/games/fire/model/Alien.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Alien extends ex.Actor { 5 | 6 | description:string; 7 | 8 | constructor(x:number,y:number,width?:number,height?:number) { 9 | super(x,y,width,height); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /src/app/games/pong/model/Ball.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as ex from "excalibur/dist/excalibur"; 4 | 5 | export class Ball extends ex.Actor { 6 | 7 | description:string; 8 | 9 | constructor(x:number,y:number,width?:number,height?:number) { 10 | super(x,y,width,height); 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /src/app/games/pong2/model/Ball.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import * as ex from "excalibur/dist/excalibur"; 4 | 5 | export class Ball extends ex.Actor { 6 | 7 | description:string; 8 | 9 | constructor(x:number,y:number,width?:number,height?:number) { 10 | super(x,y,width,height); 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /src/app/games/fire/model/Dot.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | 5 | export class Dot extends ex.Actor { 6 | 7 | description:string; 8 | 9 | constructor(x:number,y:number,width?:number,height?:number) { 10 | super(x,y,width,height); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /src/app/games/freestyle/model/Alien.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | export class Alien extends ex.Actor { 5 | 6 | description:string; 7 | 8 | constructor(x:number,y:number,width?:number,height?:number) { 9 | super(x,y,width,height); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /src/app/games/freestyle/model/Dot.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | 5 | export class Dot extends ex.Actor { 6 | 7 | description:string; 8 | 9 | constructor(x:number,y:number,width?:number,height?:number) { 10 | super(x,y,width,height); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /src/app/games/fire/model/Health.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | 5 | export class Health extends ex.Actor { 6 | 7 | description:string; 8 | health:number = 100; 9 | 10 | constructor(x:number,y:number,width?:number,height?:number) { 11 | super(x,y,width,height); 12 | } 13 | 14 | 15 | 16 | } -------------------------------------------------------------------------------- /src/app/games/freestyle/model/Health.ts: -------------------------------------------------------------------------------- 1 | import * as ex from "excalibur"; 2 | 3 | 4 | 5 | export class Health extends ex.Actor { 6 | 7 | description:string; 8 | health:number = 100; 9 | 10 | constructor(x:number,y:number,width?:number,height?:number) { 11 | super(x,y,width,height); 12 | } 13 | 14 | 15 | 16 | } -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Game 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Game 3 | 4 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 5 | 6 | ## Build 7 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 8 | 9 | # excaliburJsAngular *for university course 10 | excaliburJs games in angular 4 11 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false, 8 | }; 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component,OnInit } from '@angular/core'; 2 | import { Router } from "@angular/router"; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent implements OnInit { 10 | 11 | constructor(private router:Router) { 12 | router.navigate(['games']); 13 | } 14 | 15 | ngOnInit(): void { 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0%; 3 | } 4 | 5 | .container { 6 | display: flex; 7 | display: -ms-flexbox; 8 | display: -webkit-flex; 9 | -webkit-flex-flow: row wrap; 10 | flex-flow: row wrap; 11 | min-height: 10px; 12 | flex-direction: column; 13 | } 14 | 15 | .sidenav-container { 16 | width: 100%; 17 | height: 100%; 18 | border: 1px solid rgba(0, 0, 0, 0.5); 19 | } 20 | 21 | .sidenav-md { 22 | padding: 20px; 23 | } 24 | 25 | .side-nav-button { 26 | display: flex; 27 | height: 100%; 28 | align-items: flex-start; 29 | justify-content: flex-start; 30 | background-color: transparent; 31 | } -------------------------------------------------------------------------------- /src/app/games/games.component.ts: -------------------------------------------------------------------------------- 1 | import { Component,OnInit } from '@angular/core'; 2 | import { Router } from "@angular/router"; 3 | import {games} from "./games" 4 | import {Message} from 'primeng/primeng'; 5 | 6 | @Component({ 7 | templateUrl: './games.component.html', 8 | styleUrls: ['./games.component.css'] 9 | }) 10 | export class GamesComponent implements OnInit { 11 | 12 | myGames = games; 13 | msg: Message[] = []; 14 | 15 | constructor(private router:Router) { 16 | } 17 | 18 | ngOnInit(): void { 19 | } 20 | 21 | 22 | loadGame(url:string) { 23 | if(url){ 24 | this.router.navigate([url]); 25 | } 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | #/dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/app/games/games.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 |
8 | {{game.title}} 9 | {{game.id}} 10 |
11 | Photo of a pong game 12 | 13 |

14 | {{game.description}} 15 |

16 |
17 | 18 | 19 | 20 |
21 | 22 |
23 |
24 |
25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "game" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "css", 58 | "component": {} 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "game", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^4.4.3", 16 | "@angular/cdk": "^2.0.0-beta.12", 17 | "@angular/common": "^4.2.4", 18 | "@angular/compiler": "^4.2.4", 19 | "@angular/core": "^4.2.4", 20 | "@angular/forms": "^4.2.4", 21 | "@angular/http": "^4.2.4", 22 | "@angular/material": "^2.0.0-beta.12", 23 | "@angular/platform-browser": "^4.2.4", 24 | "@angular/platform-browser-dynamic": "^4.2.4", 25 | "@angular/router": "^4.2.4", 26 | "core-js": "^2.4.1", 27 | "primeng": "^4.2.1", 28 | "rxjs": "^5.4.2", 29 | "zone.js": "^0.8.14" 30 | }, 31 | "devDependencies": { 32 | "@angular/cli": "1.4.3", 33 | "@angular/compiler-cli": "^4.2.4", 34 | "@angular/language-service": "^4.2.4", 35 | "@types/jasmine": "~2.5.53", 36 | "@types/jasminewd2": "~2.0.2", 37 | "codelyzer": "~3.1.1", 38 | "jasmine-core": "~2.6.2", 39 | "jasmine-spec-reporter": "~4.1.0", 40 | "karma": "~1.7.0", 41 | "karma-chrome-launcher": "~2.1.1", 42 | "karma-cli": "~1.0.1", 43 | "karma-coverage-istanbul-reporter": "^1.2.1", 44 | "karma-jasmine": "~1.1.0", 45 | "karma-jasmine-html-reporter": "^0.2.2", 46 | "protractor": "~5.1.2", 47 | "tslint": "~5.3.2", 48 | "concurrently": "^3.0.0", 49 | "excalibur": "^0.12.1", 50 | "typescript": "~2.3.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/games/games.ts: -------------------------------------------------------------------------------- 1 | 2 | //Mock Game Data 3 | export const games = [ 4 | { 5 | title:'Pong', 6 | description:'This is a sample brick breaking game.', 7 | icon:'/assets/pong.png', 8 | iconAlt:'/assets/pong.png', 9 | iconSmall:'/assets/pong.png', 10 | url:'/pong', 11 | extra:'', 12 | id:1 13 | }, 14 | { 15 | title:'Pong2Ball', 16 | description:'Pong with a multiplier brick ball', 17 | icon:'/assets/pong2.jpg', 18 | iconAlt:'/assets/pong2.jpg', 19 | iconSmall:'/assets/pong2_small.png', 20 | url:'/pong2', 21 | extra:'', 22 | id:2 23 | }, 24 | { 25 | title:'Fire Shot!', 26 | description:'Kill the aliens Arcade!', 27 | icon:'/assets/fire.jpg', 28 | iconAlt:'/assets/fire_icon.png', 29 | iconSmall:'/assets/fire_icon.png', 30 | url:'/fire', 31 | extra:'', 32 | id:3 33 | }, 34 | { 35 | title:'Freestyle', 36 | description:'Game Description goes here', 37 | icon:'/assets/pong.png', 38 | iconAlt:'/assets/pong.png', 39 | iconSmall:'/assets/empty.png', 40 | url:'/freestyle', 41 | extra:'', 42 | id:4 43 | }, 44 | { 45 | title:'Empty', 46 | description:'Game Description goes here', 47 | icon:'/assets/pong.png', 48 | iconAlt:'/assets/pong.png', 49 | iconSmall:'/assets/empty.png', 50 | url:'', 51 | extra:'', 52 | id:5 53 | }, 54 | { 55 | title:'Empty', 56 | description:'Game Description goes here', 57 | icon:'/assets/pong.png', 58 | iconAlt:'/assets/pong.png', 59 | iconSmall:'/assets/empty.png', 60 | url:'', 61 | extra:'', 62 | id:6 63 | } 64 | ]; -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import {HttpClientModule} from '@angular/common/http'; 4 | import { RouterModule, Routes } from '@angular/router'; 5 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; 6 | import {MatButtonModule,MatDialogModule, MatCheckboxModule , MatCardModule , MatGridListModule, MatSnackBarModule } from '@angular/material'; 7 | 8 | //main components 9 | import { AppComponent } from './app.component'; 10 | import { PongComponent } from "./games/pong/pong.component"; 11 | import { GamesComponent } from "./games/games.component"; 12 | import { PongComponent2 } from './games/pong2/pong2.component'; 13 | import { FireComponent } from './games/fire/fire.component'; 14 | import { FreestyleComponent } from './games/freestyle/freestyle.component'; 15 | 16 | const routes: Routes = [ 17 | { 18 | path: 'pong', 19 | component: PongComponent, 20 | }, 21 | { 22 | path: 'pong2', 23 | component:PongComponent2 24 | }, 25 | { 26 | path: 'fire', 27 | component:FireComponent 28 | }, 29 | { 30 | path: 'freestyle', 31 | component:FreestyleComponent 32 | }, 33 | { 34 | path:'games', 35 | component:GamesComponent 36 | } 37 | ]; 38 | 39 | @NgModule({ 40 | declarations: [ 41 | AppComponent, 42 | PongComponent, 43 | PongComponent2, 44 | FireComponent, 45 | FreestyleComponent, 46 | GamesComponent 47 | ], 48 | imports: [ 49 | BrowserModule, 50 | HttpClientModule, 51 | RouterModule, 52 | RouterModule.forRoot(routes), 53 | BrowserAnimationsModule, 54 | MatButtonModule, 55 | MatCheckboxModule, 56 | MatCardModule, 57 | MatGridListModule, 58 | MatDialogModule, 59 | ], 60 | providers: [], 61 | bootstrap: [AppComponent], 62 | exports:[RouterModule] 63 | }) 64 | 65 | export class AppModule { 66 | } 67 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** Evergreen browsers require these. **/ 41 | import 'core-js/es6/reflect'; 42 | import 'core-js/es7/reflect'; 43 | 44 | 45 | /** 46 | * Required to support Web Animations `@angular/platform-browser/animations`. 47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 48 | **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | /** 70 | * Need to import at least one locale-data with intl. 71 | */ 72 | // import 'intl/locale-data/jsonp/en'; 73 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs" 19 | ], 20 | "import-spacing": true, 21 | "indent": [ 22 | true, 23 | "spaces" 24 | ], 25 | "interface-over-type-literal": true, 26 | "label-position": true, 27 | "max-line-length": [ 28 | true, 29 | 140 30 | ], 31 | "member-access": false, 32 | "member-ordering": [ 33 | true, 34 | { 35 | "order": [ 36 | "static-field", 37 | "instance-field", 38 | "static-method", 39 | "instance-method" 40 | ] 41 | } 42 | ], 43 | "no-arg": true, 44 | "no-bitwise": true, 45 | "no-console": [ 46 | true, 47 | "debug", 48 | "info", 49 | "time", 50 | "timeEnd", 51 | "trace" 52 | ], 53 | "no-construct": true, 54 | "no-debugger": true, 55 | "no-duplicate-super": true, 56 | "no-empty": false, 57 | "no-empty-interface": true, 58 | "no-eval": true, 59 | "no-inferrable-types": [ 60 | true, 61 | "ignore-params" 62 | ], 63 | "no-misused-new": true, 64 | "no-non-null-assertion": true, 65 | "no-shadowed-variable": true, 66 | "no-string-literal": false, 67 | "no-string-throw": true, 68 | "no-switch-case-fall-through": true, 69 | "no-trailing-whitespace": true, 70 | "no-unnecessary-initializer": true, 71 | "no-unused-expression": true, 72 | "no-use-before-declare": true, 73 | "no-var-keyword": true, 74 | "object-literal-sort-keys": false, 75 | "one-line": [ 76 | true, 77 | "check-open-brace", 78 | "check-catch", 79 | "check-else", 80 | "check-whitespace" 81 | ], 82 | "prefer-const": true, 83 | "quotemark": [ 84 | true, 85 | "single" 86 | ], 87 | "radix": true, 88 | "semicolon": [ 89 | true, 90 | "always" 91 | ], 92 | "triple-equals": [ 93 | true, 94 | "allow-null-check" 95 | ], 96 | "typedef-whitespace": [ 97 | true, 98 | { 99 | "call-signature": "nospace", 100 | "index-signature": "nospace", 101 | "parameter": "nospace", 102 | "property-declaration": "nospace", 103 | "variable-declaration": "nospace" 104 | } 105 | ], 106 | "typeof-compare": true, 107 | "unified-signatures": true, 108 | "variable-name": false, 109 | "whitespace": [ 110 | true, 111 | "check-branch", 112 | "check-decl", 113 | "check-operator", 114 | "check-separator", 115 | "check-type" 116 | ], 117 | "directive-selector": [ 118 | true, 119 | "attribute", 120 | "app", 121 | "camelCase" 122 | ], 123 | "component-selector": [ 124 | true, 125 | "element", 126 | "app", 127 | "kebab-case" 128 | ], 129 | "use-input-property-decorator": true, 130 | "use-output-property-decorator": true, 131 | "use-host-property-decorator": true, 132 | "no-input-rename": true, 133 | "no-output-rename": true, 134 | "use-life-cycle-interface": true, 135 | "use-pipe-transform-interface": true, 136 | "component-class-suffix": true, 137 | "directive-class-suffix": true, 138 | "invoke-injectable": true 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/app/games/freestyle/freestyle.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { Ship } from "./model/Ship"; 3 | import { Shot } from "./model/Shot"; 4 | import { Alien } from "./model/Alien"; 5 | import * as ex from "excalibur"; 6 | import { PointerButton } from "Input/Index"; 7 | import { Dot } from "./model/Dot"; 8 | import { Health } from "./model/Health"; 9 | 10 | 11 | 12 | 13 | @Component({ 14 | templateUrl: 'freestyle.component.html', 15 | styleUrls: ['freestyle.component.css'] 16 | }) 17 | export class FreestyleComponent implements OnInit { 18 | 19 | title = 'kill the aliens Game!'; 20 | game:ex.Engine; 21 | ship:Ship; 22 | shots:Shot; 23 | aliens:Alien[] = []; 24 | health:Health; 25 | message:string; 26 | 27 | randomeAlienSpaceFrom:number = 550; 28 | randomeAlienSpaceTo:number = 1500; 29 | alienSpeedStar:number = 100; 30 | 31 | constructor() { 32 | } 33 | 34 | goHome() { 35 | window.location.href = '/'; 36 | } 37 | 38 | ngOnInit(): void { 39 | this.game = new ex.Engine({ 40 | width: window.screen.width/1.5, 41 | height: window.screen.height/1.5 42 | }); 43 | this.game.backgroundColor = ex.Color.fromHex('06032c'); 44 | 45 | this.game.start(); 46 | 47 | this.addSpaceShip(); 48 | this.setSpaceShipMovement(); 49 | this.setHealthBar(); 50 | this.addAliens(); 51 | this.setSpaceBackgroundMovement(); 52 | } 53 | 54 | setHealthBar() { 55 | this.health = new Health(this.game.getDrawWidth()-110,20, 200, 20); 56 | this.health.color = ex.Color.Cyan; 57 | this.health.collisionType = ex.CollisionType.PreventCollision; 58 | this.game.add(this.health); 59 | } 60 | 61 | addSpaceShip() { 62 | this.ship = new Ship(150,this.game.getDrawHeight()-40,30,40); 63 | this.ship.color = ex.Color.Red; 64 | this.ship.collisionType = ex.CollisionType.Fixed; 65 | this.game.add(this.ship); 66 | } 67 | 68 | setSpaceShipMovement() { 69 | this.game.input.pointers.primary.on('move',(event:PointerEvent)=> { 70 | this.ship.pos.x = event.x; 71 | }); 72 | 73 | this.game.input.pointers.primary.on('down',(event:PointerEvent)=> { 74 | this.shotFire(event.x); 75 | }); 76 | } 77 | 78 | 79 | async addAliens() { 80 | while(true) { 81 | await this.sleep(this.getRandomeBetween(this.randomeAlienSpaceFrom,this.randomeAlienSpaceTo)); 82 | 83 | // if(this.randomeAlienSpaceFrom > 0) { 84 | // this.randomeAlienSpaceFrom = --this.randomeAlienSpaceFrom -20; 85 | // this.randomeAlienSpaceTo = --this.randomeAlienSpaceTo - 40; 86 | // } 87 | 88 | let alien = new Alien(this.getRandomeBetween(50,600),0,30,30); 89 | alien.color = ex.Color.Orange; 90 | alien.vel.setTo(0,this.alienSpeedStar); 91 | alien.collisionType = ex.CollisionType.Active; 92 | alien.on('collision',(event:any)=> { 93 | if(event.other instanceof Shot) { 94 | alien.kill(); 95 | alien.remove; 96 | } else if(event.other instanceof Ship) { 97 | 98 | } 99 | }); 100 | this.alienSpeedStar += 10; 101 | this.game.add(alien); 102 | } 103 | } 104 | 105 | shotFire(x:number) { 106 | let shot = new Shot(x,this.game.getDrawHeight(),10,10); 107 | shot.color = ex.Color.Red; 108 | shot.vel.setTo(0,-1000); 109 | shot.collisionType = ex.CollisionType.Passive; 110 | this.game.add(shot); 111 | } 112 | 113 | 114 | async setSpaceBackgroundMovement() { 115 | while(true) { 116 | 117 | //apo Dot(0-500,0,4,4) 118 | //Dot(0,500,4,4) 119 | for(let x =1; x <= 650; x = x+4){ 120 | await this.sleep(20); 121 | let rand = 0; 122 | if((x*2) > 750) { 123 | rand = this.getRandomeBetween(0,x); 124 | } else { 125 | rand = this.getRandomeBetween(x,x*2); 126 | } 127 | let dotx = new Dot(rand,this.getRandomeBetween(1,50),3,3); 128 | dotx.color = ex.Color.DarkGray; 129 | dotx.vel.setTo(550,550); 130 | dotx.collisionType = ex.CollisionType.PreventCollision; 131 | this.game.add(dotx); 132 | 133 | await this.sleep(20); 134 | let doty = new Dot(this.getRandomeBetween(1,50),rand,3,3); 135 | doty.color = ex.Color.DarkGray; 136 | doty.vel.setTo(450,450); 137 | doty.collisionType = ex.CollisionType.PreventCollision; 138 | this.game.add(doty); 139 | } 140 | 141 | } 142 | } 143 | 144 | sleep(ms) { 145 | return new Promise(resolve => setTimeout(resolve, ms)); 146 | } 147 | 148 | getRandomeBetween(first:number,sec:number) { 149 | return Math.floor(Math.random() * sec) + first; 150 | } 151 | 152 | } -------------------------------------------------------------------------------- /src/app/games/pong/pong.component.ts: -------------------------------------------------------------------------------- 1 | import { Component,OnInit } from '@angular/core'; 2 | import * as ex from 'excalibur'; 3 | import { Ball } from "./model/Ball"; 4 | import { Brick } from "./model/Brick"; 5 | import { Events } from "excalibur"; 6 | import { Paddle } from "./model/Paddle"; 7 | import { delay } from "q"; 8 | 9 | @Component({ 10 | templateUrl: 'pong.component.html', 11 | styleUrls: ['pong.component.css'] 12 | }) 13 | export class PongComponent implements OnInit { 14 | 15 | title = 'My Pong Game!'; 16 | game:ex.Engine; 17 | paddle:Paddle; 18 | balls:Ball[] = []; 19 | bricks:Brick[] = []; 20 | message:string; 21 | 22 | constructor() { 23 | } 24 | 25 | goHome() { 26 | window.location.href = '/'; 27 | } 28 | 29 | 30 | 31 | ngOnInit(): void { 32 | this.game = new ex.Engine({ 33 | width: window.screen.width/1.5, 34 | height: window.screen.height/1.5 35 | }); 36 | 37 | this.game.start(); 38 | this.addPaddle(); 39 | this.setPaddleMovement(); 40 | this.addBricks(); 41 | let ball = this.addBall(); 42 | ball.description = "a simple ball"; 43 | this.game.add(this.setBallEvents(ball)); 44 | } 45 | 46 | 47 | addPaddle() { 48 | this.paddle = new Paddle(150, this.game.getDrawHeight() - 40, 200, 20); 49 | this.paddle.color = ex.Color.Chartreuse; 50 | this.paddle.collisionType = ex.CollisionType.Fixed; 51 | this.game.add(this.paddle); 52 | } 53 | 54 | setPaddleMovement() { 55 | this.game.input.pointers.primary.on('move',(event:PointerEvent)=> { 56 | //pad.pos.x = event.x; 57 | this.paddle.pos.x = event.x; 58 | }); 59 | } 60 | 61 | addBall() : Ball { 62 | let ball = new Ball(this.getRandomStartPosition(),300,15,15); 63 | ball.color = this.getRandomColor(); 64 | ball.vel.setTo(150,150); 65 | ball.collisionType = ex.CollisionType.Passive; 66 | return ball; 67 | } 68 | 69 | addBricks() { 70 | // Padding between bricks 71 | let padding = 5; // px 72 | let xoffset = 35; // x-offset 73 | let yoffset = 20; // y-offset 74 | let columns = 10; 75 | let rows = 5; 76 | let brickColor = [ex.Color.Violet, ex.Color.Orange, ex.Color.Yellow]; 77 | // Individual brick width with padding factored in 78 | let brickWidth = this.game.getDrawWidth() / columns - padding - padding/columns; // px 79 | let brickHeight = 10; // px 80 | for (let j = 0; j < rows; j++) { 81 | for (let i = 0; i < columns; i++) { 82 | this.bricks.push(new ex.Actor(xoffset + i * (brickWidth + padding) + padding, yoffset + j * (brickHeight + padding) + padding, brickWidth, brickHeight, brickColor[j % brickColor.length])); 83 | } 84 | } 85 | 86 | this.bricks.forEach((brick) => { 87 | // Make sure that bricks can participate in collisions 88 | brick.collisionType = ex.CollisionType.Active; 89 | // Add the brick to the current scene to be drawn 90 | this.game.add(brick); 91 | }); 92 | } 93 | 94 | setBallEvents(ball:Ball) { 95 | ball.on('update',(event:any) => { 96 | if(event.other instanceof Ball){ 97 | return; 98 | } 99 | if (event.target.pos.x < (event.target.getWidth() / 2)) { 100 | event.target.vel.x *= -1; 101 | } 102 | // If the ball collides with the right side 103 | // of the screen reverse the x velocity 104 | if (event.target.pos.x + (event.target.getWidth() / 2) > this.game.getDrawWidth()) { 105 | event.target.vel.x *= -1; 106 | } 107 | // If the ball collides with the top 108 | // of the screen reverse the y velocity 109 | if (event.target.pos.y < (event.target.getHeight() / 2)) { 110 | event.target.vel.y *= -1; 111 | } 112 | }); 113 | 114 | ball.on('collision',(event:any) => { 115 | if(event.other instanceof Ball){ 116 | return; 117 | } 118 | 119 | 120 | if(this.bricks.indexOf(event.other) > -1) { 121 | // kill removes an actor from the current scene 122 | // therefore it will no longer be drawn or updated 123 | if(!event.other.isKilled()) { 124 | event.other.kill(); 125 | } 126 | } 127 | 128 | let intersection =event.intersection.normalize(); 129 | // The largest component of intersection is our axis to flip 130 | if (Math.abs(intersection.x) > Math.abs(intersection.y)) { 131 | ball.vel.x *= -1; 132 | } else { 133 | 134 | ball.vel.y *= -1; 135 | } 136 | }); 137 | 138 | ball.on('exitviewport', () =>{ 139 | //alert('You lose!'); 140 | //do stuff 141 | ball.kill(); 142 | }); 143 | 144 | return ball; 145 | } 146 | 147 | 148 | 149 | 150 | getRandomColor():ex.Color { 151 | let rand = Math.floor(Math.random() * 4) +1; 152 | if(rand == 1){ 153 | return ex.Color.Red; 154 | } else if(rand == 2){ 155 | return ex.Color.Green; 156 | } else if(rand == 3){ 157 | return ex.Color.Yellow; 158 | } else{ 159 | return ex.Color.Cyan; 160 | } 161 | } 162 | 163 | getRandomStartPosition() { 164 | let rand = Math.floor(Math.random() * 400) +50; 165 | return rand; 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /src/app/games/pong2/pong2.component.ts: -------------------------------------------------------------------------------- 1 | import { Component,OnInit } from '@angular/core'; 2 | import * as ex from 'excalibur'; 3 | import { Ball } from "./model/Ball"; 4 | import { Brick } from "./model/Brick"; 5 | import { Events } from "excalibur"; 6 | import { Paddle } from "./model/Paddle"; 7 | import { delay } from "q"; 8 | 9 | @Component({ 10 | templateUrl: 'pong2.component.html', 11 | styleUrls: ['pong2.component.css'] 12 | }) 13 | export class PongComponent2 implements OnInit { 14 | 15 | title = 'My Game!'; 16 | game:ex.Engine; 17 | paddle:Paddle; 18 | balls:Ball[]; 19 | bricks:Brick[] = []; 20 | message:string; 21 | 22 | constructor() { 23 | } 24 | 25 | goHome() { 26 | window.location.href = '/'; 27 | } 28 | 29 | 30 | 31 | ngOnInit(): void { 32 | this.balls = []; 33 | this.game = new ex.Engine({ 34 | width: window.screen.width/1.5, 35 | height: window.screen.height/1.5 36 | }); 37 | 38 | this.game.start(); 39 | this.addPaddle(); 40 | this.setPaddleMovement(); 41 | this.addBricks(); 42 | for(let i =0; i < 20; i++){ 43 | let ball = this.addBall(); 44 | ball.description = "a simple ball"; 45 | this.balls.push(ball); 46 | } 47 | 48 | this.game.add(this.setBallEvents(this.balls.pop())); 49 | //let ball = this.addBall(); 50 | //this.setBallEvents(this.addBall()); 51 | } 52 | 53 | 54 | addPaddle() { 55 | this.paddle = new Paddle(150, this.game.getDrawHeight() - 40, 200, 20); 56 | this.paddle.color = ex.Color.Chartreuse; 57 | this.paddle.collisionType = ex.CollisionType.Fixed; 58 | this.game.add(this.paddle); 59 | } 60 | 61 | setPaddleMovement() { 62 | this.game.input.pointers.primary.on('move',(event:PointerEvent)=> { 63 | //pad.pos.x = event.x; 64 | this.paddle.pos.x = event.x; 65 | }); 66 | } 67 | 68 | addBall() : Ball { 69 | let ball = new Ball(this.getRandomStartPosition(),300,15,15); 70 | ball.color = this.getRandomColor(); 71 | ball.vel.setTo(150,150); 72 | ball.collisionType = ex.CollisionType.Passive; 73 | return ball; 74 | } 75 | 76 | addBricks() { 77 | // Padding between bricks 78 | let padding = 5; // px 79 | let xoffset = 35; // x-offset 80 | let yoffset = 20; // y-offset 81 | let columns = 10; 82 | let rows = 5; 83 | let brickColor = [ex.Color.Violet, ex.Color.Orange, ex.Color.Yellow]; 84 | // Individual brick width with padding factored in 85 | let brickWidth = this.game.getDrawWidth() / columns - padding - padding/columns; // px 86 | let brickHeight = 10; // px 87 | for (let j = 0; j < rows; j++) { 88 | for (let i = 0; i < columns; i++) { 89 | this.bricks.push(new ex.Actor(xoffset + i * (brickWidth + padding) + padding, yoffset + j * (brickHeight + padding) + padding, brickWidth, brickHeight, brickColor[j % brickColor.length])); 90 | } 91 | } 92 | 93 | this.bricks.forEach((brick) => { 94 | // Make sure that bricks can participate in collisions 95 | brick.collisionType = ex.CollisionType.Active; 96 | // Add the brick to the current scene to be drawn 97 | this.game.add(brick); 98 | }); 99 | } 100 | 101 | setBallEvents(ball:Ball) { 102 | ball.on('update',(event:any) => { 103 | if(event.other instanceof Ball){ 104 | return; 105 | } 106 | if (event.target.pos.x < (event.target.getWidth() / 2)) { 107 | event.target.vel.x *= -1; 108 | } 109 | // If the ball collides with the right side 110 | // of the screen reverse the x velocity 111 | if (event.target.pos.x + (event.target.getWidth() / 2) > this.game.getDrawWidth()) { 112 | event.target.vel.x *= -1; 113 | } 114 | // If the ball collides with the top 115 | // of the screen reverse the y velocity 116 | if (event.target.pos.y < (event.target.getHeight() / 2)) { 117 | event.target.vel.y *= -1; 118 | } 119 | }); 120 | 121 | ball.on('collision',(event:any) => { 122 | if(event.other instanceof Ball){ 123 | return; 124 | } 125 | 126 | 127 | if(this.bricks.indexOf(event.other) > -1) { 128 | // kill removes an actor from the current scene 129 | // therefore it will no longer be drawn or updated 130 | if(!event.other.isKilled()) { 131 | event.other.kill(); 132 | if(event.other.isKilled()) { 133 | if(this.balls.length > 0){ 134 | 135 | this.game.add(this.setBallEvents(this.balls.pop())); 136 | } 137 | } 138 | } 139 | 140 | if(ball.vel.x > 0){ 141 | ball.vel.x += 15; 142 | } else { 143 | ball.vel.x -= 15; 144 | } 145 | if(ball.vel.y > 0){ 146 | ball.vel.y += 15; 147 | } else { 148 | ball.vel.y -=15; 149 | } 150 | 151 | //this.game.add(this.balls.pop()); 152 | // if(this.balls.length <= 5){ 153 | // this.setBallEvents(this.addBall()); 154 | // } 155 | 156 | } 157 | 158 | let intersection =event.intersection.normalize(); 159 | // The largest component of intersection is our axis to flip 160 | if (Math.abs(intersection.x) > Math.abs(intersection.y)) { 161 | ball.vel.x *= -1; 162 | } else { 163 | 164 | ball.vel.y *= -1; 165 | } 166 | }); 167 | 168 | ball.on('exitviewport', () =>{ 169 | //alert('You lose!'); 170 | //do stuff 171 | ball.kill(); 172 | }); 173 | 174 | return ball; 175 | } 176 | 177 | 178 | 179 | 180 | 181 | 182 | getRandomColor():ex.Color { 183 | let rand = Math.floor(Math.random() * 4) +1; 184 | if(rand == 1){ 185 | return ex.Color.Red; 186 | } else if(rand == 2){ 187 | return ex.Color.Green; 188 | } else if(rand == 3){ 189 | return ex.Color.Yellow; 190 | } else{ 191 | return ex.Color.Cyan; 192 | } 193 | } 194 | 195 | getRandomStartPosition() { 196 | let rand = Math.floor(Math.random() * 400) +50; 197 | return rand; 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /src/app/games/fire/fire.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Inject } from "@angular/core"; 2 | import { Ship } from "./model/Ship"; 3 | import { Shot } from "./model/Shot"; 4 | import { Alien } from "./model/Alien"; 5 | import * as ex from "excalibur"; 6 | import { PointerButton } from "Input/Index"; 7 | import { Dot } from "./model/Dot"; 8 | import { Health } from "./model/Health"; 9 | 10 | 11 | @Component({ 12 | templateUrl: 'fire.component.html', 13 | styleUrls: ['fire.component.css'] 14 | }) 15 | export class FireComponent implements OnInit { 16 | 17 | title = 'kill the aliens Game!'; 18 | game:ex.Engine; 19 | ship:Ship; 20 | shots:Shot; 21 | aliens:Alien[] = []; 22 | health:Health; 23 | message:string; 24 | 25 | enemyTexture:ex.Texture = new ex.Texture('assets/enemy.png'); 26 | fighterTexture = new ex.Texture('assets/fighter.png'); 27 | birdTexture = new ex.Texture('assets/bird.png'); 28 | explodeSound = new ex.Sound('assets/explode.wav'); 29 | hitSound = new ex.Sound('assets/hit.wav'); 30 | colisionSound = new ex.Sound('assets/colision.wav'); 31 | loader:ex.Loader = new ex.Loader([this.enemyTexture,this.fighterTexture,this.birdTexture,this.explodeSound,this.hitSound,this.colisionSound]); 32 | 33 | randomeAlienSpaceFrom:number = 550; 34 | randomeAlienSpaceTo:number = 1500; 35 | alienSpeedStar:number = 100; 36 | 37 | constructor() { 38 | } 39 | 40 | goHome() { 41 | window.location.href = '/'; 42 | } 43 | 44 | ngOnInit(): void { 45 | console.log(this.fighterTexture); 46 | this.game = new ex.Engine({ 47 | width: window.screen.width/1.5, 48 | height: window.screen.height/1.5 49 | }); 50 | this.game.backgroundColor = ex.Color.fromHex('06032c'); 51 | this.game.start(this.loader); 52 | 53 | this.addSpaceShip(); 54 | this.setSpaceShipMovement(); 55 | this.setHealthBar(); 56 | this.addAliens(); 57 | this.setSpaceBackgroundMovement(); 58 | } 59 | 60 | setHealthBar() { 61 | this.health = new Health(this.game.getDrawWidth()-110,20, 200, 20); 62 | this.health.color = ex.Color.Cyan; 63 | this.health.collisionType = ex.CollisionType.PreventCollision; 64 | this.game.add(this.health); 65 | } 66 | 67 | addSpaceShip() { 68 | this.ship = new Ship(150,this.game.getDrawHeight()-40,40,40); 69 | this.ship.color = ex.Color.Red; 70 | this.ship.collisionType = ex.CollisionType.Fixed; 71 | this.ship.addDrawing(this.fighterTexture); 72 | this.game.add(this.ship); 73 | } 74 | 75 | setSpaceShipMovement() { 76 | this.game.input.pointers.primary.on('move',(event:PointerEvent)=> { 77 | this.ship.pos.x = event.x; 78 | }); 79 | 80 | this.game.input.pointers.primary.on('down',(event:PointerEvent)=> { 81 | this.shotFire(event.x); 82 | }); 83 | } 84 | 85 | 86 | async addAliens() { 87 | while(true) { 88 | await this.sleep(this.getRandomeBetween(this.randomeAlienSpaceFrom,this.randomeAlienSpaceTo)); 89 | 90 | if(this.randomeAlienSpaceFrom > 0) { 91 | this.randomeAlienSpaceFrom = --this.randomeAlienSpaceFrom -20; 92 | this.randomeAlienSpaceTo = --this.randomeAlienSpaceTo - 40; 93 | } 94 | 95 | 96 | let alien = new Alien(this.getRandomeBetween(50,600),0,40,40); 97 | alien.color = ex.Color.Orange; 98 | alien.vel.setTo(0,this.alienSpeedStar); 99 | alien.collisionType = ex.CollisionType.Active; 100 | if(this.getRandomeBetween(2,4) == 3) { 101 | alien.addDrawing(this.birdTexture); 102 | } else { 103 | alien.addDrawing(this.enemyTexture); 104 | } 105 | alien.on('collision',(event:any)=> { 106 | if(event.other instanceof Shot) { 107 | this.health.x -= 2; 108 | if(this.health.x < 30) { 109 | confirm("YOU WON!!! :)"); 110 | this.goHome(); 111 | } 112 | this.explodeSound.play(); 113 | } else if(event.other instanceof Ship) { 114 | this.colisionSound.play(); 115 | this.health.setWidth(this.health.getWidth()-10); 116 | if(this.health.getWidth() <= 0) { 117 | confirm("YOU LOST! :("); 118 | this.goHome(); 119 | } 120 | } 121 | alien.kill(); 122 | alien.remove; 123 | }); 124 | this.alienSpeedStar += 10; 125 | this.game.add(alien); 126 | } 127 | } 128 | 129 | shotFire(x:number) { 130 | let shot = new Shot(x,this.game.getDrawHeight(),5,5); 131 | shot.color = ex.Color.Red; 132 | shot.vel.setTo(0,-1000); 133 | shot.collisionType = ex.CollisionType.Passive; 134 | this.game.add(shot); 135 | this.hitSound.play(); 136 | } 137 | 138 | 139 | async setSpaceBackgroundMovement() { 140 | while(true) { 141 | 142 | //apo Dot(0-500,0,4,4) 143 | //Dot(0,500,4,4) 144 | for(let x =1; x <= 650; x = x+4){ 145 | await this.sleep(20); 146 | let rand = 0; 147 | if((x*2) > 750) { 148 | rand = this.getRandomeBetween(0,x); 149 | } else { 150 | rand = this.getRandomeBetween(x,x*2); 151 | } 152 | let dotx = new Dot(rand,this.getRandomeBetween(1,50),3,3); 153 | dotx.color = ex.Color.DarkGray; 154 | dotx.vel.setTo(550,550); 155 | dotx.collisionType = ex.CollisionType.PreventCollision; 156 | this.game.add(dotx); 157 | 158 | await this.sleep(20); 159 | let doty = new Dot(this.getRandomeBetween(1,50),rand,3,3); 160 | doty.color = ex.Color.DarkGray; 161 | doty.vel.setTo(450,450); 162 | doty.collisionType = ex.CollisionType.PreventCollision; 163 | this.game.add(doty); 164 | } 165 | 166 | } 167 | } 168 | 169 | sleep(ms) { 170 | return new Promise(resolve => setTimeout(resolve, ms)); 171 | } 172 | 173 | getRandomeBetween(first:number,sec:number) { 174 | return Math.floor(Math.random() * sec) + first; 175 | } 176 | 177 | } 178 | 179 | 180 | 181 | --------------------------------------------------------------------------------