xonecas.io
211
Ze

zen / commit 44de4c5

made some improvements, now using images for aliens, and cannon

xonecas2011-01-29 44de4c58e8846f8dacf650421601eb3f67574d59 parent bc7733b

5 files changed

css/style.css+7−1
@@ -75,7 +75,7 @@ pre, code, kbd, samp { font-family: monospace, sans-serif; }
7575
7676 body, select, input, textarea {
7777 /* #444 looks better than black: twitter.com/H_FJ/statuses/11800719859 */
78- color: #444;
78+ color: #000; background-color: #444;
7979 /* set your base font here, to apply evenly */
8080 /* font-family: Georgia, serif; */
8181 }
@@ -171,6 +171,8 @@ button { width: auto; overflow: visible; }
171171 /* Primary Styles
172172 Author: xonecas
173173 */
174+
175+
174176 #fontLoader {
175177 width: 200px;
176178 margin: 50px auto;
@@ -178,6 +180,10 @@ button { width: auto; overflow: visible; }
178180 font-size: 1.846153846em; /* 24px/13px */
179181 }
180182
183+#imageLoader {
184+ display: none;
185+}
186+
181187 canvas {
182188 position: absolute;
183189 top: 0; left: 0;
images/alien.png+0−0
Binary file, not shown.
images/laser.png+0−0
Binary file, not shown.
index.html+3−2
@@ -45,8 +45,9 @@
4545
4646 </section>
4747
48- <footer>
49-
48+ <footer id="imageLoader">
49+ <img src="images/alien.png" id="alien" />
50+ <img src="images/laser.png" id="laser" />
5051 </footer>
5152 </div> <!--! end of #container -->
5253
js/script.js+46−16
@@ -1,5 +1,7 @@
11 /* Author: xonecas
22
3+ this file needs to be cleaned up and organized
4+
35 */
46
57 (function (window, undefined) {
@@ -9,15 +11,14 @@
911 $(window).load(function () {
1012 $('#fontLoader').remove();
1113
12- if (Modernizr.canvas && Modernizr.canvastext) {
14+ if (Modernizr.canvas) {
1315
1416 var canvas = document.createElement('canvas'),
1517 canvasWidth = $(window).width() - 38,
1618 canvasHeight = $(window).height(),
17- startX = Math.ceil(canvasWidth / 2),
18- startY = canvasHeight - 20,
19- currentX = startX,
20- currentY = startY;
19+ center = Math.ceil(canvasWidth / 2),
20+ currentX = center + 10,
21+ currentY = canvasHeight - 58;
2122
2223
2324 $(canvas).attr({
@@ -28,31 +29,60 @@
2829 $('#main').html(canvas);
2930
3031 var ctx = canvas.getContext('2d');
31- ctx.font = '38px oxy';
32- ctx.fillStyle = '#444444';
32+ var alien = $("#alien").get(0),
33+ laser = $('#laser').get(0);
34+
35+ ctx.fillStyle = '#fff';
36+
37+ ctx.drawImage(laser, currentX, currentY, 38, 38);
38+
39+ var z = 11, startx = center - 279, consty = 20;
40+ while (z--) {
41+ ctx.drawImage(alien, startx, consty, 38, 38);
42+ startx += 58;
43+ }
3344
34- ctx.fillText('o', startX, startY);
3545
3646 $(document).keydown(function (ev) {
3747 switch(ev.which) {
38- case 37:
39- case 39:
48+ case 37: // left arrow
49+ case 39: // right arrow
4050 var keepMoving = 10;
4151 (function animate () {
4252 if (currentX <= 38 ||
4353 currentX >= (canvasWidth -38))
44- return currentX = (currentX <= 38)? 40: canvasWidth -40;
54+ return currentX = (currentX <= 38)? 40: canvasWidth -40;
4555
46- ctx.fillStyle = '#ffffff';
47- ctx.fillRect(38, 38, currentX, currentY);
56+ ctx.fillStyle = '#444';
57+ ctx.fillRect(currentX -2, currentY , 42, 38);
4858
4959 currentX += (ev.which === 37)? -2: 2;
5060
51- ctx.fillStyle = '#444444';
52- ctx.fillText('o', currentX, currentY);
61+ ctx.fillStyle = '#ffffff';
62+ ctx.drawImage(laser, currentX, currentY, 38, 38);
5363 if (--keepMoving)
5464 setTimeout(animate, 20);
55- })();
65+ }) ();
66+ break;
67+
68+ case 32: // space bar
69+ var originX = currentX +18,
70+ originY = currentY;
71+
72+ (function fly () {
73+ ctx.fillStyle = '#444';
74+ ctx.fillRect(originX, originY, 2, 10);
75+
76+ originY -= 22;
77+ ctx.fillStyle = '#fff';
78+ ctx.fillRect(originX, originY, 2, 10);
79+
80+ if (originY >= -10)
81+ setTimeout(fly, 30);
82+ }) ();
83+ break;
84+ default:
85+ ev.preventDefault();
5686 }
5787
5888 //log(ev.which);