-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add constraints to edge of map so the horse can't walk past the edge of the canvas #81
Comments
I'm working on this one! Hopefully I'll have it done by Saturday! |
Sweet! Thanks @dinaelhanan . We will be excited to see what you can do. |
As I'm working through this, I'm stuck on where in the code I should put my code. I'm sorry if it sounds like a dumb question I just really want to be able to tackle this! I'm thinking that I should put it in an eventlistener like the ones below in the mygameArea function.
Or in this function, which includes the code that clears the apples when you're close to it.
|
Ok I've found this: Thanks again. |
I think perhaps the answer your liking for us the “component” function in game.js . I’m currently on mobile and can’t really compare the two very well. But that might get you pointed in the right direction? |
Well not quite. The component is a piece. The maximum and minimum the horse would be able to go would be the size of the canvas. |
Hi @thalaeg, that sounds good, thanks for the help! But also, the issue I'm having is with applying the max canvas size to that part of the myGameArea. Do I put it with the eventlisteners? I am just confused as to how I would set a maximum value that a horse can move in. I thought at first that i would have to change something in places that are in charge of how the horse moves. Any help would be appreciated! |
Sure thing. Now, I must admit, I am no expert in JS! Nor am I a coding guru, but what I would do is determine how big the canvas is (i.e. this.cavas.height = x) and then add a listener to when the game redraws the horse to not let it be redrawn past the canvas parameters. Since that is the case I would think it would go in the "this.newPos = function ()" because it is checking to see if it is past that location or not. A resource that I used to get the game board up and going is W3 schools. I think you will find it VERY helpful! I recommend checking it out. https://www.w3schools.com/graphics/game_canvas.asp |
Thanks for the resources. I'll go over them, try my best, and let you know if I'm struggling with anything! Thanks! @thalaeg |
No description provided.
The text was updated successfully, but these errors were encountered: