-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
Arrow keys = Vince AWSD = Jerry JIKL = Bart
@Tsmith18256 Please code review! |
@@ -0,0 +1,3 @@ | |||
export default class GameEvent { | |||
|
|||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this empty?
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta bunch of var
s 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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NumberTools.isInRect. Will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good idea 👍
Going to address comments before pull request is merged. |
Arrow keys = Vince
AWSD = Jerry
JIKL = Bart