Commits

Philipp Tiefenbacher  committed f774be5 Draft

drawing ship as circle now

  • Participants
  • Parent commits 930bc07

Comments (0)

Files changed (2)

File src/game/CellSpace.js

 
 	loader.load("clear", "src/game/shaders/clear.shader", "text");
 	loader.load("mixPalette", "src/game/shaders/mixPalette.shader", "text");
+
 	loader.load("drawRect", "src/game/shaders/drawRect.shader", "text");
+	loader.load("drawCircle", "src/game/shaders/drawCircle.shader", "text");
+
 	loader.load("painter", "src/game/shaders/primitiveRenderer.shader", "text");
 	loader.load("intersectSpawn", "src/game/shaders/intersectSpawn.shader", "text");
 
 
 		var clearShader = reactor.compileShader(data.clear);
 		var paintShader = reactor.compileShader(data.painter);
+
 		var drawRectShader = reactor.compileShader(data.drawRect);
+		var drawCircleShader = reactor.compileShader(data.drawCircle);
+
 		var mixShader = reactor.compileShader(data.mixPalette);
 		var intersectSpawnShader = reactor.compileShader(data.intersectSpawn);
 		var copyShader = reactor.compileShader(data.copyPaste);
 		var gameLoop = new utils.AnimationLoop(function() {
 			
 			// USER INPUT Poll Keyboard //////////////////////////////////////////////////
-			var stepSize = 2;
+			var stepSize = 1.5;
 			if (keyboard.isPressed(keyboard.UP)) shipY += stepSize;
 			if (keyboard.isPressed(keyboard.DOWN)) shipY -= stepSize;
 			if (keyboard.isPressed(keyboard.LEFT)) shipX -= stepSize;
 			reactor.step(shipRule, shipDish);
 
 			// "DRAW" SHIP
-			reactor.mixDish(drawRectShader, shipDish, {rectPos: [shipX+1, shipY+1], rectSize: [6, 6], state: (shipRule.nrStates-1)/255});
+			//reactor.mixDish(drawRectShader, shipDish, {rectPos: [shipX, shipY], rectSize: [6, 6], state: (shipRule.nrStates-1)/255});
+			reactor.mixDish(drawCircleShader, shipDish, {center: [shipX, shipY], radius: 3.5, state: (shipRule.nrStates-1)/255});
 			//reactor.mixDish(drawRectShader, enemyDish, {rectPos: [shipX+1, shipY+1], rectSize: [3, 3], state: 0});
 
 			// Dish INTERACTION ///////////////////////////////////

File src/game/shaders/drawCircle.shader

+#ifdef GL_ES
+	precision highp float;
+#endif
+
+uniform sampler2D texFrame;
+
+uniform vec2 center;
+uniform float radius;
+uniform float state;
+
+varying vec2 vTexCoord;
+void main(void) {
+	vec4 color = texture2D(texFrame, vTexCoord);
+	
+	float dx = center.x - gl_FragCoord.x;
+	float dy = center.y - gl_FragCoord.y;
+	float d = sqrt(dx*dx + dy*dy);
+
+	if (d < radius)
+	{
+		gl_FragColor = vec4(0., 0., 0., state);
+	}
+	else
+	{
+		gl_FragColor = color;
+	}
+}