public GameObject player;
public GameObject platformPrefab;
public float minY = -4.5f;
public float maxY = 4.7f;
public float ratio = 1.2f;
public float sizeplatformony;
public float lastvalue;
Vector2 spawnFix;
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Platform"))
{
Value = player.transform.position.y + Random.Range(MinY MaxY);
Vector2 targetPosition = new Vector2(Random.Range(-1.8f, 1.8f), value);
if(Value-lastvalue > sizeplatformony + ratio){
GameObject p = Instantiate(platformPrefab, targetPosition, Quaternion.identity);
Destroy(collision.gameObject);
lastvalue = Value;
} else {
GameObject p = Instantiate(platformPrefab, targetPosition+ratio, Quaternion.identity);
Destroy(collision.gameObject);
lastvalue = Value + ratio;
}
}
}
const lerp = (min, max, value) => (1 - value) * min + value * max;
const LEVELS = 10;
const MAX_EXPERIENCE = 600000;
const multipliers = [];
for (let index = 0; index < LEVELS - 1; index++) {
multipliers.push(
lerp(1, 2, index / LEVELS)
);
}
const total = multipliers.reduce((total, value) => total + value, 0);
const step = MAX_EXPERIENCE / total;
const { levels } = multipliers.reduce((store, multiplier, index) => {
const experience = step * multiplier;
store.levels.push({
level: index + 1,
experience: {
current: store.total,
next: store.total + experience,
need: experience
}
});
store.total += experience;
if (index + 1 === LEVELS - 1) {
store.levels.push({
level: LEVELS,
experience: {
current: store.total
}
});
}
return store;
}, { levels: [], total: 0 });
console.log(levels);
/*
[
{
level: 1,
experience: { current: 0, next: 47619.04761904762, need: 47619.04761904762 }
},
{
level: 2,
experience: { current: 47619.04761904762, next: 100000, need: 52380.95238095238 }
},
{
level: 3,
experience: { current: 100000, next: 157142.85714285716, need: 57142.85714285715 }
},
{
level: 4,
experience: { current: 157142.85714285716, next: 219047.61904761905, need: 61904.761904761894 }
},
{
level: 5,
experience: { current: 219047.61904761905, next: 285714.2857142857, need: 66666.66666666666 }
},
{
level: 6,
experience: { current: 285714.2857142857, next: 357142.8571428571, need: 71428.57142857142 }
},
{
level: 7,
experience: { current: 357142.8571428571, next: 433333.3333333333, need: 76190.4761904762 }
},
{
level: 8,
experience: { current: 433333.3333333333, next: 514285.71428571426, need: 80952.38095238095 }
},
{
level: 9,
experience: { current: 514285.71428571426, next: 600000, need: 85714.28571428571 }
},
{
level: 10,
experience: { current: 600000 }
}
]
*/
const lerp = (min, max, value) => (1 - value) * min + value * max;
const easeInCubic = value => value * value * value;
const LEVELS = 10;
const MAX_EXPERIENCE = 600000;
const multipliers = [];
for (let index = 0; index < LEVELS - 1; index++) {
multipliers.push(
lerp(1, 2, easeInCubic(index / LEVELS))
);
}
const total = multipliers.reduce((total, value) => total + value, 0);
const step = MAX_EXPERIENCE / total;
const { levels } = multipliers.reduce((store, multiplier, index) => {
const experience = step * multiplier;
store.levels.push({
level: index + 1,
experience: {
current: store.total,
next: store.total + experience,
need: experience
}
});
store.total += experience;
if (index + 1 === LEVELS - 1) {
store.levels.push({
level: LEVELS,
experience: {
current: store.total
}
});
}
return store;
}, { levels: [], total: 0 });
console.log(levels);
/*
[
{
level: 1,
experience: { current: 0, next: 58275.058275058276, need: 58275.058275058276 }
},
{
level: 2,
experience: { current: 58275.058275058276, next: 116608.3916083916, need: 58333.33333333333 }
},
{
level: 3,
experience: { current: 116608.3916083916, next: 175349.65034965036, need: 58741.258741258745 }
},
{
level: 4,
experience: { current: 175349.65034965036, next: 235198.13519813522, need: 59848.48484848485 }
},
{
level: 5,
experience: { current: 235198.13519813522, next: 297202.79720279726, need: 62004.66200466201 }
},
{
level: 6,
experience: { current: 297202.79720279726, next: 362762.2377622378, need: 65559.44055944055 }
},
{
level: 7,
experience: { current: 362762.2377622378, next: 433624.70862470864, need: 70862.47086247086 }
},
{
level: 8,
experience: { current: 433624.70862470864, next: 511888.1118881119, need: 78263.40326340326 }
},
{
level: 9,
experience: { current: 511888.1118881119, next: 600000, need: 88111.88811188811 }
},
{
level: 10,
experience: { current: 600000 }
}
]
*/
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d");
canvas.width = canvas.height = 300;
var x = 150,
y = 150,
velY = 0,
velX = 0,
speed = 2,
friction = 0.98,
keys = [];
function update() {
requestAnimationFrame(update);
if (keys[38]) {
if (velY > -speed) {
velY--;
}
}
if (keys[40]) {
if (velY < speed) {
velY++;
}
}
if (keys[39]) {
if (velX < speed) {
velX++;
}
}
if (keys[37]) {
if (velX > -speed) {
velX--;
}
}
velY *= friction;
y += velY;
velX *= friction;
x += velX;
if (x >= 295) {
x = 295;
} else if (x <= 5) {
x = 5;
}
if (y > 295) {
y = 295;
} else if (y <= 5) {
y = 5;
}
ctx.clearRect(0, 0, 300, 300);
ctx.beginPath();
ctx.arc(x, y, 5, 0, Math.PI * 2);
ctx.fill();
}
update();
document.body.addEventListener("keydown", function (e) {
keys[e.keyCode] = true;
});
document.body.addEventListener("keyup", function (e) {
keys[e.keyCode] = false;
});
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
ws.binaryType = 'arraybuffer';
for (var i = 0; i < this.food.length; i++) {
const {x: x1, y: y1} = this.position
const r1 = this.cell_radius
const {x: x2, y: y2} = this.food[i]
const r2 = this.food_size
const distance = Math.sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) )
const intersects = distance <= r1 + r2
if(intersects) {
console.log('I EAT', this.food[i])
}
}