배포 : https://kimmsoll.github.io/whale-game-js/
깃헙 : https://github.com/kimmsoll/whale-game-js
// 고래 생성
const createItems = () => {
for(let i=1; i<=30; i++){
const img = document.createElement("img")
img.setAttribute("src",`./imgs/icons/${i}.png`);
img.setAttribute("class", "whale");
img.setAttribute("data-num", i);
displayItems(img);
}
}
// 고래들을 랜덤하게 배치
const displayItems = (item) => {
gameField.appendChild(item);
const xy = getRandomPosition();
item.style.left = `${xy[0]}px`;
item.style.top = `${xy[1]}px`;
}
const hideSplash = () => {
setTimeout(()=>{
const splashScreen = document.querySelector(".splash");
splashScreen.style.zIndex = -1;
}, 2000);
}
window.addEventListener("load", hideSplash);
- 서서히 사라지는 스크린
// 시간대 감지하여 배경 이미지 표시
const checkHours = () => {
const splashBg = document.querySelector("#splash-screen");
const now = new Date();
const hour = now.getHours();
if(hour>=6 && hour<20){
gameField.style.backgroundImage = "url('./imgs/bg/bg1.png')";
splashBg.style.backgroundImage = "url('./imgs/bg/bg1.png')";
}else{
gameField.style.backgroundImage = "url('./imgs/bg/bg2.png')";
splashBg.style.backgroundImage = "url('./imgs/bg/bg2.png')";
}
}
- 아침 ~ 초저녁
- 저녁 ~ 새벽
redoBtn.addEventListener("click", () => location.reload());