Difference between revisions of "Blocks"

From CodeStuff
Jump to: navigation, search
(Created page with "file:PlanetCute_Water_Block.png <edcode> var water = loadImage("PlanetCute_Water_Block.png"); function move() { } function draw() { for (var ty = 0; ty<10; ty++)...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
This is a simple demo using just three images.
 +
 
[[file:PlanetCute_Water_Block.png]]
 
[[file:PlanetCute_Water_Block.png]]
 +
[[file:PlanetCute_Wall_Block_Tall.png]]
 +
[[file:PlanetCute_Character_Pink_Girl.png]]
  
 +
<edcode>var map = [    ["_","_","_","_","_","_","_"],
 +
              ["_","_","_","_","_","_","_"],
 +
              ["_","_","H","H","_","_","_"],
 +
              ["_","_","_","_","_","_","_"],
 +
              ["_","_","_","_","H","_","_"],
 +
              ["_","_","_","_","_","_","_"]    ];
  
<edcode>
 
 
var water = loadImage("PlanetCute_Water_Block.png");
 
var water = loadImage("PlanetCute_Water_Block.png");
 +
var block = loadImage("PlanetCute_Wall_Block_Tall.png");
 +
var character = loadImage("PlanetCute Character Pink Girl.png");
 +
 
 +
var tiles = {"_": water, "H":block};
 +
 
 +
var px=100;
 +
var py=100;
  
 
function move() {
 
function move() {
 +
  if (keyIsDown(38)) py-=2;
 +
  if (keyIsDown(40)) py+=2;
  
 +
  if (keyIsDown(37)) px-=2;
 +
  if (keyIsDown(39)) px+=2;
 
}
 
}
  
function draw() {
+
function draw() {
 
+
   for (var ty = 0; ty<6; ty++){
   for (var ty = 0; ty<10; ty++){
+
     for (var tx = 0; tx<7; tx++){
     for (var tx = 0; ty<10; ty++){
+
         drawImage(tiles[map[ty][tx]],tx*100,ty*80-50);
         drawImage(water,tx*100,ty*100);
+
 
     }  
 
     }  
 
   }
 
   }
 +
  drawImage(character,px,py); 
 
}
 
}
  
 
run(move,draw);
 
run(move,draw);
 
 
</edcode>
 
</edcode>

Latest revision as of 11:18, 27 January 2012

This is a simple demo using just three images.

PlanetCute Water Block.png PlanetCute Wall Block Tall.png PlanetCute Character Pink Girl.png