summaryrefslogtreecommitdiff
path: root/engine/stage.cpp
blob: 53d7f59fe7be0f418732183628102e263cc70509 (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
#include "stage.h"

#include "texturesdl.h"

#include <SDL/SDL_opengl.h>
#include <cmath>

Stage::Stage() {
	player = new Player();
	
	texture = new TextureSDL("textures/shot1.png");
	shader = new GLShaderProgram();
	
	enemy_list.push_back(new Enemy(Vector2(0.25, 0.75)));
	enemy_list.push_back(new Enemy(Vector2(0.75, 0.75)));
	
	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)));
	
	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<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
		(*it)->update();
	}
}

void Stage::draw() {
	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);
	glBindTexture(GL_TEXTURE_2D, texture->tex());
	
	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);
}