-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.vhd
More file actions
72 lines (62 loc) · 2.47 KB
/
field.vhd
File metadata and controls
72 lines (62 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-----------------------------------------------------------------------------
-- File Name: field.vhd
-- Description: Returns whether an x,y coordinate is part of the field/wall.
-----------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.STD_LOGIC_1164.ALL;
USE ieee.numeric_std.ALL;
USE work.declarations.ALL;
ENTITY field IS
PORT (
clk, rstn : IN STD_LOGIC;
xscan, yscan : IN INTEGER;
mode : IN STD_LOGIC_VECTOR(MODE_STATE_WIDTH-1 downto 0);
flag : OUT STD_LOGIC
);
END field;
ARCHITECTURE behaviour OF field IS
-- DEFINE CONSTANTS
CONSTANT X_MIN : INTEGER := 0;
CONSTANT Y_MIN : INTEGER := 0;
CONSTANT X_MAX : INTEGER := 640;
CONSTANT Y_MAX : INTEGER := 480;
CONSTANT BORDER_SIZE : INTEGER := 30;
-- Define the record type for a basic rectangular wall
type wall_type is record
x_left : integer;
x_right : integer;
y_top : integer;
y_bottom : integer;
end record;
-- Declare and initialiSe the array of walls
type wall_array_type is array (natural range <>) of wall_type;
constant walls : wall_array_type := (
(x_left => X_MIN, x_right => BORDER_SIZE, y_top => Y_MIN, y_bottom => Y_MAX), -- Left border
(x_left => X_MIN, x_right => X_MAX, y_top => Y_MIN, y_bottom => BORDER_SIZE), -- Top border
(x_left => X_MAX - BORDER_SIZE, x_right => X_MAX, y_top => Y_MIN, y_bottom => Y_MAX), -- Right border
(x_left => X_MIN, x_right => X_MAX, y_top => Y_MAX-BORDER_SIZE, y_bottom => Y_MAX), -- Bottom border
(x_left => 150, x_right => 200, y_top => Y_MIN, y_bottom => 160), -- Wall one
(x_left => 150, x_right => 200, y_top => 320, y_bottom => Y_MAX), -- Wall two
(x_left => 300, x_right => 350, y_top => 160, y_bottom => 320) -- Wall three
);
BEGIN
-- Process to detect if a wall is on the given coords
detect_wall : PROCESS (clk, rstn)
variable i : integer;
BEGIN
IF rstn = '0' THEN
flag <= '0';
ELSIF rising_edge(clk) THEN
flag <= '0'; -- Default no wall
-- TODO: Use different fields for different game modes.
-- Loop through each wall and check
for i in walls'range loop
IF (xscan > walls(i).x_left AND xscan < walls(i).x_right AND
yscan > walls(i).y_top AND yscan < walls(i).y_bottom) THEN
flag <= '1';
exit; -- Exit if wall found.
END IF;
end loop;
END IF;
END PROCESS;
END behaviour;