Skip to content

Instantly share code, notes, and snippets.

View hex13's full-sized avatar
💭
slavic code master

Łukasz Lityński hex13

💭
slavic code master
  • JavaScript developer
  • Warsaw/Poland
View GitHub Profile
@hex13
hex13 / gist:6795950
Last active December 24, 2015 12:09
spaceshooter, tutorial, step 0, index.html
<!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>
@hex13
hex13 / gist:6800626
Last active December 24, 2015 12:49
spaceshooter, tutorial, step 1, basic structure
function loadImages(directory, fileNames, onComplete) {
};
function initialize() {
// tu bedzie kod inicjalizujacy gre...
};
$(document).ready(function() {
@hex13
hex13 / gist:6800682
Last active December 24, 2015 12:49
spaceshooter, tutorial, step 1, loadImages-a
function loadImages(directory, fileNames, onComplete) {
fileNames.forEach(function(fileName) {
var img = new Image();
img.src = directory + '/' + fileName; // here!!! magic happens
});
};
@hex13
hex13 / gist:6800760
Last active December 24, 2015 12:49
spaceshooter, tutorial, step1, loadImages
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)
};
@hex13
hex13 / gist:6800874
Last active December 24, 2015 12:58
spaceshooter, tutorial, step1
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)
@hex13
hex13 / gist:6845442
Last active December 24, 2015 18:49
EntityPrototype
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
};
var entities = [];
var canvas, ctx;
@hex13
hex13 / gist:6845628
Created October 5, 2013 20:25
createEntity
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;
};
@hex13
hex13 / gist:6845734
Created October 5, 2013 20:37
initCanvas
function initCanvas() {
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
};
initCanvas();