Skip to content

Commit a14817c

Browse files
committed
initial commit
0 parents  commit a14817c

8 files changed

Lines changed: 247 additions & 0 deletions

File tree

README.md

Whitespace-only changes.

assets/bullet0.png

262 Bytes
Loading

assets/shmup-ship.png

749 Bytes
Loading

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link href="reset.css" rel="stylesheet" type="text/css"/>
5+
<script src="phaser.min.js"></script>
6+
</head>
7+
<body>
8+
<script src="source.js"></script>
9+
</body>
10+
</html>

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "phaser",
3+
"main": "index.html",
4+
"window": {
5+
"width": 320,
6+
"height": 240,
7+
"max_width": 320,
8+
"max_height": 240,
9+
"resizable": false,
10+
"fullscreen": false,
11+
"frame": false,
12+
"transparent": false
13+
}
14+
}

phaser.min.js

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

reset.css

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
html5doctor.com Reset Stylesheet
3+
v1.6.1
4+
Last Updated: 2010-09-17
5+
Author: Richard Clark - http://richclarkdesign.com
6+
Twitter: @rich_clark
7+
*/
8+
9+
html, body, div, span, object, iframe,
10+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
11+
abbr, address, cite, code,
12+
del, dfn, em, img, ins, kbd, q, samp,
13+
small, strong, sub, sup, var,
14+
b, i,
15+
dl, dt, dd, ol, ul, li,
16+
fieldset, form, label, legend,
17+
table, caption, tbody, tfoot, thead, tr, th, td,
18+
article, aside, canvas, details, figcaption, figure,
19+
footer, header, hgroup, menu, nav, section, summary,
20+
time, mark, audio, video {
21+
margin:0;
22+
padding:0;
23+
border:0;
24+
outline:0;
25+
font-size:100%;
26+
vertical-align:baseline;
27+
background:transparent;
28+
}
29+
30+
body {
31+
line-height:1;
32+
}
33+
34+
article,aside,details,figcaption,figure,
35+
footer,header,hgroup,menu,nav,section {
36+
display:block;
37+
}
38+
39+
nav ul {
40+
list-style:none;
41+
}
42+
43+
blockquote, q {
44+
quotes:none;
45+
}
46+
47+
blockquote:before, blockquote:after,
48+
q:before, q:after {
49+
content:'';
50+
content:none;
51+
}
52+
53+
a {
54+
margin:0;
55+
padding:0;
56+
font-size:100%;
57+
vertical-align:baseline;
58+
background:transparent;
59+
}
60+
61+
/* change colours to suit your needs */
62+
ins {
63+
background-color:#ff9;
64+
color:#000;
65+
text-decoration:none;
66+
}
67+
68+
/* change colours to suit your needs */
69+
mark {
70+
background-color:#ff9;
71+
color:#000;
72+
font-style:italic;
73+
font-weight:bold;
74+
}
75+
76+
del {
77+
text-decoration: line-through;
78+
}
79+
80+
abbr[title], dfn[title] {
81+
border-bottom:1px dotted;
82+
cursor:help;
83+
}
84+
85+
table {
86+
border-collapse:collapse;
87+
border-spacing:0;
88+
}
89+
90+
/* change border colour to suit your needs */
91+
hr {
92+
display:block;
93+
height:1px;
94+
border:0;
95+
border-top:1px solid #cccccc;
96+
margin:1em 0;
97+
padding:0;
98+
}
99+
100+
input, select {
101+
vertical-align:middle;
102+
}

source.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
var game = new Phaser.Game(320, 240, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
3+
4+
function preload() {
5+
6+
game.load.image('phaser', 'assets/shmup-ship.png');
7+
game.load.image('bullet', 'assets/bullet0.png');
8+
9+
}
10+
11+
var sprite;
12+
var bullet;
13+
var bullets;
14+
var bulletTime = 0;
15+
16+
// Left, right and space key for controls
17+
var upKey;
18+
var downKey;
19+
var leftKey;
20+
var rightKey;
21+
var fireKey;
22+
var escKey;
23+
24+
function create() {
25+
26+
game.physics.startSystem(Phaser.Physics.ARCADE);
27+
28+
game.stage.backgroundColor = '#2d2d2d';
29+
30+
bullets = game.add.group();
31+
32+
bullets.enableBody = true;
33+
34+
bullets.physicsBodyType = Phaser.Physics.ARCADE;
35+
36+
bullets.createMultiple(10, 'bullet');
37+
bullets.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', resetBullet, this);
38+
bullets.setAll('checkWorldBounds', true);
39+
40+
sprite = game.add.sprite(150, 180, 'phaser');
41+
42+
game.physics.enable(sprite, Phaser.Physics.ARCADE);
43+
44+
// Register the keys.
45+
this.upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
46+
this.downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
47+
this.leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
48+
this.rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
49+
this.fireKey = game.input.keyboard.addKey(Phaser.Keyboard.J);
50+
this.escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC);
51+
52+
// Stop the following keys from propagating up to the browser
53+
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.UP, Phaser.Keyboard.DOWN, Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.J, Phaser.Keyboard.ESC ]);
54+
55+
}
56+
57+
function update() {
58+
59+
sprite.body.velocity.x = 0;
60+
sprite.body.velocity.y = 0;
61+
62+
// If true, it means that this key is down. If not, it means that the key is not down (was released/not pressed)
63+
if (this.upKey.isDown)
64+
{
65+
sprite.body.velocity.y = -200;
66+
}
67+
68+
if (this.downKey.isDown)
69+
{
70+
sprite.body.velocity.y = 200;
71+
}
72+
73+
if (this.leftKey.isDown)
74+
{
75+
sprite.body.velocity.x = -200;
76+
}
77+
78+
if (this.rightKey.isDown)
79+
{
80+
sprite.body.velocity.x = 200;
81+
}
82+
83+
if (this.fireKey.isDown)
84+
{
85+
fireBullet();
86+
}
87+
88+
if (this.escKey.isDown)
89+
{
90+
// nwjs related code to close the application
91+
nw.App.closeAllWindows();
92+
}
93+
}
94+
95+
function fireBullet () {
96+
97+
if (game.time.now > bulletTime)
98+
{
99+
bullet = bullets.getFirstExists(false);
100+
101+
if (bullet)
102+
{
103+
bullet.reset(sprite.x + 6, sprite.y - 8);
104+
bullet.body.velocity.y = -300;
105+
bulletTime = game.time.now + 250;
106+
}
107+
}
108+
109+
}
110+
111+
// Called if the bullet goes out of the screen
112+
function resetBullet (bullet) {
113+
114+
bullet.kill();
115+
116+
}
117+

0 commit comments

Comments
 (0)