Allow user to connect multiple screen.

Dependencies:   mbed-rtos mbed

Committer:
Ratchapong
Date:
Wed Mar 11 05:00:37 2015 +0000
Revision:
0:052d0f82433e
Working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ratchapong 0:052d0f82433e 1 #include "Graphics.h"
Ratchapong 0:052d0f82433e 2
Ratchapong 0:052d0f82433e 3
Ratchapong 0:052d0f82433e 4
Ratchapong 0:052d0f82433e 5 class Controller
Ratchapong 0:052d0f82433e 6 {
Ratchapong 0:052d0f82433e 7 public:
Ratchapong 0:052d0f82433e 8
Ratchapong 0:052d0f82433e 9 AnalogIn& sliderh;
Ratchapong 0:052d0f82433e 10 AnalogIn& sliderv;
Ratchapong 0:052d0f82433e 11
Ratchapong 0:052d0f82433e 12 public:
Ratchapong 0:052d0f82433e 13 Controller(AnalogIn& sliderh, AnalogIn& sliderv) : sliderh(sliderh), sliderv(sliderv) {
Ratchapong 0:052d0f82433e 14
Ratchapong 0:052d0f82433e 15 }
Ratchapong 0:052d0f82433e 16 };
Ratchapong 0:052d0f82433e 17
Ratchapong 0:052d0f82433e 18 class Game
Ratchapong 0:052d0f82433e 19 {
Ratchapong 0:052d0f82433e 20 private:
Ratchapong 0:052d0f82433e 21 Renderer& renderer;
Ratchapong 0:052d0f82433e 22 Controller& controller;
Ratchapong 0:052d0f82433e 23 Scene scene;
Ratchapong 0:052d0f82433e 24
Ratchapong 0:052d0f82433e 25 public:
Ratchapong 0:052d0f82433e 26 Game(Renderer& renderer, Controller& ctrl)
Ratchapong 0:052d0f82433e 27 : renderer(renderer), controller(ctrl) {
Ratchapong 0:052d0f82433e 28
Ratchapong 0:052d0f82433e 29 scene.bg = renderer.background;
Ratchapong 0:052d0f82433e 30
Ratchapong 0:052d0f82433e 31 buildScene();
Ratchapong 0:052d0f82433e 32 }
Ratchapong 0:052d0f82433e 33
Ratchapong 0:052d0f82433e 34 private:
Ratchapong 0:052d0f82433e 35 void buildScene() {
Ratchapong 0:052d0f82433e 36
Ratchapong 0:052d0f82433e 37
Ratchapong 0:052d0f82433e 38 Block pad;
Ratchapong 0:052d0f82433e 39 pad.locked = true;
Ratchapong 0:052d0f82433e 40 pad.coord.x = 10;
Ratchapong 0:052d0f82433e 41 pad.coord.y = 10;
Ratchapong 0:052d0f82433e 42 pad.copy();
Ratchapong 0:052d0f82433e 43 pad.color = -1;
Ratchapong 0:052d0f82433e 44 scene.paddle = pad;
Ratchapong 0:052d0f82433e 45 }
Ratchapong 0:052d0f82433e 46
Ratchapong 0:052d0f82433e 47
Ratchapong 0:052d0f82433e 48 public:
Ratchapong 0:052d0f82433e 49 void getInput(int posx, int posy) {
Ratchapong 0:052d0f82433e 50 scene.paddle.store_prev();
Ratchapong 0:052d0f82433e 51
Ratchapong 0:052d0f82433e 52 if (posx > 600) {
Ratchapong 0:052d0f82433e 53 scene.paddle.coord.x = scene.paddle.coord.x + 5;
Ratchapong 0:052d0f82433e 54 } else if (posx < 400) {
Ratchapong 0:052d0f82433e 55 scene.paddle.coord.x = scene.paddle.coord.x - 5;
Ratchapong 0:052d0f82433e 56 }
Ratchapong 0:052d0f82433e 57
Ratchapong 0:052d0f82433e 58 if (posy > 600) {
Ratchapong 0:052d0f82433e 59 scene.paddle.coord.y = scene.paddle.coord.y + 5;
Ratchapong 0:052d0f82433e 60 } else if (posy < 400) {
Ratchapong 0:052d0f82433e 61 scene.paddle.coord.y = scene.paddle.coord.y - 5;
Ratchapong 0:052d0f82433e 62 }
Ratchapong 0:052d0f82433e 63
Ratchapong 0:052d0f82433e 64
Ratchapong 0:052d0f82433e 65 scene.paddle.updated = true;
Ratchapong 0:052d0f82433e 66 }
Ratchapong 0:052d0f82433e 67
Ratchapong 0:052d0f82433e 68
Ratchapong 0:052d0f82433e 69 void loop() {
Ratchapong 0:052d0f82433e 70 renderer.render(scene);
Ratchapong 0:052d0f82433e 71 }
Ratchapong 0:052d0f82433e 72
Ratchapong 0:052d0f82433e 73
Ratchapong 0:052d0f82433e 74 };
Ratchapong 0:052d0f82433e 75