1. Pedro Ferreira
  2. tower_defense

Commits

Pedro Ferreira  committed 2d90f34

- add create_release script (for the website)
- add loading message (when loading the images with preloadjs)
- fix, use BASE_URL instead of G.BASE_URL (for the script to work)
- fix, update the .tick_attack() from the anti-air and bash tower (forgot to update when changed the game to use the delta time)

  • Participants
  • Parent commits d3b71e3
  • Branches default
  • Tags v1.0.0

Comments (0)

Files changed (8)

File create_release/copy_files_config.txt

View file
  • Ignore whitespace
+{
+    "resultingFolder": "tower_defense",
+    "basePath": "..",
+    "files":
+        [
+            "css/",
+            "images/",
+            "libraries/",
+            "maps/",
+            "manifest.json"
+        ]
+}

File create_release/create_server_template.py

View file
  • Ignore whitespace
+# python3
+
+import os.path
+import argparse
+import sys
+
+sys.path.append( 'C:/Users/drk/Dropbox/projects/' )
+
+
+import create_release_script.create_server_template as create_server_template
+
+
+    # relative paths
+default_indexPath = '../index.html'
+default_appName = 'tower_defense'
+default_copyToPath = 'C:/Users/drk/Dropbox/projects/website/templates/{}/'.format( default_appName )
+
+
+def go( indexPath= default_indexPath,
+        appName= default_appName,
+        copyToPath= default_copyToPath,
+        templateName= None ):
+
+    indexPath = os.path.realpath( indexPath )
+    copyToPath = os.path.realpath( copyToPath )
+
+    create_server_template.go( indexPath, appName, copyToPath, templateName )
+
+
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser( description= 'Create the server template.' )
+
+    parser.add_argument( 'indexPath', nargs= '?', default= default_indexPath )
+    parser.add_argument( 'appName', nargs= '?', default= default_appName )
+    parser.add_argument( 'copyToPath', nargs= '?', default= default_copyToPath )
+
+    args = parser.parse_args()
+
+    go( args.indexPath, args.appName, args.copyToPath )

File create_release/main.py

View file
  • Ignore whitespace
+# python3
+
+import argparse
+import sys
+import os.path
+
+sys.path.append( 'C:/Users/drk/Dropbox/projects/' )
+
+import create_release_script.main as main
+
+
+    # relative paths
+default_htmlFile = "../index.html"
+default_concatenateConfig = "concatenate_config.txt"
+default_copyFilesConfig = "copy_files_config.txt"
+default_resultingFolder = "tower_defense"
+
+
+def go( htmlFile= default_htmlFile,
+        copyFilesConfig= default_copyFilesConfig,
+        concatenateConfig= default_concatenateConfig,
+        resultingFolder= default_resultingFolder ):
+
+        # absolute paths
+    htmlFile = os.path.realpath( htmlFile )
+    copyFilesConfig = os.path.realpath( copyFilesConfig )
+    concatenateConfig = os.path.realpath( concatenateConfig )
+    resultingFolder = os.path.realpath( resultingFolder )
+
+    baseDirectory = os.path.realpath( '' )
+
+
+    main.go( htmlFile, copyFilesConfig, concatenateConfig, resultingFolder, baseDirectory )
+
+
+    
+
+if __name__ == '__main__':    
+
+    parser = argparse.ArgumentParser( description= 'Generate the release files of the program.' )
+
+    parser.add_argument( 'htmlFile', help= 'Path to the index.html.', nargs= '?', default= default_htmlFile )
+    parser.add_argument( 'copyFilesConfig', help= 'Path to the configuration file that tells which files to copy.', nargs= '?', default= default_copyFilesConfig )
+    parser.add_argument( 'concatenateConfig', help= 'Path to the configuration file to tell which files to concatenate (and the order).', nargs= '?', default= default_concatenateConfig )
+    parser.add_argument( 'resultingFolder', help= "Name of the folder that is created in the current path and contains the copies.", nargs= "?", default= default_resultingFolder )
+
+
+    args = parser.parse_args()
+
+    go( args.htmlFile, args.copyFilesConfig, args.concatenateConfig, args.resultingFolder )

File css/style.css

View file
  • Ignore whitespace
 
     /* Main Menu */
 
+#LoadMessage
+    {
+    position: fixed;
+    text-align: center;
+    }
+
 #MainMenu, #HighScore
     {
     display: none;

File index.html

View file
  • Ignore whitespace
     <script type="text/javascript" src="libraries/preloadjs-0.4.1.min.js"></script>
     <script type="text/javascript" src="libraries/astar.js"></script>
 
-
+    <!-- CONCATENATE_START -->
     <script type="text/javascript" src="scripts/utilities.js"></script>
     <script type="text/javascript" src="scripts/bullet.js"></script>
     <script type="text/javascript" src="scripts/tower.js"></script>
     <script type="text/javascript" src="scripts/high_score.js"></script>
     <script type="text/javascript" src="scripts/map.js"></script>
     <script type="text/javascript" src="scripts/main.js"></script>
+    <!-- CONCATENATE_END -->
 
     <link rel="stylesheet" href="css/style.css" />
 </head>
         <div id="Message"></div>
     </div>
 
+    <div id="LoadMessage"></div>
+
 </body>
 </html>

File scripts/main.js

View file
  • Ignore whitespace
     CANVAS: null,
     STAGE: null,
     PRELOAD: null,
-    BASE_URL: '',
     FPS: 20,
     GAME_MENU_HEIGHT: 100
 };
 
+var BASE_URL = '';
+
 
 window.onload = function()
 {
 G.PRELOAD = new createjs.LoadQueue();
 
 var manifest = [
-        { id: 'easy', src: G.BASE_URL + 'maps/easy.json' },
-        { id: 'medium', src: G.BASE_URL + 'maps/medium.json' },
-        { id: 'hard', src: G.BASE_URL + 'maps/hard.json' },
-        { id: 'creep', src: G.BASE_URL + 'images/creep.png' },
-        { id: 'creep_slow', src: G.BASE_URL + 'images/creep_slow.png' },
-        { id: 'creep_group', src: G.BASE_URL + 'images/creep_group.png' },
-        { id: 'creep_fast', src: G.BASE_URL + 'images/creep_fast.png' },
-        { id: 'creep_fast_slow', src: G.BASE_URL + 'images/creep_fast_slow.png' },
-        { id: 'creep_fly', src: G.BASE_URL + 'images/creep_fly.png' },
-        { id: 'creep_fly_slow', src: G.BASE_URL + 'images/creep_fly_slow.png' },
-        { id: 'creep_spawn', src: G.BASE_URL + 'images/creep_spawn.png' },
-        { id: 'creep_spawn_slow', src: G.BASE_URL + 'images/creep_spawn_slow.png' },
-        { id: 'creep_spawned', src: G.BASE_URL + 'images/creep_spawned.png' },
-        { id: 'creep_spawned_slow', src: G.BASE_URL + 'images/creep_spawned_slow.png' },
-        { id: 'creep_immune', src: G.BASE_URL + 'images/creep_immune.png' },
-        { id: 'tower_base0', src: G.BASE_URL + 'images/tower_base0.png' },
-        { id: 'tower_base1', src: G.BASE_URL + 'images/tower_base1.png' },
-        { id: 'tower_base2', src: G.BASE_URL + 'images/tower_base2.png' },
-        { id: 'tower_basic', src: G.BASE_URL + 'images/tower_basic.png' },
-        { id: 'tower_fast', src: G.BASE_URL + 'images/tower_fast.png' },
-        { id: 'tower_rocket', src: G.BASE_URL + 'images/tower_rocket.png' },
-        { id: 'tower_frost', src: G.BASE_URL + 'images/tower_frost.png' },
-        { id: 'tower_anti_air', src: G.BASE_URL + 'images/tower_anti_air.png' },
-        { id: 'tower_bash', src: G.BASE_URL + 'images/tower_bash.png' },
-        { id: 'tower_bash_attack', src: G.BASE_URL + 'images/tower_bash_attack.png' },
-        { id: 'bullet', src: G.BASE_URL + 'images/bullet.png' },
-        { id: 'highlight', src: G.BASE_URL + 'images/highlight.png' },
-        { id: 'highlight_not_available', src: G.BASE_URL + 'images/highlight_not_available.png' }
+        { id: 'easy', src: BASE_URL + 'maps/easy.json' },
+        { id: 'medium', src: BASE_URL + 'maps/medium.json' },
+        { id: 'hard', src: BASE_URL + 'maps/hard.json' },
+        { id: 'creep', src: BASE_URL + 'images/creep.png' },
+        { id: 'creep_slow', src: BASE_URL + 'images/creep_slow.png' },
+        { id: 'creep_group', src: BASE_URL + 'images/creep_group.png' },
+        { id: 'creep_fast', src: BASE_URL + 'images/creep_fast.png' },
+        { id: 'creep_fast_slow', src: BASE_URL + 'images/creep_fast_slow.png' },
+        { id: 'creep_fly', src: BASE_URL + 'images/creep_fly.png' },
+        { id: 'creep_fly_slow', src: BASE_URL + 'images/creep_fly_slow.png' },
+        { id: 'creep_spawn', src: BASE_URL + 'images/creep_spawn.png' },
+        { id: 'creep_spawn_slow', src: BASE_URL + 'images/creep_spawn_slow.png' },
+        { id: 'creep_spawned', src: BASE_URL + 'images/creep_spawned.png' },
+        { id: 'creep_spawned_slow', src: BASE_URL + 'images/creep_spawned_slow.png' },
+        { id: 'creep_immune', src: BASE_URL + 'images/creep_immune.png' },
+        { id: 'tower_base0', src: BASE_URL + 'images/tower_base0.png' },
+        { id: 'tower_base1', src: BASE_URL + 'images/tower_base1.png' },
+        { id: 'tower_base2', src: BASE_URL + 'images/tower_base2.png' },
+        { id: 'tower_basic', src: BASE_URL + 'images/tower_basic.png' },
+        { id: 'tower_fast', src: BASE_URL + 'images/tower_fast.png' },
+        { id: 'tower_rocket', src: BASE_URL + 'images/tower_rocket.png' },
+        { id: 'tower_frost', src: BASE_URL + 'images/tower_frost.png' },
+        { id: 'tower_anti_air', src: BASE_URL + 'images/tower_anti_air.png' },
+        { id: 'tower_bash', src: BASE_URL + 'images/tower_bash.png' },
+        { id: 'tower_bash_attack', src: BASE_URL + 'images/tower_bash_attack.png' },
+        { id: 'bullet', src: BASE_URL + 'images/bullet.png' },
+        { id: 'highlight', src: BASE_URL + 'images/highlight.png' },
+        { id: 'highlight_not_available', src: BASE_URL + 'images/highlight_not_available.png' }
     ];
 
+var loadMessage = document.querySelector( '#LoadMessage' );
+
+var left = $( window ).width() / 2;
+var top = $( window ).height() / 2;
+
+$( loadMessage ).css( 'top', top + 'px' );
+$( loadMessage ).css( 'left', left + 'px' );
+
 G.PRELOAD.addEventListener( 'progress', function( event )
     {
-        // "Loading " + ( event.progress*100 | 0 ) + "%"
+    $( loadMessage ).text( (event.progress * 100 | 0) + '%' );
     });
-G.PRELOAD.addEventListener( 'complete', MainMenu.open );
+G.PRELOAD.addEventListener( 'complete', function()
+    {
+    $( loadMessage ).css( 'display', 'none' );
+
+    MainMenu.open();
+    });
 G.PRELOAD.loadManifest( manifest, true );
 };

File scripts/tower_anti_air.js

View file
  • Ignore whitespace
 
 
 
-TowerAntiAir.prototype.tick_attack = function()
+TowerAntiAir.prototype.tick_attack = function( deltaTime )
 {
-if ( this.damage > 0 )
+this.attack_count -= deltaTime;
+
+    // see if we can attack right now
+if ( this.attack_count <= 0 )
     {
-        // see if we can attack right now
-    if ( this.attack_count <= 0 )
+    this.getTargets();
+
+    var targets = this.targets;
+
+        // check if its currently attacking a unit
+    if ( this.targets.length > 0 )
         {
-        this.getTargets();
+        this.rotateTower( targets[ 0 ] );
+        var x = this.getX();
+        var y = this.getY();
+        var radius = this.range;
 
-        var targets = this.targets;
+        for (var a = 0 ; a < this.targets.length ; a++)
+            {
+            var target = this.targets[ a ];
 
-            // check if its currently attacking a unit
-        if ( this.targets.length > 0 )
-            {
-            this.rotateTower( targets[ 0 ] );
-            var x = this.getX();
-            var y = this.getY();
-            var radius = this.range;
+            if ( target.removed )
+                {
+                this.targets.splice( a, 1 );
+                a--;
+                }
 
-            for (var a = 0 ; a < this.targets.length ; a++)
+            else
                 {
-                var target = this.targets[ a ];
+                    // check if the unit is within the tower's range
+                if ( circleCircleCollision( x, y, radius, target.getX(), target.getY(), target.width / 2 ) )
+                    {
+                    this.attack_count = this.attack_interval;
+                    new Bullet({
+                            shooter: this,
+                            target: target
+                        });
+                    }
 
-                if ( target.removed )
+                    // can't attack anymore, find other target
+                else
                     {
                     this.targets.splice( a, 1 );
                     a--;
                     }
-
-                else
-                    {
-                        // check if the unit is within the tower's range
-                    if ( circleCircleCollision( x, y, radius, target.getX(), target.getY(), target.width / 2 ) )
-                        {
-                        this.attack_count = this.attack_limit;
-                        new Bullet({
-                                shooter: this,
-                                target: target
-                            });
-                        }
-
-                        // can't attack anymore, find other target
-                    else
-                        {
-                        this.targets.splice( a, 1 );
-                        a--;
-                        }
-                    }
                 }
             }
         }
-
-        // we need to wait a bit
-    else
-        {
-        this.attack_count--;
-        }
     }
 };
 

File scripts/tower_bash.js

View file
  • Ignore whitespace
 Tower.call( this, args );
 
     // have the attack animation depend on the attack speed
-this.attack_animation_limit = parseInt( this.attack_limit / 4, 10 );
-this.attack_animation_alpha_step = 1 / this.attack_animation_limit;
+this.attack_animation_interval = parseInt( this.attack_interval / 4, 10 );
+this.attack_animation_alpha_step = 1 / this.attack_animation_interval;
 }
 
 INHERIT_PROTOTYPE( TowerBash, Tower );
 Tower.prototype.upgrade.call( this );
 
     // the attack speed may have changed in the upgrade, so need to update this as well
-this.attack_animation_limit = parseInt( this.attack_limit / 4, 10 );
+this.attack_animation_interval = parseInt( this.attack_limit / 4, 10 );
 
 var scale = (this.width + this.range) / this.attack_animation_length; // scale the image according to the tower's range
 
 };
 
 
-TowerBash.prototype.tick_attack = function()
+TowerBash.prototype.tick_attack = function( deltaTime )
 {
-if ( this.damage > 0 )
+this.attack_count -= deltaTime;
+
+
+if ( this.attack_count <= this.attack_animation_interval )
     {
-    if ( this.attack_count <= this.attack_animation_limit )
+    this.attack_animation.visible = false;
+    }
+
+else
+    {
+    this.attack_animation.alpha -= this.attack_animation_alpha_step;
+    }
+
+    // see if we can attack right now
+if ( this.attack_count <= 0 )
+    {
+    var target = this.targetUnit;
+
+        // check if its currently attacking a unit
+    if ( target && !target.removed )
         {
-        this.attack_animation.visible = false;
-        }
+        this.rotateTower( target );
 
-    else
-        {
-        this.attack_animation.alpha -= this.attack_animation_alpha_step;
-        }
 
-        // see if we can attack right now
-    if ( this.attack_count <= 0 )
-        {
-        var target = this.targetUnit;
+            // check if the unit is within the tower's range
+        if ( circleCircleCollision( this.getX(), this.getY(), this.range, target.getX(), target.getY(), target.width / 2 ) )
+            {
+            this.attack_count = this.attack_interval;
+            this.attack_animation.visible = true;
+            this.attack_animation.alpha = 1;
 
-            // check if its currently attacking a unit
-        if ( target )
-            {
-            this.rotateTower( target );
-
-
-                // check if the unit is within the tower's range
-            if ( circleCircleCollision( this.getX(), this.getY(), this.range, target.getX(), target.getY(), target.width / 2 ) )
-                {
-                this.attack_count = this.attack_limit;
-                this.attack_animation.visible = true;
-                this.attack_animation.alpha = 1;
-
-                this.attack();
-                }
-
-                // can't attack anymore, find other target
-            else
-                {
-                this.targetUnit = null;
-                }
+            this.attack();
             }
 
-            // find a target
+            // can't attack anymore, find other target
         else
             {
-            this.targetUnit = Map.getUnitInRange( this );
+            this.targetUnit = null;
             }
         }
 
-        // we need to wait a bit
+        // find a target
     else
         {
-        this.attack_count--;
+        this.targetUnit = Map.getUnitInRange( this );
         }
     }
 };