Hot Post

Mini game Halloween "Shoot the zombie"


Shoot the zombie

Hãy cùng tạo trang game Bằn Zombie cho website của bạn. Luật chơi rất đơn giản: bạn hãy ngắm bắn những con Zombie trong khoảng thời gian 10s bằng cách click vào chúng.


CSS

@import url(http://fonts.googleapis.com/css?family=Sancreek);

/* ==================
General layout classes
======================   */
body {
  background-color: teal;
  text-align: center;
  color: #ccc;
  font-family: sans-serif;
}

h1 {
  font-family: "Sancreek";
  font-size: 3em;
  margin-bottom: 0;
}

h2 { bna5
  display:inline-block; 
  background-color: #ccc;
  color: #777;
  padding: 10px;
  margin: 10px auto;
}

h2:hover {
  background-color: #222;
  cursor: pointer;
}

.game_info, .speel_zone {
  width: 400px;
  margin: 0 auto;
}

.speel_zone {
  cursor: url(http://www.rw-designer.com/cursor-extern.php?id=38558);
  
  /*cursor:url(/img/magnify.cur), -moz-zoom-in, auto;*/
  border: 3px solid #ccc;
  height: 400px;
  position: relative;
}

/* zombie div  */
.zombie {
  position: relative;
  width: 80px;
  height: 80px;
  background: url(http://icons.iconarchive.com/icons/yootheme/halloween/512/geek-zombie-icon.png);
  background-size:80px;
  display: none;
}

.final_score {
  font-family: "Sancreek";
  font-size: 5em;
  line-height: 400px;
}

.game_started {
  display: none;
}

.score {
  float: left;
}

.timer {
  float: right;
}


/* =========== HELPERS ========= */
.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}
 
.clearfix {
    display: inline-block;
}
 
html[xmlns] .clearfix {
    display: block;
}
 
* html .clearfix {
    height: 1%;
}

Javascript

<script type='text/javascript'>
//<![CDATA[
(function($) {
  // start game
  // set global variables
  var score, timer_interval, timer = 0;
  
  $( '.start_game' ).click(function() {
    start_game();
  });
  
  $( '.zombie' ).click(function() {
    $(this).css('top', getRandom(0, 320)+'px');
    $(this).css('left', getRandom(0, 320)+'px');
    score += 1;
    show_score();
  });
  
  function show_score(){
    $('.score').text('Score: '+score);
  }
  
  function show_timer(){
    $('.timer').text('Timer: '+timer);
  }
  
  function show_final_score(){
    $('.final_score').text('Score: '+score);
    $( '.final_score' ).show();
  }
  
  function start_game(){
    $( '.game_not_started' ).hide();
    $( '.final_score' ).hide();
    $( '.game_started' ).show();
    $( '.zombie' ).show();
    
    
    score = 0;
    show_score();
    
    timer = 10;
    timer_interval = setInterval(timer_countdown, 100);
    show_timer();
  }
  
  function stop_game(){
    $( '.hide' ).show();
    $( '.game_not_started' ).show();
    $( '.game_started' ).hide();
    $( '.final_score' ).show();
    $( '.zombie' ).hide();
    show_final_score();
  }
  

  function timer_countdown(){
    timer -= 0.1;
    timer = Math.round(timer*10)/10;
    if (timer <= 0)
    {
      clearInterval(timer_interval);
      stop_game();
    }
    
    show_timer();
  }
  
})(jQuery);

// ========= HELPERS ===============
function getRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
//]]>
</script>

HTML

<h1>Shoot the zombie</h1>
<div class='game_info clearfix'>
  <div class="game_not_started">
    <h2 class='start_game'>Start game</h2>
  </div>
  <div class="game_started">
    <span class="score"></span>
    <span class="timer"></span>
  </div>
</div>

<div class="speel_zone">
  
  <div class='zombie'></div>
  <div class="final_score"></div>
</div>


Nếu có bất kỳ vấn đề khó khăn hay câu hỏi gì, bạn đừng ngần ngại, hãy để lại bình luận ở form bên dưới nhé.
Chúc bạn thành công!

Created by Iris Tips
Đăng ký nhận tin khuyến mãi, thủ thuật mới

Mẹo nhỏ khi bình luận
  • - Để viết chữ in đậm hãy sử dụng thẻ <b>chữ in đậm</b>
  • - Để viết chữ in nghiêng hãy sử dụng thẻ <i>chữ in nghiêng</i>
  • - Để viết code hãy sử dụng công cụ Conversion ở bên dưới để mã hóa và sau đó dán vào khung bình luận.
  • - Để chèn hình ảnh, video chỉ cần dán link trực tiếp của hình ảnh hoặc video vào khung bình luận (hỗ trợ: jpg, gif, png, bmp, Youtube).
  • - Bạn có thể upload hình ảnh, tập tin trực tiếp từ máy tính bằng cách sử dụng công cụ Up ảnh hoặc Up file ở bên dưới.
  • - Bạn có thể check vào ô Notify me ở khung nhận xét để nhận thông báo qua email khi ai đó trả lời bình luận của bạn.

0 Response to "Mini game Halloween "Shoot the zombie""

Đăng nhập bằng Google


Trở thành người đầu tiên bình luận cho bài viết này!