frhd/
lib.rs

1#![allow(dead_code)]
2
3// NOTE: This isn't working right now. Why? Good question.
4// TODO: Document my code so I can use it in the future.
5
6mod encode;
7mod entities;
8
9pub struct Track {
10    pub trackdata: String,
11    pub physical: Vec<String>,
12    pub scenery: Vec<String>,
13    pub powerups: String,
14}
15
16impl Track {
17    // Lines
18    pub fn insert_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, line_type: char) {
19        if line_type == 'p' {
20            self.physical.push(entities::Line{ line_type, x1, y1, x2, y2 }.encode());
21        } else {
22            self.scenery.push(entities::Line{ line_type, x1, y1, x2, y2 }.encode());
23        }
24    }
25    
26    // Powerups
27    pub fn insert_check(&mut self, x: i32, y: i32) {
28        self.powerups += &entities::Powerup { powerup_type: 'C', x, y, rotation: 999 }.encode();
29    }
30
31    pub fn insert_star(&mut self, x: i32, y: i32) {
32        self.powerups += &entities::Powerup { powerup_type: 'T', x, y, rotation: 999 }.encode();
33    }
34
35    pub fn insert_slow_mo(&mut self, x: i32, y: i32) {
36        self.powerups += &entities::Powerup { powerup_type: 'S', x, y, rotation: 999 }.encode();
37    }
38
39    pub fn insert_bomb(&mut self, x: i32, y: i32) {
40        self.powerups += &entities::Powerup { powerup_type: 'O', x, y, rotation: 999 }.encode();
41    }
42
43    pub fn insert_gravity(&mut self, x: i32, y: i32, rot: i32) {
44        self.powerups += &entities::Powerup { powerup_type: 'G', x, y, rotation: rot }.encode();
45    }
46    
47    pub fn insert_boost(&mut self, x: i32, y: i32, rot: i32) {
48        self.powerups += &entities::Powerup { powerup_type: 'B', x, y, rotation: rot }.encode();
49    }
50
51    pub fn insert_anti_gravity(&mut self, x: i32, y: i32) {
52        self.powerups += &entities::Powerup { powerup_type: 'A', x, y, rotation: 999 }.encode();
53    }
54
55    pub fn insert_teleport(&mut self, x1: i32, y1: i32, x2: i32, y2: i32) {
56        self.powerups += &entities::Teleport { x1, y1, x2, y2 }.encode();
57    }
58
59    // Vehicles
60    pub fn insert_helicopter(&mut self, x: i32, y: i32) {
61        self.powerups += &entities::Powerup { powerup_type: '1', x, y, rotation: 1000 }.encode();
62    }
63
64    pub fn insert_truck(&mut self, x: i32, y: i32) {
65        self.powerups += &entities::Powerup { powerup_type: '2', x, y, rotation: 1000 }.encode();
66    }
67
68    pub fn insert_balloon(&mut self, x: i32, y: i32) {
69        self.powerups += &entities::Powerup { powerup_type: '3', x, y, rotation: 1000 }.encode();
70    }
71
72    pub fn insert_blob(&mut self, x: i32, y: i32) {
73        self.powerups += &entities::Powerup { powerup_type: '4', x, y, rotation: 1000 }.encode();
74    }
75    
76    // Track code
77    pub fn generate_code(&mut self) -> String {
78        for physical_line in &self.physical {
79            self.trackdata += physical_line;
80        }
81
82        for scenery_line in &self.scenery {
83            self.trackdata += scenery_line;
84        }
85
86        let mut final_data = String::new();
87
88        for line in &self.physical {
89            final_data += line;
90        }
91
92        final_data += "#";
93
94        for line in &self.scenery {
95            final_data += line;
96        }
97
98        final_data += "#";
99        final_data += &self.powerups;
100        final_data += "#";
101
102        return final_data;
103    }
104}