<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>STG</title>
<style type="text/css">
body { background-color:#000; color:#fff; margin:0; overflow:hidden;}
#waku { overflow:hidden; margin:0;}
#title {float:left; margin:1ex;}
#score { float:right; margin:1ex;}
#jiki { position:absolute; z-index:2; }
#tama { display:none; position:absolute;z-index:0; }
</style>
<body>
<div id="waku">
<div id="header">
<div id="title">なんて名前にしようかな〜</div>
<div id="score">SCORE : <span id="point">0</span></div>
<img src="jiki.gif" width="40" height="40" alt="自" id="jiki">
<img src="tama.gif" id="tama" width="10" height="20" alt="玉">
</div>
</div>
<script type="text/javascript">
var Pmouse = {x:240, y:600};
function getInnerView() {
var C = document
.defaultView ;
return {
innerWidth : C.innerWidth -8,
innerHeight: C.innerHeight -30
};
}
var Star = function (element) {
this.element = element;
this.timerID = null;
this.interval = 40;
this.x = 0;
this.y = 0;
this.z = 0;
this.init(1);
};
Star.prototype.loop = function (cb_) {
this.timerID = (function (o) {
return setInterval(function () { return cb_.call(o); }, o.interval);
})(this);
};
Star.prototype.init = function (n) {
var v = getInnerView();
this.x = Math.random() * v.innerWidth;
this.y = Math.random() * v.innerHeight * Boolean(n);
this.z = Math.random() * 5 + 1;
return true;
};
Star.prototype.fall = function () {
var v = getInnerView();
this.y += this.z;
if (this.y > v.innerHeight) this.init();
this.element.style.top = this.y + 'px';
this.element.style.left = this.x + 'px';
};
Star.create = function () {
var d = document, e = d.createElement('p'), s = e.style, o;
e.appendChild(d.createTextNode('*'));
s.color = '#660';
s.position = 'absolute';
o = new this(d.body.appendChild(e));
o.loop(o.fall);
return o;
};
Star.start = function (n) { for (var i = 0; i < n; i ++) this.create(); };
Star.start(10);
Jiki = function () {
this.init.apply(this, arguments);
};
Jiki.prototype.init = function () {
var v = getInnerView();
this.element = document.getElementById('jiki');
this.x = v.innerWidth / 2 |0;
this.y = v.innerHeight - 60;
this.s = this.element.style;
this.max_x = v.innerWidth - this.element.offsetWidth;
this.max_y = v.innerHeight - this.element.offsetHeight;
addEvent( document, 'mousemove', (function (cb_) { return function(evt) { cb_.mouse_move(evt); };})(this), false);
addEvent( document, 'mousedown', (function (cb_) { return function(evt) { cb_.mouse_down(evt); };})(this), false);
addEvent( document, 'mouseup', (function (cb_) { return function(evt) { cb_.mouse_up(evt); };})(this), false);
this.timerId = setInterval( (function(cb_) { return function() { cb_.move(); };})(this), 10);
this.timerId2 = setInterval( (function(cb_) { return function() { cb_.shot(); };})(this), 350);
};
Jiki.prototype.mouse_move = function (evt) {
this.mouse_x = evt.clientX;
this.mouse_y = evt.clientY;
}
Jiki.prototype.move = function (evt) {
this.x += (this.mouse_x < this.x -8 ) * -2 + (this.mouse_x > this.x +8) *2;
this.y += (this.mouse_y < this.y -8 ) * -2 + (this.mouse_y > this.y +8) *2;
if (this.max_x < this.x) this.x = this.max_x;
if (this.max_y < this.y) this.y = this.max_y;
this.s.left = this.x + 'px';
this.s.top = this.y + 'px';
}
Jiki.prototype.mouse_down = function (evt) { return this.shot_f = true; }
Jiki.prototype.mouse_up = function (evt) { return this.shot_f = false; }
function addEvent(element, evt, eventHandler, flag){
element.addEventListener(evt, eventHandler, flag);
}
Jiki.prototype.shot = function () {
if (! this.shot_f) return;
var c = document.getElementById('tama').cloneNode(false), s = c.style;
document.getElementById('waku').appendChild(c);
s.display = 'inline';
var x = this.x+15;
var y = this.y;
var t = 8;
s.left = x + 'px';
var P = function shotloop(){
s.top = (y -= t)+ 'px';
if( y < 1) return document.getElementById('waku').removeChild(c);
setTimeout(shotloop, 5);
}
P();
}
Teki = function () {
};
var J = new Jiki();
</script>