ELEC2645 (2018/19) / Mbed 2 deprecated el17set_

Dependencies:   mbed

Committer:
S_Tingle
Date:
Thu May 09 14:40:58 2019 +0000
Revision:
26:3652bc2fe3fc
Parent:
23:5e8a435e568f
I understand the university's rules on plagiarism. I hereby declare this my own independent work.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
S_Tingle 13:c3b550fc2445 1 #include "Coin.h"
S_Tingle 13:c3b550fc2445 2
S_Tingle 22:8e38efeae0c9 3 Coin::Coin()
S_Tingle 22:8e38efeae0c9 4 {
S_Tingle 22:8e38efeae0c9 5 coin = 0;
S_Tingle 22:8e38efeae0c9 6 _spawn = true;
S_Tingle 13:c3b550fc2445 7 }
S_Tingle 13:c3b550fc2445 8
S_Tingle 22:8e38efeae0c9 9 Coin::~Coin()
S_Tingle 22:8e38efeae0c9 10 {
S_Tingle 13:c3b550fc2445 11
S_Tingle 13:c3b550fc2445 12 }
S_Tingle 13:c3b550fc2445 13
S_Tingle 22:8e38efeae0c9 14 void Coin::init(int x, int y)
S_Tingle 22:8e38efeae0c9 15 {
S_Tingle 22:8e38efeae0c9 16 x_coin = x;
S_Tingle 22:8e38efeae0c9 17 y_coin = y;
S_Tingle 22:8e38efeae0c9 18 }
S_Tingle 22:8e38efeae0c9 19
S_Tingle 22:8e38efeae0c9 20 int Coin::get_x_coin()
S_Tingle 22:8e38efeae0c9 21 {
S_Tingle 22:8e38efeae0c9 22 return x_coin;
S_Tingle 13:c3b550fc2445 23 }
S_Tingle 13:c3b550fc2445 24
S_Tingle 22:8e38efeae0c9 25 int Coin::get_y_coin()
S_Tingle 22:8e38efeae0c9 26 {
S_Tingle 22:8e38efeae0c9 27 return y_coin;
S_Tingle 13:c3b550fc2445 28 }
S_Tingle 13:c3b550fc2445 29
S_Tingle 26:3652bc2fe3fc 30 // gets current number of coins collected //
S_Tingle 22:8e38efeae0c9 31 int Coin::get_coins()
S_Tingle 22:8e38efeae0c9 32 {
S_Tingle 22:8e38efeae0c9 33 return coin;
S_Tingle 13:c3b550fc2445 34 }
S_Tingle 13:c3b550fc2445 35
S_Tingle 22:8e38efeae0c9 36 void Coin::drawSprite(N5110 &lcd)
S_Tingle 22:8e38efeae0c9 37 {
S_Tingle 22:8e38efeae0c9 38 lcd.drawSprite(x_coin,y_coin,2,2,(int *)coin_01);
S_Tingle 13:c3b550fc2445 39 }
S_Tingle 13:c3b550fc2445 40
S_Tingle 22:8e38efeae0c9 41 bool Coin::collidePlayer(int x, int y, Gamepad &pad)
S_Tingle 22:8e38efeae0c9 42 {
S_Tingle 22:8e38efeae0c9 43 // detects for all x and y values whether the hitboxes of the coin //
S_Tingle 22:8e38efeae0c9 44 // and controllable character collide //
S_Tingle 22:8e38efeae0c9 45 for (int ix = 0; ix < 7; ix++) {
S_Tingle 22:8e38efeae0c9 46 for (int iy = 0; iy < 7; iy++) {
S_Tingle 22:8e38efeae0c9 47 if ( x + ix == x_coin - 1 && y + iy == y_coin) {
S_Tingle 22:8e38efeae0c9 48 pad.tone(650,0.25);
S_Tingle 22:8e38efeae0c9 49 return true;
S_Tingle 22:8e38efeae0c9 50 } else if ( x + ix == x_coin + 2 && y + iy == y_coin) {
S_Tingle 22:8e38efeae0c9 51 pad.tone(650,0.25);
S_Tingle 22:8e38efeae0c9 52 return true;
S_Tingle 22:8e38efeae0c9 53 } else if ( x + ix == x_coin && y + iy == y_coin - 1) {
S_Tingle 22:8e38efeae0c9 54 pad.tone(650,0.25);
S_Tingle 22:8e38efeae0c9 55 return true;
S_Tingle 22:8e38efeae0c9 56 } else if ( x + ix == x_coin && y + iy == y_coin + 2) {
S_Tingle 22:8e38efeae0c9 57 pad.tone(650,0.25);
S_Tingle 22:8e38efeae0c9 58 return true;
S_Tingle 22:8e38efeae0c9 59 }
S_Tingle 16:37d98c281eb3 60 }
S_Tingle 22:8e38efeae0c9 61 }
S_Tingle 22:8e38efeae0c9 62 return false;
S_Tingle 16:37d98c281eb3 63 }
S_Tingle 16:37d98c281eb3 64
S_Tingle 22:8e38efeae0c9 65 void Coin::spawn(int x, int y, N5110 &lcd, Gamepad &pad)
S_Tingle 22:8e38efeae0c9 66 {
S_Tingle 22:8e38efeae0c9 67 // if collision true the increment coin value //
S_Tingle 22:8e38efeae0c9 68 // and move the sprite off screen //
S_Tingle 22:8e38efeae0c9 69 drawSprite(lcd);
S_Tingle 22:8e38efeae0c9 70 if (collidePlayer(x,y,pad) == true) {
S_Tingle 22:8e38efeae0c9 71 x_coin = 100;
S_Tingle 22:8e38efeae0c9 72 y_coin = 100;
S_Tingle 22:8e38efeae0c9 73 coin++;
S_Tingle 22:8e38efeae0c9 74 }
S_Tingle 13:c3b550fc2445 75 }