<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// TODO: add intersects method to Circle

CLASS({
  package: 'foam.demos.supersnake',
  name: 'Scale',
  extendsModel: 'foam.graphics.Circle',
  traits: [ 'foam.physics.Physical' ]
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Snake',
  extendsModel: 'foam.graphics.CView',
  requires: [
    'foam.demos.supersnake.Scale',
    'foam.demos.supersnake.Laser'
  ],
  imports: [
    'game'
  ],

  imports: [ 'timer' ],
  constants: { R: 20 },

  properties: [
//    { name: 'scales', factory: function() { return []; } },
    { name: 'sx', defaultValue: 240 },
    { name: 'sy', defaultValue: 240 },
    { name: 'vx', defaultValue: 1 },
    { name: 'vy', defaultValue: 0 },
    { name: 'length', defaultValue: 5 }
  ],
  methods: [
    function init() {
      this.SUPER();

      this.timer.i$.addListener(this.tick);
    },
    function up()    { this.vy = -1; this.vx =  0; },
    function down()  { this.vy =  1; this.vx =  0; },
    function left()  { this.vy =  0; this.vx = -1; },
    function right() { this.vy =  0; this.vx =  1; },
    function fire () {
      this.Laser.create({x: this.sx, y: this.sy, vx: this.vx, vy: this.vy});
    },
    function intersects(o) {
      return this.children[this.children.length-1].intersects(o);
    }
  ],
  listeners: [
    {
      name: 'tick',
      isMerged: 150,
      code: function() {
        this.sx += this.vx * 2*this.R;
        this.sy += this.vy * 2*this.R;
        if ( this.children.length )
          this.children[this.children.length-1].color = 'green';
        this.addChild(this.Scale.create({x: this.sx, y: this.sy, radius: this.R, color: 'red'}));
        if ( this.children.length > this.length ) {
          this.children.shift();
        }
      }
    }
  ]
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Food',
  extendsModel: 'foam.graphics.Circle',
  traits: [ 'foam.physics.Physical' ],
  properties: [
    { name: 'color', defaultValue: 'darkblue' }
  ],
  methods: [
    function init() {
      this.SUPER();

      Movement.animate(15000, function() {
        this.r = 0;
      }.bind(this))();
    }
  ]
});

// TODO: add explode method
CLASS({
  package: 'foam.demos.supersnake',
  name: 'Mushroom',
  extendsModel: 'foam.graphics.Circle',
  traits: [ 'foam.physics.Physical' ],
  requires: [ 'foam.graphics.Rectangle' ],
  properties: [
    { name: 'color', defaultValue: 'red' },
    { name: 'endAngle', defaultValue: Math.PI },
    'stem'
  ],
  methods: [
    function init() {
      this.SUPER();

      this.addChild(this.stem = this.Rectangle.create({
        x: -7.5,
        y: -0.5,
        width: 15,
        height: 20,
        background: 'gray'
      }));
    }
  ]
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Laser',
  extendsModel: 'foam.graphics.Circle',
  traits: [ 'foam.physics.Physical' ],
  imports: [ 'game' ],
  properties: [
    { name: 'color',  defaultValue: 'yellow' },
    { name: 'r',      defaultValue: 12 },
    'vx', 'vy'<commit_msg>Removed Physical trait from snake game objects.<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// TODO: add intersects method to Circle

CLASS({
  package: 'foam.demos.supersnake',
  name: 'Scale',
  extendsModel: 'foam.graphics.Circle',
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Snake',
  extendsModel: 'foam.graphics.CView',
  requires: [
    'foam.demos.supersnake.Scale',
    'foam.demos.supersnake.Laser'
  ],
  imports: [
    'game'
  ],

  imports: [ 'timer' ],
  constants: { R: 20 },

  properties: [
//    { name: 'scales', factory: function() { return []; } },
    { name: 'sx', defaultValue: 240 },
    { name: 'sy', defaultValue: 240 },
    { name: 'vx', defaultValue: 1 },
    { name: 'vy', defaultValue: 0 },
    { name: 'length', defaultValue: 5 }
  ],
  methods: [
    function init() {
      this.SUPER();

      this.timer.i$.addListener(this.tick);
    },
    function up()    { this.vy = -1; this.vx =  0; },
    function down()  { this.vy =  1; this.vx =  0; },
    function left()  { this.vy =  0; this.vx = -1; },
    function right() { this.vy =  0; this.vx =  1; },
    function fire () {
      this.Laser.create({x: this.sx, y: this.sy, vx: this.vx, vy: this.vy});
    },
    function intersects(o) {
      return this.children[this.children.length-1].intersects(o);
    }
  ],
  listeners: [
    {
      name: 'tick',
      isMerged: 150,
      code: function() {
        this.sx += this.vx * 2*this.R;
        this.sy += this.vy * 2*this.R;
        if ( this.children.length )
          this.children[this.children.length-1].color = 'green';
        this.addChild(this.Scale.create({x: this.sx, y: this.sy, radius: this.R, color: 'red'}));
        if ( this.children.length > this.length ) {
          this.children.shift();
        }
      }
    }
  ]
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Food',
  extendsModel: 'foam.graphics.Circle',
  properties: [
    { name: 'color', defaultValue: 'darkblue' }
  ],
  methods: [
    function init() {
      this.SUPER();

      Movement.animate(15000, function() {
        this.r = 0;
      }.bind(this))();
    }
  ]
});

// TODO: add explode method
CLASS({
  package: 'foam.demos.supersnake',
  name: 'Mushroom',
  extendsModel: 'foam.graphics.Circle',
  requires: [ 'foam.graphics.Rectangle' ],
  properties: [
    { name: 'color', defaultValue: 'red' },
    { name: 'endAngle', defaultValue: Math.PI },
    'stem'
  ],
  methods: [
    function init() {
      this.SUPER();

      this.addChild(this.stem = this.Rectangle.create({
        x: -7.5,
        y: -0.5,
        width: 15,
        height: 20,
        background: 'gray'
      }));
    }
  ]
});


CLASS({
  package: 'foam.demos.supersnake',
  name: 'Laser',
  extendsModel: 'foam.graphics.Circle',
  imports: [ 'game' ],
  properties: [
    { name: 'color',  defaultValue: 'yellow' },
    { name: 'r',      defaultValue: 12 },
    'vx', 'vy'
{'fraction_non_alphanumeric': 0.166363254446156, 'fraction_numerical': 0.014003640946646127, 'mean_word_length': 2.563872255489022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4100745', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2471, 'n_words': 603}