diff --git a/private/background.m b/private/background.m new file mode 100644 index 0000000..8cb9006 --- /dev/null +++ b/private/background.m @@ -0,0 +1,13 @@ +function background(system) + +screenWidth = 800; +imageWidth = 558; +padding = (screenWidth - imageWidth)/2; + +Screen('DrawTexture', system.w, system.tex.ocean_border, ... + [], [0, 0, screenWidth, 299] ); + +Screen('DrawTexture', system.w, system.tex.ocean_bottom, ... + [], [padding, 0, 558+padding 299] ); + +end \ No newline at end of file diff --git a/private/choice.m b/private/choice.m index 378bdae..9bcb0ab 100644 --- a/private/choice.m +++ b/private/choice.m @@ -1,33 +1,57 @@ function [onset, output] = choice(system, t, varargin) - ideal = GetSecs()+t.onset; - Screen('DrawTexture', system.w, system.tex.ocean_bottom); - Screen('DrawTexture', system.w, system.tex.astronaut{1,1}); - - %% positon choice options - chest_w = 27;chest_h = 27; %TODO: use sprite - % TODO: use DrawTextures (many at once) - Screen('DrawTexture', system.w, system.tex.chest,... - [], [ system.pos.left.x system.pos.left.y system.pos.left.x+chest_w system.pos.left.y+chest_h] ); - Screen('DrawTexture', system.w, system.tex.chest,... - [], [ system.pos.up.x system.pos.up.y system.pos.up.x+chest_w system.pos.up.y+chest_h] ); - Screen('DrawTexture', system.w, system.tex.chest,... - [], [ system.pos.right.x system.pos.right.y system.pos.right.x+chest_w system.pos.right.y+chest_h] ); - - onset = Screen('Flip', system.w, ideal); - - keys = KbName({'Left','Up', 'Right'}); - [k rt] = waitForKeys(keys, onset + t.max_rt); - if rt > 0 - idx = find(keys == k,1); - well_prob = t.chance(idx); - output.score = (rand(1) <= well_prob); - else - output.score = 0 - end - oupput.onset_ideal = ideal; - output.key = k; - output.rt = rt; - - % TODO: animate avatar walk in while loop? +ideal = GetSecs()+t.onset; + background(system); +Screen('DrawTexture', system.w, system.tex.astronaut{1,1}); + +%% positon choice options +chest_w = 27;chest_h = 27; %TODO: use sprite +% TODO: use DrawTextures (many at once) +keys = []; + +% chest graphics +Screen('DrawTexture', system.w, system.tex.chest,... + [], [ system.pos.left.x system.pos.left.y system.pos.left.x+chest_w system.pos.left.y+chest_h] ); +Screen('DrawTexture', system.w, system.tex.chest,... + [], [ system.pos.up.x system.pos.up.y system.pos.up.x+chest_w system.pos.up.y+chest_h] ); +Screen('DrawTexture', system.w, system.tex.chest,... + [], [ system.pos.right.x system.pos.right.y system.pos.right.x+chest_w system.pos.right.y+chest_h] ); +% add keys to chests +if ismember('right', t.choices) + Screen('DrawTexture', system.w, system.tex.key,... + [], [ system.pos.right.x system.pos.right.y system.pos.right.x+chest_w system.pos.right.y+chest_h] ); + keys = [keys, system.keys.right]; +end + +if ismember('left', t.choices) + Screen('DrawTexture', system.w, system.tex.key,... + [], [ system.pos.left.x system.pos.left.y system.pos.left.x+chest_w system.pos.left.y+chest_h] ); + keys = [keys, system.keys.left]; + +end + +if ismember('up', t.choices) + Screen('DrawTexture', system.w, system.tex.key,... + [], [ system.pos.up.x system.pos.up.y system.pos.up.x+chest_w system.pos.up.y+chest_h] ); + keys = [keys, system.keys.up]; + + +end + + +onset = Screen('Flip', system.w, ideal); + +[k rt] = waitForKeys(keys, onset + t.max_rt); +if rt > 0 + idx = find(keys == k,1); + well_prob = t.chance(idx); + output.score = (rand(1) <= well_prob); +else + output.score = 0 +end +oupput.onset_ideal = ideal; +output.key = k; +output.rt = rt; + +% TODO: animate avatar walk in while loop? end diff --git a/private/instructions.m b/private/instructions.m index 26e28ca..b59a488 100644 --- a/private/instructions.m +++ b/private/instructions.m @@ -9,6 +9,9 @@ % run onset = Screen('Flip', system.w, 0); - acceptkeys = KbName({'Space','Left','Up','Right','Return','1'}); - [output.k output.rt] = waitForKeys(acceptkeys,Inf); -end + acceptkeys = KbName({'space','LeftArrow','UpArrow','RightArrow','Return','1'}); %changed these to add Arrow - seems that pyschotoolbox didnt recognize just "left" -SDM 20240723 + + [output.k output.rt] = waitForKeys(acceptkeys,Inf); + + +end diff --git a/private/load_events.m b/private/load_events.m index 0e2ca65..53304c9 100644 --- a/private/load_events.m +++ b/private/load_events.m @@ -7,8 +7,9 @@ timing(i).event_name = 'choice'; timing(i).func = @choice; timing(i).chance = [1,1,1]; % left, up, right - timing(i).max_rt = 2; + timing(i).max_rt = 20; timing(i).i = i; + timing(i).choices = ['up','right']; i=i+1; timing(i).event_name = 'isi'; diff --git a/private/load_system.m b/private/load_system.m index 1eea6fa..d2e42e8 100644 --- a/private/load_system.m +++ b/private/load_system.m @@ -1,6 +1,10 @@ function system = load_system(varargin) fprintf('# loading system (daq, TODO: audio)\n'); system = struct('hid',load_daq(varargin{:})); + system.keys.up = KbName('UpArrow'); + system.keys.right = KbName('RightArrow'); + system.keys.left = KbName('LeftArrow'); + end function hid = load_daq(varargin) diff --git a/private/load_textures.m b/private/load_textures.m index db3a62d..fdbfd02 100644 --- a/private/load_textures.m +++ b/private/load_textures.m @@ -8,21 +8,23 @@ for f = imgs' [~, fname, ~] = fileparts(f.name); fname(fname=='-')='_'; [img, ~, alpha] = imread(fullfile(f.folder,f.name)); - img(:,:,4) = alpha; + if size(img,2) >= 2 + img(:,:,4) = alpha; + end % TODO: scale images to screen size % sprites within one file. have animations frames in a grid if ismember(fname, avatar_sprites) % 4 rows 3 cols sprites = cell(4,4); - [x,y,_] =size(img); + [x,y,z] =size(img); % z was missing, added 20240723 SDM h= floor(y/4); wd = floor(x/4); for i=1:4; for j=1:4; ii=(i-1)*h+1; jj=(j-1)*h+1; img_sub = img(jj:(jj+wd-1),ii:(ii+h-1),:); tmp_tex = Screen('MakeTexture',w, img_sub); - sprites(i,j) = tmp_tex; + sprites(i,j) = {tmp_tex}; end;end tex_struct.(fname) = sprites; else diff --git a/private/setup_screen.m b/private/setup_screen.m index 72bfcda..e86bd7d 100644 --- a/private/setup_screen.m +++ b/private/setup_screen.m @@ -17,7 +17,7 @@ end function w = testscreen() - bg = [0 0 0]; + bg = [254 227 180]; screen = 0; res = [0 0 800 600]; Screen('Preference', 'SkipSyncTests', 2);