Cleaning up the animation for the "bird"
This is still just exploratory really. No where close to anything worthwhile
This commit is contained in:
parent
cd6d9e87ee
commit
43031413a7
|
@ -78,6 +78,7 @@ package body Flappybit.LCD is
|
|||
Y => 0,
|
||||
Width => Width,
|
||||
Height => Height);
|
||||
|
||||
Initialized := True;
|
||||
|
||||
end Initialize;
|
||||
|
@ -102,4 +103,5 @@ package body Flappybit.LCD is
|
|||
Screen.Update_Layers;
|
||||
end Update;
|
||||
|
||||
|
||||
end Flappybit.LCD;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
with HAL.Bitmap; use HAL.Bitmap;
|
||||
|
||||
package body Flappybit.Sprites is
|
||||
|
||||
function Height (B : in Bird) return Positive is
|
||||
|
@ -16,13 +18,52 @@ package body Flappybit.Sprites is
|
|||
begin
|
||||
return (B.X, B.y);
|
||||
end Position;
|
||||
|
||||
procedure Tick (B : in Bird) is
|
||||
|
||||
|
||||
procedure Set_Position (B : in out Bird; Origin : in Point) is
|
||||
begin
|
||||
B.X := Origin.X;
|
||||
B.Y := Origin.Y;
|
||||
end Set_Position;
|
||||
|
||||
procedure Tick (B : in out Bird) is
|
||||
begin
|
||||
|
||||
B.Buffer.Set_Source (B.Color);
|
||||
B.Buffer.Fill_Rect (((B.X, B.Y), B.Width, B.Height));
|
||||
|
||||
if B.Y = 150 then
|
||||
B.Trajectory := Right;
|
||||
elsif B.Y = 0 then
|
||||
B.Trajectory := Left;
|
||||
end if;
|
||||
|
||||
if B.Trajectory = Left then
|
||||
-- Erase before drawing a little bit anew
|
||||
B.Buffer.Set_Source (Transparent);
|
||||
B.Buffer.Draw_Line (
|
||||
(B.X, B.Y),
|
||||
((B.X + B.Height), B.Y)
|
||||
);
|
||||
-- Move across the screen in one direction for now
|
||||
B.Y := B.Y + 1;
|
||||
end if;
|
||||
|
||||
if B.Trajectory = Right then
|
||||
-- Erase before drawing a little bit anew
|
||||
B.Buffer.Set_Source (Transparent);
|
||||
B.Buffer.Draw_Line (
|
||||
(B.X, B.Y + B.Width),
|
||||
((B.X + B.Height), B.Y + B.Width)
|
||||
);
|
||||
-- Move across the screen in one direction for now
|
||||
B.Y := B.Y - 1;
|
||||
end if;
|
||||
|
||||
end Tick;
|
||||
|
||||
procedure Set_Framebuffer (B : in out Bird; Buffer : in HAL.Bitmap.Any_Bitmap_Buffer) is
|
||||
procedure Set_Framebuffer (B : in out Bird;
|
||||
Buffer : in HAL.Bitmap.Any_Bitmap_Buffer) is
|
||||
begin
|
||||
B.Buffer := Buffer;
|
||||
end Set_Framebuffer;
|
||||
|
|
|
@ -5,12 +5,15 @@ with Flappybit;
|
|||
|
||||
package Flappybit.Sprites is
|
||||
|
||||
type Direction is (Left, Right, Up, Down);
|
||||
|
||||
type Bird is new Flappybit.Sprite with private;
|
||||
function Height (B : in Bird) return Positive;
|
||||
function Width (B : in Bird) return Positive;
|
||||
function Position (B : in Bird) return Point;
|
||||
procedure Set_Position (B : in out Bird; Origin : in Point);
|
||||
|
||||
procedure Tick (B : in Bird);
|
||||
procedure Tick (B : in out Bird);
|
||||
procedure Set_Framebuffer (B : in out Bird; Buffer : in HAL.Bitmap.Any_Bitmap_Buffer);
|
||||
|
||||
private
|
||||
|
@ -18,6 +21,7 @@ private
|
|||
type Bird is new Flappybit.Sprite with record
|
||||
Buffer : HAL.Bitmap.Any_Bitmap_Buffer;
|
||||
Alive : Boolean := True;
|
||||
Trajectory : Direction := Left;
|
||||
Color : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.Blue;
|
||||
X : Natural;
|
||||
Y : Natural;
|
||||
|
|
|
@ -8,13 +8,19 @@ package Flappybit is
|
|||
Y : Natural;
|
||||
end record;
|
||||
|
||||
type Rectangle is record
|
||||
Origin : Point;
|
||||
Width : Positive;
|
||||
Height : Positive;
|
||||
end record;
|
||||
|
||||
type Sprite is interface;
|
||||
|
||||
function Height (S : in Sprite) return Positive is abstract;
|
||||
function Width (S : in Sprite) return Positive is abstract;
|
||||
function Position (S : in Sprite) return Point is abstract;
|
||||
|
||||
procedure Tick (S : in Sprite) is abstract;
|
||||
procedure Tick (S : in out Sprite) is abstract;
|
||||
-- Perform the Sprite's "work" during the runloop
|
||||
|
||||
procedure Set_Framebuffer (S : in out Sprite; Framebuffer : in HAL.Bitmap.Any_Bitmap_Buffer ) is abstract;
|
||||
|
|
53
src/main.adb
53
src/main.adb
|
@ -6,70 +6,21 @@ with HAL.Bitmap; use HAL.Bitmap;
|
|||
with Flappybit.Sprites;
|
||||
|
||||
procedure Main is
|
||||
|
||||
Bird : Flappybit.Sprites.Bird;
|
||||
|
||||
Center : Positive := 20;
|
||||
Background : constant Bitmap_Color := Black;
|
||||
Block : constant Bitmap_Color := Green;
|
||||
Size : constant := 5;
|
||||
P : Point := (2, 0);
|
||||
R : Rect := ( P, Size, 10 );
|
||||
Left_to_Right : Boolean := True;
|
||||
begin
|
||||
Initialize;
|
||||
--On;/
|
||||
|
||||
Framebuffer.Set_Source (Background);
|
||||
Framebuffer.Fill;
|
||||
Update;
|
||||
|
||||
Bird.Set_Framebuffer (Framebuffer);
|
||||
Bird.Set_Position ((0, 0));
|
||||
|
||||
loop
|
||||
Bird.TIck;
|
||||
|
||||
Update;
|
||||
Framebuffer.Set_Source (Block);
|
||||
Framebuffer.Fill_Rect (R);
|
||||
|
||||
if R.Position.Y = 150 then
|
||||
Left_to_Right := False;
|
||||
end if;
|
||||
|
||||
if R.Position.Y = 0 then
|
||||
Left_to_Right := True;
|
||||
end if;
|
||||
|
||||
|
||||
Framebuffer.Set_Source (Background);
|
||||
|
||||
if Left_to_Right then
|
||||
Framebuffer.Draw_Line (
|
||||
(R.Position.X + 0, R.Position.Y),
|
||||
(R.Position.X + Size, R.Position.Y) );
|
||||
R.Position.Y := R.Position.Y + 1;
|
||||
else
|
||||
Framebuffer.Draw_Line (
|
||||
(R.Position.X + 0, R.Position.Y + 10),
|
||||
(R.Position.X + Size, R.Position.Y + 10) );
|
||||
R.Position.Y := R.Position.Y - 1;
|
||||
end if;
|
||||
Update;
|
||||
|
||||
Framebuffer.Set_Source (Block);
|
||||
Framebuffer.Fill_Rect (R);
|
||||
Update;
|
||||
-- end if;
|
||||
|
||||
-- if State (Button_A) = Pressed then
|
||||
|
||||
-- Framebuffer.Set_Source (Hot_Pink);
|
||||
-- Framebuffer.Fill_Circle ((Center, Center), 20);
|
||||
-- Center := (Center + 1);
|
||||
-- Update;
|
||||
-- end if;
|
||||
|
||||
-- MicroBit.Time.Delay_Ms (1);
|
||||
end loop;
|
||||
|
||||
end Main;
|
||||
|
|
Loading…
Reference in New Issue