- Author:
- Mikhail Davydov
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- azproduction.ru
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/358
- Shortlink:
- https://js1k.com/358
- Blog post:
- please update here!
- Bytes:
- 955
- Chars:
- 955
- Submission
this.onload=function(){var m=document,b=m.getElementById('c'),c=b.getContext('2d'),v=10,r=['0110','1111','0110','1111'],e=['1111','0110','1111','0110'],i=0,j=0,k=0,f=[],o=Math.random,y=function(){f.push([~~(o()*56),-3]);},s=1,h=5,q=28,t=74,g=0,n=0,d=function(t,x,y,r){while(r[i]){j=0;while(r[i][j]){if(r[i][j]*1)t.fillRect(v*(x+j),v*(y+i),v,v);j++;}i++;}i=0;j=0;},w=function(){if(!s||n)return;c.clearRect(0,0,600,800);while(f[k]){f[k][1]++;if(Math.sqrt((f[k][0]-q)*(f[k][0]-q)+(f[k][1]-t)*(f[k][1]-t))<4){n=1;}d(c,f[k][0],f[k][1],e);if (f[k][1]>80){f.splice(k,1);k--;g++;}k++;}if(!(h%5)&&o()>0.3){y();}k=0;c.fillStyle=n?'red':'teal';d(c,q,t,r);c.fillStyle='#000';h++;m.title="Score: "+g;if(n){alert('Game Over. Your Score: '+g);m.location=m.location;}};b.setAttribute('width',600);b.setAttribute('height',800);m.addEventListener('keyup',function(e){if(e.keyCode==37){q--;if(q<0)q=0;}if(e.keyCode==39){q++;if(q>56)q=56;}},true);y();this.setInterval(w,50);}
- Description
- Oldstyle pixel car game.
- Base64 encoded
dGhpcy5vbmxvYWQ9ZnVuY3Rpb24oKXt2YXIgbT1kb2N1bWVudCxiPW0uZ2V0RWxlbWVudEJ5SWQoJ2MnKSxjPWIuZ2V0Q29udGV4dCgnMmQnKSx2PTEwLHI9WycwMTEwJywnMTExMScsJzAxMTAnLCcxMTExJ10sZT1bJzExMTEnLCcwMTEwJywnMTExMScsJzAxMTAnXSxpPTAsaj0wLGs9MCxmPVtdLG89TWF0aC5yYW5kb20seT1mdW5jdGlvbigpe2YucHVzaChbfn4obygpKjU2KSwtM10pO30scz0xLGg9NSxxPTI4LHQ9NzQsZz0wLG49MCxkPWZ1bmN0aW9uKHQseCx5LHIpe3doaWxlKHJbaV0pe2o9MDt3aGlsZShyW2ldW2pdKXtpZihyW2ldW2pdKjEpdC5maWxsUmVjdCh2Kih4K2opLHYqKHkraSksdix2KTtqKys7fWkrKzt9aT0wO2o9MDt9LHc9ZnVuY3Rpb24oKXtpZighc3x8bilyZXR1cm47Yy5jbGVhclJlY3QoMCwwLDYwMCw4MDApO3doaWxlKGZba10pe2Zba11bMV0rKztpZihNYXRoLnNxcnQoKGZba11bMF0tcSkqKGZba11bMF0tcSkrKGZba11bMV0tdCkqKGZba11bMV0tdCkpPDQpe249MTt9ZChjLGZba11bMF0sZltrXVsxXSxlKTtpZiAoZltrXVsxXT44MCl7Zi5zcGxpY2UoaywxKTtrLS07ZysrO31rKys7fWlmKCEoaCU1KSYmbygpPjAuMyl7eSgpO31rPTA7Yy5maWxsU3R5bGU9bj8ncmVkJzondGVhbCc7ZChjLHEsdCxyKTtjLmZpbGxTdHlsZT0nIzAwMCc7aCsrO20udGl0bGU9IlNjb3JlOiAiK2c7aWYobil7YWxlcnQoJ0dhbWUgT3Zlci4gWW91ciBTY29yZTogJytnKTttLmxvY2F0aW9uPW0ubG9jYXRpb247fX07Yi5zZXRBdHRyaWJ1dGUoJ3dpZHRoJyw2MDApO2Iuc2V0QXR0cmlidXRlKCdoZWlnaHQnLDgwMCk7bS5hZGRFdmVudExpc3RlbmVyKCdrZXl1cCcsZnVuY3Rpb24oZSl7aWYoZS5rZXlDb2RlPT0zNyl7cS0tO2lmKHE8MClxPTA7fWlmKGUua2V5Q29kZT09Mzkpe3ErKztpZihxPjU2KXE9NTY7fX0sdHJ1ZSk7eSgpO3RoaXMuc2V0SW50ZXJ2YWwodyw1MCk7fQ==
- Original source
this.onload=function(){
var m=document,
b = m.getElementById('c'),
c = b.getContext('2d'),
v = 10, // Block size
r = ['0110','1111','0110','1111'], // Car model one
e = ['1111','0110','1111','0110'], // Car model two
i = 0, // Counters
j = 0, // Counters
k = 0, // Counters
f = [], // Cars positions
o = Math.random,
y = function() // Cars generator
{
f.push([
~~(o() * 56),
-3
]);
},
s = 1,
h = 5, // Frame
q = 28, // Main car position X
t = 74, // Main car position Y
g = 0, // score
n = 0, // game over flag
d = function(/* Context */t,/* Car X */ x, /* Car Y */ y, /* Car model */ r) // Draw car function
{
while(r[i]){
j = 0;
while(r[i][j]){
if(r[i][j] * 1) t.fillRect(v * (x + j), v * (y + i), v, v);
j++;
}
i++;
}
i=0;
j=0;
},
w = function(){ // Frame function
if(!s||n)return;
c.clearRect(0, 0, 600, 800);
while(f[k]){
f[k][1]++;
if(Math.sqrt((f[k][0]-q)*(f[k][0]-q)+(f[k][1]-t)*(f[k][1]-t))<4){ // Check collision
n = 1; // game over
}
d(c,f[k][0],f[k][1],e); // Draw car
if (f[k][1] > 80){ // Delete car out of screen
f.splice(k,1);
k--;
g++;
}
k++;
}
if(!(h % 5) && o() > 0.3){ // generate random car
y();
}
k=0;
c.fillStyle=n?'red':'teal';
d(c,q,t,r); // Draw Main Car
c.fillStyle='#000';
h++;
m.title = "Score: " + g; // Output info
if(n){ // Gameover message
alert('Game Over. Your Score: ' + g);
m.location=m.location;
}
};
// Init canvas
b.setAttribute('width', 600);
b.setAttribute('height', 800);
// Init eventlistener
m.addEventListener('keyup', function(e){
if(e.keyCode == 37){
q--;
if (q < 0)q = 0;
}
if(e.keyCode == 39){
q++;
if (q > 56) q = 56;
}
},true);
y(); // Draw first car
this.setInterval(w, 50); // Init frame function
}