SC CODE: // Copyright 2024. Civilware. All rights reserved.
// TELA Decentralized Web Document (TELA-DOC-1)
Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "effects.js")
31 STORE("descrHdr", "Effects file")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "effects.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "a17338b5ea4d3e3e26c342c21c979491c7b0e825a5ded4d77f9e51e4f2b3834")
37 STORE("fileCheckS", "33b5a2f0b952f4fb8473b5d85515333914d314673c57db3a7f8f170aeadc6b2")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*//msgs
function showEphemeralMessage(text, duration = 5000) {
const ui = document.getElementById("ui");
const msg = document.createElementNS("http://www.w3.org/2000/svg", "text");
msg.setAttribute("x",window.innerWidth / 2);
msg.setAttribute("y", 80);
msg.setAttribute("text-anchor", "middle");
msg.setAttribute("fill", "white");
msg.setAttribute("font-size", "28");
msg.setAttribute("opacity", "1");
msg.textContent = text;
ui.appendChild(msg);
// fade out
msg.animate(
[
{ opacity: 1 },
{ opacity: 0 }
],
{
duration: duration,
easing: "ease-out",
fill: "forwards"
}
);
// remove after fade
setTimeout(() => msg.remove(), duration);
}
// parallax
function addBackground(bg){
if(bg === "stars"){
generateStars(document.getElementById("bg-deep"), 200, 0.5, 0.3);
generateStars(document.getElementById("bg-mid"), 150, 1.0, 0.6);
generateStars(document.getElementById("bg-front"), 80, 1.5, 0.9);
}else{
document.getElementById("bg-deep").innerHTML = "";
document.getElementById("bg-mid").innerHTML = "";
document.getElementById("bg-front").innerHTML = "";
}
}
function generateStars(group, count, size, opacity) {
for (let i = 0; i < count; i++) {
const x = Math.random() * WORLD_W;
const y = Math.random() * WORLD_H;
const star = document.createElementNS("http://www.w3.org/2000/svg", "circle");
star.setAttribute("cx", x);
star.setAttribute("cy", y);
star.setAttribute("r", size);
star.setAttribute("fill", "white");
star.setAttribute("opacity", opacity);
group.appendChild(star);
star.animate([
{ opacity: 0.2 },
{ opacity: 1.0 },
{ opacity: 0.2 }
], {
duration: 2000 + Math.random() * 2000,
iterations: Infinity
});
}
}
// animate corpse
function deathAnimation(enemy) {
if (enemy.state === "dying") {
enemy.deathTimer += dt/1000;
const t = Math.min(enemy.deathTimer / .5, 1);
// shift skeleton downward so pivot looks correct
if(enemy.skeletonOffsetY < 80){
enemy.skeletonOffsetY = lerp(0, 80, t);
}
// Rotate backward over 0.5 seconds
if (enemy.deathTimer >= 1 && enemy.onGround) {
enemy.state = "dead";
let svgNode = document.getElementById(enemy.id)
svgNode.parentNode.insertBefore(svgNode, svgNode.parentNode.firstChild);
}
}
}
// flying hats
function spawnHat(target){
const hat = target.skeleton.torso.children.head.children.hat;
delete target.skeleton.torso.children.head.children.hat;
const hatObj = {
x: target.x,
y: target.y - 20,
vx: (Math.random() * 4 - 2),
vy: -6,
rotation: 0,
rotationSpeed: (Math.random() > .5 ? -Math.random(): Math.random())*2,
poly: hat.poly,
life: 2000,
g: null,
node: null
};
game.hats.push(hatObj);
const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
const polyNode = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
let fill = "#54f"
if(target.type ==="grunt" | target.type ==="defender"){
fill = "#b8a878"
}else if(target.type ==="boss"){
fill = "#000"
}
polyNode.setAttribute("fill",fill);
g.appendChild(polyNode);
document.getElementById("objects").appendChild(g);
hatObj.g = g;
hatObj.node = polyNode;
target.hasHat = false;
}
// Audio
let volume = .5;
let audioCtx;
function initAudio() {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
}
function sfxHuh() {
const ctx = audioCtx;
const o = ctx.createOscillator();
const g = ctx.createGain();
o.type = "sine";
o.frequency.setValueAtTime(80 + Math.random()*20, ctx.currentTime);
g.gain.setValueAtTime(volume * 0.6, ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.12);
o.connect(g).connect(ctx.destination);
o.start();
o.stop(ctx.currentTime + 0.12);
}
function sfxHit() {
const ctx = audioCtx;
// Breath noise
const buffer = ctx.createBuffer(1, 3000, 44100);
const data = buffer.getChannelData(0);
for (let i = 0; i < data.length; i++) {
data[i] = (Math.random() * 2 - 1) * (1 - i / data.length);
}
const noise = ctx.createBufferSource();
noise.buffer = buffer;
// Throat pop (low sine)
const o = ctx.createOscillator();
o.type = "sine";
o.frequency.setValueAtTime(120 + Math.random()*40, ctx.currentTime);
// Gain envelope
const g = ctx.createGain();
g.gain.setValueAtTime(volume * 0.5, ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.08);
noise.connect(g);
o.connect(g);
g.connect(ctx.destination);
noise.start();
o.start();
o.stop(ctx.currentTime + 0.08);
}
*/ |
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'// Copyright 2024. Civilware. All rights reserved.
// TELA Decentralized Web Document (TELA-DOC-1)
Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "effects.js")
31 STORE("descrHdr", "Effects file")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "effects.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "a17338b5ea4d3e3e26c342c21c979491c7b0e825a5ded4d77f9e51e4f2b3834")
37 STORE("fileCheckS", "33b5a2f0b952f4fb8473b5d85515333914d314673c57db3a7f8f170aeadc6b2")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*//msgs
function showEphemeralMessage(text, duration = 5000) {
const ui = document.getElementById("ui");
const msg = document.createElementNS("http://www.w3.org/2000/svg", "text");
msg.setAttribute("x",window.innerWidth / 2);
msg.setAttribute("y", 80);
msg.setAttribute("text-anchor", "middle");
msg.setAttribute("fill", "white");
msg.setAttribute("font-size", "28");
msg.setAttribute("opacity", "1");
msg.textContent = text;
ui.appendChild(msg);
// fade out
msg.animate(
[
{ opacity: 1 },
{ opacity: 0 }
],
{
duration: duration,
easing: "ease-out",
fill: "forwards"
}
);
// remove after fade
setTimeout(() => msg.remove(), duration);
}
// parallax
function addBackground(bg){
if(bg === "stars"){
generateStars(document.getElementById("bg-deep"), 200, 0.5, 0.3);
generateStars(document.getElementById("bg-mid"), 150, 1.0, 0.6);
generateStars(document.getElementById("bg-front"), 80, 1.5, 0.9);
}else{
document.getElementById("bg-deep").innerHTML = "";
document.getElementById("bg-mid").innerHTML = "";
document.getElementById("bg-front").innerHTML = "";
}
}
function generateStars(group, count, size, opacity) {
for (let i = 0; i < count; i++) {
const x = Math.random() * WORLD_W;
const y = Math.random() * WORLD_H;
const star = document.createElementNS("http://www.w3.org/2000/svg", "circle");
star.setAttribute("cx", x);
star.setAttribute("cy", y);
star.setAttribute("r", size);
star.setAttribute("fill", "white");
star.setAttribute("opacity", opacity);
group.appendChild(star);
star.animate([
{ opacity: 0.2 },
{ opacity: 1.0 },
{ opacity: 0.2 }
], {
duration: 2000 + Math.random() * 2000,
iterations: Infinity
});
}
}
// animate corpse
function deathAnimation(enemy) {
if (enemy.state === "dying") {
enemy.deathTimer += dt/1000;
const t = Math.min(enemy.deathTimer / .5, 1);
// shift skeleton downward so pivot looks correct
if(enemy.skeletonOffsetY < 80){
enemy.skeletonOffsetY = lerp(0, 80, t);
}
// Rotate backward over 0.5 seconds
if (enemy.deathTimer >= 1 && enemy.onGround) {
enemy.state = "dead";
let svgNode = document.getElementById(enemy.id)
svgNode.parentNode.insertBefore(svgNode, svgNode.parentNode.firstChild);
}
}
}
// flying hats
function spawnHat(target){
const hat = target.skeleton.torso.children.head.children.hat;
delete target.skeleton.torso.children.head.children.hat;
const hatObj = {
x: target.x,
y: target.y - 20,
vx: (Math.random() * 4 - 2),
vy: -6,
rotation: 0,
rotationSpeed: (Math.random() > .5 ? -Math.random(): Math.random())*2,
poly: hat.poly,
life: 2000,
g: null,
node: null
};
game.hats.push(hatObj);
const g = document.createElementNS("http://www.w3.org/2000/svg", "g");
const polyNode = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
let fill = "#54f"
if(target.type ==="grunt" | target.type ==="defender"){
fill = "#b8a878"
}else if(target.type ==="boss"){
fill = "#000"
}
polyNode.setAttribute("fill",fill);
g.appendChild(polyNode);
document.getElementById("objects").appendChild(g);
hatObj.g = g;
hatObj.node = polyNode;
target.hasHat = false;
}
// Audio
let volume = .5;
let audioCtx;
function initAudio() {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
}
function sfxHuh() {
const ctx = audioCtx;
const o = ctx.createOscillator();
const g = ctx.createGain();
o.type = "sine";
o.frequency.setValueAtTime(80 + Math.random()*20, ctx.currentTime);
g.gain.setValueAtTime(volume * 0.6, ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.12);
o.connect(g).connect(ctx.destination);
o.start();
o.stop(ctx.currentTime + 0.12);
}
function sfxHit() {
const ctx = audioCtx;
// Breath noise
const buffer = ctx.createBuffer(1, 3000, 44100);
const data = buffer.getChannelData(0);
for (let i = 0; i < data.length; i++) {
data[i] = (Math.random() * 2 - 1) * (1 - i / data.length);
}
const noise = ctx.createBufferSource();
noise.buffer = buffer;
// Throat pop (low sine)
const o = ctx.createOscillator();
o.type = "sine";
o.frequency.setValueAtTime(120 + Math.random()*40, ctx.currentTime);
// Gain envelope
const g = ctx.createGain();
g.gain.setValueAtTime(volume * 0.5, ctx.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.08);
noise.connect(g);
o.connect(g);
g.connect(ctx.destination);
noise.start();
o.start();
o.stop(ctx.currentTime + 0.08);
}
*/'] |