Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <canvas id="ctx" width="800" height="500" style="border:1px solid #000000;background-image:url('space-1.jpg')"></canvas>
- <script>
- /* Základní popisky*/
- var ctx = document.getElementById("ctx").getContext("2d");
- ctx.font = '30px Arial';
- ctx.fillStyle = 'white';
- var count = 0;
- var points = 0;
- var pressed_start = false;
- /* Interakce s klávesnicí */
- document.onkeydown = function(event){
- if (event.keyCode === 68 && falcon.x < 600 ) { //d
- falcon.x += 10;
- bullet.x +=10;
- }
- if (event.keyCode === 83 && falcon.y < 360){ //s
- falcon.y +=10;
- }
- if (event.keyCode === 65 && falcon.x > 0) { //a
- falcon.x -=10;
- bullet.x -=10;
- }
- if (event.keyCode === 87 && falcon.y > 0) { //w
- falcon.y -=10;
- }
- if (event.keyCode === 80) { //p
- pressed_start = true;
- }
- if (event.keyCode === 32) {
- }
- };
- //32 mezerník
- /* Entity*/
- falcon = {
- x : 600,
- y : 10,
- img : 'falcon1.png'
- };
- bullet = {
- x : falcon.x,
- y : falcon.y+55,
- img : 'bullet.png'
- };
- enemy = {
- x: 0,
- y : Math.round(Math.ceil((Math.random() * 360) + 1)/10)*10,
- img : 'enemy_1.png'
- };
- setInterval(update,10);
- function drawEntity(entity){
- var Img = new Image();
- Img.src = entity.img;
- ctx.drawImage(Img,entity.x,entity.y);
- }
- function hittedEnemy(){
- if(bullet.y === enemy.y) {
- return true;
- } else {
- return false;
- }
- }
- function fireBullet(){
- bullet.x -=10;
- }
- function game(){
- drawEntity(enemy);
- }
- function update(){
- /* Vyčištění */
- ctx.clearRect(0,0,800,500);
- /*Vypsání/Vykreslíní XY/Falcona*/
- drawEntity(falcon);
- ctx.fillText("X : " + falcon.x + " Y : " + falcon.y, 600,480);
- ctx.fillText("X : " + enemy.x + " Y : " + enemy.y, 500,380);
- /* Kulla*/
- drawEntity(bullet);
- bullet.y = falcon.y+55;
- /* Hra*/
- setTimeout(drawEntity(enemy),5000);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement