Browse Source

Site updated: 2020-03-21 11:51:37

schtonn 5 years ago
parent
commit
29da50d6c9
7 changed files with 140 additions and 19 deletions
  1. 1 1
      css/main.css
  2. 23 4
      games/index.html
  3. BIN
      images/bird.png
  4. BIN
      images/pipe.png
  5. 101 0
      js/bird.js
  6. 1 0
      js/phaser.min.js
  7. 14 14
      lib/pace/README.html

+ 1 - 1
css/main.css

@@ -1235,7 +1235,7 @@ pre .javascript .function {
 }
 .links-of-author a::before,
 .links-of-author span.exturl::before {
-  background: #ff79ac;
+  background: #1bdf25;
   border-radius: 50%;
   content: ' ';
   display: inline-block;

+ 23 - 4
games/index.html

@@ -22,15 +22,15 @@
     var CONFIG = {"hostname":"schtonn.github.io","root":"/","scheme":"Muse","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideLeftIn"}}};
   </script>
 
-  <meta name="description" content="→\rightarrow→To be continued">
+  <meta name="description" content="#game_div, p {       width: 400px;       margin: auto;       margin-top: 20px;     }                      Press the spacebar to jump  →\rightarrow→To be continued">
 <meta property="og:type" content="website">
 <meta property="og:title" content="games">
 <meta property="og:url" content="https://schtonn.github.io/games/index.html">
 <meta property="og:site_name" content="Alex&#39;s Blog">
-<meta property="og:description" content="→\rightarrow→To be continued">
+<meta property="og:description" content="#game_div, p {       width: 400px;       margin: auto;       margin-top: 20px;     }                      Press the spacebar to jump  →\rightarrow→To be continued">
 <meta property="og:locale" content="en_US">
-<meta property="article:published_time" content="2020-03-20T12:07:24.747Z">
-<meta property="article:modified_time" content="2020-03-20T12:07:24.747Z">
+<meta property="article:published_time" content="2020-03-21T03:48:53.626Z">
+<meta property="article:modified_time" content="2020-03-21T03:48:53.626Z">
 <meta property="article:author" content="Alex">
 <meta name="twitter:card" content="summary">
 
@@ -186,6 +186,25 @@
 <object type="application/x-shockwave-flash" style="outline:none;" data="/js/ballclock.swf?" width="600" height="440"><param name="movie" value="/js/ballclock.swf?"></param><param name="AllowScriptAccess" value="always"></param><param name="wmode" value="opaque"></param></object>
 <object type="application/x-shockwave-flash" style="outline:none;" data="/js/dog.swf?3?" width="600" height="440"><param name="movie" value="/js/dog.swf?3?"></param><param name="AllowScriptAccess" value="always"></param><param name="wmode" value="opaque"></param><param name="bgcolor" value="FFFFFF"/></object>
 </p>
+<head>
+  <style>
+    #game_div, p {
+      width: 400px;
+      margin: auto;
+      margin-top: 20px;
+    }
+  </style>
+  <script type="text/javascript" src="/js/phaser.min.js"></script>
+  <script type="text/javascript" src="/js/bird.js"></script>
+</head>
+<body>
+  <div style="text-align:center;clear:both">
+<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
+<script src="/follow.js" type="text/javascript"></script>
+</div>
+  <div id="game_div"> </div>
+<p>Press the spacebar to jump</p>
+</body>
 <p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>→</mo></mrow><annotation encoding="application/x-tex">\rightarrow</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">→</span></span></span></span>To be continued</p>
 
       </div>

BIN
images/bird.png


BIN
images/pipe.png


+ 101 - 0
js/bird.js

@@ -0,0 +1,101 @@
+// Initialize Phaser, and creates a 400x490px game
+var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
+var game_state = {};
+
+// Creates a new 'main' state that will contain the game
+game_state.main = function() { };  
+game_state.main.prototype = {
+
+    // Function called first to load all the assets
+    preload: function() { 
+        // Change the background color of the game
+        this.game.stage.backgroundColor = '#71c5cf';
+
+        // Load the bird sprite
+        this.game.load.image('bird', '/../images/bird.png');
+
+        // Load the pipe sprite
+        this.game.load.image('pipe', '/../images/pipe.png');
+    },
+
+    // Fuction called after 'preload' to setup the game 
+    create: function() { 
+        // Display the bird on the screen
+        this.bird = this.game.add.sprite(100, 245, 'bird');
+        
+        // Add gravity to the bird to make it fall
+        this.bird.body.gravity.y = 1000; 
+
+        // Call the 'jump' function when the spacekey is hit
+        var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
+        space_key.onDown.add(this.jump, this); 
+
+        // Create a group of 20 pipes
+        this.pipes = game.add.group();
+        this.pipes.createMultiple(20, 'pipe');  
+
+        // Timer that calls 'add_row_of_pipes' ever 1.5 seconds
+        this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);           
+
+        // Add a score label on the top left of the screen
+        this.score = 0;
+        var style = { font: "30px Arial", fill: "#ffffff" };
+        this.label_score = this.game.add.text(20, 20, "0", style);  
+    },
+
+    // This function is called 60 times per second
+    update: function() {
+        // If the bird is out of the world (too high or too low), call the 'restart_game' function
+        if (this.bird.inWorld == false)
+            this.restart_game(); 
+
+        // If the bird overlap any pipes, call 'restart_game'
+        this.game.physics.overlap(this.bird, this.pipes, this.restart_game, null, this);      
+    },
+
+    // Make the bird jump 
+    jump: function() {
+        // Add a vertical velocity to the bird
+        this.bird.body.velocity.y = -350;
+    },
+
+    // Restart the game
+    restart_game: function() {
+        // Remove the timer
+        this.game.time.events.remove(this.timer);
+
+        // Start the 'main' state, which restarts the game
+        this.game.state.start('main');
+    },
+
+    // Add a pipe on the screen
+    add_one_pipe: function(x, y) {
+        // Get the first dead pipe of our group
+        var pipe = this.pipes.getFirstDead();
+
+        // Set the new position of the pipe
+        pipe.reset(x, y);
+
+         // Add velocity to the pipe to make it move left
+        pipe.body.velocity.x = -200; 
+               
+        // Kill the pipe when it's no longer visible 
+        pipe.outOfBoundsKill = true;
+    },
+
+    // Add a row of 6 pipes with a hole somewhere in the middle
+    add_row_of_pipes: function() {
+        var hole = Math.floor(Math.random()*5)+1;
+        
+        for (var i = 0; i < 8; i++)
+            if (i != hole && i != hole +1) 
+                this.add_one_pipe(400, i*60+10);   
+    
+        this.score += 1;
+        this.label_score.content = this.score;  
+    },
+};
+
+// Add and start the 'main' state to start the game
+game.state.add('main', game_state.main);  
+game.state.start('main'); 

File diff suppressed because it is too large
+ 1 - 0
js/phaser.min.js


+ 14 - 14
lib/pace/README.html

@@ -3,30 +3,30 @@
 <h2>If you want to use the CDN instead of clone this repo, please jump to the Step 3.</h2>
 <h2 align="center">Step 1 &rarr; Go to NexT dir</h2>
 <p>Change dir to <strong>NexT</strong> directory. There must be <code>layout</code>, <code>source</code>, <code>languages</code> and other directories:</p>
-<pre class="highlight"><code class="sh">$ <span class="built_in">cd</span> themes/next
+<pre class="highlight"><code class="sh">$ <span class="hljs-built_in">cd</span> themes/next
 $ ls
-_config.yml  crowdin.yml  docs  gulpfile.js  languages  layout  LICENSE.md  package.json  README.md  scripts  <span class="built_in">source</span>
+_config.yml  crowdin.yml  docs  gulpfile.js  languages  layout  LICENSE.md  package.json  README.md  scripts  <span class="hljs-built_in">source</span>
 </code></pre>
 <h2 align="center">Step 2 &rarr; Get module</h2>
 <p>Install module to <code>source/lib</code> directory:</p>
-<pre class="highlight"><code class="sh">$ git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-pace <span class="built_in">source</span>/lib/pace
+<pre class="highlight"><code class="sh">$ git <span class="hljs-built_in">clone</span> https://github.com/theme-next/theme-next-pace <span class="hljs-built_in">source</span>/lib/pace
 </code></pre>
 <h2 align="center">Step 3 &rarr; Set it up</h2>
 <p>Enable module in <strong>NexT</strong> <code>_config.yml</code> file and select your theme:</p>
-<pre class="highlight"><code class="yml"><span class="attr">pace:</span>
-  <span class="attr">enable:</span> <span class="literal">true</span>
-  <span class="comment"># Themes list:</span>
-  <span class="comment"># big-counter | bounce | barber-shop | center-atom | center-circle | center-radar | center-simple</span>
-  <span class="comment"># corner-indicator | fill-left | flat-top | flash | loading-bar | mac-osx | material | minimal</span>
-  <span class="attr">theme:</span> <span class="string">minimal</span>
+<pre class="highlight"><code class="yml"><span class="hljs-attr">pace:</span>
+  <span class="hljs-attr">enable:</span> <span class="hljs-literal">true</span>
+  <span class="hljs-comment"># Themes list:</span>
+  <span class="hljs-comment"># big-counter | bounce | barber-shop | center-atom | center-circle | center-radar | center-simple</span>
+  <span class="hljs-comment"># corner-indicator | fill-left | flat-top | flash | loading-bar | mac-osx | material | minimal</span>
+  <span class="hljs-attr">theme:</span> <span class="hljs-string">minimal</span>
 </code></pre>
 <p><strong>And, if you wants to use the CDN, then need to set:</strong> (you also need to find your corresponding theme css link in <a href="https://www.jsdelivr.com/package/npm/pace-js?path=themes" target="_blank" rel="noopener">jsdelivr</a>)</p>
-<pre class="highlight"><code class="yml"><span class="attr">vendors:</span>
-  <span class="string">...</span>
-  <span class="attr">pace:</span> <span class="string">//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js</span>
-  <span class="attr">pace_css:</span> <span class="string">//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css</span>
+<pre class="highlight"><code class="yml"><span class="hljs-attr">vendors:</span>
+  <span class="hljs-string">...</span>
+  <span class="hljs-attr">pace:</span> <span class="hljs-string">//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js</span>
+  <span class="hljs-attr">pace_css:</span> <span class="hljs-string">//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css</span>
 </code></pre>
 <h1 align="center">Update</h1>
-<pre class="highlight"><code class="sh">$ <span class="built_in">cd</span> themes/next/<span class="built_in">source</span>/lib/pace
+<pre class="highlight"><code class="sh">$ <span class="hljs-built_in">cd</span> themes/next/<span class="hljs-built_in">source</span>/lib/pace
 $ git pull
 </code></pre>

Some files were not shown because too many files changed in this diff