summaryrefslogtreecommitdiff
path: root/engine/stage.cpp
blob: 9a5bedd07c89dbe8031632ec9730722e77feb9d7 (plain)
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
#include "stage.h"

#include "config.h"

#include <wriggle/texturestbi.h>

#include <wriggle/gl.h>
#include <cmath>

Stage::Stage() {
	background = new Background();
	
	player = new Player();
	
	texture = new TextureSTBI("textures/shot1.png");
	shader = new GLShaderProgram();
	
	enemy_list.push_back(new Enemy1(Vector2(0.25, 0.75), patterns));
	enemy_list.push_back(new Enemy1(Vector2(0.75, 0.75), patterns));
	enemy_list.push_back(new Enemy2(Vector2(0.50, 0.80), patterns));
	
	//patterns.push_back(new BulletPattern3(Vector2(0.5, 0.5)));
	//patterns.push_back(new BulletPattern1(Vector2(0.5, 0.8)));
	//patterns.push_back(new BulletPattern2(Vector2(0.2, 0.5)));
	//patterns.push_back(new BulletPattern2(Vector2(0.5, 0.5)));
	//patterns.push_back(new BulletPattern2(Vector2(0.8, 0.5)));
	//patterns.push_back(new BulletPattern4(Vector2(0.5, 0.8)));
	
	GLFragmentShader shader1("shaders/bullet_fragment.glsl");
	GLVertexShader shader2("shaders/bullet_vertex.glsl");
	shader->attach(shader1);
	shader->attach(shader2);
	shader->link();
}

void Stage::update() {
	player->update();

	for(std::vector<Enemy*>::iterator it = enemy_list.begin(); it < enemy_list.end(); it++) {
		(*it)->update();
	}
	
	for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
		(*it)->update();
	}
}

void Stage::draw() {
	background->draw();
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-0.5, 1.5, -Config::viewport_aspect * 0.5, Config::viewport_aspect * 1.5, 0, 10);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	player->draw();
	
	for(std::vector<Enemy*>::iterator it = enemy_list.begin(); it < enemy_list.end(); it++) {
		Enemy* enemy = (*it);
		enemy->draw();
	}
	
	shader->use();
	glPointSize(32.0);
	glEnable(GL_TEXTURE_2D);
	texture->bind();
	
	for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
		BulletPattern *bp = (*it);
		glColor3f(bp->color_r, bp->color_g, bp->color_b);
		bp->draw();
	}
	
	glUseProgram(0);
}