백괴게임>이의섭 |
백괴게임>이의섭 |
1번째 줄: |
1번째 줄: |
| if(documentTitle === "사용자:이의섭/놀이터"){
| |
|
| |
| $(function() {
| |
|
| |
|
| var messageSpace = document.getElementById("message");
| |
| var battleSpace = document.getElementById("battle");
| |
| var hpSpace = document.getElementById("hpbar");
| |
|
| |
| battleSpace.innerHTML = '<canvas id="cvs" width="150" height="150">게임 화면입니다. 만약 이 화면이 정상적으로 출력되지 않는다면 망한 겁니다.</canvas>';
| |
|
| |
| var canvasBody = document.getElementById("cvs");
| |
| var canvas = canvasBody.getContext("2d");
| |
|
| |
| var sheet = document.createElement('style');
| |
| sheet.innerHTML = "canvas {border: 10px solid white;}";
| |
| document.body.appendChild(sheet);
| |
|
| |
|
| |
| var x, y, size, speed;
| |
| x = 800;
| |
| y = 600;
| |
| size = 10;
| |
| speed = 5;
| |
|
| |
| function drawHeart() {
| |
| canvas.fillStyle = "red";
| |
| canvas.beginPath();
| |
| canvas.moveTo(x - size, y);
| |
| canvas.lineTo(x - size, y - size/2);
| |
| canvas.lineTo(x - (size / 2), y - size);
| |
| canvas.lineTo(x, y - size/2);
| |
| canvas.lineTo(x + (size / 2), y - size);
| |
| canvas.lineTo(x + size, y - size/2);
| |
| canvas.lineTo(x + size, y);
| |
| canvas.lineTo(x, y + size);
| |
| canvas.lineTo(x - size, y);
| |
| canvas.fill();
| |
| canvas.closePath();
| |
| }
| |
|
| |
| var isKeyDown = [];
| |
|
| |
| function onKeyDown(e){
| |
| isKeyDown[e.keyCode] = true;
| |
| console.log("Down " + e.keyCode);
| |
| }
| |
|
| |
| function onKeyUp(e){
| |
| isKeyDown[e.keyCode] = false;
| |
| console.log("Up " + e.keyCode);
| |
| }
| |
|
| |
| function moveHeart(){
| |
| if(isKeyDown[37]){
| |
| x = Math.max(x-speed, 10);
| |
| }
| |
| if(isKeyDown[38]){
| |
| y = Math.max(y-speed, 10);
| |
| }
| |
| if(isKeyDown[39]){
| |
| x = Math.min(x+speed, 140);
| |
| }
| |
| if(isKeyDown[40]){
| |
| y = Math.min(y+speed, 140);
| |
| }
| |
| }
| |
|
| |
| window.addEventListener("keydown",onKeyDown,false);
| |
| window.addEventListener("keyup",onKeyUp,false);
| |
|
| |
| setInterval(moveHeart, 30);
| |
|
| |
| var type_speed = 100;
| |
|
| |
|
| |
| var stringToType = text1;
| |
| var i = 0;
| |
|
| |
| function switchString() {
| |
| if (stringToType === text1) stringToType = text2;
| |
| else if (stringToType === text2) stringToType = text3;
| |
| else if (stringToType === text3) stringToType = text4;
| |
| else if (stringToType === text4) stringToType = text5;
| |
| else if (stringToType === text5) stringToType = text6;
| |
| else if (stringToType === text6) stringToType = text7;
| |
| else if (stringToType === text7) stringToType = text8;
| |
| else if (stringToType === text8) stringToType = text9;
| |
| else if (stringToType === text9){
| |
| generateBullets();
| |
| return;
| |
| }
| |
|
| |
| else if (stringToType === text10) stringToType = text11;
| |
| else if (stringToType === text11){
| |
| generateBullets();
| |
| return;
| |
| }
| |
|
| |
| else if (stringToType === text12){
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ' + text13;
| |
| generateBullets();
| |
| return;
| |
| }
| |
|
| |
| else if (stringToType === text14) stringToType = text15;
| |
| else if (stringToType === text15) stringToType = text30;
| |
|
| |
| else if (stringToType === text21) stringToType = text22;
| |
| else if (stringToType === text22) stringToType = text23;
| |
| else if (stringToType === text23) stringToType = text30;
| |
|
| |
| else{
| |
| generateUltraBullets();
| |
| return;
| |
| }
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
|
| |
| typeMessage();
| |
| }
| |
|
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
|
| |
| function typeMessage() {
| |
| if (i == stringToType.length) {
| |
| setTimeout(switchString, 1000);
| |
| i=0;
| |
| return;
| |
| } else {
| |
| messageSpace.innerHTML += stringToType[i];
| |
| setTimeout(typeMessage, type_speed);
| |
| i++;
| |
| }
| |
| }
| |
|
| |
| var haveToGenerateBullet = 0;
| |
| var bulletY;
| |
| var hp=20;
| |
|
| |
| function generateBullets(){
| |
| haveToGenerateBullet = 1;
| |
| bulletY = -10;
| |
| setTimeout(cancelGenerateBullets, 3000);
| |
| }
| |
|
| |
| function cancelGenerateBullets(){
| |
| haveToGenerateBullet = 0;
| |
| if(hp == 20){
| |
| if(stringToType === text9){
| |
| stringToType = text10;
| |
| i=0;
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
| typeMessage();
| |
| return;
| |
| }
| |
| if(stringToType === text11){
| |
| stringToType = text12;
| |
| i=0;
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
| typeMessage();
| |
| return;
| |
| }
| |
| if(stringToType === text12){
| |
| stringToType = text14;
| |
| i=0;
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
| typeMessage();
| |
| return;
| |
| }
| |
| }
| |
| }
| |
|
| |
| function drawBullet(){
| |
| for(i=30; i<=120; i+=30){
| |
| canvas.beginPath();
| |
| canvas.arc(i, bulletY, 4, 0, Math.PI*2);
| |
| canvas.fillStyle = "white";
| |
| canvas.fill();
| |
|
| |
| if((i-x)*(i-x)+(bulletY-y)*(bulletY-y)<size*size){
| |
| console.log("collide");
| |
| stringToType = text21;
| |
| typeSpeed = 300;
| |
| i=0;
| |
| messageSpace.innerHTML = '<span style="color:yellow">플라위</span>: ';
| |
| hp -= 19;
| |
| cancelGenerateBullets();
| |
| typeMessage();
| |
| return;
| |
| }
| |
|
| |
| }
| |
| bulletY += 1.6;
| |
| }
| |
|
| |
| function changeHPbar(){
| |
| hpSpace.innerHTML = "LV 1 | HP "+hp+"/20";
| |
| }
| |
|
| |
| var haveToGenerateUltraBullet;
| |
|
| |
| function generateUltraBullets(){
| |
| haveToGenerateUltraBullet = 1;
| |
| bulletY = -10;
| |
| }
| |
|
| |
| function drawUltraBullet(){
| |
| for(i=10; i<=140; i+=10){
| |
| canvas.beginPath();
| |
| canvas.arc(i, bulletY, 4, 0, Math.PI*2);
| |
| canvas.fillStyle = "white";
| |
| canvas.fill();
| |
|
| |
| if((i-x)*(i-x)+(bulletY-y)*(bulletY-y)<size*size){
| |
| console.log("collide");
| |
| haveToGenerateUltraBullet = 0;
| |
| hp = 20;
| |
| messageSpace.innerHTML = '<a href="https://game.uncyclopedia.kr/wiki/Undertale: The Challenge/폐허/입구2/토리엘">계속하기</a>';
| |
| return;
| |
| }
| |
|
| |
| }
| |
| bulletY += 1.6;
| |
| }
| |
|
| |
| function drawCanvas(){
| |
| canvas.clearRect(0, 0, 150, 150);
| |
|
| |
| drawHeart();
| |
| if(haveToGenerateBullet === 1) drawBullet();
| |
| if(haveToGenerateUltraBullet === 1) drawUltraBullet();
| |
| }
| |
|
| |
| setInterval(drawCanvas, 30);
| |
| setInterval(changeHPbar);
| |
|
| |
| typeMessage();
| |
| });
| |
|
| |
| }
| |
|
| |
| // 여기까지 코드 입력 //
| |
|
| |
|
| |
| }
| |
|
| |
| }
| |
| $( plugin_Undertale )
| |