Skip to content

Commit

Permalink
Some more work, like stopping at the end and a round ball!
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed Jul 15, 2009
1 parent a0887a4 commit 62f01f3
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 206 deletions.
32 changes: 16 additions & 16 deletions ausgabe.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ausgabe is
Port ( X : in integer range 0 to 640;
Y : in integer range 0 to 480;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
rgb_out: out STD_LOGIC_VECTOR (2 downto 0);
Y : in integer range 0 to 480;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
rgb_out: out STD_LOGIC_VECTOR (2 downto 0);
clk25 : in bit);
end ausgabe;

architecture Behavioral of ausgabe is

begin

process
begin
if X < 640 and X > 0 then
if Y < 480 and Y >= 0 then
rgb_out <= rgb_in(0) & rgb_in(1) & rgb_in(2); -- just make it, so that
else -- R,G,B comes in that order
rgb_out <= "000";
end if;
begin

process
begin
if X < 640 and X > 0 then
if Y < 480 and Y >= 0 then
rgb_out <= rgb_in(0) & rgb_in(1) & rgb_in(2); -- just make it, so that
else -- R,G,B comes in that order
rgb_out <= "000";
end if;
else
rgb_out <= "000";
end if;
end process;
rgb_out <= "000";
end if;
end process;

end Behavioral;

68 changes: 34 additions & 34 deletions background.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,60 @@ use IEEE.STD_LOGIC_UNSIGNED.ALL;
--use UNISIM.VComponents.all;

entity background is
Port (
switch : in bit;
Port (
switch : in bit;
X : in integer range 0 to 640;
Y : in integer range 0 to 480;
rgb_out : out STD_LOGIC_VECTOR (2 downto 0);
clk25 : in bit);
end background;

architecture Behavioral of background is

architecture Behavioral of background is

component farbwechsel
Port (
X : in integer range 0 to 640;
Y : in integer range 0 to 480;
rgb_out : out STD_LOGIC_VECTOR (2 downto 0);
clk25 : in bit);
end component;
end component;

signal chosen_background : STD_LOGIC_VECTOR (2 downto 0);
signal rgbs : STD_LOGIC_VECTOR (23 downto 0);
signal will_switch : bit;
signal count_up : integer range 0 to 25000000;
signal chosen_background : STD_LOGIC_VECTOR (2 downto 0);
signal rgbs : STD_LOGIC_VECTOR (23 downto 0);
signal will_switch : bit;
signal count_up : integer range 0 to 6250000;
begin


farbw : farbwechsel port map (
X => X,
Y => Y,
rgb_out => rgbs(23 downto 21),
clk25 => clk25);

rgbs(20 downto 18) <= "111";

process
begin
if clk25'event and clk25 = '1' then
clk25 => clk25);

rgbs(20 downto 18) <= "111";

process
begin
if clk25'event and clk25 = '1' then
if switch = '1' then
will_switch <= '1';
end if;
count_up <= count_up + 1;
if count_up = 25000000 then
if will_switch = '1' then
chosen_background <= chosen_background + "001";
will_switch <= '0';
end if;
count_up <= 0;
end if;
end if;

case chosen_background is
when "000" => rgb_out <= rgbs(23 downto 21); --farbwechsel
when "001" => rgb_out <= rgbs(20 downto 18); --weiss
when others => rgb_out <= "000"; --schwarz
end case;
end process;
end if;
count_up <= count_up + 1;
if count_up = 6250000 then
if will_switch = '1' then
chosen_background <= chosen_background + "001";
will_switch <= '0';
end if;
count_up <= 0;
end if;
end if;

case chosen_background is
when "000" => rgb_out <= rgbs(23 downto 21); --farbwechsel
when "001" => rgb_out <= rgbs(20 downto 18); --weiss
when others => rgb_out <= "000"; --schwarz
end case;
end process;

end Behavioral;

84 changes: 43 additions & 41 deletions balken.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ entity balken is
Y : in integer range 0 to 480;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
rgb_out : out STD_LOGIC_VECTOR (2 downto 0);
clk25 : in bit);
clk25 : in bit;
reset : in bit);
end balken;

architecture Behavioral of balken is
signal ldir,rdir : bit;
signal ltop,rtop : integer range 0 to 480 := 200;
signal countUp : integer range 0 to 208000 := 0;
signal ltop,rtop : integer range 0 to 480 := 215;
signal countUp : integer range 0 to 156000 := 0;
signal hold : bit_vector (1 downto 0);
begin

bar_left <= ltop;
Expand All @@ -51,55 +52,56 @@ begin
begin
rgb_out <= rgb_in;

if X < 20
if X < 20
and X > 4
and Y > ltop
and Y < (ltop + 50) then
rgb_out <= "100";
end if;

if X > 619
if X > 619
and X < 635
and Y > rtop
and Y < (rtop + 50) then
rgb_out <= "010";
end if;
end if;

if clk25'event and clk25='1' then --for movement
countUp <= countUp + 1;
if countUp = 208000 then

if buttons(0) = '1' then
rdir <= not rdir;
end if;
if buttons(1) = '1' then
ldir <= not ldir;
end if;

if rtop = 1 then
rdir <= '1';
end if;
if rtop = 430 then
rdir <= '0';
end if;

if ltop = 1 then
ldir <= '1';
end if;
if ltop = 430 then
ldir <= '0';
end if;

case ldir is
when '0' => ltop <= ltop - 1;
when '1' => ltop <= ltop + 1;
end case;

case rdir is
when '0' => rtop <= rtop - 1;
when '1' => rtop <= rtop + 1;
end case;
if countUp = 156000 then
hold <= "00";

-- move left
if (ltop < 2 and buttons(0) = '1')
or (ltop > 429 and buttons(0) = '0') then
hold(0) <= '1';
end if;
if hold(0) = '0' then
case buttons(0) is
when '0' => ltop <= ltop + 1;
when '1' => ltop <= ltop - 1;
end case;
end if;

-- move right
if (rtop < 2 and buttons(1) = '1')
or (rtop > 429 and buttons(1) = '0') then
hold(1) <= '1';
end if;
if hold(1) = '0' then
case buttons(1) is
when '0' => rtop <= rtop + 1;
when '1' => rtop <= rtop - 1;
end case;
end if;

countUp <= 0;
countUp <= 0;
end if;
end if;

if reset = '1' then
rtop <= 215;
ltop <= 215;
end if;
end process;

Expand Down
80 changes: 54 additions & 26 deletions ball.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,71 @@ use IEEE.STD_LOGIC_UNSIGNED.ALL;
--use UNISIM.VComponents.all;

entity ball is
Port ( bar_left : in integer range 0 to 430;
Port ( hold : in bit;
bar_left : in integer range 0 to 430;
bar_right : in integer range 0 to 430;
X : in integer range 0 to 640;
Y : in integer range 0 to 480;
game_over : out bit;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
rgb_out : out STD_LOGIC_VECTOR (2 downto 0);
clk25 : in bit);
clk25 : in bit;
reset : in bit);
end ball;

architecture Behavioral of ball is
signal lr : bit := '0'; --left/right
signal ud : bit := '1'; --up/down
signal x_pos : integer range 0 to 640 := 200;
signal y_pos : integer range 0 to 480 := 200;
signal countUp : integer range 0 to 312500 := 0;
signal x_pos : integer range 0 to 640 := 320;
signal y_pos : integer range 0 to 480 := 240;
signal deltaX, deltaY : integer range 0 to 640;
signal countUp : integer range 0 to 208000 := 0;
signal gameOver : bit;
begin

process
begin
rgb_out <= rgb_in;

if (x_pos > X) then
deltaX <= x_pos - X;
else
deltaX <= X - x_pos;
end if;
if (y_pos > Y) then
deltaY <= y_pos - Y;
else
deltaY <= Y - y_pos;
end if;

if X > (x_pos - 4) and (X < x_pos + 4)
and Y > (y_pos - 4) and (Y < y_pos + 4) then
if ((deltaY * deltaY) + (deltaX * deltaX)) < 16 then
rgb_out <= "001";
end if;

if clk25'event and clk25='1' then --for movement
countUp <= countUp + 1;
if countUp = 312500 then
gameOver <= reset;
if countUp = 208000 then

if x_pos < 23 then
if (bar_left < y_pos
and bar_left + 50 > y_pos) then
lr <= '1';
lr <= '1';
else
x_pos <= 200;
y_pos <= 200;
if x_pos < 5 then
gameOver <= '1';
end if;
end if;
end if;
end if;

if x_pos > 615 then
if (bar_right < y_pos
and bar_right + 50 > y_pos) then
lr <= '0';
else
x_pos <= 200;
y_pos <= 200;
if x_pos > 635 then
gameOver <= '1';
end if;
end if;
end if;

Expand All @@ -85,18 +103,28 @@ begin
ud <= '0';
end if;

case lr is
when '0' => x_pos <= x_pos - 1;
when '1' => x_pos <= x_pos + 1;
end case;

case ud is
when '0' => y_pos <= y_pos - 1;
when '1' => y_pos <= y_pos + 1;
end case;
if hold = '0' then
case lr is
when '0' => x_pos <= x_pos - 1;
when '1' => x_pos <= x_pos + 1;
end case;

case ud is
when '0' => y_pos <= y_pos - 1;
when '1' => y_pos <= y_pos + 1;
end case;
end if;

countUp <= 0;
end if;
countUp <= 0;
end if;
end if;

if gameOver = '1' then
x_pos <= 320;
y_pos <= 240;
game_over <= '1';
else
game_over <= '0';
end if;
end process;

Expand Down
Loading

0 comments on commit 62f01f3

Please sign in to comment.