Commit 657b4305 authored by Terence Martin's avatar Terence Martin
Browse files

Merge branch 'dev'

parents 1f4f3fdf 934f560b
.idea/workspace.xml
*.sublime-workspace
upload
......@@ -39,6 +39,9 @@
<li>
<a data-target="#controlsModal" data-toggle="modal" href="#controlsModal">Controls</a>
</li>
<li>
<a href="https://gitlab.com/OdatNurd/ts-game-engine">Source Code</a>
</li>
<li>
<button id="controlBtn" class="btn navbar-btn btn-default">Stop Game</button>
</li>
......@@ -47,13 +50,14 @@
<!--/.nav-collapse -->
</div>
</nav>
<div id="gameContent" class="container">
<div class="container-fluid">
<div id="gameContent"></div>
</div>
<footer class="footer" data-pg-collapsed>
<div class="navbar navbar-default navbar-fixed-bottom" data-pg-collapsed>
<div class="container">
<p class="text-muted">Collision Test Copyright&copy; 2016 Terence Martin</p>
</div>
</footer>
</div>
<div class="modal fade pg-show-modal" id="helpAbout" tabindex="-1" role="dialog" aria-hidden="true"
data-pg-collapsed>
<div class="modal-dialog">
......@@ -93,6 +97,8 @@
</div>
<div class="modal-body">
<dl>
<dt>F</dt>
<dd>Toggle fullscreen mode on the canvas (if supported by the browser)</dd>
<dt>P</dt>
<dd>Change collision type to 'POINT'</dd>
<dt>R</dt>
......@@ -114,7 +120,7 @@
<script src="bootstrap/assets/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script>
<script src="js/engine-0.3.0.js"></script>
<script src="js/engine-0.3.1.js"></script>
<script src="js/collide-test.js"></script>
</body>
</html>
......@@ -11,6 +11,7 @@ html
body
{
margin-top: 50px;
margin-bottom: 60px;
}
......@@ -44,6 +45,14 @@ body > .container
padding-left: 15px;
}
#gameContent
{
/* The native top left corner should be the center of the viewport. */
position: absolute;
left: 50%;
top: 50%;
}
code
{
font-size: 80%;
......
......@@ -50,13 +50,14 @@
<!--/.nav-collapse -->
</div>
</nav>
<div id="gameContent" class="container">
<div class="container-fluid">
<div id="gameContent"></div>
</div>
<footer class="footer" data-pg-collapsed>
<div class="navbar navbar-default navbar-fixed-bottom" data-pg-collapsed>
<div class="container">
<p class="text-muted">SomethingOrOther Copyright&copy; 2016 Terence Martin</p>
</div>
</footer>
</div>
<div class="modal fade pg-show-modal" id="helpAbout" tabindex="-1" role="dialog" aria-hidden="true"
data-pg-collapsed>
<div class="modal-dialog">
......@@ -90,6 +91,8 @@
</div>
<div class="modal-body">
<dl>
<dt>F</dt>
<dd>Toggle fullscreen mode on the canvas (if supported by the browser)</dd>
<dt>M</dt>
<dd>Toggle the mute state of the music</dd>
<dt>S</dt>
......@@ -108,7 +111,7 @@
<script src="bootstrap/assets/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/assets/js/ie10-viewport-bug-workaround.js"></script>
<script src="js/engine-0.3.0.js"></script>
<script src="js/engine-0.3.1.js"></script>
<script src="js/game.js"></script>
</body>
</html>
......@@ -363,6 +363,10 @@ var nurdz;
this._mode = CollisionTestType.RECTANGLE;
this._currentCollider = this._rect;
return !eventObj.ctrlKey;
// For the F key, toggle between full screen mode and windowed mode.
case KeyCodes.KEY_F:
this._stage.toggleFullscreen();
return true;
}
// Let the default happen
return _super.prototype.inputKeyDown.call(this, eventObj);
......@@ -373,7 +377,7 @@ var nurdz;
nurdz.contentLoaded(window, function () {
try {
// Set up the stage.
var stage = new nurdz.game.Stage('gameContent');
var stage = new nurdz.game.Stage('gameContent', 'black', true, '#a0a0a0');
// Set up the default values used for creating a screen shot.
nurdz.game.Stage.screenshotFilenameBase = "screenshot";
nurdz.game.Stage.screenshotWindowTitle = "Screenshot";
......
......@@ -769,6 +769,33 @@ declare module nurdz.game {
* @param newY the new y to set.
*/
y: number;
/**
* Set the components of this Vector to the same as the vector or point provided. In the case of a
* point, the vector will be relative to the screen origin.
*
* @param point the point or vector to copy from
* @returns {Vector2D} this vector after the operation completes, for chaining calls.
*/
setTo(point: Point | Vector2D): Vector2D;
/**
* Set the position of this vector to the same as the values passed in
*
* @param x new X-coordinate for this point
* @param y new Y-coordinate for this point
* @returns {Vector2D} this point after the operation completes, for chaining calls.
*/
setToXY(x: number, y: number): Vector2D;
/**
* Set the components of this vector to the first two values in the array passed in, where the first
* value is treated as the X value and the second value is treated as the Y value.
*
* It is valid for the array to have more than two elements, but if it has fewer than two, nothing
* happens.
*
* @param array the array to get the new values from.
* @returns {Vector2D} this vector after the operation completes, for chaining calls.
*/
setToArray(array: Array<number>): Vector2D;
/**
* Get the magnitude of this vector.
*
......@@ -1080,6 +1107,12 @@ declare module nurdz.game {
* @see Vector2D.normalize
*/
scale(factor: number): Vector2D;
/**
* Return a copy of this vector as an array of two numbers in x, y ordering.
*
* @returns {Array<number>} the vector as an array of two numbers.
*/
toArray(): Array<number>;
/**
* Display a string version of the vector for debugging purposes.
*
......@@ -3533,6 +3566,27 @@ declare module nurdz.game {
* @type {HTMLCanvasElement}
*/
private _canvas;
/**
* The element that contains the canvas element; this is used to control the position of the
* canvas in the page.
*
* @type {HTMLElement}
*/
private _container;
/**
* Controls whether the stage automatically scales itself to fill the
* window or not.
*
* When this is false, the stage is of a specific size, and although it
* will keep itself centered in the page, it will remain that size.
*
* When this is true, the canvas will expand itself to try and fill
* the entire page body (less the header and footer) while maintaining
* aspect.
*
* @type {Boolean}
*/
private _canScale;
/**
* The object responsible for rendering to our canvas.
*
......@@ -3619,29 +3673,44 @@ declare module nurdz.game {
*/
currentScene: Scene;
/**
* Obtain the current engine update tick. This is incremented once every time the frame update
* loop is invoked, and can be used to time things in a crude fashion.
* Obtain the current engine update tick. This is incremented once every time the frame update loop is
* invoked, and can be used to time things in a crude fashion.
*
* The frame update loop is invoked at a set frame rate.
*
* @returns {number}
*/
tick: number;
/**
* Determine if the anything is currently being presented full screen or not. This tracks the current
* state independent of what the user has explicitly requested, so for example if the user turns on
* fullscreen mode, then presses escape to exit it, this will return false the way you expect it to.
*
* Note: This doesn't check explicitly that it is the stage that is fullscreen, just that something
* on the page is fullscreen.
*
* @return {boolean} true if the canvas is currently fullscreen, or false otherwise
*/
isFullscreen: boolean;
/**
* Create the stage on which all rendering for the game will be done.
*
* A canvas will be created and inserted into the DOM as the last child of the container DIV with the
* ID provided.
*
* The CSS of the DIV will be modified to have a width and height of the canvas, with options that
* cause it to center itself.
* The style of the div will be modified so that the canvas is properly contained and positioned in
* the page.
*
* @param containerDivID the ID of the DIV that should contain the created canvas
* @param initialColor the color to clear the canvas to once it is created
* @param surroundColor the color to set the page area that surrounds the canvas or null to leave the
* page as is
*
* @constructor
*
* @throws {ReferenceError} if there is no element with the ID provided
*/
constructor(containerDivID: string, initialColor?: string);
constructor(containerDivID: string, initialColor?: string, canScale?: boolean, surroundColor?: string);
/**
* This function gets executed in a loop to run the game. Each execution will cause an update and
* render to be issued to the current scene.
......@@ -3670,6 +3739,19 @@ declare module nurdz.game {
* @see Stage.run
*/
stop(): void;
/**
* Attempt to either enter fullscreen mode for the stage or exit it, as determined by the boolean
* parameter provided. Trying to put the stage into the state that it is already in does nothing.
*
* This is not guaranteed to work, since it requires that the user allow the request to proceed.
*
* @param enter true to enter fullscreen if not already in it, or false to exit fullscreen.
*/
fullscreen(enter?: boolean): void;
/**
* Toggle the current fullscreen state of the stage, depending on what the current state is.
*/
toggleFullscreen(): void;
/**
* Request preloading of an image filename. When the run() method is invoked, the game loop will
* not start until all images requested by this method call are available.
......@@ -3877,6 +3959,15 @@ declare module nurdz.game {
* created or the one provided
*/
calculateMousePos(mouseEvent: MouseEvent, point?: Point): Point;
/**
* Recalculate the size of the current window and the scale factor that should be applied to the
* canvas and its container so that the canvas is maximized inside the client area of the containing
* page.
*
* This requires that the canvas and its container already exist, and that the canvas is a child of
* the container. Various styles are also required on the container.
*/
private changeCanvasScale;
/**
* Handler for key down events. This gets triggered whenever the game is running and any key is
* pressed.
......@@ -3933,6 +4024,19 @@ declare module nurdz.game {
* @param evt the event object for this event.
*/
private mouseWheelEvent;
/**
* Perform a simple check to see if the given touch event is happening within the bounds of the
* canvas (regardless of its scale).
*/
private touchInCanvas(touch);
/**
* Handler for touch events. When a touch event is triggered, it is handled by converting the touch
* event into an appropriate mouse event and then dispatching the mouse event. Thus on touch enabled
* devices (e.g. tablets), touching works as a mouse does.
*
* @param evt the event object for this event.
*/
private touchEvent;
/**
* Turn on input handling for the game. This will capture keyboard events from the document and mouse
* events for the canvas provided.
......
This diff is collapsed.
......@@ -316,6 +316,10 @@ var nurdz;
case KeyCodes.KEY_SPACEBAR:
this._guy.toggleAnimation();
return true;
// For the F key, toggle between full screen mode and windowed mode.
case KeyCodes.KEY_F:
this._stage.toggleFullscreen();
return true;
default:
// Let the super do what super does. This allows screen shots to still work as expected.
return _super.prototype.inputKeyDown.call(this, eventObj);
......@@ -327,7 +331,7 @@ var nurdz;
nurdz.contentLoaded(window, function () {
try {
// Set up the stage.
var stage = new nurdz.game.Stage('gameContent');
var stage = new nurdz.game.Stage('gameContent', 'black', true);
// Set up the default values used for creating a screen shot.
nurdz.game.Stage.screenshotFilenameBase = "screenshot";
nurdz.game.Stage.screenshotWindowTitle = "Screenshot";
......
{
"folders":
[
{
"folder_exclude_patterns":
[
"tools",
"bootstrap",
".idea"
],
"path": "."
}
]
}
......@@ -522,6 +522,11 @@ module nurdz.main
this._mode = CollisionTestType.RECTANGLE;
this._currentCollider = this._rect;
return !eventObj.ctrlKey;
// For the F key, toggle between full screen mode and windowed mode.
case KeyCodes.KEY_F:
this._stage.toggleFullscreen();
return true;
}
// Let the default happen
......@@ -535,7 +540,7 @@ module nurdz.main
try
{
// Set up the stage.
var stage = new game.Stage ('gameContent');
var stage = new game.Stage ('gameContent', 'black', true, '#a0a0a0');
// Set up the default values used for creating a screen shot.
game.Stage.screenshotFilenameBase = "screenshot";
......
......@@ -8,7 +8,7 @@
"outFile": "../../js/collide-test.js"
},
"files": [
"../../js/engine-0.3.0.d.ts",
"../../js/engine-0.3.1.d.ts",
"main.ts"
]
}
This diff is collapsed.
......@@ -66,6 +66,52 @@ module nurdz.game
set y (newY : number)
{ this._y = newY; }
/**
* Set the components of this Vector to the same as the vector or point provided. In the case of a
* point, the vector will be relative to the screen origin.
*
* @param point the point or vector to copy from
* @returns {Vector2D} this vector after the operation completes, for chaining calls.
*/
setTo (point : Point|Vector2D) : Vector2D
{
return this.setToXY (point.x, point.y)
}
/**
* Set the position of this vector to the same as the values passed in
*
* @param x new X-coordinate for this point
* @param y new Y-coordinate for this point
* @returns {Vector2D} this point after the operation completes, for chaining calls.
*/
setToXY (x : number, y : number) : Vector2D
{
this._x = x;
this._y = y;
return this;
}
/**
* Set the components of this vector to the first two values in the array passed in, where the first
* value is treated as the X value and the second value is treated as the Y value.
*
* It is valid for the array to have more than two elements, but if it has fewer than two, nothing
* happens.
*
* @param array the array to get the new values from.
* @returns {Vector2D} this vector after the operation completes, for chaining calls.
*/
setToArray (array : Array<number>) : Vector2D
{
if (array.length >= 2)
{
this._x = array[0];
this._y = array[1];
return this;
}
}
/**
* Get the magnitude of this vector.
*
......@@ -593,6 +639,16 @@ module nurdz.game
return this;
}
/**
* Return a copy of this vector as an array of two numbers in x, y ordering.
*
* @returns {Array<number>} the vector as an array of two numbers.
*/
toArray () : Array<number>
{
return [this._x, this._y];
}
/**
* Display a string version of the vector for debugging purposes.
*
......
......@@ -5,7 +5,7 @@
"noImplicitAny": false,
"declaration": true,
"sourceMap": false,
"outFile": "../../js/engine-0.3.0.js"
"outFile": "../../js/engine-0.3.1.js"
},
"files": [
"nurdz.ts",
......
......@@ -425,6 +425,11 @@ module nurdz.main
this._guy.toggleAnimation ();
return true;
// For the F key, toggle between full screen mode and windowed mode.
case KeyCodes.KEY_F:
this._stage.toggleFullscreen();
return true;
default:
// Let the super do what super does. This allows screen shots to still work as expected.
return super.inputKeyDown (eventObj);
......@@ -438,7 +443,7 @@ module nurdz.main
try
{
// Set up the stage.
var stage = new game.Stage ('gameContent');
var stage = new game.Stage ('gameContent', 'black', true);
// Set up the default values used for creating a screen shot.
game.Stage.screenshotFilenameBase = "screenshot";
......
......@@ -8,7 +8,7 @@
"outFile": "../../js/game.js"
},
"files": [
"../../js/engine-0.3.0.d.ts",
"../../js/engine-0.3.1.d.ts",
"main.ts"
]
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment