Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 14:24:57 07/31/2014
  6. -- Design Name:
  7. -- Module Name: ball - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. entity ball is
  26.  
  27. Port ( v_sync : in STD_LOGIC;
  28. pixel_row : in STD_LOGIC_VECTOR(9 downto 0);
  29. pixel_col : in STD_LOGIC_VECTOR(9 downto 0);
  30. red : out STD_LOGIC;
  31. green : out STD_LOGIC;
  32. blue : out STD_LOGIC);
  33. end ball;
  34.  
  35. architecture Behavioral of ball is
  36. constant size: integer:=8;
  37. signal ball_on: STD_LOGIC;
  38. --indicates whether ball is over current pixel position
  39. --current ball position-intitialized to center of screen
  40. signal ball_x: STD_LOGIC_VECTOR(9 downto 0):= CONV_STD_LOGIC_VECTOR(320,10);
  41. signal ball_y: STD_LOGIC_VECTOR(9 downto 0):= CONV_STD_LOGIC_VECTOR(240,10);
  42.  
  43. --current ball motion-initialized to +4 pixels/frame
  44. signal ball_y_motion: STD_LOGIC_VECTOR(9 downto 0):= "0000001000";
  45. signal ball_x_motion: STD_LOGIC_VECTOR(9 downto 0):= "0000001000";
  46. begin
  47. blue <= '1';
  48. --color setup for red ball on white background
  49. green <= not ball_on;
  50. red <= not ball_on;
  51. --process to draw ball current pixel address is covered by ball position
  52. bdraw: process (ball_x, ball_y, pixel_row, pixel_col) is
  53.  
  54. variable bx,by,pr,pc,sz,x,y: integer;
  55.  
  56.  
  57. begin
  58. bx:=conv_integer(ball_x);
  59. by:=conv_integer(ball_y);
  60. pr:=conv_integer(pixel_row);
  61. pc:=conv_integer(pixel_col);
  62.  
  63. x:=pr-bx;
  64. y:=pc-by;
  65.  
  66. if (size*size >= ((x*x)+(y*y))) then
  67. ball_on<='1';
  68. else
  69. ball_on<='0';
  70. end if;
  71. --if (pixel_col >= ball_x - size) and
  72. -- (pixel_col <=ball_x + size) and
  73. -- (pixel_row >= ball_y - size) and
  74. -- (pixel_row <= ball_y + size) then
  75. --ball_on <= '1';
  76. --else ball_on <= '0';
  77. --end if;
  78.  
  79. end process;
  80. --process to move ball once every frame (i.e. once every vsync pulse)
  81. mball: process
  82. begin
  83. wait until rising_edge(v_sync);
  84. --allow for bounce off top or bottom of screen
  85. if ball_y + size >= 640 then
  86. ball_y_motion <= "1111111100";
  87. -- -4 pixels
  88. elsif ball_y <= size then
  89. ball_y_motion <= "0000000100";
  90. -- +4 pixels
  91. end if;
  92. -- Horizontal Motion
  93. ball_x <= ball_x + ball_x_motion;
  94. if ball_x + size >= 480 then
  95. ball_x_motion <= "1111111100";
  96. -- -4 pixels
  97. elsif ball_x <= size then
  98. ball_x_motion <= "0000000100";
  99. -- +4 pixels
  100. end if;
  101. ball_y <= ball_y + ball_y_motion;
  102. ball_x <= ball_x + ball_x_motion;
  103. --compute next ball position
  104. end process;
  105. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement