Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}
body { 
  background-color: #222;
} 

/*ゲーム画面*/
#game-screen {
  margin: 0 auto;
}



              
            
!

JS

              
                //設定用
const Config = {
  //画面の解像度
  Screen: {
    Width: 256,//幅
    Height: 256,//高さ
    BackGroundColor: 0x444444,//背景色
  },
  Keys: { //キーボード入力
    Up: "w",
    Right: "d",
    Down: "s",
    Left: "a",
    A: "n",
    B: "m",
    Start: "Enter"
  },
  vpadType: DirKey8way,
  // vpadType: DirKey4way /*切り替えできます*/
}

//読みこむデータリスト(名前:ファイルパス)
const Resource = {
  Player: 'https://dl.dropbox.com/s/7e213pc0swzogf3/hikoki.png?dl=0',
}

//上のリストを読み込みやすい形に変えてます
const assets = [];
for (let key in Resource) {
  assets.push(Resource[key]);
}

let core;//ゲームの基幹プログラム用の変数
let inputManager;

//ブラウザの読み込みが完了したら実行されます
window.onload = () => {
  //設定した画面サイズでcoreを作成
  core = new Game(Config.Screen.Width, Config.Screen.Height, Config.Screen.BackGroundColor);
  inputManager = new InputManager();

  //データのロード
  core.preload(assets);

  //読み込み完了でメインシーンに切り替わります
  core.onload = () => {
    core.replaceScene(new MainScene());
  }
}

let player;
let bullet;
//メインシーン
class MainScene extends Container {
  constructor(){
    super();
    
    player = new EnchantSprite(16, 16);
    this.addChild(player);
    player.image = core.resources[Resource.Player].texture; 
    player.position.set(Config.Screen.Width*0.5, Config.Screen.Height*0.5);
    player.anchor.set(0.5, 0.5)

    bullet = new Graphics();
    this.addChild(bullet);
    bullet.circFill(0, 0, 4, 0xff0000);
    bullet.y = -10;
  }
  update(delta){
    super.update(delta);
    inputManager.gamePad.update();
    
    const oblique = 1 / Math.sqrt(2);//ななめ移動の値
    switch(inputManager.checkDirection()){
      case inputManager.keyDirections.UP:
        player.y--;
        break;
      case inputManager.keyDirections.UP_RIGHT:
        player.x += oblique;
        player.y -= oblique;
        break;
      case inputManager.keyDirections.RIGHT:
        player.x++;
        break;
      case inputManager.keyDirections.DOWN_RIGHT:
        player.x += oblique;
        player.y += oblique;
        break;
      case inputManager.keyDirections.DOWN:
        player.y++;
        break;
      case inputManager.keyDirections.DOWN_LEFT:
        player.x -= oblique;
        player.y += oblique;
        break;
      case inputManager.keyDirections.LEFT:
        player.x--;
        break;
      case inputManager.keyDirections.UP_LEFT:
        player.x -= oblique;
        player.y -= oblique;
        break;
      default:
        break;
    }

    
    if(inputManager.checkButton("A") == inputManager.keyStatus.DOWN){
      if(bullet.y <= -20){
        bullet.clear();
        bullet.circFill(0, 0, 4, 0xff0000);
        bullet.y = player.y;
        bullet.x = player.x;
      }
    }
    if(inputManager.checkButton("B") == inputManager.keyStatus.DOWN){
      if(bullet.y <= -20){
        bullet.clear();
        bullet.circFill(0, 0, 8, 0x00ffff);
        bullet.y = player.y;
        bullet.x = player.x;
      }
    }
    if(inputManager.checkButton("Start") == inputManager.keyStatus.DOWN){
      core.pushScene(new PauseScene());
    }   

    bullet.y -= 4;
  }
}

class PauseScene extends Container {
  constructor(){
    super();
    
    const t = new PIXI.Text('PAUSE', new PIXI.TextStyle({
      fontFamily: 'sans-serif',
      fontSize: 32,
      fill: 0xffffff,
    }));
    t.anchor.set(0.5, 0.5);
    t.position.set(Config.Screen.Width*0.5, Config.Screen.Height*0.5);
    this.addChild(t);
  }
  update(delta){
    super.update(delta);
    inputManager.gamePad.update();
    if(inputManager.checkButton("Start") == inputManager.keyStatus.DOWN){
      core.popScene();
    }  
  }
}

              
            
!
999px

Console