Permalink
Browse files

fixed serious bug in canvas sizing

  • Loading branch information...
1 parent 1dd0c64 commit af23eab8424c7661a7abe870223174e89a81e71f @erdbeerschnitzel committed Feb 26, 2012
Showing with 37 additions and 13 deletions.
  1. +8 −4 Ball.dart
  2. +3 −1 mc1.dart
  3. +25 −5 mc1.dart.js
  4. +1 −1 mc1.html
  5. +0 −2 style.css
View
@@ -6,12 +6,16 @@ class Ball {
Ball(){
- pos_X = (2 + Math.random()*Math.random()*324324).abs();
- pos_Y = (2 + Math.random()*Math.random()*324324).abs();
+ pos_X = (2 + Math.random()*Math.random()*400).abs();
+ pos_Y = (2 + Math.random()*Math.random()*400).abs();
- while(pos_X > 300) pos_X = 0 + pos_X / 2;
+ while(pos_X > 300) pos_X = (pos_X / 2).toInt();
- while(pos_Y > 140) pos_Y = 0 + pos_Y / 2;
+ while(pos_Y > 300) pos_Y = (pos_Y / 2).toInt();
+
+ if(pos_X < 5) pos_X += 10;
+
+ if(pos_Y < 5) pos_Y += 10;
//while(pos_X > 385) pos_X = pos_X - 50;
//while(pos_Y > 385) pos_Y = pos_Y - 50;
View
@@ -64,7 +64,9 @@ class mc {
}else {
- writeStatus('to the ' + snake.direction + ' --> x: ' + snake.pos_X + ' y: ' + snake.pos_Y);
+ writeStatus(" " + drawingArea.width + " -> " + drawingArea.height);
+ //writeStatus("ball pos: " + ball.pos_X.toInt() + ", " + ball.pos_Y.toInt() + ' to the ' + snake.direction + ' --> x: ' + snake.pos_X + ' y: ' + snake.pos_Y);
+ //writeStatus('to the ' + snake.direction + ' --> x: ' + snake.pos_X + ' y: ' + snake.pos_Y);
}
}
View
@@ -233,6 +233,13 @@ function StackOverflowException() {
StackOverflowException.prototype.toString = function() {
return "Stack Overflow";
}
+// ********** Code for BadNumberFormatException **************
+function BadNumberFormatException(_s) {
+ this._s = _s;
+}
+BadNumberFormatException.prototype.toString = function() {
+ return ("BadNumberFormatException: '" + this._s + "'");
+}
// ********** Code for NullPointerException **************
function NullPointerException() {
@@ -420,6 +427,17 @@ NumImplementation.prototype.abs = function() {
NumImplementation.prototype.hashCode = function() {
'use strict'; return this & 0x1FFFFFFF;
}
+NumImplementation.prototype.toInt = function() {
+
+ 'use strict';
+ if (isNaN(this)) $throw(new BadNumberFormatException("NaN"));
+ if ((this == Infinity) || (this == -Infinity)) {
+ $throw(new BadNumberFormatException("Infinity"));
+ }
+ var truncated = (this < 0) ? Math.ceil(this) : Math.floor(this);
+ if (truncated == -0.0) return 0;
+ return truncated;
+}
// ********** Code for Collections **************
function Collections() {}
Collections.collectionToString = function(c) {
@@ -6458,7 +6476,7 @@ mc.prototype.drawSnake = function() {
html_get$document().get$on().get$keyPress().remove(this.get$onKeyPress(), false);
}
else {
- this.writeStatus($$add($$add($$add("to the ", this.snake.direction), " --> x: ") + this.snake.pos_X, " y: ") + this.snake.pos_Y);
+ this.writeStatus($$add(" " + drawingArea.get$width(), " -> ") + drawingArea.get$height());
}
}
mc.prototype.get$drawSnake = function() {
@@ -6528,10 +6546,12 @@ Snake.prototype.touchesWall = function(canvas) {
// ********** Code for Ball **************
function Ball() {
this.size = (8);
- this.pos_X = ((2) + Math.random() * Math.random() * (324324)).abs();
- this.pos_Y = ((2) + Math.random() * Math.random() * (324324)).abs();
- while (this.pos_X > (300)) this.pos_X = (0) + this.pos_X / (2);
- while (this.pos_Y > (140)) this.pos_Y = (0) + this.pos_Y / (2);
+ this.pos_X = ((2) + Math.random() * Math.random() * (400)).abs();
+ this.pos_Y = ((2) + Math.random() * Math.random() * (400)).abs();
+ while (this.pos_X > (300)) this.pos_X = (this.pos_X / (2)).toInt();
+ while (this.pos_Y > (300)) this.pos_Y = (this.pos_Y / (2)).toInt();
+ if (this.pos_X < (5)) this.pos_X = this.pos_X + (10);
+ if (this.pos_Y < (5)) this.pos_Y = this.pos_Y + (10);
}
// ********** Code for top level **************
function main() {
View
@@ -28,7 +28,7 @@ <h2 id="snake">dart is not running</h2>
</ul>
- <canvas id="drawingArea">canwhat</canvas>
+ <canvas id="drawingArea" width="400" height="400">canwhat</canvas>
</div>
View
@@ -6,6 +6,4 @@ text-align: center;
border-color:black;
border-width:2px;
border-style:solid;
-height:400px;
-width:400px;
}

0 comments on commit af23eab

Please sign in to comment.