Shooting and Moving
- Goal for the day
- There is one big idea here.
- If I am located at (x,y), traveling at an angle of θ and I take a step.
- x will change by stepSize*cos(θ)
- y will change by stepSize*sin(θ)
-
- r is the size of the step.
- Note what is really important here is that each object keeps track of it's own transformation information.
- The object must maintain
- current rotation 0 ≤ θ < 360
- current location (x,y)
- This gets updated when the object is moved.
- And is used when the object is drawn.
- Center the object at the origin.
- Rotate by θ
- Scale if needed.
- Translate by (x,y)
- I added shots because I wanted to.
- How could we modify this to check for impacts avoid collisions?
- Remeber, we can querry the contex for the current transformation matrix.
- So we could compute our "center" in canvas coordinates.
- And projecting a point from the center, we could also compute our "scaled" radius.
- So we could build a vector of scene elements.
- And compute collision as before.