Permalink
Browse files

the word is alive!

  • Loading branch information...
1 parent 2d9e5eb commit dec597d433dfb87809f08ef9cf9590872e4b72ac @pedronveloso committed May 5, 2012
Showing with 59 additions and 17 deletions.
  1. BIN banana.png
  2. +57 −15 dart/MainGameScreen.dart
  3. +2 −2 main_game_screen.html
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -2,8 +2,6 @@
//program starts here
main() {
- document.body.nodes.add(new Element.html('<div>"hello"</div>'));
- document.query('#status').innerHTML = "chegou aqui 1";
new MainGameScreen().Init();
}
@@ -12,36 +10,80 @@ class MainGameScreen {
//initialize the canvas we'll be drawing on
Init(){
- document.query('#status').innerHTML = "chegou aqui 2";
CanvasElement canvas = document.query("#canvas");
ctx = canvas.getContext("2d");
- drawFrame();
+ window.setInterval(f() => drawFrame(), 20);
+ word_x = 512;
+ word_y = 10;
+
+ player1Won = true;
+ isStopped = false;
+
}
// draws a single frame of the game
void drawFrame() {
document.query('#status').innerHTML = "chegou aqui 3";
- ctx.beginPath();
ctx.clearRect(0, 0, 1024, 400);
- ctx.setLineWidth(2);
- ctx.setFillColor(BACKGROUND_COLOR);
- ctx.setStrokeColor(BACKGROUND_COLOR);
- ctx.fill();
-
- ctx.closePath();
-
+ ctx.setLineWidth(1);
+
+ drawWord(word_x, word_y, "banana");
//draw line just to know it's working for now
+ /*ctx.setStrokeColor(BACKGROUND_COLOR);
ctx.moveTo(0, 0);
ctx.lineTo(500, 400);
- ctx.stroke();
+ ctx.closePath();
+ ctx.stroke();*/
+ if (!isStopped){
+ if (word_y>(SCREEN_LIMIT+10))
+ word_y=5;
+ word_y++;
+ }
}
// draws a banana at X,Y and with a given text
- void drawBanana(num x, num y, String text){
- //ctx.drawImage(canvas_OR_image_OR_video, sx_OR_x, sy_OR_y);
+ void drawWord(num x, num y, String text){
+ document.query('#status').innerHTML = "chegou aqui 4";
+ ctx.setStrokeColor(NORMAL_TEXT_COLOR);
+ ctx.font = "20pt Arial";
+ ctx.strokeText(text, x, y);
+ ctx.setFillColor(PLAYER1_TEXT_COLOR);
+ ctx.fill();
+ document.query('#status').innerHTML = "chegou aqui 5";
+ }
+
+ /**
+ * Call this to set that a player won
+ **/
+ void playerWon(int playerNumber){
+ isStopped=true;
+ if (playerNumber==1)
+ {
+ player1Won = true;
+ }
+ else{
+ player1Won = false;
+ }
+ }
+
+ /**
+ * Starts a new Round with a given word
+ **/
+ void startNewRound(String word){
+ isStopped=false;
}
//variables here
CanvasRenderingContext2D ctx;
static final String BACKGROUND_COLOR = "orange";
+ static final String NORMAL_TEXT_COLOR = "black";
+ static final String PLAYER1_TEXT_COLOR = "blue";
+ static final String PLAYER2_TEXT_COLOR = "red";
+
+ int word_x, word_y;
+ final int SCREEN_LIMIT = 400;
+
+ bool isStopped; // defines that word animation is stopped
+ bool drawNow;
+ bool player1Won;
}
View
@@ -5,7 +5,7 @@
<title>typo attack!</title>
</head>
<body>
- <h1>TYPO ATTACK</h1>
+ <h1 id="status">TYPO ATTACK</h1>
<br/>
<br>
<br>
@@ -21,7 +21,7 @@
</div>
<button type="button">start</button>
<div>
- <canvas id="canvas" width="1024" height="400" style="display:none"></canvas>
+ <canvas id="canvas" width="1024" height="400" style="display:inline"></canvas>
</div>
<script type="application/dart" src="./dart/MainGameScreen.dart"></script>
<script src="../dart.js"></script>

0 comments on commit dec597d

Please sign in to comment.