Dependencies: mbed
Diff: SnakeEngine/SnakeEngine.cpp
- Revision:
- 10:62d8cb7742c3
- Parent:
- 9:561e5681b7a6
- Child:
- 13:72bc2579e85e
--- a/SnakeEngine/SnakeEngine.cpp Tue Apr 03 12:24:18 2018 +0000 +++ b/SnakeEngine/SnakeEngine.cpp Wed Apr 04 12:25:51 2018 +0000 @@ -10,42 +10,36 @@ { } -/* -Direction get_snake_direction() -{ - - Direction output; - Direction input = get_input_dir(); - //int state = W; - - StateDirection fsm[4] = { - - {N,{N,E,N,W}}, - {E,{N,E,S,E}}, - {S,{S,E,S,W}}, - {W,{N,W,S,W}} -}; + - output = fsm[state].output; // set ouput depending on current state - state = fsm[state].nextState[input]; // read input (BusIn) and update curent state - - return output; - -} -*/ - -void SnakeEngine::init(int food_pos_x, int food_pos_y) +void SnakeEngine::init() { - Vector2D food_pos = _food.get_rand_pos(); + /*Vector2D food_pos = _food.get_rand_pos(); _fx = food_pos.x; _fy = food_pos.y; - _food.init(_fx,_fy); + _food.init(_fx,_fy);*/ + _snake.init(); } +void SnakeEngine::get_input(Gamepad &pad, Snake &snake) +{ + _next = pad.get_direction(); + _cur = snake.get_snake_direction(); + +} + +void SnakeEngine::update(Gamepad &pad) +{ + + _snake.update(_next, _cur); + +} + + void SnakeEngine::draw(N5110 &lcd) { @@ -53,5 +47,7 @@ lcd.setContrast(0.5); _food.update(); _food.draw(lcd); + _snake.update(_next, _cur); + _snake.draw(lcd); } \ No newline at end of file