This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initCanvas() { | |
canvas = document.getElementById('canvas'); | |
ctx = canvas.getContext('2d'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createEntity(entityName, properties) { | |
var entity = Object.create(EntityPrototype); | |
entity.img = images[entityName]; | |
for (var propertyName in properties) | |
entity[propertyName] = properties[propertyName]; | |
entities.push(entity); | |
return entity; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var entities = []; | |
var canvas, ctx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EntityPrototype = { | |
draw: function(context) { | |
context.drawImage(this.img, this.x, this.y); | |
}, | |
move: function() { | |
this.x += this.vx; | |
this.y += this.vy; | |
}, | |
x: 0, y:0, vx:0, vy:0 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var images = {}; | |
function loadImages(directory, fileNames, onComplete) { | |
var imagesLeft = fileNames.length; | |
fileNames.forEach(function(fileName) { | |
var img = new Image(); | |
img.onload = function() { | |
imagesLeft--; | |
if (imagesLeft <= 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadImages(directory, fileNames, onComplete) { | |
var imagesLeft = fileNames.length; | |
fileNames.forEach(function(fileName) { | |
var img = new Image(); | |
img.onload = function() { | |
imagesLeft--; // tu zliczamy ile obrazkow się zaladowalo | |
if (imagesLeft <= 0) // jesli wszystkie obrazki sie zaladowaly... | |
onComplete(); // uruchamiamy funkcje onComplete (podana jako argument funkcji) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadImages(directory, fileNames, onComplete) { | |
fileNames.forEach(function(fileName) { | |
var img = new Image(); | |
img.src = directory + '/' + fileName; // here!!! magic happens | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadImages(directory, fileNames, onComplete) { | |
}; | |
function initialize() { | |
// tu bedzie kod inicjalizujacy gre... | |
}; | |
$(document).ready(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>space shooter - tutorial - 13zmiennych.blogspot.com </title> | |
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script src="index.js"></script> | |
</head> | |
<body> |
NewerOlder