-
Notifications
You must be signed in to change notification settings - Fork 0
/
PongInvaders.h
110 lines (79 loc) · 2 KB
/
PongInvaders.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef PONGINVADERS_H
#define PONGINVADERS_H
#define ALLEGRO_STATICLINK
#include "allegro5/allegro.h"
#include "allegro5/allegro_native_dialog.h"
#include "allegro5/allegro_ttf.h"
#include "allegro5/allegro_font.h"
#include "allegro5/allegro_primitives.h"
#include "allegro5/allegro_image.h"
#include <vector>
#include <time.h>
#include <cmath>
#include <iostream>
#include <string>
#define DISPLAY_WIDTH 1280
#define DISPLAY_HEIGHT 720
class Egg
{
public:
/* Generates an egg at random position on the screen */
Egg();
int get_x() const {return cx;}
int get_y() const {return cy;}
/* Draws the egg with the Allegro library */
void draw();
/* Returns coordinates at the center of the egg */
std::vector<int> get_coord();
protected:
// radii
int rx, ry;
// center
int cx, cy;
std::vector<int> egg_info;
ALLEGRO_COLOR white = al_map_rgb(255,255,255);
ALLEGRO_COLOR black = al_map_rgb(0,0,0);
};
class Ball: public Egg
{
public:
/* Does the same thing the Egg() constructor does, and defines more variables */
Ball();
int get_radius() const {return rx;}
/* Increases the values of cx and cy by spd_x and spd_y */
void update();
/* Changes velocity based on parameter given */
void hit_wall(int wall);
/* Increases the speed */
void incr_speed();
/* Draws the ball */
void draw();
protected:
float spd_x, spd_y;
};
class Enemy: public Ball
{
public:
Enemy() {Ball(); rx = 30; enemy_bmp = al_load_bitmap("enemy.gif");}
void draw();
private:
ALLEGRO_BITMAP* enemy_bmp;
};
class Laser
{
public:
Laser(int paddle_x, int paddle_y);
int get_y1() const {return y1;}
int get_x2() const {return x2;}
int get_y2() const {return y2;}
/* Adds the value of each speed to each coordinate */
void update();
void draw();
private:
int x1, y1, x2, y2;
float spd_x, spd_y;
int len;
int line_thickness;
ALLEGRO_COLOR red = al_map_rgb(255,50,50);
};
#endif // PONGINVADERS_H