Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Enemy/Enemy.cpp
- Revision:
- 4:3446009e2f38
- Child:
- 5:096017b99011
diff -r 3d35ab70b565 -r 3446009e2f38 Enemy/Enemy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Enemy/Enemy.cpp Tue May 07 19:25:20 2019 +0000 @@ -0,0 +1,48 @@ +#include "Enemy.h" + +Enemy::Enemy() { + +} + +void Enemy::init() { // Once an enemy has been created it writes nothing new until it dies +} + +int Enemy::write(int enemy_true, int map_x1, int map_y1) { // use collision mechanic to re-draw if both enemies are in 1 location + if (enemy_true == -1) { + return -1; + } else if (enemy_true == 0) { // create new enemy only if required + random_position(); + _x = map_x1 + 42 + _col * 20; // x pos of left wall + screen width / 2 + x pos of enemy + _y = map_y1 + 24 + _row * 10; // y pos of left wall + screen height / 2 + y pos of enemy + return 1; + } else { + return 1; + } +} + +void Enemy::draw(N5110 &lcd) { + lcd.drawCircle( _x, _y, 10, FILL_BLACK); + + + /* + int enemy[10][20] = { + {0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0}, + {0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,0,0,0}, + {0,0,1,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,0,0}, + {1,1,1,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,1}, + {1,1,1,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,1}, + {0,0,1,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,0,0}, + {0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,1,0,0,0,0}, + {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}, + }; + lcd.drawSprite( _x, _y, 20, 10, (int *)enemy); + */ +} + +void Enemy::random_position() { // finds random postion for enemy out of 50 options + _col = rand() % 5; + _row = rand() % 10; + // spacesi = _row * 5 + _col; :: int Shows space 0 - 49. Could be useful. +}