Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

images added to tiles.html

  • Loading branch information...
commit f4548545ff9d87f172bf9a8774045f149ed92ef5 1 parent 7fc55ed
Allan Callaghan authored April 13, 2012
BIN  teachprogramming/static/projects/images/block.gif
BIN  teachprogramming/static/projects/images/smile.gif
31  teachprogramming/static/projects/tiles.html
@@ -36,15 +36,26 @@
36 36
         variables.grid[2][2] = 1;                                 // VER: blocks not blocks_random
37 37
         variables.grid[3][5] = 1;                                 // VER: blocks not blocks_random
38 38
         variables.grid[4][9] = 1;                                 // VER: blocks not blocks_random
39  
-        for (y=0 ; y<variables.grid.length ; y++){                // VER: blocks_random
40  
-            for (x=0 ; x<variables.grid[y].length; x++) {         // VER: blocks_random
  39
+        for (var y=0 ; y<variables.grid.length ; y++){            // VER: blocks_random
  40
+            for (var x=0 ; x<variables.grid[y].length; x++) {     // VER: blocks_random
41 41
                 if (Math.random()<0.1) {                          // VER: blocks_random
42 42
                     variables.grid[y][x] = 1;                     // VER: blocks_random
43 43
                 }                                                 // VER: blocks_random
44 44
             }                                                     // VER: blocks_random
45 45
         }                                                         // VER: blocks_random
  46
+                                                                  // VER: blocks_random
  47
+        if (variables.images===undefined) {             // VER: images
  48
+            variables.images = {};                      // VER: images
  49
+            function load_image(image_filename) {       // VER: images
  50
+                i = new Image();                        // VER: images
  51
+                i.src = "images/"+image_filename+".gif" // VER: images
  52
+                variables.images[image_filename] = i;   // VER: images
  53
+            }                                           // VER: images
  54
+            load_image("smile");                        // VER: images
  55
+            load_image("block");                        // VER: images
  56
+        }                                               // VER: images
46 57
     }
47  
-
  58
+    
48 59
     function timerEvent() {
49 60
         context.fillStyle = variables.color_background;     
50 61
         context.fillRect(0, 0, canvas.width, canvas.height);
@@ -62,17 +73,19 @@
62 73
                                                                                                                    // VER: limit
63 74
         variables.grid[variables.player_y_pos][variables.player_x_pos] = 0; // VER: eat
64 75
                                                                             // VER: eat
65  
-        for (y=0 ; y<variables.grid.length ; y++){                          // VER: blocks
66  
-            for (x=0 ; x<variables.grid[y].length; x++) {                   // VER: blocks
  76
+        for (var y=0 ; y<variables.grid.length ; y++){                      // VER: blocks
  77
+            for (var x=0 ; x<variables.grid[y].length; x++) {               // VER: blocks
67 78
                 if (variables.grid[y][x]==1) {                              // VER: blocks
68  
-                    context.fillStyle = variables.color_block;              // VER: blocks
69  
-                    context.fillRect(x*variables.block_size, y*variables.block_size, variables.block_size, variables.block_size); // VER: blocks
  79
+                    //context.fillStyle = variables.color_block;              // VER: blocks not images
  80
+                    //context.fillRect(x*variables.block_size, y*variables.block_size, variables.block_size, variables.block_size); // VER: blocks not images
  81
+                    context.drawImage(variables.images.block, x*variables.block_size, y*variables.block_size); // VER: images
70 82
                 }                                                           // VER: blocks
71 83
             }                                                               // VER: blocks
72 84
         }                                                                   // VER: blocks
73 85
                                                                             // VER: blocks
74  
-        context.fillStyle = variables.color_player;                                                                                                              // VER: player
75  
-        context.fillRect(variables.player_x_pos*variables.block_size, variables.player_y_pos*variables.block_size, variables.block_size, variables.block_size);  // VER: player
  86
+        //context.fillStyle = variables.color_player;                                                                                                              // VER: player not images
  87
+        //context.fillRect(variables.player_x_pos*variables.block_size, variables.player_y_pos*variables.block_size, variables.block_size, variables.block_size);  // VER: player not images
  88
+        context.drawImage(variables.images.smile, variables.player_x_pos*variables.block_size, variables.player_y_pos*variables.block_size); // VER: images
76 89
     }
77 90
     
78 91
     reset();
10  teachprogramming/templates/projects/tiles.mako
@@ -8,7 +8,8 @@
8 8
         'blocks_random' :'1,player,blocks,blocks_random',
9 9
         'limit'         :'1,player,blocks,limit',
10 10
         'eat'           :'1,player,blocks,blocks_random,limit,eat',
11  
-        'full'          :'1,player,blocks,blocks_random,limit,eat',
  11
+        'images'        :'1,player,blocks,images',
  12
+        'full'          :'1,player,blocks,blocks_random,limit,eat,images',
12 13
     }
13 14
 %>
14 15
 
@@ -30,8 +31,11 @@ ${self.show_diff(vername['player'],vername['blocks'])}
30 31
 <h3>Blocks Random</h3>
31 32
 ${self.show_diff(vername['blocks'],vername['blocks_random'])}
32 33
 
  34
+<h2>eat</h2>
  35
+${self.show_diff(vername['blocks_random'],vername['eat'])}
  36
+
33 37
 <h2>limit</h2>
34 38
 ${self.show_diff(vername['blocks'],vername['limit'])}
35 39
 
36  
-<h2>eat</h2>
37  
-${self.show_diff(vername['blocks_random'],vername['eat'])}
  40
+<h2>images</h2>
  41
+${self.show_diff(vername['blocks'],vername['images'])}

0 notes on commit f454854

Please sign in to comment.
Something went wrong with that request. Please try again.