From 46eefaa62e84a4f5f9d2877d9ccb9f189ab3e91a Mon Sep 17 00:00:00 2001 From: Markus Scully Date: Sat, 29 Jun 2013 10:48:15 +0100 Subject: [PATCH] Version 0.2 Added base for new physics, not yet working, and fixed falling on top of other cubes. --- .gitattributes | 22 ----- .gitignore | 215 ------------------------------------------------- favicon.png | Bin 305 -> 0 bytes sint.js | 93 +++++++++++++++------ sprites.png | Bin 1247 -> 0 bytes sprites2.png | Bin 845 -> 0 bytes 6 files changed, 69 insertions(+), 261 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .gitignore delete mode 100644 favicon.png delete mode 100644 sprites.png delete mode 100644 sprites2.png diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 412eeda..0000000 --- a/.gitattributes +++ /dev/null @@ -1,22 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b9d6bd9..0000000 --- a/.gitignore +++ /dev/null @@ -1,215 +0,0 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap -.DS_Store - - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg diff --git a/favicon.png b/favicon.png deleted file mode 100644 index 0b0b6472de0217e2fef34c754d2a204cf2f9e76d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 305 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7*pj^6T^Rm@;DWu&Co?cG za29w(7Bet#eE?xbr!^)s7#JAXOFVsD+3&JS3bUw3G{+Y)Ffi=%ba4!^IDK@IE!QCj zf!6y18-*{eV$oTSRf!3G;8bqoloBVS&BufknqO81^#yv>P0(xR}rI=RWV6KIS#wls+}p zoSm}%km)M!2-C-=NoMv*8y9}ylnUUzSE;ahlM=(5ycw?=W&S)6opPh8$7W&>qweg! zeIFliUEa9;AG_R^bNusk4`q3MOpyB6ASZXH?V+rSV$RQ_g-7xj7#J8lUHx3vIVCg! E0D9YUlmGw# diff --git a/sint.js b/sint.js index 5a2297e..78a5814 100644 --- a/sint.js +++ b/sint.js @@ -17,39 +17,35 @@ window.requestAnimFrame = (function(){ })(); // Set up variables. - function reset(){ + // Create arrays. actors = []; controllers = []; particles = []; ais = []; keys = []; + // Create 2 actors. actors[0] = new Actor(1, 200, 3, 5, 5); actors[1] = new Actor(2, 200, 3, 50, 5); - actors[2] = new Actor(2, 200, 1, 100, -100); - - controllers[0] = new Controller(actors[0], [[68, 'moveRight'], [65, 'moveLeft'], [87, 'jump'], [67, 'camera'], [77, 'flo', 100]]); + // Create player key controllers. + controllers[0] = new Controller(actors[0], [[68, 'moveRight'], [65, 'moveLeft'], [87, 'jump'], [67, 'camera'], [77, 'stream', 100]]); controllers[1] = new Controller(actors[1], [[39, 'moveRight'], [37, 'moveLeft'], [38, 'jump'], [88, 'camera'], [78, 'bounce', 100]]); - controllers[2] = new Controller(actors[2], [[90, 'camera']]); - ais[0] = new Ai(actors[2], 'pace'); - - particles[0] = new Particle(0, 0, 2000, 100, 200, 10, 0); - - camera = [actors[0], actors[1]]; - canvas.style.background = '#fff'; + camera = [actors[0], actors[1]]; // Set camera. + canvas.style.background = '#fff'; // Set canvas style. canvas.style.display = 'block'; - canvas.style.border = '1px solid #ddd' - spritesheet = new Image() + canvas.style.border = '1px solid #ddd'; + spritesheet = new Image(); spritesheet.src = 'newsprites.png'; document.addEventListener('keydown', keyDown, true); document.addEventListener('keyup', keyUp, true); animate(); } -level = [ +// Define the level. +levels = [ ['#...................#'] ,['#...................#'] ,['########............#'] @@ -62,10 +58,12 @@ function animate() { loopGame(); } +// Round a number. function r(num){ return Math.round(num); } +// Add key pressed to key list. function keyDown(e){ var keyPress; if (typeof event !== 'undefined') { @@ -78,6 +76,7 @@ function keyDown(e){ } } +// Remove key from key list. function keyUp(e){ var keyPress; if (typeof event !== 'undefined') { @@ -180,6 +179,9 @@ function Actor(type, health, power, xpos, ypos){ case 'flo': particles.push(new Particle(2, 0, 100000, this.x, this.y - 16, this.xvel * 4 + ((Math.random() - 0.5) * 10), -10)); break; + case 'new': + particles.push(new Particle(3, 0, 10000, this.x, this.y - 1, this.xvel * 4 + ((Math.random() - 0.5) * 5), -6 + this.yvel * 2)); + break; } this.actionsturn.push(type); } @@ -188,12 +190,12 @@ function Actor(type, health, power, xpos, ypos){ this.left = this.right = false; for(j in actors){ if(actors[j].image != this.image){ - if(actors[j].x + 17 > this.x && this.x > actors[j].x && this.sameY(actors[j])){ + if(actors[j].x + 16 > this.x && this.x > actors[j].x && this.sameY(actors[j])){ this.left = true; this.x = actors[j].x + 16; this.xvel = (this.xvel < 0 ? 0 : this.xvel); } - if(this.x + 17 > actors[j].x && this.x < actors[j].x && this.sameY(actors[j])){ + if(this.x + 16 > actors[j].x && this.x < actors[j].x && this.sameY(actors[j])){ this.right = true; this.x = actors[j].x - 16; this.xvel = (this.xvel > 0 ? 0 : this.xvel); @@ -204,28 +206,33 @@ function Actor(type, health, power, xpos, ypos){ this.yCheck = function(){ this.up = this.down = false; + if(this.y >= 216){ this.down = true; this.y = 216; - this.yvel = 0; } + for(j in actors){ if(actors[j].image != this.image){ - if(this.y + 15 > actors[j].y && this.y < actors[j].y + 15 && this.sameX(actors[j])){ - this.down = true; - this.y = actors[j].y - 18; - this.yvel = 0; + if(this.y + 16 > actors[j].y && this.y < actors[j].y + 16 && this.sameX(actors[j])){ + if(this.y < actors[j].y){ + this.down = true; + this.y = actors[j].y - 16; + }else{ + this.up = true; + this.y = actors[j].y + 16; + } } } } } this.sameY = function(obj){ - return (this.y < obj.y + 15 && this.y + 15 > obj.y); + return (this.y < obj.y + 15 && this.y + 16 > obj.y); } this.sameX = function(obj){ - return (this.x + 16 > obj.x && this.x < obj.x + 16); + return (this.x + 15 > obj.x && this.x < obj.x + 15); } this.simulate = function(){ @@ -272,7 +279,7 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){ this.yvel = yvel; this.type = type; this.life = lifespan; - this.size = [3, 5, 7][type]; + this.size = [3, 5, 7, 32][type]; this.created = this.timeup = new Date(); this.timeup = new Date(this.timeup.getTime() + lifespan); this.deleteme = false; @@ -309,6 +316,14 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){ context.strokeRect(r(this.x - lookx) + 0.5, r(213 - (this.y - 216) - looky) + 0.5, 5, 5); context.globalAlpha = 1; break; + case 3: + context.globalAlpha = 0.5; + context.lineWidth = 2; + context.strokeStyle = '#000'; + context.strokeRect(r(this.x - lookx) + 0.5, r(this.y - looky) + 0.5, 32, 32); + context.strokeStyle = '#777'; + context.strokeRect(r(this.x - lookx) + 0.5, r(213 - (this.y - 216) - looky) + 0.5, 32, 32); + context.globalAlpha = 1; } } @@ -358,6 +373,12 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){ } } break; + case 3: + //this.yvel += (this.onGround() ? 0 : 0.007 * speed); + //if(this.onGround()){ + // this.y = 216 - this.size; + // this.yvel = (this.yvel > 2 ? this.yvel * -0.7 : 0); + break; } if(thisLoop > this.timeup){ this.deleteme = true; @@ -365,6 +386,30 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){ } } +// Collision detection class +function Box(x, y, w, h, xvel, yvel, colgroup){ + this.x = x; + this.y = y; + this.width = w; + this.height = h; + this.col = colgroup; + + this.reset = function(){ + this.down = this.up = this.left = this.right = false; + } + + this.collide = function(){ + + } + + this.move = function(xmov, ymov){ + this.x += xmov; + this.y += ymov; + this.reset(); + + } +} + // Run game. var speed; diff --git a/sprites.png b/sprites.png deleted file mode 100644 index 212c69d8cc9d7452db9e9612e0e6f11970cc9267..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1247 zcmeAS@N?(olHy`uVBq!ia0y~yU@%}{U~u4IVqjpn?366Xz`(#+;1OBOz`*qZgc+UI zn9N{cV43LY;uw-~@9m6>+0m&I$Ko@&{>qCi_bCj&)YP0LxaGp#8>I@;3sbeOh^aSk zb)30l3G2-l9?#D{TcG=Df?>4&DucJ4w^CvgHC>|HZ{_x^%?Xfvz3tZBH(76v-JkyX zsm|+F_iyJkDnI$KJHvn8oX=mX@4c_J*HS7~I-k?x^?K>LZcW=%QbNPeIU7hbvKci&%a$idPhdvEXp4dvwN1NBpexRJK zap~voNEPuDf5h)(imEm)Y&|=%A;>)YojC8_|Eoa~YZm4%QZX?3p0q^d{@KUo-EC#h zf4si?=G;&Hh|1t8ENw;lE_0?xyqfWBefed>T;9EUUQEt6eFfE3+ZJVR_V8Pj`Jc6Z zznT}5v+()r7Mg}zK5vOsQMdMwc3$5#>A-~_#io98QmZO|OKoMmo#S&>PSqg-z>EH{?$b+8@FtGm+|`hExYqOUVay7{vNqnD1Ls`dSA|@ zPB-gY{FQH+CC%Gyju_mO4^8?izfIdwXYSm)v7YN+clXR*(k`)y-Fj+7?HcX7*$>)F zIqh6^Y;8B*Tm15#{^q>CWrBxqD%*OkvAbw3y8XjvsZFZ#iqk6g=o?P*tSP;A)`QJ( zj-W^_}BabRyhU6)lR$uhZV>FDJ`)x`@t=ZNIh0Q!0pX~e>apr&JS>8>DzFyCd zT2p7Y-{Lu&jSYf-rO!(HXk-jY?70-H`t z91_oVt-B&pdhXt0`3s9*%>GjJjN7>1^32VK!@f(uvN~&*ujJ2~R(s^$vild9U!Fe0 z^-SD&s^$5c&7TF>HNLFTtqk7$M){lB-!?gq__Q#C{WDgcsXQk)r(N#i`R6y?-{k({ zwVkjp=b77@?wP0Nm>=(d>-(%BjW>4xNxP){%lR)Fzoe$Ieg?@se{-<%g(puSx^bb- z|1&jWCbq6_I~00l;qBDKJKqxDI4?Aw(i?95Rak=SdcoZT9~UgVRQ1pP$^rjB=VI-g z8~IG{Kb&1NfB6TUc_)f1tCoH}CJ;G+W9I}u$%!JB6QyoWRIr?+HgnRN|4f?{1d9}9 zjg&M$DVc6kb}UlyHB!=y&;R#*^Xk?ZkM~>JXXafwGiQ;~7d#tJ zuWI|}KCyN6iq*XzUrKOYF1Wkv;A5B6um2hLB-Cm5&f2h*fq{X+)78&qol`;+0LKnz AtN;K2 diff --git a/sprites2.png b/sprites2.png deleted file mode 100644 index 8e1be95fc9d845dcfdb13ee184ed6ea77f27d3cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 845 zcmeAS@N?(olHy`uVBq!ia0y~yUx1HVvZta~cqDVIyd&{p z@(;n7Uy^s87+!iJd+ArBkbl`*%ead3r_`rmjhFDBp1OU6I3w$1`_6 zQQg4!uHZ;T@uQ!IG~F35{QY$P)Xl%^^BHS?Z~8W??q4qRgHO(pmj55|v*#_J&tg$G z^FEL6`%}Nq$1ncY6<0ce&DDXCK_$~{OMmY2)ko}9)Y zzjE7^q-DAD85sl&SA6TT%UUlX5XzCkB))6K-J5O&v5hmH&5^jnXf|sni$CXao;6k) zzgFBn78atZFj1{IcsBRM^DLj29@rLhBT7x?z}a_ZJY9~4E4~Tt&EgMbToS0N!t5yg z_o>i6UWOYtRxReu(H6S*S5mQck=f=~VTKF>XKffx@I2h~E2f~{CW5IT`s3u!3%AMM z?b))~@Lv1ssM9U#h9Ut|S1rEE8qlU+~qsoAhIvq>Fu*Hcked^_(z$*hTNw>bJrIggjC ztXaJJ%i_}Pc?ENY%+gJ=W@vk~ZD%%FE*{lrDIR*uZ|(;v!{-U}b03$jnVWR$fE|0Z zp{oZ&4?^uy(KB`g>r;> z_?OMgSARKsb+fQtmZ$gu_YJlcA7_|tczaOxw$g$|X3^>oU-aI}u9X(vx9`%|tAgPr ze~N!R-YGlv!{P_kqS^f4&T%v@IvHbV+vO2;d+(QXYqqT2c(C6z&;Op>zl6UAethTZ zEPg+H)4o|A8{@~-?}w+fTsPrapQB=NkkhZANqEi!7Ii#K>Hm!SOT0gwSFh@4U|?YI MboFyt=akR{07Q+16aWAK