Permalink
Browse files

stuff

  • Loading branch information...
1 parent 4f6e9a9 commit 856150cb9e649e056d3175f4d58557ec04093509 @playerx playerx committed Feb 26, 2014
View
1 Jok.Pitching/Jok.Pitching/App_Start/BundleConfig.cs
@@ -14,6 +14,7 @@ public static void RegisterBundles(BundleCollection bundles)
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
+ "~/Scripts/jquery.cookie.js",
"~/Scripts/kinetic-v5.0.1.min.js",
"~/Scripts/Game.js"));
View
30 Jok.Pitching/Jok.Pitching/Content/Site.css
@@ -128,3 +128,33 @@ img {
text-align: center;
display: none;
}
+
+
+#Menu .finish .highscore {
+ color: red;
+ font-weight: bold;
+ margin-bottom: 10px;
+ text-shadow: 0 0 5px rgb(173, 173, 171);
+ font-size: 36px;
+}
+
+#Menu .finish .results {
+ margin-bottom: 20px;
+}
+
+#Menu .top_speakers_btn {
+ margin-top: 20px;
+}
+
+
+#StartGame {
+ min-width: 260px;
+ height: 70px;
+ font-size: 26px;
+}
+
+#PlayAgain {
+ min-width: 260px;
+ height: 70px;
+ font-size: 26px;
+}
View
1 Jok.Pitching/Jok.Pitching/Jok.Pitching.csproj
@@ -157,6 +157,7 @@
<Content Include="Scripts\Game.js" />
<Content Include="Scripts\jquery-1.10.2.js" />
<Content Include="Scripts\jquery-1.10.2.min.js" />
+ <Content Include="Scripts\jquery.cookie.js" />
<Content Include="Scripts\kinetic-v5.0.1.min.js" />
<Content Include="Scripts\modernizr-2.6.2.js" />
<Content Include="Scripts\respond.js" />
View
15 Jok.Pitching/Jok.Pitching/Resources/Play.Designer.cs
@@ -61,7 +61,7 @@ public class Play {
}
/// <summary>
- /// Looks up a localized string similar to Start Speech.
+ /// Looks up a localized string similar to Play (as Speaker).
/// </summary>
public static string A001 {
get {
@@ -106,7 +106,7 @@ public class Play {
}
/// <summary>
- /// Looks up a localized string similar to Your Score is: .
+ /// Looks up a localized string similar to Your Score: .
/// </summary>
public static string A006 {
get {
@@ -115,12 +115,21 @@ public class Play {
}
/// <summary>
- /// Looks up a localized string similar to .
+ /// Looks up a localized string similar to Highscore:.
/// </summary>
public static string A007 {
get {
return ResourceManager.GetString("A007", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to Top Speakers.
+ /// </summary>
+ public static string A008 {
+ get {
+ return ResourceManager.GetString("A008", resourceCulture);
+ }
+ }
}
}
View
9 Jok.Pitching/Jok.Pitching/Resources/Play.resx
@@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="A001" xml:space="preserve">
- <value>Start Speech</value>
+ <value>Play (as Speaker)</value>
</data>
<data name="A002" xml:space="preserve">
<value>You are winner!</value>
@@ -133,9 +133,12 @@
<value>Game Finished.</value>
</data>
<data name="A006" xml:space="preserve">
- <value>Your Score is: </value>
+ <value>Your Score: </value>
</data>
<data name="A007" xml:space="preserve">
- <value />
+ <value>Highscore:</value>
+ </data>
+ <data name="A008" xml:space="preserve">
+ <value>Top Speakers</value>
</data>
</root>
View
138 Jok.Pitching/Jok.Pitching/Scripts/Game.js
@@ -26,12 +26,42 @@ var Game = {
$(document).on('keydown', this.UIKeyDown);
//$(document).on('click', '#Container', this.UIFire);
- $(document).on('click', '#StartGame', this.UIStartGame);
- $(document).on('click', '#PlayAgain', this.UIPlayAgain);
+ $(document).on('click touchstart', '#StartGame', this.UIStartGame);
+ $(document).on('click touchstart', '#PlayAgain', this.UIPlayAgain);
$(document).on('click', '#Game .volume', this.UIToggleMusic);
+ $(document).on('click touchstart', '#Menu .top_speakers_btn', this.UIShowLeaderboard);
- if (window.DeviceMotionEvent) {
- window.addEventListener('devicemotion', this.deviceMotionHandler, false);
+ window.addEventListener("touchmove", function (event) {
+ if (!event.target.classList.contains('scrollable')) {
+ // no more scrolling
+ event.preventDefault();
+ }
+ }, false);
+
+ if (window.JM) {
+ function onSuccess(acceleration) {
+
+ Game.setUserAvatarByCoef(acceleration.y);
+
+ };
+
+ function onError() {
+ console.log('onError!');
+ };
+
+ var options = { frequency: 100 };
+
+ var watchID = window.JM.accelerometer.watchAcceleration(onSuccess, onError, options);
+ }
+ else {
+ if (window.DeviceMotionEvent) {
+ window.addEventListener('devicemotion', this.deviceMotionHandler, false);
+ }
+ }
+
+
+ if (window.gamecenter) {
+ window.gamecenter.auth();
}
//this.bgAudio = new Audio('/Audio/Lights.mp3');
@@ -84,6 +114,15 @@ var Game = {
this.initAnimation();
},
+ UIShowLeaderboard: function () {
+ if (!window.gamecenter) return;
+
+ var data = {
+ period: "today",
+ leaderboardId: "speakers"
+ };
+ window.gamecenter.showLeaderboard(function () { }, function () { }, data);
+ },
UIKeyDown: function (e) {
@@ -93,16 +132,22 @@ var Game = {
if (left < 160)
return;
- Game.userImg.setPosition({ x: left - 20 });
- //$('#Game .user_avatar').css('left', left - 10);
+ new Kinetic.Tween({
+ node: Game.userImg,
+ duration: 0.02,
+ x: left - 20,
+ }).play();
}
if (e.keyCode == 39) { // right
if (left > 800)
return;
- Game.userImg.setPosition({ x: left + 20 });
- //$('#Game .user_avatar').css('left', left + 10);
+ new Kinetic.Tween({
+ node: Game.userImg,
+ duration: 0.02,
+ x: left + 20,
+ }).play();
}
},
@@ -250,15 +295,22 @@ var Game = {
this.fireTomato2(x, y);
- this.tomatoFireHandler = setTimeout(this.autoFireTomato.bind(this), 500 / tomatosCount + Math.random() * 300);
+ var nextFireInterval = 500 / tomatosCount + Math.random() * 300;
+ if (this.score > 800)
+ nextFireInterval = Math.random() * 200;
+
+ this.tomatoFireHandler = setTimeout(this.autoFireTomato.bind(this), nextFireInterval);
},
finishGame: function (isWinner) {
if (this.isFinished) return;
+ var highscore = this.saveHighScore(this.score);
+
//$('#Menu .finish .results').html(isWinner ? ML.A002 : ML.A003);
- $('#Menu .finish .results').html(ML.A006 + ' ' + this.score);
+ $('#Menu .finish .results span').html(this.score);
+ $('#Menu .finish .highscore span').html(highscore);
$('#Menu .finish').show();
$('#Menu .start').hide();
$('#Menu').show();
@@ -273,6 +325,55 @@ var Game = {
//}
},
+ setUserAvatarByCoef: function (coef) {
+
+ var range = 3;
+
+ var rotateCoef = coef;
+ if (rotateCoef < -1 * range)
+ rotateCoef = -1 * range;
+
+ if (rotateCoef > range)
+ rotateCoef = range;
+
+ rotateCoef += range;
+
+ if (rotateCoef <= 0)
+ rotateCoef = 0.01
+
+
+ var width = 800 - 160;
+ var left = 160 + width * rotateCoef / (range * 2);
+
+
+ //console.log(rotateCoef, width, left);
+
+ new Kinetic.Tween({
+ node: Game.userImg,
+ duration: 0.1,
+ x: left,
+ }).play();
+
+ //Game.userImg.setPosition({ x: left });
+ },
+
+ saveHighScore: function (value) {
+ var highscore = parseInt($.cookie('hightscore'));
+ if (highscore && highscore > value) return highscore;
+
+ $.cookie('hightscore', value, { expire: 100000 });
+
+ if (window.gamecenter) {
+ var data = {
+ score: value,
+ leaderboardId: "speakers"
+ };
+ window.gamecenter.submitScore(function () { }, function () { }, data);
+ }
+
+ return value;
+ },
+
fxSplashPlay: function () {
@@ -425,20 +526,3 @@ var Game = {
Game.init();
-
-if (window.JM) {
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- };
-
- function onError() {
- alert('onError!');
- };
-
- var options = { frequency: 50 };
-
- var watchID = window.JM.accelerometer.watchAcceleration(onSuccess, onError, options);
-}
View
BIN Jok.Pitching/Jok.Pitching/Scripts/_references.js
Binary file not shown.
View
117 Jok.Pitching/Jok.Pitching/Scripts/jquery.cookie.js
@@ -0,0 +1,117 @@
+/*!
+ * jQuery Cookie Plugin v1.4.0
+ * https://github.com/carhartl/jquery-cookie
+ *
+ * Copyright 2013 Klaus Hartl
+ * Released under the MIT license
+ */
+(function (factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as anonymous module.
+ define(['jquery'], factory);
+ } else {
+ // Browser globals.
+ factory(jQuery);
+ }
+}(function ($) {
+
+ var pluses = /\+/g;
+
+ function encode(s) {
+ return config.raw ? s : encodeURIComponent(s);
+ }
+
+ function decode(s) {
+ return config.raw ? s : decodeURIComponent(s);
+ }
+
+ function stringifyCookieValue(value) {
+ return encode(config.json ? JSON.stringify(value) : String(value));
+ }
+
+ function parseCookieValue(s) {
+ if (s.indexOf('"') === 0) {
+ // This is a quoted cookie as according to RFC2068, unescape...
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+ }
+
+ try {
+ // Replace server-side written pluses with spaces.
+ // If we can't decode the cookie, ignore it, it's unusable.
+ s = decodeURIComponent(s.replace(pluses, ' '));
+ } catch(e) {
+ return;
+ }
+
+ try {
+ // If we can't parse the cookie, ignore it, it's unusable.
+ return config.json ? JSON.parse(s) : s;
+ } catch(e) {}
+ }
+
+ function read(s, converter) {
+ var value = config.raw ? s : parseCookieValue(s);
+ return $.isFunction(converter) ? converter(value) : value;
+ }
+
+ var config = $.cookie = function (key, value, options) {
+
+ // Write
+ if (value !== undefined && !$.isFunction(value)) {
+ options = $.extend({}, config.defaults, options);
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
+ }
+
+ return (document.cookie = [
+ encode(key), '=', stringifyCookieValue(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
+ }
+
+ // Read
+
+ var result = key ? undefined : {};
+
+ // To prevent the for loop in the first place assign an empty array
+ // in case there are no cookies at all. Also prevents odd result when
+ // calling $.cookie().
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
+
+ for (var i = 0, l = cookies.length; i < l; i++) {
+ var parts = cookies[i].split('=');
+ var name = decode(parts.shift());
+ var cookie = parts.join('=');
+
+ if (key && key === name) {
+ // If second argument (value) is a function it's a converter...
+ result = read(cookie, value);
+ break;
+ }
+
+ // Prevent storing a cookie that we couldn't decode.
+ if (!key && (cookie = read(cookie)) !== undefined) {
+ result[name] = cookie;
+ }
+ }
+
+ return result;
+ };
+
+ config.defaults = {};
+
+ $.removeCookie = function (key, options) {
+ if ($.cookie(key) !== undefined) {
+ // Must not alter options, thus extending a fresh object...
+ $.cookie(key, '', $.extend({}, options, { expires: -1 }));
+ return true;
+ }
+ return false;
+ };
+
+}));
View
20 Jok.Pitching/Jok.Pitching/Views/Home/Play.cshtml
@@ -7,7 +7,6 @@
var ML = {
A002: '@R.A002',
A003: '@R.A003',
- A006: '@R.A006',
}
var RootUrl = '@System.Configuration.ConfigurationManager.AppSettings["SiteUrl"]';
</script>
@@ -23,12 +22,23 @@
<div id="Menu">
<div class="start">
<img src="@Url.ContentAbsUrl("~/Images/gamejam.png")" /><br /><br />
- <button id="StartGame" class="btn btn-default btn-lg">@R.A001</button>
+ <div>
+ <button id="StartGame" class="btn btn-default btn-lg">@R.A001</button>
+ </div>
+ <div>
+ <button class="top_speakers_btn btn btn-lg btn-danger">@R.A008</button>
+ </div>
</div>
<div class="finish">
- <div class="results"></div>
- <button id="PlayAgain" class="btn btn-default btn-lg">@R.A004</button>
+ <div class="highscore">@R.A007 <span></span></div>
+ <div class="results">@R.A006 <span></span></div>
+ <div>
+ <button id="PlayAgain" class="btn btn-default btn-lg">@R.A004</button>
+ </div>
+ <div>
+ <button class="top_speakers_btn btn btn-lg btn-danger">@R.A008</button>
+ </div>
</div>
</div>
@Scripts.Render("~/bundles/js")
-</div>
+</div>
View
2 Jok.Pitching/Jok.Pitching/Web.config
@@ -35,7 +35,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
- <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
+ <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
View
2 Jok.Pitching/Jok.Pitching/packages.config
@@ -2,7 +2,9 @@
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
+ <package id="FastClick" version="0.6.11" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
+ <package id="jQuery.Cookie" version="1.4.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />

0 comments on commit 856150c

Please sign in to comment.