1. Philipp Tiefenbacher
  2. WebEvoCell

Commits

Philipp Tiefenbacher  committed 92c3baf Draft

added canvas click for copy paste hack

  • Participants
  • Parent commits f8cf4ff
  • Branches default

Comments (0)

Files changed (2)

File src/game/CellSpace.js

View file
  • Ignore whitespace
 	var fpsMonotor = new utils.FPSMonitor("fpsMonitor");
 
 	// Setup core 	
-	var context = document.getElementById('c');
-	var reactor = new  EC.Reactor(context, gameW, gameH);
+	var canvas = document.getElementById('c');
+	var reactor = new  EC.Reactor(canvas, gameW, gameH);
 	reactor.setRenderSize(gameW*zoom, gameH*zoom);
 	var gl = reactor.gl;		
 
 		shipExplosionDish.randomize(shipExplosionRule.nrStates, 0.01);
 
 		var shipX = gameW/2, shipY = gameH/2;
+
+		function handleCanvasMouseDown(evt) {
+			var coords = canvas.relMouseCoords(evt);
+			var x = coords.x;
+			var y = coords.y;
+
+			x /= zoom;
+			y /= zoom;
+			y = gameH-y;
+	
 		
+			reactor.mixDish(copyShader, enemyDish, {
+						destinationPos: [x, y], destinationSize: [bufferDish.width, bufferDish.height],
+						texSource: bufferDish, sourcePos: [0, 0], sourceRes: [bufferDish.width, bufferDish.height], 	
+						}); 		
+			
+
+			evt.preventDefault();
+			evt.stopPropagation();
+		}
+		canvas.addEventListener('mousedown', handleCanvasMouseDown, false);
+
 		var cnt = 0;
 		var gameLoop = new utils.AnimationLoop(function() {
 			// USER INPUT Poll Keyboard //////////////////////////////////////////////////
 					shipX = gameW/2, shipY = gameH/2;
 			}
 
+			if (keyboard.isPressed(65+2))
+			{
+				enemyDish.setAll(0);
+			}
+
 			
 			// copy paste stuff
-			if (keyboard.isPressed(65+2))
+			if (keyboard.isPressed(65+7))
 			{
 				reactor.mixDish(copyShader, bufferDish, {
 					destinationPos: [0, 0], destinationSize: [bufferDish.width, bufferDish.height],

File src/game/Utils.js

View file
  • Ignore whitespace
 define(["jquery", "libs/FileSaver"], function($, saveAs) {
+	function relMouseCoords(event){
+		var totalOffsetX = 0;
+		var totalOffsetY = 0;
+		var canvasX = 0;
+		var canvasY = 0;
+		var currentElement = this;
+
+		do{
+		  totalOffsetX += currentElement.offsetLeft;
+		  totalOffsetY += currentElement.offsetTop;
+		}
+		while(currentElement = currentElement.offsetParent)
+
+		canvasX = event.pageX - totalOffsetX;
+		canvasY = event.pageY - totalOffsetY;
+
+		return {x:canvasX, y:canvasY}
+	}
+	HTMLCanvasElement.prototype.relMouseCoords = relMouseCoords;
+
 	function getFromURL(url, responseType, cb) {
 		var r = new XMLHttpRequest();
 		r.open("GET", url, true);