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 COINWITHBOUNDARY_TEST_H
yzjdxl 1:00a4ea97c4cd 2 #define COINWITHBOUNDARY_TEST_H
yzjdxl 1:00a4ea97c4cd 3
yzjdxl 1:00a4ea97c4cd 4 /** CoinWithBoundayr-test Class
yzjdxl 1:00a4ea97c4cd 5 * @brief Check that the coin object correctly collides with boundary
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 CoinWithBoundary_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 coin's size
yzjdxl 1:00a4ea97c4cd 19 coin.init(2.5,1);
yzjdxl 1:00a4ea97c4cd 20 game.init(17,2,2.5,1);
yzjdxl 1:00a4ea97c4cd 21
yzjdxl 2:6dc7bc55c1cb 22 // initial coin position
yzjdxl 1:00a4ea97c4cd 23 Vector2D initial_coin_position = {5,0};
yzjdxl 1:00a4ea97c4cd 24 coin.set_position(initial_coin_position);
yzjdxl 1:00a4ea97c4cd 25
yzjdxl 2:6dc7bc55c1cb 26 // Read the position of coin
yzjdxl 1:00a4ea97c4cd 27 Vecotr2D read_coin_position = coin.get_position;
yzjdxl 1:00a4ea97c4cd 28 printf("%f, %f\n", read_coin_position.x, read_coin_position.y);
yzjdxl 1:00a4ea97c4cd 29
yzjdxl 2:6dc7bc55c1cb 30 // Set the velocity to 0, 48 so that the coin can collide with bottom boundary immediately
yzjdxl 1:00a4ea97c4cd 31 Vector2D velocity = {0, 48};
yzjdxl 1:00a4ea97c4cd 32 coin.set_velocity(velocity);
yzjdxl 1:00a4ea97c4cd 33
yzjdxl 2:6dc7bc55c1cb 34 // Update the coin
yzjdxl 1:00a4ea97c4cd 35 coin.update();
yzjdxl 1:00a4ea97c4cd 36
yzjdxl 2:6dc7bc55c1cb 37 // get the result of colliding analysis
yzjdxl 1:00a4ea97c4cd 38 int nodead = game.update(pad);
yzjdxl 1:00a4ea97c4cd 39
yzjdxl 1:00a4ea97c4cd 40 bool success = true;
yzjdxl 1:00a4ea97c4cd 41
yzjdxl 2:6dc7bc55c1cb 42 // failed if game is not over
yzjdxl 1:00a4ea97c4cd 43 if (nodead != 0) {
yzjdxl 1:00a4ea97c4cd 44 success = false;
yzjdxl 1:00a4ea97c4cd 45 }
yzjdxl 1:00a4ea97c4cd 46
yzjdxl 1:00a4ea97c4cd 47 return success;
yzjdxl 1:00a4ea97c4cd 48 }
yzjdxl 1:00a4ea97c4cd 49 #endif