ELEC2645 (2018/19) / Mbed 2 deprecated el17aj

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

CrossHairs Class Reference

CrossHairs Class Reference

CrossHairs Class. More...

#include <CrossHairs.h>

Public Member Functions

void init (int speed)
 Initialises the cross hairs at center position.
void draw (N5110 &lcd)
 Draws the cross hairs on the lcd.
void update (float angle, float mag)
 Updates the position of the cross hairs based on user input.
Vector2D get_pos ()
 accessors and mutators
void set_pos (Vector2D p)
 sets the position of the cross hairs

Detailed Description

CrossHairs Class.

Author:
Adam Jones, University of Leeds Interacts with the Cross Hairs which the user uses to aim in the game
Date:
April 2019 Revision 1.0
#include "N5110.h"

int crossHairsSprite[7][7] =   {
    { 0,0,1,1,1,0,0 },
    { 0,1,0,0,0,1,0 },
    { 1,0,0,1,0,0,1 },
    { 1,0,1,1,1,0,1 },
    { 1,0,0,1,0,0,1 },
    { 0,1,0,0,0,1,0 },
    { 0,0,1,1,1,0,0 },
};


int main()
{
    // first need to initialise display
    lcd.init();
    
    //make object of cross hairs class
    CrossHairs _crossHairs; 
    
    //initialise cross hairs object
    _crossHairs.init(CrossHairsSpeed);
    
    float _angle = 180.0 // degrees
    float _mag = 1.0 // magnitude 0.0 to 1.0
    //update position of cross hairs
    _crossHairs.update(_angle,_mag);
    
    //call to add cross hairs to screen
    _crossHairs.draw(lcd);
    
    //returns Vector2D position
    Vector2D crossHairsLoc = _crossHairs.get_pos();
    
    
    Vector2d newPos = = {10,20}; //{x,y};
    //set cross hairs position
    _crossHairs.setPos(newPos);
}

Definition at line 64 of file CrossHairs.h.


Member Function Documentation

void draw ( N5110 lcd )

Draws the cross hairs on the lcd.

Parameters:
lcdthe N5110 object

Definition at line 37 of file CrossHairs.cpp.

Vector2D get_pos (  )

accessors and mutators

gets the position of the cross hairs

Returns:
a Vector2D value of the coordinates

Definition at line 74 of file CrossHairs.cpp.

void init ( int  speed )

Initialises the cross hairs at center position.

Parameters:
speedSpeed of cross hairs in pixels per frame (integer)

Definition at line 24 of file CrossHairs.cpp.

void set_pos ( Vector2D  p )

sets the position of the cross hairs

Parameters:
positionVector2D coordinate value

Definition at line 80 of file CrossHairs.cpp.

void update ( float  angle,
float  mag 
)

Updates the position of the cross hairs based on user input.

Parameters:
angleangle in degrees
magnitudemagnitude from 0.0 to 1.0 to allow user to control speed of motion

Definition at line 44 of file CrossHairs.cpp.