A basic Spidey hat, leave hat on when roping.
authornemo
Mon, 02 Nov 2009 18:24:58 +0000
changeset 2597 f777ac80ffef
parent 2596 41b46f83d088
child 2598 e118329666ff
A basic Spidey hat, leave hat on when roping.
hedgewars/uGears.pas
hedgewars/uStore.pas
share/hedgewars/Data/Graphics/Hats/spidey.png
--- a/hedgewars/uGears.pas	Sun Nov 01 17:19:55 2009 +0000
+++ b/hedgewars/uGears.pas	Mon Nov 02 18:24:58 2009 +0000
@@ -781,7 +781,7 @@
 var i, t: LongInt;
 	amt: TAmmoType;
 	hx, hy, cx, cy, tx, ty, sx, sy, m: LongInt;  // hedgehog, crosshair, temp, sprite, direction
-	lx, ly, dx, dy, ax, ay, aAngle, dAngle: real;  // laser, change
+	lx, ly, dx, dy, ax, ay, aAngle, dAngle, hAngle: real;  // laser, change
 	defaultPos, HatVisible: boolean;
     VertexBuffer: array [0..1] of TVertex2f;
 begin
@@ -928,10 +928,12 @@
 				if Gear^.X < CurAmmoGear^.X then
 					begin
 					dAngle:= 0;
+					hAngle:= 180;
 					i:= 1
 					end else
 					begin
 					dAngle:= 180;
+					hAngle:= 0;
 					i:= -1
 					end;
                 sx:= hwRound(Gear^.X) + WorldDx;
@@ -941,6 +943,10 @@
 						1,
 						0,
 						DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + dAngle);
+			    with PHedgehog(Gear^.Hedgehog)^ do
+                   if (HatTex <> nil) then
+					DrawRotatedTextureF(HatTex, 1.0, -1.0, -6.0, sx, sy, 0, i, 32,
+                        i*DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + hAngle);
 				defaultPos:= false
 				end;
 			gtBlowTorch: begin
@@ -1036,7 +1042,6 @@
         1,
         0);
 	HatVisible:= true;
-	HatVisible:= true;
 	defaultPos:= false
 	end else
 
--- a/hedgewars/uStore.pas	Sun Nov 01 17:19:55 2009 +0000
+++ b/hedgewars/uStore.pas	Mon Nov 02 18:24:58 2009 +0000
@@ -37,6 +37,7 @@
 procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture);
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt);
+procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
@@ -456,7 +457,64 @@
 begin
 glPushMatrix;
 glTranslatef(X, Y, 0);
-glScalef(Scale, Scale, 1.0);
+
+if Dir < 0 then
+	hw:= - 16
+else
+	hw:= 16;
+
+ft:= Frame / Frames * Texture^.ry;
+fb:= (Frame + 1) / Frames * Texture^.ry;
+
+glBindTexture(GL_TEXTURE_2D, Texture^.id);
+
+VertexBuffer[0].X:= -hw;
+VertexBuffer[0].Y:= -16;
+VertexBuffer[1].X:= hw;
+VertexBuffer[1].Y:= -16;
+VertexBuffer[2].X:= hw;
+VertexBuffer[2].Y:= 16;
+VertexBuffer[3].X:= -hw;
+VertexBuffer[3].Y:= 16;
+
+TextureBuffer[0].X:= 0;
+TextureBuffer[0].Y:= ft;
+TextureBuffer[1].X:= Texture^.rx;
+TextureBuffer[1].Y:= ft;
+TextureBuffer[2].X:= Texture^.rx;
+TextureBuffer[2].Y:= fb;
+TextureBuffer[3].X:= 0;
+TextureBuffer[3].Y:= fb;
+
+glEnableClientState(GL_VERTEX_ARRAY);
+glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
+glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
+glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+
+glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+glDisableClientState(GL_VERTEX_ARRAY);
+
+
+glPopMatrix
+end;
+
+procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
+var ft, fb: GLfloat;
+	hw: LongInt;
+    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
+begin
+glPushMatrix;
+glTranslatef(X, Y, 0);
+
+if Dir < 0 then
+   glRotatef(Angle, 0, 0, -1)
+else
+   glRotatef(Angle, 0, 0,  1);
+
+glTranslatef(Dir*OffsetX, OffsetY, 0);
+glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 if Dir < 0 then
 	hw:= - 16
Binary file share/hedgewars/Data/Graphics/Hats/spidey.png has changed