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", "gameplay.js")
31 STORE("descrHdr", "Gameplay JS file")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "gameplay.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "935dd777bb6f04951775ef6d53c10dd6943028b0e62eeefcd19e4a724c3bd05")
37 STORE("fileCheckS", "d1ee66ae739f857b67adb9b27c1c96919d23895830fb7f9d597dce698a85157")
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
/*//---------------
// Game mechanics
function fire(){
const player = game.player;
if (player.cooldown > 0) return;
player.cooldown = 100; // reload time
const angle = player.angle;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = player.x + cos * 40;
const by = player.y + sin * 40;
game.projectiles.push({
type: "player",
x: bx,
y: by,
angle: player.angle,
speed: 1.2,
dx: cos * 12,
dy: sin * 12,
life: 1000,// ms
damage: 4,
startX: bx,
startY: by
});
sfxGun();
}
function fireTurretBullet() {
const t = game.player.turret;
if (t.cooldown > 0) return;
if (game.player.ammo-- < 0 ) return;
t.cooldown = 600; // reload time
const angle = game.player.angle + t.offset;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = game.player.x + cos * 25;
const by = game.player.y + sin * 25;
game.projectiles.push({
type: "turret",
x: bx,
y: by,
angle: angle,
speed: 1.2,
dx: cos * 12,
dy: sin * 12,
life: 800,
damage: 50,
startX: bx,
startY: by
});
sfxGun();
}
function spawnEnemyBullet(x, y, angle) {
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = x + cos * 40;
const by = y + sin * 40;
game.projectiles.push({
x,
y,
angle,
speed: 1,
dx: cos * 12,
dy: sin * 12,
life: 900,
type: "enemy",
damage: 4,
startX: bx,
startY: by
});
}
function spawnBigEnemyBullet(x, y, angle) {
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = x + cos * 40;
const by = y + sin * 40;
game.projectiles.push({
x,
y,
angle,
speed: 0.6,
dx: cos * 12,
dy: sin * 12,
life: 800,
type: "tank",
damage: 10,
startX: bx,
startY: by
});
}
function getRandomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function spawnEnemyFromBase(base) {
const verts = base.poly;
const count = verts.length;
// pick a random edge
const i = Math.floor(Math.random() * count);
const j = (i + 1) % count;
// edge endpoints in world space
const x1 = base.x + verts[i].x;
const y1 = base.y + verts[i].y;
const x2 = base.x + verts[j].x;
const y2 = base.y + verts[j].y;
// pick random point along the edge
const t = Math.random();
const ex = x1 + (x2 - x1) * t;
const ey = y1 + (y2 - y1) * t;
// compute outward normal
const dx = x2 - x1;
const dy = y2 - y1;
const len = Math.hypot(dx, dy);
// normalized perpendicular (normal)
const nx = -dy / len;
const ny = dx / len;
// spawn enemy slightly outside the base
const spawnDist = 20;
const sx = ex + nx * spawnDist;
const sy = ey + ny * spawnDist;
let typeName = base.enemyTypes[
getRandomInteger(0,base.enemyTypes.length -1)
];
if(typeName == "tank"){
game.enemies.push({
type: typeName,
x: sx,
y: sy,
angle: Math.random() * Math.PI * 2,
speed: enemyTypes[typeName].speed,
hp: enemyTypes[typeName].hp,
ai: enemyTypes[typeName],
poly: enemyTypes[typeName].poly,
fireCooldown: 0,
fireRate: enemyTypes[typeName].fireRate,
weight: enemyTypes[typeName].weight,
idealRange: enemyTypes[typeName].idealRange,
hullTurnSpeed: enemyTypes[typeName].hullTurnSpeed,
repositioning: false,
turret: {
angle: Math.random() * Math.PI * 2,
turnSpeed: enemyTypes[typeName].turretTurnSpeed,
poly: enemyTypes[typeName].turretPoly
}
});
}else{
game.enemies.push({
type: typeName,
x: sx,
y: sy,
angle: Math.random() * Math.PI * 2,
speed: enemyTypes[typeName].speed,
hp: enemyTypes[typeName].hp,
ai: enemyTypes[typeName],
poly: enemyTypes[typeName].poly,
fireCooldown: 0,
fireRate: enemyTypes[typeName].fireRate,
weight: enemyTypes[typeName].weight, // Push power
windshield:enemyTypes[typeName].windshield
});
}
}
// not used yet
function spawnEnemyRandom() {
game.enemies.push({
x: Math.random() * WORLD_W,
y: Math.random() * WORLD_H,
angle: 0,
speed: 0.1,
hp: 3
});
}
function spawnEnemyOffscreen() {
const viewW = sw * zoom;
const viewH = sh * zoom;
const camX = camCenter.x;
const camY = camCenter.y;
// pick a side
const side = Math.floor(Math.random() * 4);
let x, y;
if (side === 0) { // left
x = camX - viewW/2 - 200;
y = camY + (Math.random() - 0.5) * viewH;
}
if (side === 1) { // right
x = camX + viewW/2 + 200;
y = camY + (Math.random() - 0.5) * viewH;
}
if (side === 2) { // top
x = camX + (Math.random() - 0.5) * viewW;
y = camY - viewH/2 - 200;
}
if (side === 3) { // bottom
x = camX + (Math.random() - 0.5) * viewW;
y = camY + viewH/2 + 200;
}
game.enemies.push({ x, y, angle:0, speed:0.1, hp:3 });
}
*/ |
| 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", "gameplay.js")
31 STORE("descrHdr", "Gameplay JS file")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "gameplay.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "935dd777bb6f04951775ef6d53c10dd6943028b0e62eeefcd19e4a724c3bd05")
37 STORE("fileCheckS", "d1ee66ae739f857b67adb9b27c1c96919d23895830fb7f9d597dce698a85157")
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
/*//---------------
// Game mechanics
function fire(){
const player = game.player;
if (player.cooldown > 0) return;
player.cooldown = 100; // reload time
const angle = player.angle;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = player.x + cos * 40;
const by = player.y + sin * 40;
game.projectiles.push({
type: "player",
x: bx,
y: by,
angle: player.angle,
speed: 1.2,
dx: cos * 12,
dy: sin * 12,
life: 1000,// ms
damage: 4,
startX: bx,
startY: by
});
sfxGun();
}
function fireTurretBullet() {
const t = game.player.turret;
if (t.cooldown > 0) return;
if (game.player.ammo-- < 0 ) return;
t.cooldown = 600; // reload time
const angle = game.player.angle + t.offset;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = game.player.x + cos * 25;
const by = game.player.y + sin * 25;
game.projectiles.push({
type: "turret",
x: bx,
y: by,
angle: angle,
speed: 1.2,
dx: cos * 12,
dy: sin * 12,
life: 800,
damage: 50,
startX: bx,
startY: by
});
sfxGun();
}
function spawnEnemyBullet(x, y, angle) {
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = x + cos * 40;
const by = y + sin * 40;
game.projectiles.push({
x,
y,
angle,
speed: 1,
dx: cos * 12,
dy: sin * 12,
life: 900,
type: "enemy",
damage: 4,
startX: bx,
startY: by
});
}
function spawnBigEnemyBullet(x, y, angle) {
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const bx = x + cos * 40;
const by = y + sin * 40;
game.projectiles.push({
x,
y,
angle,
speed: 0.6,
dx: cos * 12,
dy: sin * 12,
life: 800,
type: "tank",
damage: 10,
startX: bx,
startY: by
});
}
function getRandomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function spawnEnemyFromBase(base) {
const verts = base.poly;
const count = verts.length;
// pick a random edge
const i = Math.floor(Math.random() * count);
const j = (i + 1) % count;
// edge endpoints in world space
const x1 = base.x + verts[i].x;
const y1 = base.y + verts[i].y;
const x2 = base.x + verts[j].x;
const y2 = base.y + verts[j].y;
// pick random point along the edge
const t = Math.random();
const ex = x1 + (x2 - x1) * t;
const ey = y1 + (y2 - y1) * t;
// compute outward normal
const dx = x2 - x1;
const dy = y2 - y1;
const len = Math.hypot(dx, dy);
// normalized perpendicular (normal)
const nx = -dy / len;
const ny = dx / len;
// spawn enemy slightly outside the base
const spawnDist = 20;
const sx = ex + nx * spawnDist;
const sy = ey + ny * spawnDist;
let typeName = base.enemyTypes[
getRandomInteger(0,base.enemyTypes.length -1)
];
if(typeName == "tank"){
game.enemies.push({
type: typeName,
x: sx,
y: sy,
angle: Math.random() * Math.PI * 2,
speed: enemyTypes[typeName].speed,
hp: enemyTypes[typeName].hp,
ai: enemyTypes[typeName],
poly: enemyTypes[typeName].poly,
fireCooldown: 0,
fireRate: enemyTypes[typeName].fireRate,
weight: enemyTypes[typeName].weight,
idealRange: enemyTypes[typeName].idealRange,
hullTurnSpeed: enemyTypes[typeName].hullTurnSpeed,
repositioning: false,
turret: {
angle: Math.random() * Math.PI * 2,
turnSpeed: enemyTypes[typeName].turretTurnSpeed,
poly: enemyTypes[typeName].turretPoly
}
});
}else{
game.enemies.push({
type: typeName,
x: sx,
y: sy,
angle: Math.random() * Math.PI * 2,
speed: enemyTypes[typeName].speed,
hp: enemyTypes[typeName].hp,
ai: enemyTypes[typeName],
poly: enemyTypes[typeName].poly,
fireCooldown: 0,
fireRate: enemyTypes[typeName].fireRate,
weight: enemyTypes[typeName].weight, // Push power
windshield:enemyTypes[typeName].windshield
});
}
}
// not used yet
function spawnEnemyRandom() {
game.enemies.push({
x: Math.random() * WORLD_W,
y: Math.random() * WORLD_H,
angle: 0,
speed: 0.1,
hp: 3
});
}
function spawnEnemyOffscreen() {
const viewW = sw * zoom;
const viewH = sh * zoom;
const camX = camCenter.x;
const camY = camCenter.y;
// pick a side
const side = Math.floor(Math.random() * 4);
let x, y;
if (side === 0) { // left
x = camX - viewW/2 - 200;
y = camY + (Math.random() - 0.5) * viewH;
}
if (side === 1) { // right
x = camX + viewW/2 + 200;
y = camY + (Math.random() - 0.5) * viewH;
}
if (side === 2) { // top
x = camX + (Math.random() - 0.5) * viewW;
y = camY - viewH/2 - 200;
}
if (side === 3) { // bottom
x = camX + (Math.random() - 0.5) * viewW;
y = camY + viewH/2 + 200;
}
game.enemies.push({ x, y, angle:0, speed:0.1, hp:3 });
}
*/'] |