Simple implementation of polygons, you can create them in the init and draw them
This commit is contained in:
parent
7a5bf13575
commit
9fd87b7f29
4
Makefile
4
Makefile
@ -11,7 +11,7 @@ CXXFLAGS=-Wall -g -O2 $(PROFILING_CFLAGS) $(GTK_CFLAGS)
|
|||||||
LIBS=$(GTK_LIBS) -lm
|
LIBS=$(GTK_LIBS) -lm
|
||||||
|
|
||||||
PROGS=balls
|
PROGS=balls
|
||||||
OBJS=balls.o c_index.o game.o gravity.o spaceship.o main.o
|
OBJS=balls.o c_index.o game.o gravity.o spaceship.o main.o polygons.o
|
||||||
|
|
||||||
# dependencies (gcc -MM *.cc)
|
# dependencies (gcc -MM *.cc)
|
||||||
balls.o: balls.cc game.h balls.h vec2d.h gravity.h
|
balls.o: balls.cc game.h balls.h vec2d.h gravity.h
|
||||||
@ -24,7 +24,7 @@ stats.o: stats.cc
|
|||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run: balls
|
run: balls
|
||||||
./balls
|
./balls n=0
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
31
polygons.cc
Normal file
31
polygons.cc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "polygons.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
polygon* polygons = nullptr;
|
||||||
|
uint n_polygons = 1;
|
||||||
|
|
||||||
|
void polygons_init_state() {
|
||||||
|
polygons = new polygon[n_polygons];
|
||||||
|
|
||||||
|
polygon poly =
|
||||||
|
polygon{{400, 400}, 0, {{0, 0}, {0, 100}, {100, 100}, {100, 0}}};
|
||||||
|
polygons[0] = poly;
|
||||||
|
}
|
||||||
|
|
||||||
|
void polygon::draw(cairo_t* cr) const {
|
||||||
|
polygon& poly = polygons[0];
|
||||||
|
vec2d& center = poly.center;
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
|
||||||
|
cairo_move_to(cr, center.x, center.y);
|
||||||
|
for (auto& point : poly.points)
|
||||||
|
cairo_line_to(cr, center.x + point.x, center.y + point.y);
|
||||||
|
cairo_line_to(cr, center.x, center.y);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void polygons_draw(cairo_t* cr) {
|
||||||
|
for (const polygon* p = polygons; p != polygons + n_polygons; ++p)
|
||||||
|
p->draw(cr);
|
||||||
|
}
|
28
polygons.h
Normal file
28
polygons.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef POLYGONS_H_INCLUDED
|
||||||
|
#define POLYGONS_H_INCLUDED
|
||||||
|
|
||||||
|
// extern ball spaceship;
|
||||||
|
|
||||||
|
#include "vec2d.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class polygon {
|
||||||
|
public:
|
||||||
|
vec2d center;
|
||||||
|
double angle;
|
||||||
|
std::vector<vec2d> points;
|
||||||
|
|
||||||
|
void draw(cairo_t* cr) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern polygon* polygons;
|
||||||
|
extern uint n_polygons;
|
||||||
|
|
||||||
|
extern void polygons_init_state();
|
||||||
|
extern void polygons_update_state();
|
||||||
|
// extern void polygon_control (double dx, double dy);
|
||||||
|
extern void polygons_draw(cairo_t* cr);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user