eval("eval(\"WXwidthZWidth;hXheightZHeight;c.style.display='block';$=I=[99,u=jM=Math,q=W/4,A=2,H=e=g=S=jjj0];a.font='14px Arial';d=BGStyle='rgb('+(l?c:[c,c,c])+')';k?GText(x,r,k):x?G(a.arc(x,y,r,j8,a.beginPath())):GRect(jjW,h)};setInterval(Bd(jQ);Yu>>8){A=m=n=2;YI){f=w=I=0;Dfor(i=p=m?20:200;i--;d(jx,y,1))d(!m&i<Ul]*2?255:64,x=q-1Jo=m?3:49)+Nk=i*6.3/p)*o+EC+Lk)*o+O2)}YU0]){Yf){Dx=e-q-Eg-C-OkVx*x+y*yzn=k*k*(m?8:.4zT-=x/n,k<(m?6:52)K!m&w<3?Ul]++:(m?Ul+2]=0:jA=9)):t-=y/n;e=(e+T+W)%W;g=(g+t+h)%h;U8]KA=9):wVT*T+t*t)_e=q+53*LH+=U7]-U5]zg=C+53*NHzU6]?w=F4,w+.1):(f=w,T=w*LHzt=w*NH));S=Jzd([Fi=-2*F-Fw*80|jk=255z0zkzFk,575-iz0],Q,j1)}_d(256-u,'The Оrion Trail',jW/2-5j(C=h/2)-u++)},20zonkeydown=onkeyup=BU((kXkeyCode-37)>>2?4:k)+5]Xtype[5]?.02:0}\"#_}else #Z=inner#Yif(#X=c.#V=M.sqrt(#U$[#Qe+S,g+S,A#Om*(l*60-40z#NM.sin(#LM.cos(#K?(I=$[0]--,#J.4*M.random(#Ga.fill#FM.min(#E(m?q-(l-1&&l)*3:l*W/2zy=#Dfor(;m--;)for(l=2+m;l--;)if(!m||$[l+2])#Bfunction(c,x,y,r,k,l){#z),#j0,)".replace(/#(\w)([^#]*)(?!$)/g,".replace(/$1/g,'$2')"))
//________________________________________________________________________
//########################################################################
//## |## |%% |##
//## _______ |## ________|%%________ |##
//## /\ ,-´ `-. |## ##################### |##
//## / / \ |## /## ## |##
//## (_ / ,.------.___,` |##____|## ORION * |##____|##
//## \__/ 0) \ |##%%%%### * * * |##%%%%###
//## ( ( .__`o |## |## * TRAIL /## |##
//## ) ,--´ |## ## __________________/## |##
//## / ( M |## ##################### |##
//## | ' E |## |%% |##
//## | ´| E |##________________|%%________________|##
//## ` | | | R |########################################
//## | \ | K |##___by @veubeke and @UlrikeErdmann__|##
//## | \_ \ | A |########################################
//## | \ \|\ T |## Code and converter scripts at |##
//##___| `\ \ \____________|##___http://games.23inch.de/orion____|##
//########################################################################
//________________________________________________________________________
//########################################################################
//## Try taking a journey by spacecraft across 20000000 miles of |##
//## space, space, and space. Try! Will you slash your ship on an |##
//## asteroid or get lost in the depths of space? |##
//## If for some reason you don't survive, don't give up! |##
//## Try again... and again...________________________________________|##
//########################################################################
//## Controls: left/right - change launch position |##
//## up - launch (hold to increase launch speed) |##
//## down - abandon ship |##
//## |##
//## Hints: The planets show their current population. |##
//## Try to change window size to change difficulty.___________|##
//########################################################################
//
// Optimizations:
// * used only one-character variables
// * used dictionary compression
// * avoided using functions where possible
// * used decreasing "for" loops: "for(i=n;i--;)"
// * see code for details...
// Character Usage:
// var: a b c i k l m n o p r x y
// format: d e g h q s t u v w
// free: j z
// format: A C H I P S T W
// free: B D E F G J K L N O Q U V X Y Z
//________________________________________________________________________
//## Initialization ######################################################
// resize canvas
width = c.width = innerWidth;
height = c.height = innerHeight;
// get rid of the extra 4px below the canvas
c.style.display = 'block';
// queue setup, init ship, keys, asteroids and planet population counts
// 0..1 - population, 2..4 - asteroids, 5..8 - key states
// opt: values are completely unrelated but evaluate to "true"
// opt: setup only has to be truthy so it's set to an array
keys = setup = [99,
// init animation
counter = 0,
// opt: remember Math
M = Math,
// opt: remember planet position
qwidth = width/4,
// init ship
shipR = 2,
angle = shipX = shipY = shipRand = 0,
0,0,0];
a.font = '14px Arial';
//________________________________________________________________________
//## Painting ############################################################
// draws a circle, the background or prints text
// opt: different functionality for 1, 4, 5 or 6 parameters
// 1 - background (hue)
// 4 - grey circle (hue,x(!=0),y,radius)
// 5 - grey text (hue,text,0,x,y(!=0))
// 6 - coloured circle (color,x(!=0),y,radius,0,1)
draw = function(c,x,y,r,k,l) {
a.fillStyle = 'rgb('+(l?c:[c,c,c])+')';
k ? a.fillText(x,r,k)
// floating point values make sure that x is never 0 after the start
: x?a.fill(a.arc(x,y,r,0,8,a.beginPath())):a.fillRect(0,0,width,height)
};
//________________________________________________________________________
//## Main Loop ###########################################################
setInterval(function(c,x,y,r,k,l) {
// remove ship at previous position
// opt: also creates the black background in the beginning
draw(0,shipX+shipRand,shipY+shipRand,shipR);
// main game
if(counter>>8) {
// reset ship size
// opt: loop variables and ship radius are set together
shipR = m = n = 2;
// setup - reset ship, draw planets and asteroids
if(setup) {
flying = speed = setup = 0;
for(;m--;)
// draw 2 planets and 3 asteroids
for(l=2+m;l--;)
// if asteroid is still there
if(!m||keys[l+2])
// compose all objects of small rings to create a black board
// look and add small random shifts to increase the effect
for(i=p=m?20:200;i--;draw(0,x,y,1))
// opt: "&" replaces "&&" if both operands are truth values
draw(!m&i<keys[l]*2?255:64,
// opt: "Math.PI*2" -> "6.3"
x = qwidth-1.4*M.random(o=m?3:49)+M.sin(k=i*6.3/p)*o
// opt: "(l==1?3:0)-l*3" -> "-(l-1&&l)*3"
+(m?qwidth-(l-1&&l)*3:l*width/2),
y = hheight+M.cos(k)*o+m*(l*60-40),2)
}
// opt: used condition instead of "clearInterval" to stop game
if(keys[0]) {
// update flying ship
if(flying) {
for(;m--;)
// update ship speed with gravitation of all objects
for(l=2+m;l--;)
if(!m||keys[l+2])
x = shipX-qwidth-(m?qwidth-(l-1&&l)*3:l*width/2),
y = shipY-hheight-m*(l*60-40), k = M.sqrt(x*x+y*y),
n = k*k*(m?8:.4), shipSX -= x/n,
// reset if ship had a collision
// opt: change ship radius to create a simple explosion
k<(m?6:52)
? (setup = keys[0]--,
// opt: "m&&(asteroids[l]=0)" -> "m?asteroids[l]=0:0"
!m&speed<3?keys[l]++:(m?keys[l+2]=0:0,shipR=9))
: shipSY -= y/n;
shipX = (shipX+shipSX+width)%width;
shipY = (shipY+shipSY+height)%height;
// reset if aborted
keys[8] ? (setup = keys[0]--,shipR=9)
: speed = M.sqrt(shipSX*shipSX+shipSY*shipSY)
}
// update launch position
else
shipX = qwidth+53*M.cos(angle+=keys[7]-keys[5]),
shipY = hheight+53*M.sin(angle),
// increase speed as long as "up" is pressed
keys[6] ? speed = M.min(4,speed+.1)
// launch if "up" has been pressed
: (flying = speed,
shipSX = speed*M.cos(angle),
shipSY = speed*M.sin(angle));
shipRand = .4*M.random(),
// draw ship
// opt: "Math.max(x,y)" -> "-Math.min(-x,-y)"
draw([M.min(i=-2*M.min(-M.min(speed*80|0,k=255),0),k),M.min(k,575-i),0],
shipX+shipRand,shipY+shipRand,shipR,0,1)
}
}
// intro animation
else
draw(256-counter,'The Оrion Trail',0,
width/2-50,(hheight=height/2)-counter++)
},20),
//________________________________________________________________________
//## Event Handler #######################################################
onkeydown = onkeyup = function(c,x,y,r,k,l) {
// opt: "key < 0 || key > 4" -> "key >> 2"
// opt: "key[9]" is used as a catch-all to avoid using "if"
// opt: "x.type == 'keydown'" -> x.type[5]
// opt: key states are actually needed values instead of true/false
keys[((k=c.keyCode-37)>>2?4:k)+5] = c.type[5]?.02:0
}
//________________________________________________________________________
//########################################################################
//## / / / / / / / / / / / / / / |##
//## demo / / / / / / / / / / / / / / |##
//## for / /__/ /________/ / /_____/ /__/ / /__/ / |##
//## / |%%| |%%%%%%%%|/ |%%%%%| |%%| / /%%/ / |##
//## / |%%| /|%%|/____/ / |%%| /|%%|/_/%%/ / |##
//## / |%%| / |%%%%%%%%| / |%%| / |%%%%%%%%\ / |##
//## /_____|%%| / /_____|%%| / |%%| / |%%| / \%%\ / |##
//## |%%%%%%%%|/ |%%%%%%%%|/ |%%|/ |%%|/ \%%\/ .com |##
//##___________________________________________________________________|##
//########################################################################