Zikang Qian / Mbed 2 deprecated el17z2q

Dependencies:   mbed

Fork of el17z2q by ELEC2645 (2017/18)

Committer:
yzjdxl
Date:
Mon May 07 22:11:43 2018 +0000
Branch:
GameEngine
Revision:
2:6dc7bc55c1cb
Parent:
1:00a4ea97c4cd
publish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yzjdxl 1:00a4ea97c4cd 1 #ifndef COINWITHBAG_TEST_H
yzjdxl 1:00a4ea97c4cd 2 #define COINWITHBAG_TEST_H
yzjdxl 1:00a4ea97c4cd 3
yzjdxl 1:00a4ea97c4cd 4 /** CoinWithBag-test Class
yzjdxl 1:00a4ea97c4cd 5 * @brief Check that the coin object correctly collides with the bag
yzjdxl 1:00a4ea97c4cd 6 * @author Zikang Qian
yzjdxl 1:00a4ea97c4cd 7 * @date April, 2018
yzjdxl 1:00a4ea97c4cd 8 */
yzjdxl 1:00a4ea97c4cd 9
yzjdxl 1:00a4ea97c4cd 10 /** \returns true if all the tests passed
yzjdxl 1:00a4ea97c4cd 11 */
yzjdxl 1:00a4ea97c4cd 12 bool CoinWithBag_test_collide()
yzjdxl 1:00a4ea97c4cd 13 {
yzjdxl 1:00a4ea97c4cd 14 Coin coin;
yzjdxl 1:00a4ea97c4cd 15 Bag bag;
yzjdxl 1:00a4ea97c4cd 16 GameEngine game;
yzjdxl 1:00a4ea97c4cd 17
yzjdxl 2:6dc7bc55c1cb 18 // initial size of coin and bag
yzjdxl 1:00a4ea97c4cd 19 coin.init(2.5,1);
yzjdxl 1:00a4ea97c4cd 20 bag.init(17,2,1);
yzjdxl 1:00a4ea97c4cd 21 game.init(17,2,2.5,1);
yzjdxl 1:00a4ea97c4cd 22
yzjdxl 2:6dc7bc55c1cb 23 // initial position of coin
yzjdxl 1:00a4ea97c4cd 24 Vector2D initial_coin_position = {5, 0};
yzjdxl 1:00a4ea97c4cd 25 coin.set_position(initial_coin_position);
yzjdxl 1:00a4ea97c4cd 26
yzjdxl 2:6dc7bc55c1cb 27 // initial position of bag, where below the coin
yzjdxl 1:00a4ea97c4cd 28 Vector2D initial_bag_position = {3, 46};
yzjdxl 1:00a4ea97c4cd 29 bag.set_position(initial_bag_position);
yzjdxl 1:00a4ea97c4cd 30
yzjdxl 2:6dc7bc55c1cb 31 // Read the position of coin
yzjdxl 1:00a4ea97c4cd 32 Vector2D read_coin_position = coin.get_position();
yzjdxl 1:00a4ea97c4cd 33 printf("%f, %f\n", read_coin_position.x, read_coin_position.y);
yzjdxl 1:00a4ea97c4cd 34
yzjdxl 2:6dc7bc55c1cb 35 // Read the position of bag
yzjdxl 1:00a4ea97c4cd 36 Vector2D read_bag_position = bag.get_position();
yzjdxl 1:00a4ea97c4cd 37 printf("%f, %f\n", read_bag_position.x, read_bag_position.y);
yzjdxl 1:00a4ea97c4cd 38
yzjdxl 2:6dc7bc55c1cb 39 // Set the velocity to 0,47 so that coin can collide with bag immediately
yzjdxl 2:6dc7bc55c1cb 40 Vector2D velocity = {0, 47};
yzjdxl 1:00a4ea97c4cd 41 coin.set_velocity(velocity);
yzjdxl 1:00a4ea97c4cd 42
yzjdxl 2:6dc7bc55c1cb 43 // Update the coin and bag
yzjdxl 1:00a4ea97c4cd 44 coin.update();
yzjdxl 1:00a4ea97c4cd 45 bag.update();
yzjdxl 1:00a4ea97c4cd 46
yzjdxl 2:6dc7bc55c1cb 47 // get the result of colliding analysis
yzjdxl 1:00a4ea97c4cd 48 int nodead = game.update(pad);
yzjdxl 1:00a4ea97c4cd 49
yzjdxl 1:00a4ea97c4cd 50 bool success = true;
yzjdxl 1:00a4ea97c4cd 51
yzjdxl 2:6dc7bc55c1cb 52 // failed if game over
yzjdxl 1:00a4ea97c4cd 53 if (nodead != 1) {
yzjdxl 1:00a4ea97c4cd 54 success = false;
yzjdxl 1:00a4ea97c4cd 55 }
yzjdxl 1:00a4ea97c4cd 56
yzjdxl 1:00a4ea97c4cd 57 return success;
yzjdxl 1:00a4ea97c4cd 58 }
yzjdxl 1:00a4ea97c4cd 59
yzjdxl 1:00a4ea97c4cd 60 #endif