TSUTAYA

非日常を楽しんでください

SaturnVoyager

<!DOCTYPE html>
<html>
<head>
  <title>

f:id:ki-ni-mu-tyu:20170920235052p:plain

f:id:ki-ni-mu-tyu:20170920235050p:plain

f:id:ki-ni-mu-tyu:20170920235057p:plain

<!DOCTYPE html>
<html>
<head>
<title>SaturnVoyager</title> <meta charset="utf-8" /> <style> #space { width: 800px; height: 800px; touch-action: none; } #START { position: absolute; left: 200px; top: 200px; } </style> <script> "use strict" var stars = [], keymap = []; var ctx, ship, score = 0, speed = 25, timer = NaN; function Ship(x, y) { this.x = x; this.y = y; this.keydown = function (e) { keymap[e.keyCode] = true; } this.keyup = function (e) { keymap[e.keyCode] = false; } this.move = function () { if (keymap[37]) { //左 this.x -= 30; } else if (keymap[39]) { this.x += 30; //右 } if (keymap[38]) { this.y -= 30; //上 } else if (keymap[40]) { this.y += 30; //下 } this.x = Math.max(-800, Math.min(800, this.x)); this.y = Math.max(-800, Math.min(800, this.y)); } } function random(v) { return Math.floor(Math.random() * v); } function init() { for (var i = 0; i < 200; i++) { stars.push({ x: random(800 * 4) - 1600, y: random(800 * 4) - 1600, z: random(4095), r: random(360), w: random(10)-5 }); } ship = new Ship(200, 200); onkeydown = ship.keydown; onkeyup = ship.keyup; var space = document.getElementById("space"); ctx = space.getContext("2d") ctx.font = "20px Arial"; repaint(); } function go() { var space = document.getElementById("space") space.onmousedown = mymousedown; space.onmouseup = mymouseup; space.oncontextmenu = function (e) { e.preventDefault(); }; space.addEventListener('touchstart', mymousedown); space.addEventListener('touchend', mymouseup); document.body.addEventListener('touchmove', function (event) { event.preventDefeult(); }, false); document.getElementById("START").style.display = "none"; document.getElementById("bgm").play(); timer = setInterval(tick, 50); } function mymousedown(e) { var mouseX = (!isNaN(e.offsetX) ? e.offsetX : e.touches[0].clientX) - 400; var mouseY = (!isNaN(e.offsetY) ? e.offsetY : e.touches[0].clientY) - 400; if (Math.abs(mouseX) > Math.abs(mouseY)) { keymap[mouseX > 0 ? 37 : 39] = true; } else { keymap[mouseY > 0 ? 38 : 40] = true; } } function mymouseup(e) { keymap = []; } function tick() { for (var i = 0; i < 200; i++) { var star = stars[i]; star.z -= speed; star.r += star.w; if (star.z < 64) { if (Math.abs(star.x - ship.x) < 50 && Math.abs(star.y - ship.y) < 50) { //衝突→ゲームオーバー clearInterval(timer); timer = NaN; document.getElementById("bgm").pause(); break; } //通過→奥へ再配置 star.x = random(800 * 4) - 1600; star.y = random(800 * 4) - 1600; star.z = 4095; } } if (score++ % 10 == 0) { speed ++; } ship.move(); repaint(); } function repaint() { ctx.fillStyle = "black" ctx.fillRect(0, 0, 800, 800); stars.sort(function (a, b) { return b.z -a.z; }); //隕石の描画 for (var i = 0; i < 200 ; i++) { var star = stars[i]; var z = star.z; var x = ((star.x - ship.x) << 9) / z + 400; var y = ((star.y - ship.y) << 9) / z + 400; var size = (50 << 9) / z; ctx.save(); ctx.translate(x, y); ctx.globalAlpha = 1- (z / 4096); ctx.rotate(star.r * Math.PI / 180); ctx.drawImage(rockImg, -size / 2, -size / 2,size, size); ctx.restore(); } //スコア ctx.drawImage(scope, 0, 0, 800, 800); ctx.fillStyle = "green"; ctx.fillText(('000000' + score).slice(-7), 670, 60); if (isNaN(timer)) { ctx.fillText("GAME OVER", 315, 350); } } </script> </head> <body onload="init()"> <!--Thanks to http://takao-suenobu.com/ & http://dova-s.jp/ --> <audio src="Escape.mp3" id="bgm" loop="loop"></audio> <canvas id="space" width=800" height="800"></canvas> <img id="START" src="start.png" onclick="go()"></br> <img id="rockImg" src="rock.png" style="display:none" /> <img id="scope" src="scope.png" width="1000" height="1000"style="display:none" /> </body> </html>

15 puzzle

<!DOCTYPE html>
<html>
<head>
    <title>15 puzzle</title>
    <meta charset="UTF-8">
    <style>
          .tile {
            width: 70px;
            height: 70px;
            border: 1px solid rgb(105, 255, 0);
            border-radius: 10px;
            text-align: center;
            font-size: 30px;
            color: rgb(210, 40, 40);
            background-color: rgb(0, 0, 0);
            box-shadow: rgb(201, 11, 255) 10px 10px;
            text-shadow: 1px 1px 3px rgb(66, 255, 0);
          }
          h1{
            color: rgb(255, 0, 0);
          }

    </style>
    <script type="text/javascript">

        "use strict";

        // 広域変数
        var tiles = [];


        // 初期化関数
        function init() {
          var table = document.getElementById("table");

        for (var i = 0 ; i < 4 ; i++) {
            var tr = document.createElement("tr");
            for (var j = 0 ; j < 4 ; j++) {
              var td = document.createElement("td");
              var index = i * 4 + j;
              td.className = "tile";
              td.index = index;
              td.value = index;
              td.textContent = index == 0 ? "" : index;
              td.onclick = click;
              tr.appendChild(td);
              tiles.push(td);
                }
                table.appendChild(tr);
                //timer = setInterval(tick,1000);
              }
              for (var i = 0; i < 1000 ; i++) {
                click({ srcElement: {index: Math.floor(Math.random() * 16)}})
              }
            }

            function click(e) {
              var i = e.srcElement.index;

              if (i - 4 >= 0 && tiles[i - 4].value == 0) {
                swap(i, i - 4); //上
            } else if (i + 4 < 16 && tiles[i + 4].value == 0) {
                swap(i, i + 4); //下
            } else if (i % 4 != 0 && tiles[i - 1].value == 0) {
                swap(i, i - 1); //左
            } else if (i %  4!= 3 && tiles[i + 1].value == 0) {
                swap(i, i + 1); //右
            }
          }

          function tick() {
            var now = new Dete();
            var elapsed = Math.floor((now.getTime() - startTime.getTime()) /1000);
            document.getElementById("time").textContent = elapsed;
          }

          function swap(i, j) {
            var tmp = tiles[i].value;
            tiles[i].textContent = tiles[j].textContent;
            tiles[i].value = tiles[j].value;
            tiles[j].textContent = tmp;
            tiles[j].value = tmp;
          }
    </script>
  </head>
<body onload="init()">
    <h1>15 puzzle</h1>
      <table id="table"></table>
</body>
</html>