Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds keyboard controls #16

Merged
merged 5 commits into from
Nov 29, 2016
Merged

Adds keyboard controls #16

merged 5 commits into from
Nov 29, 2016

Conversation

davethomas11
Copy link
Owner

Arrow keys = Vince
AWSD = Jerry
JIKL = Bart

Arrow keys = Vince
AWSD = Jerry
JIKL = Bart
@davethomas11
Copy link
Owner Author

@Tsmith18256 Please code review!

@@ -0,0 +1,3 @@
export default class GameEvent {

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this empty?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might of been thinking I needed to add stuff the base class. I will change this to an interface.


get gameObject() {
return this._gameObject;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _gameObject ever expected to change internally after the constructor? If not, you can change line 6 to be readonly gameObject: GameObject; and not have to do a getter. It will let you do an initial assignment in the constructor.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point read only is better. Will do this.

this.gameObjects = [];
Game.inputControllers = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time we create a game it resets the static inputControllers?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug will remove this.

We need to rethink input controllers in due time. Refactor as you see fit when you are working.

if (twoDContext == null) {
throw new Error('Could not get the context from the canvas');
}
this.context = twoDContext!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this ! do? (I actually have no idea)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unnecessary because of the null check. But if I hadn't checked for null it would force set context which does not allow null.

It can be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is awesome! Thank you... I was trying to do that the other day when I first did the TypeScript migration and couldn't figure it out.

return Game._viewPortWidth;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing here. Having the getters and setters in a nested class but then accessing the private properties as part of the parent class.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to leave this. But refactor as you see fit. Thinking is we need to give static access to variables that can only be set inside Game.

Thought it gave it nice name spacing having it accessed via inner class.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it less single operation than this. What if someone wanted two Game objects running?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was kinda thinking about that idea too. We probably only ever want one game, but that doesn't mean it should break if somebody makes 2

// TODO: This needs improvement. Angle changes needs to be smoother.
private calculateAngle() {

var xFactor = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta bunch of vars in this commit. Just do a find all and make these let. It's hard getting used to using let, but it's a lot nicer

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.


static handleEvent(game: Game, event: GameEvent | undefined): void {

if ((<any>event).constructor.name == (<any>SpawnEvent).name) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For casting, use as. I read on the difference one time and apparently there are issues that can arise from this notation but not as or something like that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

static getByType <T> (type: any, array:Array<T>): T | null {
var object: T | null = null;
array.forEach((e) => {
if ((<any>e).constructor.name == type.name) object = e;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above for casting

}

static getByType <T> (type: any, array:Array<T>): T | null {
var object: T | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going only undefined and no null

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change.


if (this.x < 0 || this.y < 0 ||
this.x > Game.Info.viewPortWidth ||
this.y > Game.Info.viewPortHeight) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty unclear at first glance with all these conditions, can we break it down to variables for readability? Maybe like:

let isWithinScreenX: boolean = this.x >= 0 && this.x <= Game.Info.viewPortWidth;
let isWithinScreenY: boolean = this.y >= 0 && this.y <= Game.Info.viewPortHeight;
if (!isWithinScreenX || !isWithinScreenY) {
  this.alive = false;
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumberTools.isInRect. Will change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good idea 👍

@davethomas11
Copy link
Owner Author

Going to address comments before pull request is merged.

@Tsmith18256 Tsmith18256 merged commit 379e6dd into develop Nov 29, 2016
@Tsmith18256 Tsmith18256 deleted the issue/6/basic-keyboard-input branch December 3, 2016 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants