Skip to content

Commit

Permalink
First implementation of ScreenDrawer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerike committed Jan 5, 2017
1 parent 0985b1d commit f898da1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions public/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,27 @@ framework.other = {
},
};

framework.drawer = {
secondaryCanvas : undefined,
secondaryCanvasCtx : undefined,
positions : {'CENTER' : 0, 'RIGHT' : 1, 'LEFT' : 2, 'TOP': 3, 'BOTTOM': 4},
setDrawingCanvas : function (canvas){
framework.drawer.secondaryCanvas = canvas;
framework.drawer.secondaryCanvasCtx = canvas.getContext('2d');
},

isSecondaryCanvasSet : function () {
return !framework.drawer.secondaryCanvas === undefined;
},

drawText(text, position){
if(!framework.drawer.isSecondaryCanvasSet())
return;
if (Array.isArray(position))
framework.drawer.secondaryCanvasCtx.fillText(text, position[0], position[1]);
}
};

//Shortcuts
framework.getImageData = framework.maskHandler.getImageData;
framework.createMask = framework.maskHandler.createMask;
Expand Down
4 changes: 4 additions & 0 deletions public/game.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.game_field {
position: relative;
margin: auto;
margin-top: 50px;
width: 800px;
Expand All @@ -8,7 +9,10 @@
}

canvas {
position: absolute;
width: 100%;
height: 100%;
border: 1px solid white;
top: 0;
left: 0;
}
15 changes: 15 additions & 0 deletions public/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,18 @@ function stop() {
function cont() {
pause = false;
}

function startTutorial() { //TODO: extract screen writer into a different class with its own methods
let special_message_canvas = document.getElementById('special_messages');

special_message_canvas.width = canvasWidth;
special_message_canvas.height = canvasHeight;

let special_message_context = special_message_canvas.getContext('2d');
special_message_context.textAlign = 'center';
special_message_context.fillStyle = 'white';
special_message_context.font = '60px Georgia';
special_message_context.textBaseline = 'middle';
special_message_context.fillText('Tutorial level', canvasWidth/2, canvasHeight/2);

}
1 change: 1 addition & 0 deletions resources/views/game.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% block content %}
<link rel="stylesheet" type="text/css" href="game.css">
<div class="game_field">
<canvas id="special_messages"></canvas>
<canvas id="game_canvas"></canvas>
</div>
<script src="/game_classes/Base/Entity.js"></script>
Expand Down

0 comments on commit f898da1

Please sign in to comment.