HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
//変数
//ボールの変数
var ball;
var ballImage;
//バーの変数
var bar;
var barImage;
//ブロックの変数
var block;
var blockImages = [];
var blockGroup;
var blockCount = 80;
//上と左右の変数
var wallTop;
var wallLeft;
var wallRight;
//ゲームモードの変数
var gameMode;
//メディアをロード
function preload(){
ballImage = loadImage('image/ball.png');
barImage = loadImage('image/bar.png');
blockImages[0] = loadImage('image/block1.png');
blockImages[1] = loadImage('image/block2.png');
blockImages[2] = loadImage('image/block3.png');
blockImages[3] = loadImage('image/block4.png');
blockImages[4] = loadImage('image/block5.png');
blockImages[5] = loadImage('image/block6.png');
}
//最初に1回だけ実行
function setup(){
createCanvas(600,425);
gameSetup();
}
//1フレームごとに実行
function draw(){
//背景の色
background(0);
//テキスト表示
//テキスト共通設定
fill(255,255,255);
textAlign(CENTER);
//ゲームモードによって表示されるテキストを変更
switch(gameMode){
//ゲーム開始前
case 'gameStart':
textStyle(BOLD);
textSize(40);
text('GAME START',width/2,height/2);
textStyle(NORMAL);
textSize(20);
text('クリックでスタート!',width/2,height/2+60);
textStyle(NORMAL);
textSize(15);
text('⇄キーでバーを操作できます',width/2,height/2+90);
break;
//ゲームオーバー
case 'gameOver':
textStyle(BOLD);
textSize(40);
text('GAME OVER...',width/2,height/2);
break;
//ゲームクリア
case 'gameClear':
fill(255,255,0);
textStyle(BOLD);
textSize(40);
text('CLEAR!',width/2,height/2);
break;
}
//ゲーム中の処理
gameControl();
//キー操作
keyControl();
//ゲームモード変更:プレイ中
gamePlaying();
//ゲームモード変更:ゲームオーバー
gameOver();
//ゲームモード変更:クリア
gameClear();
//全てのスプライトを表示
drawSprites();
}
//ゲームの初期化
function gameSetup(){
//ブロックのスプライト作成
blockGroup = new Group;
for(var j=0;j<8;j++){
for(var i=0;i<10;i++){
block = createSprite(30+i*60,10+j*20);
block.addImage('block',blockImages[floor(random(5))]);
block.immovable = true;
blockGroup.add(block);
}
}
//バーのスプライト作成
bar = createSprite(width/2, 380);
bar.addImage(barImage);
bar.immovable = true;
//ボールのスプライト作成
ball = createSprite();
ball.addImage(ballImage);
ball.setSpeed(10,random(80,100));
//ボールが画面外に出ないよう壁のスプライト作成
wallTop = createSprite(width/2,-5,width,10);
wallTop.immovable = true;
wallLeft = createSprite(-5,height/2,10,height);
wallLeft.immovable = true;
wallRight = createSprite(width+5,height/2,10,height);
wallRight.immovable = true;
//ゲームモード変更:プレイ開始前
gameMode = 'gameStart';
}
//ゲームプレイ中の処理
function gameControl(){
if(gameMode=='gamePlaying'){
//ボールとバーが接触したら跳ね返る
ball.bounce(bar);
//ボールと上左右の壁が接触したら跳ね返る
ball.bounce(wallTop);
ball.bounce(wallLeft);
ball.bounce(wallRight);
//ボールとブロックが接触したら跳ね返る
ball.bounce(blockGroup,function(ball,block){
//ぶつかったらブロック削除
block.remove();
//ブロックの残数カウント(0でクリア)
blockCount--;
});
//ゲーム開始前はボールとバーは同じ場所
} else if(gameMode=='gameStart'){
ball.position.x = bar.position.x;
ball.position.y = bar.position.y-20;
}
}
//ゲームモード変更:プレイ中
function gamePlaying(){
if(mouseIsPressed){
gameMode = 'gamePlaying';
}
}
//ゲームモード変更:ゲームオーバー
function gameOver(){
if(ball.position.y > height+40){
gameMode = 'gameOver';
}
}
//ゲームモード変更:クリア
function gameClear(){
if(blockCount==0){
gameMode = 'gameClear';
}
}
//キー操作
function keyControl(){
//左キーを押したときの処理
if(keyDown('LEFT')){
bar.position.x -= 3;
if(bar.position.x < 0){
bar.position.x = 0;
}
//プレイ開始前はバーとボールが一緒に動く
if(gameMode=='gameStart'){
bar.position.x -= 3;
ball.position.x -= 3;
}
//右キーを押したときの処理
} else if(keyDown('RIGHT')){
bar.position.x += 3;
if(bar.position.x > width){
bar.position.x = width;
}
//プレイ開始前はバーとボールが一緒に動く
if(gameMode=='gameStart'){
bar.position.x += 3;
ball.position.x += 3;
}
}
}
Also see: Tab Triggers