


{"id":45,"date":"2026-05-19T16:29:45","date_gmt":"2026-05-19T07:29:45","guid":{"rendered":"https:\/\/tate.stars.ne.jp\/wpc\/?p=45"},"modified":"2026-05-23T07:56:16","modified_gmt":"2026-05-22T22:56:16","slug":"block-game","status":"publish","type":"post","link":"https:\/\/tate.stars.ne.jp\/wpc\/block-game.html","title":{"rendered":"block-game"},"content":{"rendered":"<pre><code class=\"javascript\">\n\/\/block game\n\nvar bar, block, blockGroup, ball, wallLeft, wallRight, wallTop;\nvar gameScreen = 0;\nvar wallBottom;\nvar num = 0;\nvar st;\nvar sound;\nvar img;\nfunction preload(){\nsound = loadSound('img\/a.mp3');\nimg = loadImage('img\/ball2.png');\n}\n\nfunction setup() {\nvar myCanvas = createCanvas(300, 300);\nmyCanvas.parent('myContainer');\ngameInit();\n}\n\nfunction draw() {\nif (gameScreen == 0) {\ninitScreen();\n} else if (gameScreen == 1) {\ngamePlayScreen();\n} else if (gameScreen == 2) {\ngameOverScreen();\n} else if (gameScreen == 3) {\ngameClearScreen();\n}\ndrawSprites();\n}\n\nfunction initScreen() {\nbackground(190);\ntextAlign(CENTER);\ntext(\"Click to start\", width\/2, height\/1.4);\n}\nfunction gamePlayScreen() {\nbackground(200);\ngam();\n}\nfunction gameOverScreen() {\n\nbackground(200, 220, 190);\ntextAlign(CENTER);\n\/\/ fill(236, 240, 241);\nfill(0);\ntextSize(33);\ntext(\"Game Over\", width\/2-4, height\/2-40);\ntextSize(15);\ntext(\"Click to restart\", width\/2, height-30);\n}\nfunction gameClearScreen() {\nbackground(200, 200, 190);\ntextAlign(CENTER);\n\/\/ fill(236, 240, 241);\nfill(0);\ntextSize(33);\ntext(\"Game clear\", width\/2-4, height\/2-40);\ntextSize(15);\ntext(\"Click to start\", width\/2, height-30);\n\/\/ gameOver();\n}\n\nfunction gameInit() {\nvar blockWidth = 40, \/\/\u30d6\u30ed\u30c3\u30af\u306e\u5e45\nblockHeight = 16, \/\/\u30d6\u30ed\u30c3\u30af\u306e\u9ad8\u3055\nblockMargin = 4, \/\/\u30d6\u30ed\u30c3\u30af\u306e\u9593\u9694\noffset = 40; \/\/\u30d6\u30ed\u30c3\u30af\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\nwallLeft = createSprite(-5, height\/2, 10, height);\nwallLeft.immovable = true;\nwallRight=createSprite(width+5, height\/2, 10, height);\nwallRight.immovable = true;\nwallTop = createSprite(width\/2, -5, width, 10);\nwallTop.immovable = true;\nwallBottom=createSprite(width\/2, height, width, 10);\nwallBottom.immovable = true;\n\nbar = createSprite(width\/2, height-20, 80, 17);\nbar.shapeColor = \"#ffcc00\";\nbar.immovable = true;\nball = createSprite(width\/2, height\/2);\nball.addImage(img);\nball.scale = 0.5;\n\/\/ ball.setSpeed(3, random(80, 100));\nblockGroup = new Group;\nfor(var r=0;r&lt;4;r++) { \/\/\u7e26\u306e\u30d6\u30ed\u30c3\u30af\u6570\nfor(var c=0;c&lt;6;c++) { \/\/\u6a2a\u306e\u30d6\u30ed\u30c3\u30af\u6570\nblock = createSprite(offset+c*(blockWidth+blockMargin), offset+r*(blockHeight+blockMargin), blockWidth, blockHeight);\nblock.immovable = true;\nblockGroup.add(block);\n}\n}\n}\n\nfunction touchMoved() {\nbar.position.x = touchX;\n\/\/\u30d6\u30e9\u30a6\u30b6\u6a5f\u80fd\u3092\u7121\u52b9\u5316\nreturn false;\n}\n\nfunction gam(){\nif(ball.bounce(bar)) {\nvar swing=(ball.position.x-bar.position.x)\/15;\nball.setSpeed(8, ball.getDirection()+swing);\n}\nball.bounce(blockGroup,function(ball, block) {\nblock.remove();\nsound.play();\nnum += 1;\n});\nball.bounce(wallLeft);\nball.bounce(wallRight);\nball.bounce(wallTop);\nball.overlap(wallBottom,function(ball,wallBottom){\ngameOver();\n});\n\nst = \"score \"+num;\nfill(0);\nnoStroke();\nte=textAlign(CENTER);\nte.textSize(12);\nte.text(st, width\/2, 17);\nif(num==24){\ngameClear();\ngameScreen=3;\n}\n}\n\nfunction gclear(){\ngameScreen = 0;\ngameInit();\n}\n\nfunction startGame() {\nball.setSpeed(4, random(80, 100));\ngameScreen=1;\n}\n\nfunction gameClear() {\ngameScreen=3;\n\/\/ block.remove();\nbar.visible = false;\nball.visible = false;\nfor (i = 0; i&lt; blockGroup.length; i++){\ntest = blockGroup[i];\ntest.visible = false;\n}\nnum = 0;\n}\n\nfunction gameOver() {\ngameScreen=2;\n\/\/ block.remove();\nbar.visible = false;\nball.visible = false;\nfor (i = 0; i&lt; blockGroup.length; i++){\ntest = blockGroup[i];\ntest.visible = false;\n}\nnum = 0;\n}\n\nfunction restart() {\ngameScreen = 0;\ngameInit();\n}\n\nfunction mousePressed() {\nif (gameScreen==0) {\nstartGame();\n}\nif (gameScreen==2) {\nrestart();\n}\nif (gameScreen==3) {\ngclear();\n}\n}\n<\/code><\/pre>\n<p><a href=\"https:\/\/tate.stars.ne.jp\/link\/game1\/block.html\">preview<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/block game var bar, block, blockGroup, ball, wallLeft, wallRight, wallTop; var gameScreen = 0; var wallBotto [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":1,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/posts\/45\/revisions\/46"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/media\/36"}],"wp:attachment":[{"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpc\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}