1.1 Show a position on the screen

Although the class Vec2 is mainly used to calculate positions, it is also possible to show it on the screen. This can be done with the function draw(Color). The argument should contain the color in which the coordinate must be drawn.

 
Vec2 p1(0.2, 0.4); // Create a point p1, assigning x and y 
                   // with the constructor. 
Vec2 p2;           // Create a point p2. 
 
5void InitPre() 
{ 
   EE_INIT(); 
} 
 
10bool Init() 
{ 
   p2.set(-0.2, -0.5); // assign values to p2 with the set function 
   return true
} 
15 
void Shut() {} 
 
bool Update() 
{ 
20   if(Kb.bp(KB_ESC)) return false
 
   return true
} 
 
25void Draw() 
{ 
   D.clear(BLACK); // Clear the screen 
   p1.draw(RED  ); // draw p1 in red 
   p2.draw(BLUE ); // draw p2 in blue 
30   Vec2(0 ,0).draw(GREEN); // create a temporary object and draw 
                           // it in green 
}  
35

Exercise
Write this code in the editor. Don’t copy/paste it: you won’t learn anything from copying code. Make sure it runs without error. If not, compare your code with this example. Learning to understand errors is very important. Try to understand what went wrong and why.