123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src="https://cdn.rawgit.com/Trung0246/Shmup/7e079cec9a7d478ad5add01a6c97e3717ae1a600/build/Shmup.js"></script>
<script src="https://cdn.rawgit.com/Trung0246/Shmup/d0e087c7ca5f6014e42a3fdcb6fee1a2f0e800af/plugins/basicProjectile.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js"></script>
<body>
  <div id="control">
    <div id="textInput"></div></br>
    <button id="evalScript">Run script</button>
    <button id="clearTask">Clear task</button>
    <button id="clearProjectile">Clear projectile</button>
    <p id="data1"></p>
    <p id="data2"></p>
    <p id="data3"></p>
  </div>
</body>
            
          
!
            
              /*https://github.com/Trung0246/Shmup/tree/development-1.2%2B

https://www.one-tab.com/page/AgEmL0pmTsChmU6_zqsKOg
Need test for bug:
https://pastebin.com/Vxr3uznf
*/
body {
  padding: 0px;
  margin: 0px;
}
#textInput {
  width: 100%;
  height: 475px;
  margin: 0px 0px 0px 0px;
}
#control {
  position: fixed;
  top: auto;
  bottom: auto;
  left: auto;
  right: 0%;
  width: 45%;
  height: auto;
}
p {
  margin: 0px 0px 0px 0px;
  position: absolute;
}
p#data1 {
  top: 475px;
  bottom: auto;
  right: 0%;
  left: auto;
}
p#data2{
  top: 530px;
  bottom: auto;
  right: 0%;
  left: auto;
}
p#data3{
  top: 547px;
  bottom: auto;
  right: 0%;
  left: auto;
}
canvas {
  border: 2px solid black;
  border-radius: 5px;
}

input {
  margin: 0px 0px 0px 0px;
}
            
          
!
            
              HTMLCanvasElement.prototype.fitWindow = function() {
  var resize = function() {
    var rateWidth = this.width / window.innerWidth;
    var rateHeight = this.height / window.innerHeight;
    var rate = this.height / this.width;
    if (rateWidth > rateHeight) {
      this.style.width = innerWidth + "px";
      this.style.height = innerWidth * rate + "px";
    } else {
      this.style.width = innerHeight / rate + "px";
      this.style.height = innerHeight + "px";
    }
  }.bind(this);
  window.addEventListener("resize", resize, false);
  resize();
};

// requestAnim shim layer by Paul Irish
//http://paulirish.com/2011/requestanimationframe-for-smart-animating
window.requestAnimFrame = (function(){
  return window.requestAnimationFrame ||
  window.webkitRequestAnimationFrame ||
  window.mozRequestAnimationFrame ||
  window.oRequestAnimationFrame ||
  window.msRequestAnimationFrame ||
  function(callback, element){
    window.setTimeout(callback, 1000 / 60);
  };
})();

var keyboard = {
  up: false,
  down: false,
  left: false,
  right: false,
  shift: false,
};
window.addEventListener("keydown", function(e) {
  switch (e.keyCode) {
    case 37:
      keyboard.left = true;
      break;
    case 38:
      keyboard.up = true;
      break;
    case 39:
      keyboard.right = true;
      break;
    case 40:
      keyboard.down = true;
      break;
    case 16:
      keyboard.shift = true;
      break;
  }
}, false);
window.addEventListener("keyup", function(e) {
  switch (e.keyCode) {
    case 37:
      keyboard.left = false;
      break;
    case 38:
      keyboard.up = false;
      break;
    case 39:
      keyboard.right = false;
      break;
    case 40:
      keyboard.down = false;
      break;
    case 16:
      keyboard.shift = false;
      break;
  }
}, false);
window.addEventListener('keydown', function(e) {
  switch (e.keyCode) {
    case 37:
    case 38:
    case 39:
    case 40:
    case 16:
      //e.preventDefault();
    break;
  }
}, false);

function isSlow() {
  if (keyboard.shift) {
    return player.slow;
  } else {
    return 1;
  }
}

//Pre-processing
var renderer = new PIXI.autoDetectRenderer(
  384 * 2, 448 * 2,
  {antialias: false, transparent: true, resolution: 1}
);
renderer.autoResize = true;
document.body.appendChild(renderer.view);
renderer.view.fitWindow();

//var stage = new PIXI.Container(); https://github.com/kittykatattack/learningPixi
var stage = new PIXI.particles.ParticleContainer(10000 , {
  rotation: true,
  alpha: false,
  scale: false,
  uvs: false,
});

var spritesheet;

Shmup.configs({
  maxProjectile: {
    bullet: 10000,
    laser: 1,
    curve: 1,
    curveNode: 1,
  },
  scene: {
    size: {
      x: 384 * 2,
      y: 448 * 2,
    },
    boundary: 10,
  },
});

Shmup.advanced.performance.configs({
  smoothing: 10,
  maxMs: 0,
});

PIXI.loader
  .add("test", "https://cdn.rawgit.com/Trung0246/Shmup/stable/img/down_arrow_icon.png")
  .add("shotSheet", "https://i.sli.mg/bPRrPW.png")
  .load(setup);

//Variables
var player = {
  x: Shmup.advanced.data().scene.size.x / 2,
  y: Shmup.advanced.data().scene.size.y - 50,
  speed: 3.75,
  slow: 0.55,
};

//Main process
function setup() {
  /*spritesheet = PIXI.utils.TextureCache["shotSheet"];
  var bulletSprite = new PIXI.Rectangle(16 * 0, 16 * 1, 16, 16);
  spritesheet.frame = bulletSprite;*/
  spritesheet = PIXI.loader.resources["test"].texture;
  console.log("Done Loading... Now entering main loop...");
  loop();
}

function loop() {
  Shmup.advanced.performance.start();
  if (keyboard.left) {
    player.x -= player.speed * isSlow();
  } else if (keyboard.right) {
    player.x += player.speed * isSlow();
  };
  if (keyboard.up) {
    player.y -= player.speed * isSlow();
  } else if (keyboard.down) {
    player.y += player.speed * isSlow();
  };
  player.x = Math.max(0, Math.min(player.x, Shmup.advanced.data().scene.size.x));
  player.y = Math.max(0, Math.min(player.y, Shmup.advanced.data().scene.size.y));
  Shmup.update();
  renderer.render(stage);
	Shmup.advanced.performance.end();
  requestAnimFrame(loop);
}

setInterval(function() {
  document.getElementById("data1").innerHTML = "Frame: " + Shmup.advanced.data().frame + "<br/>" + "PCount: " + Shmup.advanced.process().active.length + "<br/>" + "TCount: " + Shmup.advanced.temp().task.length;
  document.getElementById("data3").innerHTML = "MS: " + Shmup.advanced.performance.ms().toFixed(3);
}, 0);
setInterval(function() {
  document.getElementById("data2").innerHTML =  "FPS: " + Shmup.advanced.performance.fps().toFixed(3);
}, 50);

var editor = ace.edit("textInput");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
editor.focus();
editor.setShowInvisibles(true);
editor.setFontSize(10.75);
editor.session.setTabSize(2);
editor.setValue(`function* example(x, y) {
  x = x || Shmup.advanced.data().scene.size.x / 2;
  y = y || Shmup.advanced.data().scene.size.y / 3.75;
  var angle = 0;
  while (true) {
    CreateShot01(x, y, 2, angle);
    angle += 5;
    yield* wait(1);
  }
}
Shmup.util.task(example, [], {update: true, reset: false});
function CreateShot01(x, y, speed, angle) {
  return Shmup.projectile.bullet.add({
    position: {
      x: x,
      y: y,
    },
    angle: Shmup.math.angle.degree.radian(angle),
    speed: speed,
    data: {
      graphic: (function() {
        var bulletImg = new PIXI.Sprite(spritesheet);
        bulletImg.anchor.set(0.5, 0.5);
        stage.addChild(bulletImg);
        return bulletImg;
      })(),
    },
    update: function(projectile) {
      projectile.data.graphic.position.set(projectile.position.x, projectile.position.y);
      projectile.data.graphic.rotation = -projectile.angle;// - Math.PI;
      if (Shmup.util.out(0, projectile.position) || deleteProjectile === true) {
        if (Shmup.advanced.process().active.length <= 1) {
          deleteProjectile = false;
        }
        stage.removeChild(projectile.data.graphic);
        Shmup.projectile.bullet.remove(projectile);
      }
    },
  });
}
function* wait(data) {
  var waiter = Shmup.util.count({
    min: 0,
    max: data,
    change: 1,
    reset: true,
  });
  while (waiter() < data) {
    yield;
  }
}
`);

document.getElementById("evalScript").onclick = function() {
  eval(editor.getValue());
};

document.getElementById("clearTask").onclick = function() {
  Shmup.advanced.temp().task = [];
};

var deleteProjectile = false;

document.getElementById("clearProjectile").onclick = function() {
  if (deleteProjectile === false) {
    deleteProjectile = true;
  } else {
    deleteProjectile = false;
  }
};

/*function* angelWings(GetX, GetY) {
  yield;
  var counter = Shmup.util.count({
    min: 0,
    max: 1,
    change: 1,
    reset: true,
  });
  GetX = GetX || Shmup.advanced.data().scene.size.x / 2;
  GetY = GetY || Shmup.advanced.data().scene.size.y / 3.75;
  var ang = 0;
  var dir = 0;
  var count = 0;
  var x = 0;
  while(true) {
    if (x == 3) {
      ang += 6.5;
      CreateShot01(GetX, GetY, 5.2, -(Shmup.math.angle.degree.to.radian(79) * Math.sin(Shmup.math.angle.degree.to.radian(ang)) - Shmup.math.angle.degree.to.radian(-5)));
      CreateShot01(GetX, GetY, 5.2, Shmup.math.angle.degree.to.radian(79) * Math.sin(Shmup.math.angle.degree.to.radian(ang)) - Shmup.math.angle.degree.to.radian(-5));
      for(var i = 1; i < 10; i ++) {
        CreateShot01(GetX, GetY, 4.5, -(Shmup.math.angle.degree.to.radian(110) * Math.sin(Shmup.math.angle.degree.to.radian(ang - 10 * i)) - Shmup.math.angle.degree.to.radian(-5)));
        CreateShot01(GetX, GetY, 4.5, Shmup.math.angle.degree.to.radian(110) * Math.sin(Shmup.math.angle.degree.to.radian(ang - 10 * i)) - Shmup.math.angle.degree.to.radian(-5));
      }
      x = 0;
    }
    x++;
    yield* Shmup.util.wait(2, function() {
      if (counter() >= 1) {
        return false;
      } else {
        return true;
      }
    });
  }
}
function CreateShot01(x, y, speed, angle) {
  Shmup.projectile.bullet.create({
    position: {
      x: x,
      y: y,
    },
    angle: angle,
    speed: speed,
    data: {
      graphic: (function() {
        var bulletImg = new PIXI.Sprite(spritesheet);
        bulletImg.anchor.set(0.5, 0.5);
        stage.addChild(bulletImg);
        return bulletImg;
      })(),
    },
    update: function(projectile) {
      projectile.data.graphic.position.set(projectile.position.x, projectile.position.y);
      projectile.data.graphic.rotation = -projectile.angle;// - Math.PI;
      if (Shmup.util.out(0, projectile.position)) {
        stage.removeChild(projectile.data.graphic);
        Shmup.projectile.bullet.vanish(projectile);
      }
    },
  });
}
Shmup.util.task([], angelWings, {update: true, reset: false});*/

/*function* example(x, y) {
  x = x || Shmup.advanced.data().scene.size.x / 2;
  y = y || Shmup.advanced.data().scene.size.y / 3.75;
  var angle = 0;
  while (true) {
    //for (var i = 1; i <= 360; i ++) {
      var obj = fireBullet(x, y, 5, angle);
      Shmup.util.task(testing, [obj], {update: true, reset: false});
      angle += /*360 / 8 +*** 0.5;
    //}
    yield* wait(1);
  }
}
Shmup.util.task(example, [], {update: true, reset: false});
function* testing(obj) {
  var angleBounce = 0, bounceTime = 1, deltaTime = 0;
  yield;
  while (bounceTime > 0) {
    yield;
    if (Shmup.util.out(5, obj.position)) {
      switch (Shmup.util.out(0, obj.position)) {
        case 1:
        case 3: {
          //Check if hit vertical wall
          angleBounce = 90;
        }
        break;
        case 2:
        case 4: {
          angleBounce = 180;
        }
        break;
      }
      obj.angle = Shmup.math.angle.bounce(obj.angle,
                  Shmup.math.angle.degree.radian(angleBounce));
      
      var margin = 0; //area of effect
      var strength = 3; //strength of forcefield
      
      function (type, position) {
        return position.x < margin ||
        data.scene.size.x < position.x ||
        position.y < margin ||
        data.scene.size.y < position.y;
      }
      
      //1: top, clock wise
      //Shmup.util.out
      
      //obj.position.x = obj.position.x + deltaTime * strength * ((obj.position.x < margin) - (obj.position.x > Shmup.advanced.data().scene.size.x - margin));
      //obj.position.y = obj.position.y + deltaTime * strength * ((obj.position.y < margin) - (obj.position.y > Shmup.advanced.data().scene.size.y - margin));
      
      
      /*obj.position = {
        x: Shmup.advanced.data().scene.size.x / 2,
        y: Shmup.advanced.data().scene.size.x / 3.75,
      },****
      
      //var margin = 0;
      //var strength = 0;
      
      //1: left for x wall
      //-1: bottom for y wall

    // Assumes boolean-to-int conversion
       // (obj.position.x < margin) - (obj.position.x > Shmup.advanced.data().scene.size.x - margin),
        //(obj.position.y < margin) - (obj.position.y > Shmup.advanced.data().scene.size.y - margin)
        
      //obj.speed = strength *  * deltaTime;
      bounceTime -= 1;
    }
  }
  while (true) {
    //This loop will just check if bullet hit wall then break it
    yield;
    if (Shmup.util.out(5, obj.position)) {
      break;
    }
  }
  //Delete bullet
  obj.data.isDelete = true;
}

//Nothing really important from here
function fireBullet(x, y, speed, angle) {
  return Shmup.projectile.bullet.add({
    position: {
      x: x,
      y: y,
    },
    angle: Shmup.math.angle.degree.radian(angle),
    speed: speed,
    data: {
      graphic: (function() {
        var bulletImg = new PIXI.Sprite(spritesheet);
        bulletImg.anchor.set(0.5, 0.5);
        stage.addChild(bulletImg);
        return bulletImg;
      })(),
      isDelete: false,
    },
    update: function(projectile) {
      projectile.data.graphic.position.set(projectile.position.x, projectile.position.y);
      projectile.data.graphic.rotation = -projectile.angle;// - Math.PI;
      if (deleteProjectile === true || projectile.data.isDelete === true) {
        if (Shmup.advanced.process().active.length <= 1) {
          deleteProjectile = false;
        }
        stage.removeChild(projectile.data.graphic);
        Shmup.projectile.bullet.remove(projectile);
      }
    },
  });
}
function* wait(data) {
  var waiter = Shmup.util.count({
    min: 0,
    max: data,
    change: 1,
    reset: true,
  });
  while (waiter() < data) {
    yield;
  }
}*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console