fixé qqu bugs sur la rotation
This commit is contained in:
parent
fd07409255
commit
c2d9da5443
@ -55,9 +55,9 @@ begin
|
||||
B<=(others=>'0');
|
||||
G<=(others=>'0');
|
||||
else
|
||||
R<=snakeIn.R;
|
||||
G<=snakeIn.G;
|
||||
B<=snakeIn.B;
|
||||
R<=std_logic_vector(snakeIn.R and resize(shift_right(snakeIn.A,3),5));
|
||||
G<=std_logic_vector(snakeIn.G and resize(shift_right(snakeIn.A,2),6));
|
||||
B<=std_logic_vector(snakeIn.B and resize(shift_right(snakeIn.A,3),5));
|
||||
end if;
|
||||
end process;
|
||||
end Behavioral;
|
||||
|
@ -61,8 +61,8 @@ architecture Behavioral of Gene_Snake is
|
||||
|
||||
-- D???claration des signaux
|
||||
signal snakeHere: std_logic; --1 si on doit afficher le pixel 0 sinon
|
||||
signal dx : signed(2 downto 0);
|
||||
signal dy : signed(2 downto 0);
|
||||
signal dx : signed(1 downto 0);
|
||||
signal dy : signed(1 downto 0);
|
||||
signal running : std_logic;
|
||||
signal startUpdate : std_logic;
|
||||
signal snakeColor : color;
|
||||
@ -72,6 +72,9 @@ begin
|
||||
|
||||
-- Process de calcul d'affichage
|
||||
process(X,Y,clk,reset,running,dx,dy,updateOrder,currentSnake,snakeHere)
|
||||
variable sX : integer; --position par rapport au sprites
|
||||
variable sY : integer;
|
||||
variable sOff : integer; --offset dans la memoire des sprites
|
||||
begin
|
||||
if(updateOrder'event and updateOrder = '1') then --si on as un signal sur pxl_clk (i.e. on vient de changer de pixel)
|
||||
if(snakeHere = '1') then
|
||||
@ -92,25 +95,33 @@ elsif(clk'event and clk = '1') then
|
||||
if(startUpdate = '1') then
|
||||
running <= '1';
|
||||
snakeHere <= '0';
|
||||
dx <= to_signed(-1,3);
|
||||
dy <= to_signed(-1,3);
|
||||
dx <= to_signed(-1,2);
|
||||
dy <= to_signed(-1,2);
|
||||
end if;
|
||||
if(running = '1') then
|
||||
if(currentSnake.isDefined = '1') then
|
||||
if(X>=currentSnake.X-8 and X<currentSnake.X+8 and Y>=currentSnake.Y-8 and Y<currentSnake.Y+8) then
|
||||
snakeHere <= '1';
|
||||
ROMAddress <= resize(shift_left(to_integer(shift_right(currentSnake.dirY,2))*(Y-currentSnake.Y)+8,4)+(to_integer(shift_right(currentSnake.dirY,2))*(X-currentSnake.X)+8),8);
|
||||
-- |-1 si dirX=-1; 1 si dirX=0 ou 1 | |position relative au centre| |pour passer de coords (-8:7) ou (-7:8) à (0:15)|
|
||||
sX := to_integer(currentSnake.dirX or "01") * to_integer(X-currentSnake.X) + 8 + to_integer(shift_right(currentSnake.dirX,1));
|
||||
sY := to_integer(currentSnake.dirY or "01") * to_integer(Y-currentSnake.Y) + 8 + to_integer(shift_right(currentSnake.dirY,1));
|
||||
case listRef is
|
||||
when to_unsigned(0,addressSize-1) => sOff := HEAD_SPRITE_OFFSET;
|
||||
when to_unsigned(3,addressSize-1) => sOff := TAIL_SPRITE_OFFSET;
|
||||
when others => sOff := BODY_SPRITE_OFFSET;
|
||||
end case;
|
||||
ROMAddress <= to_unsigned(sY*16+sX+sOff,SPRITES_ADDRESS_SIZE);
|
||||
end if;
|
||||
end if;
|
||||
|
||||
dx <= dx + 1;
|
||||
if(dx = 2) then
|
||||
dx <= to_signed(-1,3);
|
||||
dx <= to_signed(-1,2);
|
||||
dy <= dy + 1;
|
||||
end if;
|
||||
|
||||
if(dy = 2) then
|
||||
dy <= to_signed(-1,3);
|
||||
dy <= to_signed(-1,2);
|
||||
running <= '0';
|
||||
end if;
|
||||
end if;
|
||||
|
@ -6,10 +6,14 @@ package types is
|
||||
constant MAX_SNAKE : integer := 1200;
|
||||
constant SNAKE_ADDRESS_SIZE : integer :=11;
|
||||
|
||||
constant SPRITES_ADDRESS_SIZE : integer := 8;
|
||||
constant SPRITES_DATA_LENGTH : integer := 256;
|
||||
constant SPRITES_ADDRESS_SIZE : integer := 10;
|
||||
constant SPRITES_DATA_LENGTH : integer := 768;
|
||||
constant SPRITES_DATA_SIZE : integer := 24;
|
||||
|
||||
constant HEAD_SPRITE_OFFSET : integer := 0;
|
||||
constant BODY_SPRITE_OFFSET : integer := 256;
|
||||
constant TAIL_SPRITE_OFFSET : integer := 512;
|
||||
|
||||
type coord is array(0 to 39, 0 to 29) of unsigned(SNAKE_ADDRESS_SIZE-1 downto 0);
|
||||
type pos is record
|
||||
X: unsigned(9 downto 0);
|
||||
@ -22,9 +26,10 @@ package types is
|
||||
function to_pos(input : std_logic_vector) return pos;
|
||||
|
||||
type color is record
|
||||
R : STD_LOGIC_VECTOR (4 downto 0);
|
||||
G : STD_LOGIC_VECTOR (5 downto 0);
|
||||
B : STD_LOGIC_VECTOR (4 downto 0);
|
||||
R : unsigned (4 downto 0);
|
||||
G : unsigned (5 downto 0);
|
||||
B : unsigned (4 downto 0);
|
||||
A : unsigned (7 downto 0);
|
||||
end record;
|
||||
function to_color(input : std_logic_vector) return color;
|
||||
end package;
|
||||
@ -57,10 +62,10 @@ package body types is
|
||||
function to_color(input : std_logic_vector) return color is
|
||||
variable sortie : color;
|
||||
begin
|
||||
sortie.R := input(23 downto 19);
|
||||
sortie.G := input(18 downto 13);
|
||||
sortie.B := input(12 downto 8);
|
||||
--sortie.A := input(7 downto 0);
|
||||
sortie.R := unsigned(input(23 downto 19));
|
||||
sortie.G := unsigned(input(18 downto 13));
|
||||
sortie.B := unsigned(input(12 downto 8));
|
||||
sortie.A := unsigned(input(7 downto 0));
|
||||
return sortie;
|
||||
end to_color;
|
||||
end package body;
|
||||
|
@ -73,8 +73,8 @@ begin
|
||||
|
||||
currentSnake.X <= to_unsigned(8+(to_integer(index) rem 40)*16,10);
|
||||
currentSnake.Y <= to_unsigned(8+to_integer(index/40)*16,9);
|
||||
currentSnake.dirX <= to_signed(to_integer(index rem 3)-1,2);
|
||||
currentSnake.dirY <= to_signed(to_integer((index+1) rem 3)-1,2);
|
||||
currentSnake.dirX <= to_signed(-1,2);--to_signed(to_integer(index rem 3)-1,2);
|
||||
currentSnake.dirY <= to_signed(0,2);--to_signed(to_integer((index+1) rem 3)-1,2);
|
||||
currentSnake.isDefined <= '1';
|
||||
|
||||
matAddress <= to_unsigned(to_integer(index),SNAKE_ADDRESS_SIZE);
|
||||
|
BIN
sprites/corps2.png
Normal file
BIN
sprites/corps2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 B |
BIN
sprites/queue.png
Normal file
BIN
sprites/queue.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 162 B |
1024
sprites/sprites.mem
1024
sprites/sprites.mem
File diff suppressed because it is too large
Load Diff
BIN
sprites/tete2.png
Normal file
BIN
sprites/tete2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 252 B |
Loading…
x
Reference in New Issue
Block a user