-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.h
70 lines (66 loc) · 1.61 KB
/
car.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include"./SDL2-2.0.10/include/SDL.h"
#include"./SDL2-2.0.10/include/SDL_main.h"
#include "sprite.h"
#include "map.h"
#define ACCELERATION 150
#define STEERING_FORCE 25
#define MAX_SPEED 1000
enum class CarType : char {
player,
civil,
enemy,
crashed,
crashedPlayer,
missile,
enemyMissile,
bomb,
enemyBomb,
explosion
};
enum class AmmoType : char {
missile,
bomb,
multiMissile,
laser
};
class Car : public Sprite {
protected:
double speed;
CarType type;
public:
Car(SDL_Surface* sprite, const int x, const int y, const double speed, CarType type = CarType::civil);
Car();
CarType GetType();
void SetType(CarType type);
void Crash(SDL_Surface* crashedSprite, CarType type = CarType::crashed);
void SetSpeed(double speed);
double GetSpeed();
void Update(const double delta, const double playerSpeed);
MapTile CheckForCollisionWithMap(const int screenWidth, const int screenHeight, Map* map);
void SaveToFile(FILE* file);
void LoadFromFile(FILE* file);
};
class Player : public Car {
private:
double moveBuffer = 0, speedBuffer = 0, delta = 0;
int ammo = 0; AmmoType ammoType = AmmoType::missile;
public:
Player(SDL_Surface* sprite, const int x, const int y, const double speed = 50 * ACCELERATION);
AmmoType Shoot();
double GetShootCooldown();
void Accelerate();
void Brake();
void Right();
void Left();
void Update(const double delta);
int GetAmmo();
void SetAmmo(int ammo);
AmmoType GetAmmoType();
void SetAmmoType(AmmoType ammoType);
double SteeringSpeed();
double AccelerationSpeed();
void Crash(SDL_Surface* crashedSprite);
void SaveToFile(FILE* file);
void LoadFromFile(FILE* file);
};