User:Gergdown/SchizoJavaScript

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

About five years ago on the year of 2020, when everyone was locked into their houses, and when I was eight, I joined the popular kids coding website Scratch. Five years later, I learned that you can... convert scratch projects to javascript. Very, VERY, intriguing.

I thought to myself, "this IS the future of UnGames!"

Two issues.

One: I don't know javascript, and barely anyone here does. This may not seem like an issue, but for debugging and making the code not spaghettiyingly terrifying, uhh... yeah.

Two:

Codebox.png

Yeah uhhhhhhhhhhhhhhhhhh

So if anyone is insane enough to try to make a game out of this...[edit | edit source]

Here's the javascript!

For your information, Leopard is the service I used to convert the scratch projects to Javascript.

GreenFlag is just the code used to start a game. I don't know Javascript, but with my brief time with Lua, you probably just use a command to start the thing.

If you dare try to convert this into an actual game, hit me up and I'll upload the images and sounds here.

Bullets.js:[edit | edit source]

/* eslint-disable require-yield, eqeqeq */

import {

 Sprite,
 Trigger,
 Watcher,
 Costume,
 Color,
 Sound,

} from "https://unpkg.com/leopard@^1/dist/index.esm.js";

export default class Bullets extends Sprite {

 constructor(...args) {
   super(...args);
   this.costumes = [
     new Costume("red", "./Bullets/costumes/red.png", { x: 32, y: 32 }),
     new Costume("red2", "./Bullets/costumes/red2.png", { x: 30, y: 30 }),
     new Costume("homing", "./Bullets/costumes/homing.png", { x: 32, y: 32 }),
     new Costume("orange", "./Bullets/costumes/orange.png", { x: 32, y: 32 }),
     new Costume("orange2", "./Bullets/costumes/orange2.png", {
       x: 30,
       y: 30,
     }),
   ];
   this.sounds = [
     new Sound(
       "deltarune-explosion",
       "./Bullets/sounds/deltarune-explosion.wav"
     ),
   ];
   this.triggers = [
     new Trigger(Trigger.CLONE_START, this.startAsClone),
     new Trigger(Trigger.CLONE_START, this.startAsClone2),
     new Trigger(Trigger.CLONE_START, this.startAsClone3),
     new Trigger(Trigger.CLONE_START, this.startAsClone4),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "u dead" },
       this.whenIReceiveUDead
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart2
     ),
   ];
 }
 *startAsClone() {
   this.goto(240, this.random(-120, 120));
   this.effects.ghost = 100;
   this.visible = true;
   for (let i = 0; i < 5; i++) {
     this.effects.ghost -= 20;
     yield;
   }
 }
 *startAsClone2() {
   this.costume = this.random(1, 2);
   while (!(this.compare(this.x, -230) < 0)) {
     if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
       this.move((-10 + this.toNumber(this.stage.vars.difficulty) / 35) * -1);
     }
     yield;
   }
   for (let i = 0; i < 5; i++) {
     if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
       this.move((-10 + this.toNumber(this.stage.vars.difficulty) / 35) * -1);
       this.effects.ghost += 20;
     }
     yield;
   }
   this.deleteThisClone();
 }
 *startAsClone3() {
   if (this.compare(this.stage.vars.difficulty, 1) > 0) {
     if (this.random(1, 5) === 1) {
       this.costume = "homing";
       this.effects.color = 50;
       while (true) {
         this.direction = this.radToScratch(
           Math.atan2(
             this.sprites["Dot"].y - this.y,
             this.sprites["Dot"].x - this.x
           )
         );
         this.direction -= 15;
         yield;
       }
     } else {
       if (this.random(1, 5) === 2) {
         this.costume = this.random(4, 5);
         while (true) {
           if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
             this.size += 2 * (this.toNumber(this.stage.vars.difficulty) / 35);
           }
           yield;
         }
       } else {
         null;
       }
     }
   }
 }
 *startAsClone4() {
   while (true) {
     if (this.touching(this.sprites["Death"].andClones())) {
       this.visible = false;
       yield* this.startSound("deltarune-explosion");
       this.stage.vars.score += 100;
       this.deleteThisClone();
     }
     yield;
   }
 }
 *whenIReceiveGameStart() {
   this.direction = -90;
   this.visible = false;
   while (!(this.compare(this.stage.vars.difficulty, 75) > 0)) {
     yield* this.wait(
       this.random(
         1 - this.toNumber(this.stage.vars.difficulty) / 50,
         2 - this.toNumber(this.stage.vars.difficulty) / 50
       )
     );
     if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
       this.createClone();
     }
     yield;
   }
   while (true) {
     yield* this.wait(this.random(0.2, 0.5));
     if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
       this.createClone();
     }
     yield;
   }
 }
 *whenIReceiveUDead() {
   /* TODO: Implement stop other scripts in sprite */ null;
 }
 *whenIReceiveGameStart2() {
   this.stage.vars.difficulty = 0;
   this.deleteThisClone();
 }

}

Death.js[edit | edit source]

/* eslint-disable require-yield, eqeqeq */

import {

 Sprite,
 Trigger,
 Watcher,
 Costume,
 Color,
 Sound,

} from "https://unpkg.com/leopard@^1/dist/index.esm.js";

export default class Death extends Sprite {

 constructor(...args) {
   super(...args);
   this.costumes = [
     new Costume("costume1", "./Death/costumes/costume1.svg", {
       x: 384.98497582054705,
       y: 261.86185269742396,
     }),
     new Costume("bullet", "./Death/costumes/bullet.png", { x: 12, y: 2 }),
   ];
   this.sounds = [
     new Sound(
       "064-laser-thum_hYpSdXS",
       "./Death/sounds/064-laser-thum_hYpSdXS.wav"
     ),
   ];
   this.triggers = [
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart
     ),
     new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked),
     new Trigger(Trigger.CLONE_START, this.startAsClone),
     new Trigger(Trigger.CLONE_START, this.startAsClone2),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart2
     ),
   ];
 }
 *whenIReceiveGameStart() {
   yield* this.wait(1);
   while (!(this.compare(this.stage.vars.hp, 1) < 0)) {
     yield;
   }
   yield* this.wait(1);
   this.costume = "costume1";
   this.effects.ghost = 100;
   this.visible = true;
   for (let i = 0; i < 10; i++) {
     this.effects.ghost -= 10;
     yield;
   }
   while (!this.keyPressed("z")) {
     yield;
   }
   this.broadcast("game start");
   this.visible = false;
 }
 *whenGreenFlagClicked() {
   this.visible = false;
   while (true) {
     this.moveAhead();
     yield;
   }
 }
 *startAsClone() {
   this.costume = "bullet";
   yield* this.startSound("064-laser-thum_hYpSdXS");
   while (true) {
     this.effects.ghost += 2;
     yield;
   }
 }
 *startAsClone2() {
   this.goto(this.sprites["Dot"].x, this.sprites["Dot"].y);
   this.visible = true;
   this.costume = "bullet";
   while (!(this.compare(this.x, 230) > 0)) {
     this.x += 10;
     yield;
   }
   this.visible = false;
   this.deleteThisClone();
 }
 *whenIReceiveGameStart2() {
   this.visible = false;
   while (true) {
     if (this.keyPressed("z")) {
       this.createClone();
       yield* this.wait(0.5);
     }
     yield;
   }
 }

}

Dot.js[edit | edit source]

/* eslint-disable require-yield, eqeqeq */

import {

 Sprite,
 Trigger,
 Watcher,
 Costume,
 Color,
 Sound,

} from "https://unpkg.com/leopard@^1/dist/index.esm.js";

export default class Dot extends Sprite {

 constructor(...args) {
   super(...args);
   this.costumes = [
     new Costume("normal", "./Dot/costumes/normal.svg", {
       x: 7.996855118460502,
       y: 7.99684511846047,
     }),
   ];
   this.sounds = [
     new Sound(
       "deltarune-explosion2",
       "./Dot/sounds/deltarune-explosion2.wav"
     ),
   ];
   this.triggers = [
     new Trigger(
       Trigger.KEY_PRESSED,
       { key: "up arrow" },
       this.whenKeyUpArrowPressed
     ),
     new Trigger(
       Trigger.KEY_PRESSED,
       { key: "left arrow" },
       this.whenKeyLeftArrowPressed
     ),
     new Trigger(
       Trigger.KEY_PRESSED,
       { key: "down arrow" },
       this.whenKeyDownArrowPressed
     ),
     new Trigger(
       Trigger.KEY_PRESSED,
       { key: "right arrow" },
       this.whenKeyRightArrowPressed
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart2
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart3
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart4
     ),
   ];
 }
 *whenKeyUpArrowPressed() {
   if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
     while (
       !(
         !this.keyPressed("up arrow") ||
         this.compare(this.stage.vars.hp, 1) < 0
       )
     ) {
       this.y += 6;
       yield;
     }
   }
 }
 *whenKeyLeftArrowPressed() {
   if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
     while (
       !(
         !this.keyPressed("left arrow") ||
         this.compare(this.stage.vars.hp, 1) < 0
       )
     ) {
       this.x -= 6;
       yield;
     }
   }
 }
 *whenKeyDownArrowPressed() {
   if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
     while (
       !(
         !this.keyPressed("down arrow") ||
         this.compare(this.stage.vars.hp, 1) < 0
       )
     ) {
       this.y -= 6;
       yield;
     }
   }
 }
 *whenKeyRightArrowPressed() {
   if (!(this.compare(this.stage.vars.hp, 1) < 0)) {
     while (
       !(
         !this.keyPressed("right arrow") ||
         this.compare(this.stage.vars.hp, 1) < 0
       )
     ) {
       this.x += 6;
       yield;
     }
   }
 }
 *whenIReceiveGameStart() {
   this.stage.vars.hp = 50;
   this.costume = "normal";
   this.goto(-150, 0);
   while (true) {
     if (this.touching(this.sprites["Bullets"].andClones())) {
       this.stage.vars.hp--;
       yield* this.wait(0.01);
       yield* this.startSound("deltarune-explosion2");
     } else {
       this.costume = "normal";
     }
     yield;
   }
 }
 *whenIReceiveGameStart2() {
   while (true) {
     if (this.compare(this.stage.vars.hp, 1) < 0) {
       this.broadcast("u dead");
     }
     yield;
   }
 }
 *whenIReceiveGameStart3() {
   while (true) {
     this.effects.color = this.toNumber(this.stage.vars.hp) * 2;
     yield;
   }
 }
 *whenIReceiveGameStart4() {
   while (true) {
     if (this.compare(this.y, -134) < 0 || this.compare(this.y, 134) > 0) {
       this.stage.vars.hp--;
       yield* this.wait(0.01);
       yield* this.startSound("deltarune-explosion2");
     } else {
       this.costume = "normal";
     }
     yield;
   }
 }

}

Stage.js[edit | edit source]

/* eslint-disable require-yield, eqeqeq */

import {

 Stage as StageBase,
 Trigger,
 Watcher,
 Costume,
 Color,
 Sound,

} from "https://unpkg.com/leopard@^1/dist/index.esm.js";

export default class Stage extends StageBase {

 constructor(...args) {
   super(...args);
   this.costumes = [
     new Costume("backdrop1", "./Stage/costumes/backdrop1.png", {
       x: 480,
       y: 360,
     }),
   ];
   this.sounds = [
     new Sound("Cool Down", "./Stage/sounds/Cool Down.mp3"),
     new Sound(
       "deltarune-explosion",
       "./Stage/sounds/deltarune-explosion.wav"
     ),
   ];
   this.triggers = [
     new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "game start" },
       this.whenIReceiveGameStart2
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "u dead" },
       this.whenIReceiveUDead
     ),
     new Trigger(
       Trigger.BROADCAST,
       { name: "u dead" },
       this.whenIReceiveUDead2
     ),
   ];
   this.vars.difficulty = 6;
   this.vars.hp = 44;
   this.vars.score = 72;
 }
 *whenGreenFlagClicked() {
   this.broadcast("game start");
   this.vars.difficulty = 0;
   while (true) {
     yield* this.wait(1);
     this.vars.difficulty++;
     yield;
   }
 }
 *whenIReceiveGameStart() {
   this.vars.score = 0;
   while (true) {
     yield* this.wait(1 / 30);
     this.vars.score++;
     yield;
   }
 }
 *whenIReceiveGameStart2() {
   while (true) {
     yield* this.playSoundUntilDone("Cool Down");
     yield;
   }
 }
 *whenIReceiveUDead() {
   this.stopAllSounds();
 }
 *whenIReceiveUDead2() {
   /* TODO: Implement stop other scripts in sprite */ null;
   yield* this.startSound("deltarune-explosion");
 }

}

Index.js[edit | edit source]

import {

 Project,
 Sprite,

} from "https://unpkg.com/leopard@^1/dist/index.esm.js";

import Stage from "./Stage/Stage.js"; import Dot from "./Dot/Dot.js"; import Bullets from "./Bullets/Bullets.js"; import Death from "./Death/Death.js";

const stage = new Stage({ costumeNumber: 1 });

const sprites = {

 Dot: new Dot({
   x: -186,
   y: -12,
   direction: 90,
   rotationStyle: Sprite.RotationStyle.ALL_AROUND,
   costumeNumber: 1,
   size: 100,
   visible: true,
   layerOrder: 1,
 }),
 Bullets: new Bullets({
   x: -241,
   y: -120,
   direction: -90,
   rotationStyle: Sprite.RotationStyle.ALL_AROUND,
   costumeNumber: 1,
   size: 100,
   visible: false,
   layerOrder: 2,
 }),
 Death: new Death({
   x: 0,
   y: 0,
   direction: 90,
   rotationStyle: Sprite.RotationStyle.ALL_AROUND,
   costumeNumber: 1,
   size: 100,
   visible: false,
   layerOrder: 3,
 }),

};

const project = new Project(stage, sprites, {

 frameRate: 30,

}); export default project;