Blame |
Last modification |
View Log
| RSS feed
unit app_glscene_board;
interface
uses OpenGL, GLaux, glExt, sux_constant, sux_object, app_constant,
resource_texture, resource_shader, app_entity_main,
resource_list, app_glscene_board_monkey, app_particle_vertexbuffer;
type
TSettings=record
paddle:SRTexture;
ball:SRTexture;
board:SRTexture;
wallimpact:SRTexture;
paddleimpact:SRTexture;
trail:SRTexture;
warp:SRTexture;
monkey:SRTexture;
banana: SRTexture;
monkeyspeed:SXFloat;
crystal: SRTexture;
ballsparks: SRTexture;
shards: array[1..5] of SRTexture;
icon: SRTexture;
icon_pixel: SRTexture;
icon_flowers: SRTexture;
icon_slowmotion: SRTexture;
icon_createcrystals: SRTexture;
icon_concave: SRTexture;
icon_bomb: SRTexture;
flower: SRTexture;
flowerpower: SRTexture;
monkeycount: SXInt;
bananacount: SXInt;
vertexbuffermonkeys: SAPVertexBuffer;
vertexbufferbananas: SAPVertexBuffer;
end;
SAGLSBoard=class(SUXObject)
settings:TSettings;
monkeys:SRList;
procedure setMonkeyRotationSpeed(speed:SXFloat);
procedure createMonkeys;
procedure renderEntities;
procedure renderParticleSystems;
procedure renderBackGround;
procedure renderMonkeys;
procedure onTimer;
procedure initialize;
constructor Create(parent:TObject);
destructor Destroy; override;
end;
implementation
uses sux_main, gl_main, main;
// --- SAGLSBoard
procedure SAGLSBoard.setMonkeyRotationSpeed(speed:SXFloat);
begin
settings.monkeyspeed:=sx.timer.getTimer(speed*0.08);
end;
procedure SAGLSBoard.createMonkeys;
var x,y:SXInt;
monkey:SAGLSBMonkey;
pos:SXVertex2D;
interval:SXVertex2D;
i: SXInt;
begin
interval.x:=840/10;
interval.y:=680/8;
settings.monkeycount := 0;
settings.bananacount := 0;
for i := 0 to 1 do
for x := 0 to 9 do
for y := 0 to 7 do
if ((odd(x) = odd(y)) and (i = 0)) or ((odd(x) = not odd(y)) and (i = 1)) then
begin
pos.x := -100+interval.x*x+sx.math.random.getRandomFloat(0,interval.x);
pos.y := -100+interval.y*y+sx.math.random.getRandomFloat(0,interval.y);
monkey:=SAGLSBMonkey.Create(pos,sx.math.random.getRandomFloat(0,360),
sx.math.random.getRandomFloat(70,100),sx.math.random.getRandomFloat(0.7,1.0));
case i of
0 : monkey.setTexture(settings.monkey);
1 : monkey.setTexture(settings.banana);
end;
monkeys.addObject(monkey);
case i of
0 : inc(settings.monkeycount);
1 : inc(settings.bananacount);
end;
end;
settings.vertexbuffermonkeys.setVertexCount(settings.monkeycount * 4);
settings.vertexbufferbananas.setVertexCount(settings.bananacount * 4);
end;
procedure SAGLSBoard.renderEntities;
var e:SXInt;
begin
// Set up a coordinate system for the entities where the center
// of the field is (0,0).
glPushMatrix;
glTranslatef(320,260,0);
with app.game do
begin
for e:=0 to entities.getMax do getEntity(e).onRender;
end;
glPopMatrix;
end;
procedure SAGLSBoard.renderParticleSystems;
var p:SXInt;
begin
// Set up a coordinate system for the entities where the center
// of the field is (0,0).
glPushMatrix;
glTranslatef(320,260,0);
with app.game do
begin
for p:=0 to particlesystems.getMax do getParticleSystem(p).onRender;
end;
glPopMatrix;
end;
procedure SAGLSBoard.renderBackGround;
var center,size:SXVertex2D;
begin
center:=sx.convert.Vertex2DOf(320, 260);
size:=sx.convert.Vertex2DOf(280, 280);
// Render black quads.
gl.gl2D.renderRectangle(0, 0, center.x - size.x, 480, SX_GL_BLEND_OPAQUE,
sx.convert.ColorRGBOf(0, 0, 0), 1);
gl.gl2D.renderRectangle(center.x + size.x, 0, 640, 480, SX_GL_BLEND_OPAQUE,
sx.convert.ColorRGBOf(0, 0, 0), 1);
gl.gl2D.renderRectangle(0, center.y + size.y - 80, 640, 700, SX_GL_BLEND_OPAQUE,
sx.convert.ColorRGBOf(0, 0, 0), 1);
gl.gl2D.renderRectangle(center.x-size.x,center.y-size.y,center.x+size.x,center.y+size.y,settings.board,
SX_GL_BLEND_AVERAGE,sx.convert.ColorRGBOf(1,1,1),1);
end;
procedure SAGLSBoard.renderMonkeys;
var m:SXInt;
monkey: SAGLSBMonkey;
flowermode: SXBool;
begin
flowermode := (app.game.settings.effects.flowers > 0);
gl.material.resetMaterial;
gl.material.setMaterial2D;
gl.material.setMaterialBlending(SX_GL_BLEND_ADDITIVE,sx.convert.ColorRGBOf(1,1,1),1);
gl.material.setMaterialShader(app.scene.scene.particle, nil);
gl.material.renderMaterial;
if (flowermode) then gl.texture.setTexture(settings.flower);
glPushMatrix;
if (not flowermode) then gl.texture.setTexture(settings.monkey);
for m := 0 to settings.monkeycount - 1 do
begin
monkey := SAGLSBMonkey(monkeys.getObject(m));
monkey.renderMonkey(settings.vertexbuffermonkeys, m);
end;
settings.vertexbuffermonkeys.onRender;
if (not flowermode) then gl.texture.setTexture(settings.banana);
for m := settings.monkeycount to monkeys.getMax do
begin
monkey := SAGLSBMonkey(monkeys.getObject(m));
monkey.renderMonkey(settings.vertexbufferbananas, m - settings.monkeycount);
end;
settings.vertexbufferbananas.onRender;
glPopMatrix;
if (not flowermode) then
begin
gl.gl2D.renderRectangle(0,0,640,480,SX_GL_BLEND_NEGATIVEINVERT,sx.convert.ColorRGBOf(1,1,1),0.13);
end else
begin
gl.gl2D.renderRectangle(0,0,640,480,SX_GL_BLEND_NEGATIVEINVERT,sx.convert.ColorRGBOf(1,1,1),0.25);
end;
end;
procedure SAGLSBoard.onTimer;
begin
renderMonkeys;
renderEntities;
renderParticleSystems;
renderBackGround;
app.scene.postprocess.onTimer;
end;
procedure SAGLSBoard.initialize;
var s: SXInt;
begin
settings.paddle:=SRTexture.Create('textures\objects\paddle',self);
settings.ball:=SRTexture.Create('textures\objects\ball',self);
settings.board:=SRTexture.Create('textures\objects\board',self);
settings.wallimpact:=SRTexture.Create('textures\objects\wallimpact',self);
settings.paddleimpact:=SRTexture.Create('textures\objects\paddleimpact',self);
settings.trail:=SRTexture.Create('textures\objects\trail',self);
settings.warp:=SRTexture.Create('textures\objects\warp',self);
settings.monkey:=SRTexture.Create('textures\objects\monkey',self);
settings.banana := SRTexture.Create('textures\objects\banana',self);
settings.crystal := SRTexture.Create('textures\objects\crystal', self);
settings.ballsparks := SRTexture.Create('textures\particles\ballsparks', self);
for s := 1 to 5 do settings.shards[s] := SRTexture.Create('textures\particles\shard' + sx.convert.intToStr(s), self);
settings.icon := SRTexture.Create('textures\objects\icon', self);
settings.icon_pixel := SRTexture.Create('textures\objects\icon_chess', self);
settings.icon_flowers := SRTexture.Create('textures\objects\icon_flower', self);
settings.icon_slowmotion := SRTexture.Create('textures\objects\icon_hourglass', self);
settings.icon_createcrystals := SRTexture.Create('textures\objects\icon_crystal', self);
settings.icon_concave := SRTexture.Create('textures\objects\icon_concave', self);
settings.icon_bomb := SRTexture.Create('textures\objects\icon_bomb', self);
settings.flower := SRTexture.Create('textures\objects\flower', self);
settings.flowerpower := SRTexture.Create('textures\objects\flowerpower', self);
settings.vertexbuffermonkeys := SAPVertexBuffer.Create;
settings.vertexbufferbananas := SAPVertexBuffer.Create;
createMonkeys;
end;
constructor SAGLSBoard.Create(parent:TObject);
begin
inherited Create(parent,'GL Board');
monkeys:=SRList.Create(self,false,true,false);
setMonkeyRotationSpeed(0);
end;
destructor SAGLSBoard.Destroy;
var s: SXInt;
begin
monkeys.Free;
settings.paddle.Free;
settings.ball.Free;
settings.board.Free;
settings.wallimpact.Free;
settings.paddleimpact.Free;
settings.trail.Free;
settings.warp.Free;
settings.monkey.Free;
settings.banana.Free;
settings.crystal.Free;
settings.ballsparks.Free;
for s := 1 to 5 do settings.shards[s].Free;
settings.icon.Free;
settings.icon_pixel.Free;
settings.icon_flowers.Free;
settings.icon_slowmotion.Free;
settings.icon_createcrystals.Free;
settings.icon_concave.Free;
settings.icon_bomb.Free;
settings.flower.Free;
settings.flowerpower.Free;
settings.vertexbuffermonkeys.Free;
settings.vertexbufferbananas.Free;
inherited;
end;
end.