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

2017/10/05 18:07:50

MixJuice GET URL : kidspod.club/mj/379

チャージャーのDNA

画面をタップ(クリック)して、DNAを育てよう!
タップしている間、DNAはどんどん伸びていくぞ。
時間内にお手本のDNAと同じ長さにできるかチャレンジだ。
大きくズレるとゲームオーバー!
IchigoLatteで遊ぶときは、ボタンを押そう。

"The DNA of Charger"
Tap (click) the screen to grow DNA!
While tapping, DNA will grow steadily.
It is a challenge that you can make it the same length as the model DNA in time.
Game over if you shift big!
When playing with IchigoLatte, press the button.

SOURCE CODE

var pow=0;
var delay=0;
var score=0;

var m_x=6,m_h=0;
var q_x=26,q_h=0;
var b_y=20;

var start=0;
var limit=3000;


function draw(x,h){
  var i=0;
  while(i<h){
    lc(x,b_y-i);log(chr(158));
    i=i+1;
  }
}

function next(){
  cls();
  q_h=rnd(10)+5;
  delay=rnd(limit/q_h/10-10)+1;

  draw(q_x,q_h);
  lc(q_x,b_y-q_h);log(chr(249));

  pow=0;
  m_h=0;
  start=tick();

  main();
}

function main(){
  if(btn()==1){
    lc(m_x+1,b_y);log("!");
    pow=pow+1;
    if(pow%10==0){
      m_h=m_h+1;
      draw(m_x,m_h);
    }
  }else{
    lc(m_x+1,b_y);log(" ");
  }

  var r=limit-(tick()-start);
  if(r<0) r=0;
  lc(14,3);log("    ");
  lc(14,3);log(r)

  if(r==0){
    var d=m_h-q_h;
    if((-1<=d)*(d<=1)){
      result();
    } else {
      lc(12,10);log("GameOver");
      lc(12,11);log("score : ",score,"\n");

      exit();
    }
  }else{
    setTout(main,delay);
  }
}

function result(){
  lc(12,10);
  if((m_h==q_h+1)+(m_h==q_h-1)){
    score=score+1;
    log("GOOD. : +1");
  }

  if(m_h==q_h){
    score=score+3;
    log("GREAT! : +3");
  }

  setTout(next,1500);
}

next();

COMMENT