Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas id="cvs" width="400" height="400"></canvas>
              
            
!

CSS

              
                body { background-color: #FFFFFF; }
              
            
!

JS

              
                //ゲームっぽい画面表示、にできず。。。
//
//以下のコードのような実装を目指してみましたが、画像表示だけに終わりました。。。
//js on 2010-6-19
//http://jsdo.it/komagata/fCX0
//ワンダフルクエスト
//http://wonderfl.net/c/wu8f
//↑画像データは上記コードからのものを使用させてもらってまいす
//
//以下コードをbase64画像への変換に使用させていただきました
//2009-3-14 選んだファイルを Base64 エンコードする
//http://wonderfl.net/c/h1NU
//
var sunaImg; //砂
var shibafuImg; //芝生
var mizuImg; //水
var sabotenImg; //サボテン
var makkuraImg; //真っ暗
var mapImg;

//base64データ保持用
var shibafuData;       //芝生
var sunaData;          //砂
var sabotenData;       //サボテン
var mizuData;          //水
var makkuraData;       //真っ暗

//勇者用
var yuushaFrontImgOne; //勇者前向き1
var yuushaFrontImgTwo; //勇者前向き2
var yuushaFrontDataOne; //勇者前向き1のbase64データ保持用
var yuushaFrontDataTwo; //勇者前向き2のbase64データ保持用
var walkFlag = true;      //足踏み用

var ctx;

var SCALE = 1; //勇者やフィールドの拡大率
var MAPSIZE = 16; //マップの横・縦のマスの個数
var FLDSIZE = 16; //フィールド(マップ上の1マス)の横・縦のドット数
var walkFlg = true;
var frameCount = 0;
var yuushaXPos = MAPSIZE/2;
var yuushaYPos = MAPSIZE/2;

//0:砂漠 1:芝生 2:水 3:サボテン
var mapData = 
            [[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
             [ 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2],
             [ 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2],
             [ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
             [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
var bMapData = []; //フィールドが障害物か否かを記憶

window.onload = function () {
  setImageData();
  init();
}

function init() {
  canvas = document.getElementById("cvs");
  if (!canvas) return false;
  canvas.width = 400;
  canvas.height = 400;
  ctx= canvas.getContext("2d");
  if(!ctx) return false;

  sunaImg = new Image();
  sunaImg.src = sunaData;

  shibafuImg = new Image();
  shibafuImg.src = shibafuData;

  mizuImg = new Image();
  mizuImg.src = mizuData;

  sabotenImg = new Image();
  sabotenImg.src = sabotenData;

  makkuraImg = new Image();
  makkuraImg.src = makkuraData;

  yuushaFrontImgOne = new Image();
  yuushaFrontImgOne.src = yuushaFrontDataOne;

  yuushaFrontImgTwo = new Image();
  yuushaFrontImgTwo.src = yuushaFrontDataTwo;

  createMap();

  //キープレスイベントを処理
  document.addEventListener('keydown', handleKeyDown, false);

  setInterval(loop, 10);
}

function handleKeyDown(event) {
  if (event.keyCode==38) {//↑ボタン押下
    if (yuushaYPos > 0) {yuushaYPos--;}
  } else if (event.keyCode==40) {//↓ボタン押下
    if (yuushaYPos < 15) {yuushaYPos++;}
  } else if (event.keyCode==39) {//→ボタン押下
    if (yuushaXPos < 15) {yuushaXPos++;}
  } else if (event.keyCode==37) {//←ボタン押下
    if (yuushaXPos > 0) {yuushaXPos--;}
  }
  //とりあえずごまかしぎみに、キー入力された時のみ保持したマップを再描画
  ctx.putImageData(mapImg, 0, 0);
}

function loop() {
  //勇者画像表示
  //15フレーム毎に処理する
  if (frameCount++ > 15) {
    frameCount = 0;
    walkFlg = !walkFlg;
    if(walkFlg) {
      ctx.drawImage(yuushaFrontImgOne, FLDSIZE*yuushaXPos, FLDSIZE*yuushaYPos);
    } else {
      ctx.drawImage(yuushaFrontImgTwo, FLDSIZE*yuushaXPos, FLDSIZE*yuushaYPos);
    }
  }
}

function createMap() {
  for (k = 0; k < MAPSIZE; k++) bMapData[k] = []; //bMapDataを2次元配列にする

  for (j = 0; j < MAPSIZE; j++){
    for (i = 0; i < MAPSIZE; i++){
      var imgPosX = FLDSIZE * i;
      var imgPosY = FLDSIZE * j;
      var isObstacle;
      if ([mapData[j][i]] == 0) {
        ctx.drawImage(sunaImg, imgPosX, imgPosY);
        bMapData[j][i] = false;
      } else if ([mapData[j][i]] == 1) {
        ctx.drawImage(shibafuImg, imgPosX, imgPosY);
        bMapData[j][i] = false;
      } else if ([mapData[j][i]] == 2) {
        ctx.drawImage(mizuImg, imgPosX, imgPosY);
        bMapData[j][i] = true;
      } else if ([mapData[j][i]] == 3) {
        ctx.drawImage(sabotenImg, imgPosX, imgPosY);
        bMapData[j][i] = true;
      } else if ([mapData[j][i]] == 4) {
        ctx.drawImage(makkuraImg, imgPosX, imgPosY);
        bMapData[j][i] = true;
      }
      //マップをまとめて保持
      mapImg = ctx.getImageData(0, 0, MAPSIZE*FLDSIZE, MAPSIZE*FLDSIZE);
    }
  }

}

function setImageData() {
  //砂
  sunaData =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAANklEQVQokWP4v8MDE+2sYsAqDkQ4JaigAWItA34H0NdJg0ED1sAYYn4goIHI+CZKEbJZJDsJAExt+khTZWqXAAAAAElFTkSuQmCC";
  //芝生
  shibafuData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAANElEQVQokWOYdIcBExlOwyIIQTglqKABYi0BB9DXSYNBA9bAGGJ+IKCByPgmShGyWSQ7CQCHEmomoGsXjwAAAABJRU5ErkJggg==";
  //水
  mizuData =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAAcUlEQVQokZWSwQ2AMAwDvS/bsAlLMAUvFimRLIXQummQ/GivUWpHwXY27JfpuJvJDkYoyeGUd765BI8NvI4VkmNszOuMI7ErOTK7kid2JUdiV3JUZh85SrMPHEvTPa/M/sOLK/T+WV2hGPpXjD70MsYDrQTzsOkaBq4AAAAASUVORK5CYII=";
  //サボテン
  sabotenData =  "data:image/png;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951TAAABAHRSTlP/AP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////rTvmKwAAAFxJREFUGJVtj8ENwDAIA2+C7r8R725UbCAiUvNIiM8gw1MHpugngiWQ/3hZDilHUHc5EE6WSIKBOIl6hqBr8RLAd2tud+PYelLlki/NVzDsP8l/krIEz7u2Zfb/AKt1Pp87jJKZAAAAAElFTkSuQmCC";
  //真っ暗
  makkuraData =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGElEQVQ4jWNgYGD4TyEeNWDUgFEDhocBAJvM/wEeNfmLAAAAAElFTkSuQmCC";

  //勇者前向き
  yuushaFrontDataOne = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAADAFBMVEUAAACAAAAAgACAgAAAAICAAIAAgIDAwMDA3MCmyvD/8NT/4rH/1I7/xmv/uEj/qiX/qgDckgC5egCWYgBzSgBQMgD/49T/x7H/q47/j2v/c0j/VyX/VQDcSQC5PQCWMQBzJQBQGQD/1NT/sbH/jo7/a2v/SEj/JSX+AADcAAC5AACWAABzAABQAAD/1OP/scf/jqv/a4//SHP/JVf/AFXcAEm5AD2WADFzACVQABn/1PD/seL/jtT/a8b/SLj/Jar/AKrcAJK5AHqWAGJzAEpQADL/1P//sf//jv//a///SP//Jf/+AP7cANy5ALmWAJZzAHNQAFDw1P/isf/Ujv/Ga/+4SP+qJf+qAP+SANx6ALliAJZKAHMyAFDj1P/Hsf+rjv+Pa/9zSP9XJf9VAP9JANw9ALkxAJYlAHMZAFDU1P+xsf+Ojv9ra/9ISP8lJf8AAP4AANwAALkAAJYAAHMAAFDU4/+xx/+Oq/9rj/9Ic/8lV/8AVf8ASdwAPbkAMZYAJXMAGVDU8P+x4v+O1P9rxv9IuP8lqv8Aqv8AktwAerkAYpYASnMAMlDU//+x//+O//9r//9I//8l//8A/v4A3NwAubkAlpYAc3MAUFDU//Cx/+KO/9Rr/8ZI/7gl/6oA/6oA3JIAuXoAlmIAc0oAUDLU/+Ox/8eO/6tr/49I/3Ml/1cA/1UA3EkAuT0AljEAcyUAUBnU/9Sx/7GO/45r/2tI/0gl/yUA/gAA3AAAuQAAlgAAcwAAUADj/9TH/7Gr/46P/2tz/0hX/yVV/wBJ3AA9uQAxlgAlcwAZUADw/9Ti/7HU/47G/2u4/0iq/yWq/wCS3AB6uQBilgBKcwAyUAD//9T//7H//47//2v//0j//yX+/gDc3AC5uQCWlgBzcwBQUADy8vLm5uba2trOzs7CwsK2traqqqqenp6SkpKGhoZ6enpubm5iYmJWVlZKSko+Pj4yMjImJiYaGhoODg7/+/CgoKSAgID/AAAA/wD//wAAAP//AP8A///////g951TAAABAHRSTlP/AP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////rTvmKwAAAF5JREFUGJVNz4sNACEIA1CYotMye698vSYm8oKK5nQlKrmzAhVkywAJiA7YR7igPQKoMwNV48AX7g6Jopq0mNSzWuZ6L06BhJLXkTexB2OB/0fng/keG7LbYybdBu98alNb5ZfPFBgAAAAASUVORK5CYII=";
  yuushaFrontDataTwo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAADAFBMVEUAAACAAAAAgACAgAAAAICAAIAAgIDAwMDA3MCmyvD/8NT/4rH/1I7/xmv/uEj/qiX/qgDckgC5egCWYgBzSgBQMgD/49T/x7H/q47/j2v/c0j/VyX/VQDcSQC5PQCWMQBzJQBQGQD/1NT/sbH/jo7/a2v/SEj/JSX+AADcAAC5AACWAABzAABQAAD/1OP/scf/jqv/a4//SHP/JVf/AFXcAEm5AD2WADFzACVQABn/1PD/seL/jtT/a8b/SLj/Jar/AKrcAJK5AHqWAGJzAEpQADL/1P//sf//jv//a///SP//Jf/+AP7cANy5ALmWAJZzAHNQAFDw1P/isf/Ujv/Ga/+4SP+qJf+qAP+SANx6ALliAJZKAHMyAFDj1P/Hsf+rjv+Pa/9zSP9XJf9VAP9JANw9ALkxAJYlAHMZAFDU1P+xsf+Ojv9ra/9ISP8lJf8AAP4AANwAALkAAJYAAHMAAFDU4/+xx/+Oq/9rj/9Ic/8lV/8AVf8ASdwAPbkAMZYAJXMAGVDU8P+x4v+O1P9rxv9IuP8lqv8Aqv8AktwAerkAYpYASnMAMlDU//+x//+O//9r//9I//8l//8A/v4A3NwAubkAlpYAc3MAUFDU//Cx/+KO/9Rr/8ZI/7gl/6oA/6oA3JIAuXoAlmIAc0oAUDLU/+Ox/8eO/6tr/49I/3Ml/1cA/1UA3EkAuT0AljEAcyUAUBnU/9Sx/7GO/45r/2tI/0gl/yUA/gAA3AAAuQAAlgAAcwAAUADj/9TH/7Gr/46P/2tz/0hX/yVV/wBJ3AA9uQAxlgAlcwAZUADw/9Ti/7HU/47G/2u4/0iq/yWq/wCS3AB6uQBilgBKcwAyUAD//9T//7H//47//2v//0j//yX+/gDc3AC5uQCWlgBzcwBQUADy8vLm5uba2trOzs7CwsK2traqqqqenp6SkpKGhoZ6enpubm5iYmJWVlZKSko+Pj4yMjImJiYaGhoODg7/+/CgoKSAgID/AAAA/wD//wAAAP//AP8A///////g951TAAABAHRSTlP/AP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////rTvmKwAAAGNJREFUGJVVkNERAEEEQ6ki1ao9l7DMnJ/lDREb2VEdzmJrckgkDUhA6ABnhAuUo4CeeaBrHMgFpyGikDQNRlGPE7rj7SitBsMb+OsA5OMZO/Csq0mitaeN1dhbPca79n4g8wOB+V8BcL2yOAAAAABJRU5ErkJggg==";
 
}

              
            
!
999px

Console