Skip to content

Commit de7e572

Browse files
Neil BrownNeil Brown
Neil Brown
authored and
Neil Brown
committed
moved game to containers
1 parent 8bb2432 commit de7e572

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2809
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
yarn.lock
2+
yarn.lock
3+
containers/dist

containers/.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "presets": [ "es2015" ] }

containers/npm-shrinkwrap.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

containers/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "playground",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {},
7+
"devDependencies": {
8+
"babel-core": "^6.23.1",
9+
"babel-loader": "^7.1.0",
10+
"babel-preset-es2015": "^6.22.0",
11+
"copy-webpack-plugin": "2.1.6",
12+
"gsap": "^1.20.2",
13+
"html-webpack-plugin": "^2.28.0",
14+
"keyboardjs": "^2.3.3",
15+
"pixi-particles": "^2.1.1",
16+
"pixi.js": "^4.5.3",
17+
"standard": "^10.0.2",
18+
"standard-loader": "^6.0.1",
19+
"webpack": "^3.0.0",
20+
"webpack-dev-server": "^2.4.1"
21+
},
22+
"scripts": {
23+
"build": "webpack",
24+
"watch": "webpack --watch",
25+
"start": "webpack-dev-server --inline",
26+
"test": "echo \"Error: no test specified\" && exit 1"
27+
},
28+
"keywords": [],
29+
"author": "",
30+
"license": "ISC"
31+
}

containers/src/fonts/font.fnt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<font>
2+
<info face="font" size="72" bold="0" italic="0" charset="" unicode="" stretchH="100" smooth="1" aa="1" padding="2,2,2,2" spacing="0,0" outline="0"/>
3+
<common lineHeight="80" base="52" scaleW="75" scaleH="438" pages="1" packed="0"/>
4+
<pages>
5+
<page id="0" file="font.png"/>
6+
</pages>
7+
<chars count="10">
8+
<char id="48" x="2" y="2" width="34" height="53" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
9+
<char id="49" x="2" y="57" width="19" height="52" xoffset="8" yoffset="0" xadvance="40" page="0" chnl="15"/>
10+
<char id="50" x="2" y="111" width="34" height="52" xoffset="2" yoffset="0" xadvance="40" page="0" chnl="15"/>
11+
<char id="51" x="2" y="165" width="34" height="53" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
12+
<char id="52" x="23" y="57" width="36" height="52" xoffset="1" yoffset="0" xadvance="40" page="0" chnl="15"/>
13+
<char id="53" x="38" y="2" width="35" height="52" xoffset="3" yoffset="1" xadvance="40" page="0" chnl="15"/>
14+
<char id="54" x="2" y="220" width="34" height="53" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
15+
<char id="55" x="2" y="275" width="34" height="51" xoffset="3" yoffset="1" xadvance="40" page="0" chnl="15"/>
16+
<char id="56" x="2" y="328" width="34" height="53" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
17+
<char id="57" x="2" y="383" width="34" height="53" xoffset="3" yoffset="0" xadvance="40" page="0" chnl="15"/>
18+
<char id="32" x="0" y="0" width="0" height="0" xoffset="3" yoffset="0" xadvance="20" page="0" chnl="15"/>
19+
</chars>
20+
<kernings count="1">
21+
<kerning first="49" second="49" amount="-5"/>
22+
</kernings>
23+
</font>

containers/src/fonts/font.png

3.92 KB
Loading

containers/src/images/container.png

11.6 KB
Loading

containers/src/images/data.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"frames": {
3+
"container": {
4+
"frame": {
5+
"x": 1,
6+
"y": 1,
7+
"w": 126,
8+
"h": 53
9+
},
10+
"rotated": false,
11+
"trimmed": false,
12+
"spriteSourceSize": {
13+
"x": 0,
14+
"y": 0,
15+
"w": 126,
16+
"h": 53
17+
},
18+
"sourceSize": {
19+
"w": 126,
20+
"h": 53
21+
},
22+
"pivot": {
23+
"x": 0.5,
24+
"y": 0.5
25+
}
26+
},
27+
"ship": {
28+
"frame": {
29+
"x": 1,
30+
"y": 56,
31+
"w": 570,
32+
"h": 137
33+
},
34+
"rotated": false,
35+
"trimmed": true,
36+
"spriteSourceSize": {
37+
"x": 1,
38+
"y": 0,
39+
"w": 570,
40+
"h": 137
41+
},
42+
"sourceSize": {
43+
"w": 572,
44+
"h": 140
45+
},
46+
"pivot": {
47+
"x": 0.5,
48+
"y": 0.5
49+
}
50+
}
51+
},
52+
"meta": {
53+
"app": "http://free-tex-packer.com/",
54+
"version": "0.2.4",
55+
"image": "data.png",
56+
"format": "RGBA8888",
57+
"size": {
58+
"w": 1024,
59+
"h": 1024
60+
},
61+
"scale": 1
62+
}
63+
}

containers/src/images/data.png

86.6 KB
Loading

containers/src/images/ship.png

59.4 KB
Loading

containers/src/js/app.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import * as PIXI from 'pixi.js'
2+
import TimelineMax from 'gsap/TimelineMax'
3+
import keyboardJS from 'keyboardjs'
4+
import Ship from './vessel.js'
5+
import Container from './container.js'
6+
import Storage from './storage.js'
7+
import Test from './test.js'
8+
import Crane from './crane.js'
9+
import Fleet from './fleet.js'
10+
11+
const app = new PIXI.Application({
12+
width: window.innerWidth,
13+
height: window.innerHeight
14+
})
15+
16+
document.body.appendChild(app.view)
17+
18+
19+
const loader = app.loader
20+
loader.add('fonts/font.fnt')
21+
loader.add('images/data.json').load(setup)
22+
23+
let ship = undefined
24+
let graphics = undefined
25+
let id = undefined
26+
let tl = undefined
27+
let target = undefined
28+
let storage = undefined
29+
let crane = undefined
30+
let fleet = undefined
31+
let platform = undefined
32+
let container = undefined
33+
34+
function setup () {
35+
console.log('application setup')
36+
37+
fleet = new Fleet(app, loader)
38+
fleet.on('container-selected', onContainerSelected)
39+
40+
createPlatforms()
41+
createCrane()
42+
addKeyboard()
43+
}
44+
45+
function createPlatforms () {
46+
storage = new Storage(app)
47+
storage.on('platform-selected', onPlatformSelected)
48+
app.stage.addChild(storage)
49+
}
50+
51+
function createCrane() {
52+
crane = new Crane()
53+
app.stage.addChild(crane)
54+
}
55+
56+
function onPlatformSelected(value) {
57+
crane.platform = value
58+
}
59+
60+
function onContainerSelected(value) {
61+
crane.container = value
62+
}
63+
64+
app.ticker.add(animate)
65+
66+
function animate (delta) {
67+
68+
}
69+
70+
function addKeyboard () {
71+
const keys = [
72+
{ key:'a', press: aPress, release: aRelease },
73+
{ key:'b', press: bPress, release: bRelease }
74+
]
75+
76+
keys.forEach((map) => {
77+
keyboardJS.bind(map.key, (e) => {
78+
console.log(map.key + ' is pressed')
79+
map.press()
80+
e.preventRepeat()
81+
}, (e) => {
82+
console.log(map.key + ' is released')
83+
map.release()
84+
})
85+
})
86+
}
87+
88+
function aPress () {
89+
console.log('called aPress function')
90+
}
91+
92+
function aRelease () {
93+
console.log('called aRelease function')
94+
}
95+
96+
function bPress () {
97+
console.log('called bPress function')
98+
}
99+
100+
function bRelease () {
101+
console.log('called bRelease function')
102+
}

containers/src/js/bulletPool.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as PIXI from 'pixi.js'
2+
import consts from './matterConsts.js'
3+
import PlayerBullet from './playerBullet.js'
4+
5+
class BulletPool {
6+
constructor (engine, container) {
7+
this.engine = engine
8+
this.container = container
9+
this.size = 8
10+
this.pool = []
11+
this._bullet = undefined
12+
this.texture = PIXI.loader.resources['images/data.json'].textures['player_bullet.png']
13+
}
14+
15+
init (id, category) {
16+
for (var i = 0; i < this.size; i++) {
17+
const bullet = new PlayerBullet('bullet_' + i, this.engine, category)
18+
bullet.init(0, 0, 16, 32, this.texture)
19+
this.pool[i] = bullet
20+
consts.World.addBody(this.engine.world, bullet.body)
21+
this.container.addChild(bullet.sprite)
22+
}
23+
}
24+
25+
getBullet (position) {
26+
if (!this.pool[this.size - 1].alive) {
27+
this.pool[this.size - 1].spawn(position)
28+
this.pool.unshift(this.pool.pop())
29+
}
30+
}
31+
32+
remove (id) {
33+
this.pool.forEach((bullet) => {
34+
if (bullet.alive && bullet.id === id) {
35+
bullet.alive = false
36+
bullet.update()
37+
}
38+
})
39+
}
40+
41+
update () {
42+
this.pool.forEach((bullet, i) => {
43+
if (bullet.alive === true) {
44+
bullet.update()
45+
}
46+
})
47+
}
48+
}
49+
export default BulletPool

containers/src/js/container.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as PIXI from 'pixi.js'
2+
3+
export default class Container extends PIXI.Sprite {
4+
constructor(texture) {
5+
super(texture)
6+
}
7+
8+
init (ticker) {
9+
ticker.add(this.update, this)
10+
}
11+
12+
get id () {
13+
return this._id
14+
}
15+
16+
set id (value) {
17+
this._id = value
18+
}
19+
20+
update (delta) {
21+
22+
}
23+
}

containers/src/js/crane.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as PIXI from 'pixi.js'
2+
import TimelineMax from 'gsap/TimelineMax'
3+
4+
export default class Crane extends PIXI.Sprite {
5+
constructor () {
6+
super()
7+
8+
this._platform = undefined
9+
this._container = undefined
10+
11+
this._graphics = new PIXI.Graphics()
12+
this._graphics.lineStyle(2, 0x0000FF, 1);
13+
this._graphics.drawRect(0, 0, 126, 53);
14+
this.addChild(this._graphics)
15+
16+
}
17+
18+
move() {
19+
if(this._container === undefined || this._platform === undefined) {
20+
console.log('error')
21+
return
22+
}
23+
24+
let pos = this._container.parent.toGlobal(this._container)
25+
26+
this._tl = new TimelineMax({onComplete: this.collect.bind(this)})
27+
28+
this._tl.fromTo(this._graphics.position, 0.5, {x: this._graphics.position.x}, {x: pos.x})
29+
this._tl.fromTo(this._graphics.position, 0.5, {y: this._graphics.position.y}, {y: pos.y})
30+
}
31+
32+
collect () {
33+
this._container.x = 0
34+
this._container.y = 0
35+
this._graphics.addChildAt(this._container, 0)
36+
this.drop()
37+
}
38+
39+
drop() {
40+
this._tl = new TimelineMax({onComplete: () => {
41+
this._platform.addChild(this._container)
42+
this.reset()
43+
}})
44+
let pos = {x: (window.innerWidth - this._graphics.width) * 0.5, y: 0}
45+
46+
this._tl.to(this._graphics.position, 0.5, {y: pos.y})
47+
this._tl.to(this._graphics.position, 0.5, {x: this._platform.x})
48+
this._tl.to(this._graphics.position, 0.5, {y: this._platform.y})
49+
}
50+
51+
reset () {
52+
this._container = this._platform = undefined
53+
}
54+
55+
get platform () {
56+
return this._platform
57+
}
58+
59+
set platform (value) {
60+
this._platform = value
61+
this.move()
62+
}
63+
64+
get container () {
65+
return this._container
66+
}
67+
68+
set container (value) {
69+
this._container = value
70+
this.move()
71+
}
72+
}

0 commit comments

Comments
 (0)