2018-05-22 12:40:25 +02:00
|
|
|
unit platformplayer;
|
|
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
Classes, SysUtils, gl,glext,glu, globals, gameobject, renderobject, graphics,
|
|
|
|
|
gameobjectwithhealth, healthbar;
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TPlatformPlayer=class(TGameObject)
|
|
|
|
|
private
|
2018-05-22 15:48:39 +02:00
|
|
|
instances: integer;
|
|
|
|
|
ftexture: integer; static;
|
2018-05-22 12:40:25 +02:00
|
|
|
fwidth: single;
|
|
|
|
|
fheight: single;
|
2018-05-22 15:48:39 +02:00
|
|
|
//animationpos: integer;
|
2018-05-22 12:40:25 +02:00
|
|
|
protected
|
|
|
|
|
function getWidth:single; override;
|
|
|
|
|
function getHeight:single; override;
|
|
|
|
|
function getTexture: integer; override;
|
|
|
|
|
public
|
2018-05-22 15:48:39 +02:00
|
|
|
constructor create;
|
2018-05-22 12:40:25 +02:00
|
|
|
destructor destroy; override;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
function TPlatformPlayer.getWidth:single;
|
|
|
|
|
begin
|
2018-05-22 15:48:39 +02:00
|
|
|
result:=0.06;
|
2018-05-22 12:40:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TPlatformPlayer.getHeight:single;
|
|
|
|
|
begin
|
2018-05-22 15:48:39 +02:00
|
|
|
result:=0.15;
|
2018-05-22 12:40:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TPlatformPlayer.getTexture: integer;
|
|
|
|
|
begin
|
2018-05-22 15:48:39 +02:00
|
|
|
result:=ftexture; //todo: animate
|
2018-05-22 12:40:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
constructor TPlatformPlayer.create;
|
2018-05-22 12:40:25 +02:00
|
|
|
var img: tpicture;
|
|
|
|
|
pp: pointer;
|
|
|
|
|
begin
|
|
|
|
|
inherited create;
|
|
|
|
|
|
|
|
|
|
CollisionType:=ctUnrotatedRectangles;
|
|
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
glGenTextures(1, @ftexture);
|
2018-05-22 12:40:25 +02:00
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
img:=tpicture.Create;
|
|
|
|
|
img.LoadFromFile(assetsfolder+'platformplayer.png');
|
2018-05-22 12:40:25 +02:00
|
|
|
|
|
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D, ftexture);
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2018-05-22 12:40:25 +02:00
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, @pixels[0]);
|
|
|
|
|
pp:=img.BITMAP.RawImage.Data;
|
2018-05-22 12:40:25 +02:00
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.Width, img.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pp);
|
2018-05-22 12:40:25 +02:00
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2018-05-22 12:40:25 +02:00
|
|
|
|
2018-05-22 15:48:39 +02:00
|
|
|
img.free;
|
2018-05-22 12:40:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TPlatformPlayer.destroy;
|
|
|
|
|
begin
|
2018-05-22 15:48:39 +02:00
|
|
|
dec(instances);
|
|
|
|
|
if instances=0 then //destroy the texture
|
2018-05-22 12:40:25 +02:00
|
|
|
glDeleteTextures(1,@ftexture);
|
|
|
|
|
|
|
|
|
|
inherited destroy;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|