Skip to content

Instantly share code, notes, and snippets.

@romw314
Created December 11, 2023 18:39
Show Gist options
  • Save romw314/b782d21883e8a2a2584a13e59de69b8d to your computer and use it in GitHub Desktop.
Save romw314/b782d21883e8a2a2584a13e59de69b8d to your computer and use it in GitHub Desktop.
Replace appengine/pond/duck/default-ducks.js in blocklyGAMES to make ducks editable.
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Demo ducks for Pond battle.
* @author [email protected] (Neil Fraser)
*/
'use strict';
const bzz=`
<xml>
<block type="pond_cannon" x="70" y="70">
<value name="DEGREE">
<shadow type="pond_math_number">
<mutation angle_field="true" />
<field name="NUM">0</field>
</shadow>
</value>
<value name="RANGE">
<shadow type="pond_math_number">
<mutation angle_field="false" />
<field name="NUM">70</field>
</shadow>
</value>
</block>
</xml>`;
var DUCKS = [
{name: "Romut", id: "default", editable: true, blockly: `
<xml>
<block type="pond_cannon" x="70" y="70">
<value name="DEGREE">
<shadow type="pond_math_number">
<mutation angle_field="true" />
<field name="NUM">0</field>
</shadow>
</value>
<value name="RANGE">
<shadow type="pond_math_number">
<mutation angle_field="false" />
<field name="NUM">70</field>
</shadow>
</value>
</block>
</xml>`, compiled: "cannon(0, 70);", competent: false},
{name: "Marut", id: "rook", editable: true, compiled: 'cannon(0,70);',blockly:bzz},
{name: "Counter", id: "counter", editable: false, compiled: `
/* counter */
/* scan in a counter-clockwise direction (increasing degrees) */
/* moves when hit */
var range;
var last_dir = 0;
var res = 2;
var d = damage();
var angle = Math.random() * 360;
while (true) {
while ((range = scan(angle, res)) != Infinity) {
if (range > 70) { /* out of range, head toward it */
drive(angle, 50);
var i = 1;
while (i++ < 50) /* use a counter to limit move time */
;
drive (angle, 0);
if (d != damage()) {
d = damage();
run();
}
angle -= 3;
} else {
while (!cannon(angle, range))
;
if (d != damage()) {
d = damage();
run();
}
angle -= 15;
}
}
if (d != damage()) {
d = damage();
run();
}
angle += res;
angle %= 360;
}
/* run moves around the center of the field */
function run() {
var i = 0;
var x = getX();
var y = getY();
if (last_dir == 0) {
last_dir = 1;
if (y > 51) {
drive(270, 100);
while (y - 10 < getY() && i++ < 50)
;
drive(270, 0);
} else {
drive(90, 100);
while (y + 10 > getY() && i++ < 50)
;
drive(90, 0);
}
} else {
last_dir = 0;
if (x > 51) {
drive(180, 100);
while (x - 10 < getX() && i++ < 50)
;
drive(180, 0);
} else {
drive(0, 100);
while (x + 10 > getX() && i++ < 50)
;
drive(0, 0);
}
}
}`
},
{name: 'Ocut', id: 'sniper', editable: true, compiled: "cannon(0,70);", blockly:bzz}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment