Skip to content

Commit

Permalink
message
Browse files Browse the repository at this point in the history
  • Loading branch information
daishihmr committed Jan 10, 2013
1 parent 593348d commit e5b61fd
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 74 deletions.
3 changes: 2 additions & 1 deletion game/bomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var Bomb = {};
Bomb.createBomber = function(scene, bombParticlePool, texture) {
var createBombParticle = function() {
var p = new Sprite(texture);
p.npr = true;
p.centerX = 0;
p.centerY = 0;
p.texX = 4;
Expand All @@ -13,7 +14,7 @@ Bomb.createBomber = function(scene, bombParticlePool, texture) {
p.update = function() {
this.x = this.centerX + Math.cos(this.angle) * this.radius;
this.y = this.centerY + Math.sin(this.angle) * this.radius;
this.angle += 0.01;
this.angle += 0.03;
this.radius += this.radiusD;
this.radiusD -= 0.002;
this.scale = (17 - this.radius) * this.size;
Expand Down
6 changes: 3 additions & 3 deletions game/enemy-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var enemyData = {
"tankEx": {
frameIndex: 21,
hp: 10,
scale: 1.2,
scale: 1,
score: 100,
},
"bigger": {
Expand Down Expand Up @@ -63,14 +63,14 @@ var enemyData = {
"cannon2": {
frameIndex: 20,
hp: 150,
scale: 3.5,
scale: 3,
score: 400,
clear: true
},
"ship": {
frameIndex: 24,
hp: 10,
scale: 1.5,
scale: 2,
score: 200
}
};
17 changes: 10 additions & 7 deletions game/explosion.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ var Explosion = function(scene, texture) {
this.x = Math.cos(this.angle) * this.radius;
this.y = Math.sin(this.angle) * this.radius;
this.radius += this.radiusD;
this.scale += 0.17;
this.alpha -= 0.0025;
// this.radiusD *= 0.9;
this.scale += 0.02;
if (2 < this.scale) {
this.alpha -= 0.001;
}
if (this.alpha < 0) {
scene.remove(this);
}
Expand All @@ -78,19 +81,19 @@ var Explosion = function(scene, texture) {
}

var pool = [];
for (var i = 0; i < 30; i++) {
for (var i = 0; i < 50; i++) {
pool.push(createParticle());
}

return function(callback) {
var readyCount = 0;
for (var i = pool.length; i--; ) {
var p = pool[i];
p.radius = tm.util.Random.randfloat(0.1, 2);
p.angle = (i % 12) * Math.PI*2/12 - p.radius*0.3;
p.radiusD = tm.util.Random.randfloat(0.02, 0.15);
p.radius = tm.util.Random.randfloat(0.0, 0.5);
p.angle = (Math.PI*2/12) * (i%12);
p.radiusD = tm.util.Random.randfloat(0.005, 0.02);
p.alpha = 1;
p.scale = 1;
p.scale = 0.5;
p.age = 0;
p.x = Math.cos(p.angle) * p.radius;
p.y = Math.sin(p.angle) * p.radius;
Expand Down
52 changes: 32 additions & 20 deletions game/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ var MUTEKI = false;
var INITIAL_RANK = 0.5;
var COLLISION_RADUIS = 0.2*0.2;

var PLAYER_SPEED = 0.2;
var PLAYER_SCALE = 1.5;
var WEAPON_SCALE = 1.0;
var MUTEKI_TIME = 90;

var START_STAGE = 3;
var NUM_OF_STAGE = 3;

Expand All @@ -40,6 +45,7 @@ tm.preload(function() {
tm.graphics.TextureManager.add("boss1", "images/boss1.png");
tm.graphics.TextureManager.add("boss2", "images/boss2.png");
tm.graphics.TextureManager.add("boss3", "images/boss3.png");
tm.graphics.TextureManager.add("w", "images/w.png");

if (LOAD_BGM_FROM_EXTERNAL_SITE) {
tm.sound.SoundManager.add("bgm1", "http://static.dev7.jp/glshooter/sounds/nc28689.mp3", 1);
Expand Down Expand Up @@ -160,7 +166,7 @@ tm.main(function() {
var explosion = new Explosion(scene, mainTexture);
var explode = app.explode = explosion.explode;
var explodeS = app.explodeS = explosion.explodeS;
var explodeL = explosion.getExplodeL(gl, scene);
var explodeL = explosion.getExplodeL(scene);
var clearAllExplosion = app.clearAllExplosion = explosion.clearAll;

// player
Expand All @@ -186,10 +192,10 @@ tm.main(function() {
var bulletPool = [];
for (var i = 0; i < 2000; i++) {
var b = new Sprite(mainTexture);
b.isBullet = true;
b.texX = 3;
b.texY = 1;
b.scale = 0.6;
b.isBullet = true;
bullets.push(b);
bulletPool.push(b);
b.onremoved = function() {
Expand Down Expand Up @@ -273,6 +279,7 @@ tm.main(function() {
var expSoundPlaying = -1;
var createEnemy = function() {
var e = new Sprite(mainTexture);
e.isEnemy = true;
e.alpha = 0.5;
e.glow = 1;
e.onremoved = function() {
Expand Down Expand Up @@ -387,6 +394,8 @@ tm.main(function() {
gameScene.update = function() {
if (keyboard.getKeyDown("space") && !player.disabled) app.pushScene(app.pauseScene);

if (keyboard.getKey("q")) explodeL(function() {});

glowUp = false;

// control sound effect
Expand Down Expand Up @@ -443,6 +452,25 @@ tm.main(function() {
// collision
var px = player.x;
var py = player.y;
// collision weapon vs enemy
for (var j = enemies.length; j--; ) {
var e = enemies[j];
if (e.parent === null) continue;
var colLen = (e.scale+WEAPON_SCALE) * (e.scale+WEAPON_SCALE);
for (var i = weapons.length; i--; ) {
var w = weapons[i];
if (w.parent === null) continue;
var dist = (e.x-w.x)*(e.x-w.x)+(e.y-w.y)*(e.y-w.y);
if (dist < colLen) {
scene.remove(w);
glowLevel += GLOW_UP_PER_HIT; glowUp = true;
e.damage(player.power);
app.incrScore(0.01, true); // hit
w.update(); explodeS(w.x, w.y, 0.3);
break;
}
}
}
// collision player vs bullet
if (player.parent !== null && !player.muteki && !bombing && !player.disabled) {
for (var i = bullets.length; i--; ) {
Expand All @@ -467,11 +495,12 @@ tm.main(function() {
}
// collision player vs enemy
if (player.parent !== null && !player.muteki && !bombing && !player.disabled) {
var colLen = (e.scale+PLAYER_SCALE) * (e.scale+PLAYER_SCALE);
for (var i = enemies.length; i--; ) {
var e = enemies[i];
if (e.parent === null) continue;
var dist = (e.x-px)*(e.x-px)+(e.y-py)*(e.y-py);
if (dist < e.scale*2) {
if (dist < e.scale*e.scale) {
if (app.bomb < 1 && !AUTO_BOMB) {
MUTEKI || player.damage();
glowLevel = 0;
Expand All @@ -482,23 +511,6 @@ tm.main(function() {
}
}
}
// collision weapon vs enemy
for (var i = weapons.length; i--; ) {
var w = weapons[i];
if (w.parent === null) continue;
for (var j = enemies.length; j--; ) {
var e = enemies[j];
if (e.parent === null) continue;
var dist = (e.x-w.x)*(e.x-w.x)+(e.y-w.y)*(e.y-w.y);
if (dist < e.scale*2) {
scene.remove(w);
glowLevel += GLOW_UP_PER_HIT; glowUp = true;
e.damage(player.power);
app.incrScore(0.01, true); // hit
w.update(); explodeS(w.x, w.y, 0.3);
}
}
}

// GLOW-UP
if (glowUp) {
Expand Down
7 changes: 3 additions & 4 deletions game/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
// -> GLOWは敵に弾がヒットすることによって上昇するため、収束ショットの方が有利になる
// -> マウス操作の場合、回避に圧倒的なアドバンテージがある分、収束ショットを撃つことができないデメリットがある

var PLAYER_SPEED = 0.2;
var MUTEKI_TIME = 90;

var setupPlayer = function(app, scene, weapons, mouse, texture) {
var player = new Sprite(texture);
player.scale = 1.5;
player.scale = PLAYER_SCALE;
player.level = 0;
player.reset = function() {
this.x = 0;
Expand Down Expand Up @@ -226,6 +223,8 @@ var setupPlayer = function(app, scene, weapons, mouse, texture) {
var weaponPool = [];
for (var i = 0; i < 400; i++) {
var w = new Sprite(texture);
w.scale = WEAPON_SCALE;
w.isWeapon = true;
w.texX = 7;
w.texY = 1;
weapons.push(w);
Expand Down
Binary file added images/w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 28 additions & 3 deletions mylib/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var Scene;
gl.uniform1f(gl.getUniformLocation(program, "texture"), 0);

this.uniformLocationsForSprite = getUniformLocationsForSprite(gl, program, [
"x", "y", "scale", "rotation", "texX", "texY", "alpha", "texScale", "emission"
"x", "y", "scale", "scaleY", "rotation", "texX", "texY", "alpha", "texScale", "emission"
]);

this.updateMatrix();
Expand All @@ -49,6 +49,19 @@ var Scene;
this._removedChildren = [];

this.frame = 0;

var img = tm.graphics.Canvas();
img.resize(128, 32);
img.fillStyle = "rgba(255, 255, 255, 0.1)";
img.fillRect(0, 0, 128, 32);
this.mask = new Sprite(createTexture(gl, img.element));
// this.mask = new Sprite(createTexture(gl, tm.graphics.TextureManager.get("w").element));
this.mask.scale = 16;
this.mask.scaleY = 0.1;
this.mask.uniforms = this.uniformLocationsForSprite;
this.mask.texX = 0;
this.mask.texY = 0;
this.mask.texScale = 8;
};

Scene.prototype.updateMatrix = function() {
Expand All @@ -63,7 +76,10 @@ var Scene;
var children = this.children;
var removedChildren = this._removedChildren;

for (var i = 0, len = children.length; i < len; i++) children[i].update();
for (var i = 0, len = children.length; i < len; i++) {
var c = children[i];
c.update();
}

for (var i = 0, len = removedChildren.length; i < len; i++) {
var index = this.children.indexOf(removedChildren[i]);
Expand All @@ -83,7 +99,16 @@ var Scene;
var program = this.program;
gl.clear(gl.COLOR_BUFFER_BIT);

for (var i = 0, len = children.length; i < len; i++) children[i].draw(gl);
for (var i = 0, len = children.length; i < len; i++) {
children[i].draw(gl);
}

gl.blendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO);
if (this.mask.scaleY < 4) {
this.mask.scaleY += 0.05;
}
this.mask.draw(gl);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);

gl.flush();

Expand Down
8 changes: 8 additions & 0 deletions mylib/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Sprite;
this.x = 0;
this.y = 0;
this.scale = 1;
this.scaleY = 0;
this.rotation = 0;

this.texX = 0;
Expand All @@ -26,17 +27,23 @@ var Sprite;

this.update = function() {};
this.onremoved = function() {};

this.isEnemy = false;
this.isBullet = false;
this.isWeapon = false;
};

Sprite.prototype.draw = function(gl) {
if (!this.visible) return;
if (this.texture === null) this.texture = Sprite.mainTexture;

gl.bindTexture(gl.TEXTURE_2D, this.texture);

var uni = this.uniforms;
gl.uniform1f(uni["x"], this.x);
gl.uniform1f(uni["y"], this.y);
gl.uniform1f(uni["scale"], this.scale);
gl.uniform1f(uni["scaleY"], this.scaleY || this.scale);
gl.uniform1f(uni["rotation"], this.rotation);
gl.uniform1f(uni["texX"], this.texX);
gl.uniform1f(uni["texY"], this.texY);
Expand All @@ -52,6 +59,7 @@ var Sprite;
gl.uniform1f(uni["texScale"], 1);
gl.uniform1f(uni["alpha"], this.glow);
gl.uniform1f(uni["scale"], this.scale*2);
gl.uniform1f(uni["scaleY"], this.scale*2);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
Expand Down
9 changes: 5 additions & 4 deletions shaders/shader.vs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform mat4 pMat;
uniform float x;
uniform float y;
uniform float scale;
uniform float scaleY;
uniform float rotation;
uniform float texX;
uniform float texY;
Expand All @@ -15,7 +16,7 @@ varying vec2 vTextureCoord;
varying float vAlpha;
varying float vEmission;

mat4 model(vec2 xy, float scale, float rot) {
mat4 model(vec2 xy, float scale, float scaleY, float rot) {
mat4 result = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
Expand All @@ -30,8 +31,8 @@ mat4 model(vec2 xy, float scale, float rot) {
);
result = result * mat4(
scale, 0.0, 0.0, 0.0,
0.0, scale, 0.0, 0.0,
0.0, 0.0, scale, 0.0,
0.0, scaleY, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
result = result * mat4(
Expand All @@ -47,5 +48,5 @@ void main(void) {
vAlpha = alpha;
vEmission = emission;
vTextureCoord = (texCoord * texScale) + vec2(texX*64.0/512.0, texY*64.0/512.0);
gl_Position = pMat * vMat * model(vec2(x, y), scale, rotation) * vec4(position, 1.0);
gl_Position = pMat * vMat * model(vec2(x, y), scale, scaleY, rotation) * vec4(position, 1.0);
}
5 changes: 2 additions & 3 deletions test/img.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<!doctype html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Fjalla+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Orbitron:400,900' rel='stylesheet' type='text/css'>
</head>
<body style="background:black">
<body>
<canvas id="c"></canvas>
<img id="img" />
<script type="text/javascript" src="tmlib.js"></script>
<script type="text/javascript" src="../lib/tmlib.js"></script>
<script type="text/javascript" src="img.js"></script>
</body>
</html>
Loading

0 comments on commit e5b61fd

Please sign in to comment.