Skip to content

Commit 25b5d76

Browse files
author
jamie nichols
committed
Created the MouseManager class and Added the ability to drag around the camera.. Then I added the new waypoint system to move the player
1 parent c85f553 commit 25b5d76

File tree

16 files changed

+564
-121
lines changed

16 files changed

+564
-121
lines changed

.idea/workspace.xml

Lines changed: 374 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ requirejs.config({
3838
"ImageLoader":"app/classes/gfx/ImageLoader",
3939
"KeyManager":"app/classes/input/KeyManager",
4040
"Launcher":"app/classes/Launcher",
41+
"MouseManager":"app/classes/input/MouseManager",
4142
"Player":"app/classes/entities/creatures/Player",
4243
"Rectangle":"app/classes/gfx/shapes/Rectangle",
4344
"SpatialGrid":"app/classes/utils/SpatialGrid",

js/app/classes/Game.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
* jamie337nichols
1010
1111
*/
12-
define(['Class','Display','State','GameState','KeyManager','Handler','GameCamera'],function(Class,Display,State,GameState,KeyManager,Handler,GameCamera){
12+
define(['Class','Display','State','GameState','KeyManager','MouseManager','Handler','GameCamera'],function(Class,Display,State,GameState,KeyManager,MouseManager,Handler,GameCamera){
1313

1414
var _this;
1515
var running = false;
16-
var title,width,height,g,display,keyManager,handler,gameCamera;
16+
var title,width,height,g,display,keyManager,mouseManager,handler,gameCamera;
1717
var gameState,menuState,settingsState;
1818

1919
var Game = Class.extend({
@@ -22,7 +22,6 @@ define(['Class','Display','State','GameState','KeyManager','Handler','GameCamera
2222
title = _title;
2323
width = _width;
2424
height = _height;
25-
keyManager = new KeyManager();
2625
},
2726
run:function(){
2827
init();
@@ -60,6 +59,12 @@ define(['Class','Display','State','GameState','KeyManager','Handler','GameCamera
6059
getKeyManager:function() {
6160
return keyManager;
6261
},
62+
getMouseManager:function(){
63+
return mouseManager;
64+
},
65+
getDisplay:function(){
66+
return display;
67+
},
6368
getWidth:function(){
6469
return width;
6570
},
@@ -68,18 +73,27 @@ define(['Class','Display','State','GameState','KeyManager','Handler','GameCamera
6873
},
6974
getGameCamera:function(){
7075
return gameCamera;
76+
},
77+
click:function(_btn){
78+
if(State.getState()!=null){
79+
State.getState().click(_btn);
80+
}
7181
}
7282
});
7383
function init(){
84+
handler = new Handler(_this);
7485
display = new Display(title,width,height);
86+
keyManager = new KeyManager();
87+
mouseManager = new MouseManager(handler);
7588
g = display.getGraphics();
76-
handler = new Handler(_this);
89+
7790
gameCamera = new GameCamera(handler,0,0);
7891
gameState = new GameState(handler);
7992
State.setState(gameState);
8093
}
8194
function tick(_dt) {
8295
keyManager.tick();
96+
mouseManager.tick();
8397
if(State.getState()!=null){
8498
State.getState().tick(_dt);
8599
}

js/app/classes/Handler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ define(['Class'],function(Class){
2626
getKeyManager:function(){
2727
return game.getKeyManager();
2828
},
29+
getMouseManager:function(){
30+
return game.getMouseManager();
31+
},
2932
getGameCamera:function(){
3033
return game.getGameCamera();
3134
},
3235
getWorld:function() {
3336
return world;
3437
},
38+
getDisplay:function(){
39+
return game.getDisplay();
40+
},
3541
setWorld:function(_world){
3642
world = _world;
43+
},
44+
click:function(_btn){
45+
game.click(_btn);
3746
}
3847
});
3948

js/app/classes/States/GameState.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ define(['State','World'],function(State,World){
2121
},
2222
render:function(_g){
2323
this.world.render(_g);
24+
},
25+
click:function(_btn){
26+
this.world.click(_btn);
2427
}
2528
});
2629

js/app/classes/States/State.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ define(['Class'],function(Class){
1717
init:function(_handler){
1818
this.handler = _handler;
1919
},
20-
tick:function(_dt){},
21-
render:function(_g){}
20+
tick:function(_dt){
21+
throw("Every state needs a tick");
22+
},
23+
render:function(_g){
24+
throw("Every state needs a render");
25+
},
26+
click:function(){
27+
throw("Every state need a click");
28+
},
2229
});
2330
State.getState = function(){
2431
return currentState;

js/app/classes/display/Display.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ define(['Jquery','Class'],function($,Class){
3232
},
3333
getGraphics:function(){
3434
return graphics;
35+
},
36+
getCanvas:function(){
37+
return canvas;
3538
}
3639
});
3740

@@ -40,8 +43,8 @@ define(['Jquery','Class'],function($,Class){
4043
document.title = title;
4144
var body = document.body;
4245
body.innerHTML = ("<canvas id='canvas' width='"+width+"' height='"+height+"'></canvas>");
43-
graphics = document.getElementById("canvas").getContext("2d");
44-
46+
canvas = document.getElementById("canvas");
47+
graphics = canvas.getContext("2d");
4548
}
4649

4750
CanvasRenderingContext2D.prototype.myDrawImage = function(asset,_x,_y,_width,_height){

js/app/classes/entities/Entity.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ define(['Class','Rectangle'],function(Class,Rectangle){
2727
render:function(){
2828
throw("Entities Must Have a Tick Function");
2929
},
30-
30+
click:function(){
31+
throw("Entities Must Have a Click Function");
32+
},
3133
//Getters
3234
getX:function(){
3335
return this.x;
@@ -71,6 +73,16 @@ define(['Class','Rectangle'],function(Class,Rectangle){
7173
},
7274
setHeight:function(_height){
7375
this.height = _height;
76+
},
77+
getDistance:function(_ent){
78+
var xdist = this.x - _ent.x;
79+
var ydist = this.y - _ent.y;
80+
return Math.sqrt(xdist*xdist+ydist*ydist);
81+
},
82+
getAngleTo:function(_ent){
83+
var xdist = _ent.x - this.x;
84+
var ydist = _ent.y - this.y;
85+
return Math.atan2(ydist,xdist);
7486
}
7587
});
7688

js/app/classes/entities/EntityManager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ define(['Class','Rectangle'],function(Class,Rectangle){
2121
e.render(_g);
2222
});
2323
},
24+
click:function(_btn){
25+
entities.forEach(function(e){
26+
e.click(_btn);
27+
});
28+
},
2429
//Getters
2530
getPlayer:function(){
2631
return player;

js/app/classes/entities/creatures/Creature.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ define(['Entity','Tile','Rectangle'],function(Entity,Tile,Rectangle){
8484
getSpeed:function(){
8585
return this.speed;
8686
},
87+
getMovementSpeed:function(){
88+
this.lastX = this.currentX || this.x;
89+
this.lastY = this.currentY || this.y;
90+
this.currentX = this.x;
91+
this.currentY = this.y;
92+
var speedX = this.currentX - this.lastX;
93+
var speedY = this.currentY - this.lastY;
94+
return Math.sqrt(speedX*speedX+speedY*speedY);
95+
},
8796

8897
//Setters
8998
setHealth:function(_health){

0 commit comments

Comments
 (0)