Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. for (var i = 0; i < walls.coordinates.length; i=i+10 )
  2. {
  3.  
  4.  
  5. //// VANISHING POINT
  6. var vanish_x = canvas.width/2;
  7. var vanish_y = 25;
  8.  
  9.  
  10. //// COLLISIOJN WALL BOX TOP LEFT & TOP RIGHT POINT
  11. var wallleft_x = walls.coordinates[i]-xscrolled;
  12. var wallleft_y = walls.coordinates[i+1]-yscrolled;
  13.  
  14.  
  15. ctx.lineWidth=1; //todo delete later
  16. ctx.beginPath();
  17. ctx.moveTo(vanish_x, vanish_y);
  18. ctx.lineTo(wallleft_x, wallleft_y);
  19. ctx.stroke();
  20.  
  21.  
  22. var wallright_x = walls.coordinates[i]+walls.coordinates[i+2]-xscrolled;
  23. var wallright_y = walls.coordinates[i+1]-yscrolled;
  24.  
  25. var wallleft_x_offset = vanish_x - wallleft_x; // the horizontal distance between vanishing point and lefttop collision wall point
  26. var wallleft_y_offset = vanish_y - wallleft_y; // the vertical distance ...
  27.  
  28. var wallright_x_offset = vanish_x - wallright_x; // the horizontal distance between vanishing point and righttop collision wall point
  29. var wallright_y_offset = vanish_y - wallright_y; // the vertical distance ...
  30.  
  31.  
  32. ctx.strokeStyle="green"; // todo delete later
  33. ctx.lineWidth=1;
  34. ctx.beginPath();
  35. ctx.moveTo(vanish_x, vanish_y);
  36. ctx.lineTo(wallright_x, wallright_y);
  37. ctx.stroke();
  38.  
  39.  
  40.  
  41. //// CLOSER WALLBOX TOP LEFT & TOP RIGHT POINTS
  42.  
  43. var wallleftcloser_x = wallleft_x - wallleft_x_offset*0.1; // top left closer point
  44. var wallleftcloser_y = wallleft_y - wallleft_y_offset*0.1;
  45.  
  46. var wallrightcloser_x = wallright_x - wallright_x_offset*0.1; // top right closer point
  47. var wallrightcloser_y = wallleftcloser_y;
  48.  
  49. ctx.fillStyle="red"; // todo delete later
  50. ctx.fillRect(wallleftcloser_x, wallleftcloser_y, -3,3);
  51. ctx.fillRect(wallrightcloser_x, wallrightcloser_y, 3,3);
  52.  
  53. /////FURTHER WALLBOX TOP LEFT & TOP RIGHT POINTS
  54.  
  55. var wallleftfurther_x = wallleft_x + wallleft_x_offset*0.085; // top left further point
  56. var wallleftfurther_y = wallleft_y + wallleft_y_offset*0.085;
  57.  
  58. var wallrightfurther_x = wallright_x + wallright_x_offset*0.085; // top right further point
  59. var wallrightfurther_y = wallleftfurther_y;
  60.  
  61. ctx.fillStyle="cyan"; // todo delete later
  62. ctx.fillRect(wallleftfurther_x, wallleftfurther_y, -3,3);
  63. ctx.fillRect(wallrightfurther_x, wallrightfurther_y, 3,3);
  64.  
  65. /////DRAW GROUND VIA POLYGON
  66.  
  67. ctx.fillStyle = '#262';
  68. ctx.beginPath();
  69. ctx.moveTo(wallleftfurther_x, wallleftfurther_y);
  70. ctx.lineTo(wallrightfurther_x,wallrightfurther_y);
  71. ctx.lineTo(wallrightcloser_x, wallrightcloser_y);
  72. ctx.lineTo(wallleftcloser_x, wallleftcloser_y);
  73. ctx.closePath();
  74. ctx.fill();
  75.  
  76.  
  77. ////// draw Hero from herobuffer on maincanvas////////
  78.  
  79. ctx.drawImage(herobuffer,hero.x-hero.hitboxSize-xscrolled, hero.y-hero.hitboxSize*2-yscrolled);
  80.  
  81.  
  82. /////DRAW RESIZED WALL from the wall array //x //y //width /height
  83. ctx.drawImage(wall_prerendered_graphics[i*0.1], wallleftcloser_x, wallleftcloser_y, wallrightcloser_x - wallleftcloser_x, wall_prerendered_graphics[(i*0.1)].height);
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement