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: Map/Map.cpp
- Revision:
- 7:0af4ced868f5
- Parent:
- 6:12e8433382b3
- Child:
- 8:dd1037c5435b
--- a/Map/Map.cpp Thu Apr 16 16:25:53 2020 +0000
+++ b/Map/Map.cpp Sat Apr 18 16:36:52 2020 +0000
@@ -1,5 +1,8 @@
#include "Map.h"
+#define MAP_TERRIAN_Y_POSITION 42
+AnalogIn adc(PTD5);
+Serial usb(USBTX, USBRX);
Map::Map() {
}
@@ -9,12 +12,60 @@
}
void Map::init() {
- position_x_map_ = 0;
- position_y_map_ = 48;
+ position_x_map_ = -96;
+ position_y_map_ = MAP_TERRIAN_Y_POSITION;
+ get_random_hight_array();
+ get_random_length_array();
+ //usb.printf("randome seed = %f\n", rand_seed_);
}
-
+
+void Map::get_random_hight_array(){
+ srand(adc.read()*64000);
+ for(int i = 0; i < 12; i++){
+ rand_hights_[i]= rand() % 8 + 5;
+ }
+ //printf loop to check correct random numbers are genreated
+ //for (int i = 0; i < 12; i++){
+ //usb.printf("map hight random array = %d\n", rand_hights_[i]);
+ //}
+}
+
+void Map::get_random_length_array(){
+ srand(adc.read()*64000);
+ for(int i = 0; i < 12; i++){
+ rand_lengths_[i]= rand() % 16+ 15;
+ }
+}
-void Map::draw_triangle(N5110 &lcd){
- lcd.drawLine(0,48,5,43,1);
- lcd.drawLine(5,43,10,48,1);
-}
\ No newline at end of file
+void Map::draw_triangle(N5110 &lcd,int triangle_hight){
+ // draws triangle by drawing two lines with one line having negative gadient
+ lcd.drawLine(position_x_map_, position_y_map_, position_x_map_ + triangle_hight, position_y_map_ - triangle_hight,1);
+ lcd.drawLine(position_x_map_ + triangle_hight, position_y_map_ - triangle_hight,position_x_map_ + 2*triangle_hight,position_y_map_,1);
+ position_x_map_ = position_x_map_ + 2*triangle_hight,position_y_map_;
+}
+
+void Map::draw_line(N5110 &lcd,int line_length){
+ // draws triangle by drawing two lines with one line having negative gadient
+ lcd.drawLine(position_x_map_, position_y_map_, position_x_map_ + line_length, position_y_map_,1);
+ position_x_map_ = position_x_map_ + line_length;
+}
+
+void Map::draw_map(N5110 &lcd, int move_map){
+ usb.printf("position_x_map_ = %d\n", position_x_map_);
+ usb.printf("move map = %d\n", move_map);
+ int reset_position_x_map_to_origonal = position_x_map_;
+ for(int i = 0; i < 12; i++){
+ draw_triangle(lcd,rand_hights_[i]);
+ draw_line(lcd,rand_lengths_[i]);
+ }
+ position_x_map_ = reset_position_x_map_to_origonal + move_map;
+}
+
+int Map::get_position_x_map(){
+ return position_x_map_;
+}
+
+void Map::clear_map(N5110 &lcd){
+ // Clears spaceship from LCD by drawing a white sprite
+ lcd.drawRect(0, 0, 84, 48 , FILL_WHITE);
+}