Enjoy programming more!
Kidspod is a post site which supports young programmers.
First step to join us.
Register as a member
For members

2020/08/18 19:12:20

MixJuice GET URL : kidspod.club/mj/997

kawakudari

IchigoJam フォントで「かわくだり」してみました。
フォントの読み込み部分のソースコードは割愛して掲載しています。

SOURCE CODE

const CHAR_SX = 8;
const CHAR_SY = 8;

var std15 = function(drawNode, screen_sx, screen_sy, cb_sx, cb_sy){
  var that = {};
  var cb_unit = screen_sx / cb_sx / CHAR_SX;
  var charBuff = new Array(cb_sx*cb_sy);
  var cursor_x = 0;
  var cursor_y = 0;
  var white = cc.color(255, 255, 255);

  {
	  var font = ichigojamfont_data.split("\n");
	
  	var bfont = [];
  	for (var j = 0; j < font.length; j++) {
  		var code = font[j];
  		var bf = [];
  		for (var i = 0; i < 8; i++) {
  			var n = parseInt(code.substring(i * 2, i * 2 + 2), 16);
  			bf.push(n);
  		}
  		bfont.push(bf);
  	}
  	that.ichigojamfont = bfont;
  }  

  that.locate = function (x, y) {
    cursor_x = x;
    cursor_y = y;
  }

  that.putc = function (c) {
    that.putcLoc(cursor_x, cursor_y, c);
  }

  that.putcLoc = function (x, y, c) {
    charBuff [y*cb_sx+x] = c.charCodeAt(0);
  }

  that.scr = function (x, y) {
    return charBuff [y*cb_sx+x];
  }

  that.cls = function () {
    for (var y = 0; y < cb_sy; ++y) {
      for (var x = 0; x < cb_sx; ++x) {
        charBuff [y*cb_sx+x] = 0;
      }
    }
  }

  that.scroll = function () {
    for (var y = 0; y < cb_sy; ++y) {
      for (var x = 0; x < cb_sx; ++x ) {
        if (y == cb_sy-1) {
          charBuff [y*cb_sx+x] = 0;
        } else {
          charBuff [y*cb_sx+x] = charBuff [(y+1)*cb_sx+x];
        }
      }
    }
  }
  
  that.mapchar = function (cx, cy, c) {
    // [memo] '\0' == 0 -> char of blank
    var glyph = that.ichigojamfont[c];
    for(var y = 0 ; y < CHAR_SY; ++y) {
      var line = glyph[y];
      for(var x = 0 ; x < CHAR_SX; ++x) {
        if(((line >> (CHAR_SX-x-1)) & 0x1) == 0x1){
         var x0 = (cx*CHAR_SX+x)*cb_unit;
         var y0 = (480-10)-((cy*CHAR_SY+y)*cb_unit);
          drawNode.drawRect(cc.p(x0, y0), cc.p(x0+cb_unit, y0+cb_unit), white);
        }
        
      }
    }

  }

  that.ccDraw = function() {
    drawNode.clear();
    for (var y = 0; y < cb_sy; ++y) {
      for (var x = 0; x < cb_sx; ++x) {
        that.mapchar(x, y, charBuff [y*cb_sx+x]);
      }
    }  
  }
  
  that.cls();

  return that;
}


var res = {

};

var MyLayer = cc.KidspodLayer.extend({

  _std15:null,
  _frameCount:0,
  _running:true,
  _x:15,
  
  init:function(){
    this._super();
    this.scheduleUpdate();
    var size = cc.director.getWinSize();
    
    var drawNode = new cc.DrawNode();
    this._std15 = std15(drawNode,320,470,32,47);
    this.addChild(drawNode);
    return true;
  },

  update:function(dt){
    if(this._frameCount % 3 == 0) {
      if(!this._running) return;
      this._std15.locate(this._x, 5);
      this._std15.putc('0');
      this._std15.locate(Math.floor(Math.random() * Math.floor(32)), 46);
      this._std15.putc('*');
      this._std15.scroll();
      if(this._std15.scr(this._x,5) != 0){
        this._running = false;
      }
      this._std15.ccDraw();
    }
    ++this._frameCount;
  },

  onMouseDown:function(event){
    if(event._x < 160) {
      --this._x;
    } else {
      ++this._x;
    }
  },

  onKeyPressed:function(key, event){
    if(key == cc.KEY.left)  --this._x;
    if(key == cc.KEY.right) ++this._x;
    // if(key == cc.KEY.up)
    // {
    //   // キーボードの上キーが押されたとき
    // }
    // else if(key == cc.KEY.down)
    // {
    //   // キーボードの下キーが押されたとき
    // }
    // else if(key == cc.KEY.left)
    // {
    //   // キーボードの左キーが押されたとき
    // }
    // else if(key == cc.KEY.right)
    // {
    //   // キーボードの右キーが押されたとき
    // }

  },

  onTouchBegan:function(touch, event){
    if(touch.getLocation().x < 160) {
      --this._x;
    } else {
      ++this._x;
    }
  },

  onAccelerometer:function(accelero, event){

  },

});



var MyScene = cc.Scene.extend({
  onEnter:function (){
      this._super();
      var layer = new MyLayer();
      layer.init();
      this.addChild(layer);
  }
});








  

COMMENT

Kidspod運営チーム
Kidspod運営チーム2020/09/04 09:47:37

伝統のゲームですね。フォントが揃っているので、違いは画面が横長か縦長かくらいでしょうか。これだけの違いで、ゲームをプレイした感覚が変わるのが面白いですね。まるで難易度も違っているような……。