-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ShaneMcKeon/master
merge my work
- Loading branch information
Showing
21 changed files
with
980 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,112 @@ | ||
function [onset, output] = choice(system, t, varargin) | ||
|
||
allkeys = [system.keys.left system.keys.up system.keys.right]; | ||
keys = []; | ||
|
||
ideal = GetSecs()+t.onset; | ||
background(system); | ||
Screen('DrawTexture', system.w, system.tex.astronaut{1,1}); | ||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); % Show the background again | ||
Screen('DrawTexture', system.w, system.tex.astronaut{1,1},... | ||
[], [system.pos.character.x system.pos.character.y system.pos.character.x+60 system.pos.character.y+80] ); | ||
|
||
progressBar(system, t); | ||
|
||
|
||
if t.i < 3 | ||
correctTrials = 0; | ||
|
||
else | ||
|
||
correctTrials = varargin{1}(t.i-2).output.correctTrials; | ||
|
||
end | ||
|
||
totalCount(system, correctTrials); | ||
coinPile(system, correctTrials) | ||
|
||
|
||
|
||
%% positon choice options | ||
chest_w = 27;chest_h = 27; %TODO: use sprite | ||
chest_w = 60; chest_h = 60; %TODO: use sprite | ||
% TODO: use DrawTextures (many at once) | ||
keys = []; | ||
|
||
[screenWidth, screenHeight] = Screen('WindowSize', system.w); | ||
|
||
% Define the size of the white box (e.g., 100x100 pixels) | ||
boxWidth = 200; | ||
boxHeight = 200; | ||
|
||
% Calculate the position of the box in the lower right corner | ||
% The coordinates are in the form [left, top, right, bottom] | ||
boxRect = [screenWidth - boxWidth, screenHeight - boxHeight, screenWidth, screenHeight]; | ||
|
||
% Define the color white (white = [255 255 255]) | ||
black = [0 0 0]; | ||
|
||
% Draw the white box | ||
Screen('FillRect', system.w, black, boxRect); | ||
|
||
% chest graphics | ||
Screen('DrawTexture', system.w, system.tex.chest,... | ||
Screen('DrawTexture', system.w, system.tex.chest_sprites{1,1},... | ||
[], [ 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,... | ||
Screen('DrawTexture', system.w, system.tex.chest_sprites{1,1},... | ||
[], [ 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,... | ||
Screen('DrawTexture', system.w, system.tex.chest_sprites{1,1},... | ||
[], [ 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]; | ||
[], [ system.pos.right.x+20 system.pos.right.y+20 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]; | ||
[], [ system.pos.left.x+20 system.pos.left.y+20 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]; | ||
[], [ system.pos.up.x+20 system.pos.up.y+20 system.pos.up.x+chest_w system.pos.up.y+chest_h] ); | ||
keys = [keys system.keys.up]; | ||
|
||
|
||
end | ||
|
||
|
||
onset = Screen('Flip', system.w, ideal); | ||
sendDaqs(system); | ||
|
||
[k rt] = waitForKeys(keys, onset + t.max_rt); | ||
|
||
if rt > 0 | ||
idx = find(keys == k,1); | ||
idx = find(allkeys == k,1); | ||
fprintf('choice %d, key %d',idx, k) | ||
well_prob = t.chance(idx); | ||
output.score = (rand(1) <= well_prob); | ||
if idx == 1 | ||
output.pick = 'left'; | ||
|
||
elseif idx == 2 | ||
output.pick = 'up'; | ||
|
||
elseif idx == 3 | ||
output.pick = 'right'; | ||
|
||
end | ||
else | ||
output.score = 0 | ||
output.score = 0; | ||
output.pick = 'none'; | ||
end | ||
oupput.onset_ideal = ideal; | ||
output.onset_ideal = ideal; | ||
output.key = k; | ||
output.rt = rt; | ||
|
||
|
||
|
||
% TODO: animate avatar walk in while loop? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function coinPile(system, correctTrials) | ||
|
||
[screenWidth, screenHeight] = Screen('WindowSize', system.w); | ||
|
||
|
||
coinSize = 20; % 20x20 pixels | ||
|
||
% Loop through and draw 'c' number of coins based on correct trials | ||
|
||
% Parameters | ||
coins_per_row = 20; % Number of coins per row | ||
row_spacing = coinSize + 20; % Vertical spacing between rows | ||
yPos_start = screenHeight / 3; % Initial vertical position | ||
xPos_start = screenWidth / 3; % Initial horizontal position | ||
|
||
% Redraw the static coins | ||
for c = 1:(correctTrials) | ||
% Calculate row and column positions | ||
row = floor((c - 1) / coins_per_row); % Determine the current row | ||
col = mod((c - 1), coins_per_row); % Determine the column within the row | ||
|
||
% Update horizontal and vertical positions | ||
xPos = xPos_start + col * (coinSize + 10); % Horizontal position | ||
yPos = yPos_start - row * row_spacing; % Vertical position based on row number | ||
|
||
% Draw the coin | ||
Screen('DrawTexture', system.w, system.tex.starcoin, [], [xPos, yPos, xPos + coinSize, yPos + coinSize]); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
function drawScreen(system, t, color, varargin) | ||
|
||
%redraw the scene | ||
ideal = GetSecs()+t.onset; | ||
|
||
%% positon choice options | ||
chest_w = 60; chest_h = 60; %TODO: use sprite | ||
% TODO: use DrawTextures (many at once) | ||
|
||
[screenWidth, screenHeight] = Screen('WindowSize', system.w); | ||
|
||
% Define the size of the white box (e.g., 100x100 pixels) | ||
boxWidth = 200; | ||
boxHeight = 200; | ||
|
||
% Calculate the position of the box in the lower right corner | ||
% The coordinates are in the form [left, top, right, bottom] | ||
boxRect = [screenWidth - boxWidth, screenHeight - boxHeight, screenWidth, screenHeight]; | ||
|
||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); % Show the background again | ||
|
||
% Draw the box | ||
Screen('FillRect', system.w, color, boxRect); | ||
|
||
% chest graphics | ||
Screen('DrawTexture', system.w, system.tex.chest_sprites{1,1},... | ||
[], [ 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_sprites{1,1},... | ||
[], [ 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_sprites{1,1},... | ||
[], [ 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+20 system.pos.right.y+20 system.pos.right.x+chest_w system.pos.right.y+chest_h] ); | ||
end | ||
|
||
if ismember('left', t.choices) | ||
Screen('DrawTexture', system.w, system.tex.key,... | ||
[], [ system.pos.left.x+20 system.pos.left.y+20 system.pos.left.x+chest_w system.pos.left.y+chest_h] ); | ||
|
||
end | ||
|
||
if ismember('up', t.choices) | ||
Screen('DrawTexture', system.w, system.tex.key,... | ||
[], [ system.pos.up.x+20 system.pos.up.y+20 system.pos.up.x+chest_w system.pos.up.y+chest_h] ); | ||
|
||
|
||
end | ||
|
||
progressBar(system, t) | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
function dropCoin(system, t, correctTrials) | ||
|
||
[screenWidth, screenHeight] = Screen('WindowSize', system.w); | ||
ideal = GetSecs() + t.onset; | ||
|
||
color = [0 0 0]; | ||
|
||
drawScreen(system, t, color) | ||
totalCount(system, correctTrials); | ||
|
||
yStep = 10; % Step size for animating the coin downward | ||
coinSize = 20; % 20x20 pixels | ||
|
||
% Parameters | ||
coins_per_row = 20; % Number of coins per row | ||
row_spacing = coinSize + 20; % Vertical spacing between rows | ||
yPos_start = screenHeight / 3; % Initial vertical position | ||
xPos_start = screenWidth / 3; % Initial horizontal position | ||
|
||
% Loop through and draw 'c' number of coins based on correct trials | ||
for c = 1:(correctTrials - 1) | ||
% Calculate row and column positions for each static coin | ||
row = floor((c - 1) / coins_per_row); % Determine the current row | ||
col = mod((c - 1), coins_per_row); % Determine the column within the row | ||
|
||
% Update horizontal and vertical positions | ||
xPos = xPos_start + col * (coinSize + 10); % Horizontal position | ||
yPos = yPos_start - row * row_spacing; % Vertical position (rows stack upward) | ||
|
||
% Draw the static coin texture at the calculated position | ||
Screen('DrawTexture', system.w, system.tex.starcoin, [], [xPos, yPos, xPos + coinSize, yPos + coinSize]); | ||
end | ||
|
||
if correctTrials >= 1 | ||
% Floating coin's initial Y-position (above the topmost row) | ||
yStart = 0; | ||
|
||
% Floating coin's final Y-position (end point is where the static coins are) | ||
new_coin_row = floor((correctTrials - 1) / coins_per_row); % Determine the current row for the new coin | ||
yEnd = yPos_start - new_coin_row * row_spacing; % Final vertical position for the new coin | ||
xPosNewCoin = xPos_start + mod((correctTrials - 1), coins_per_row) * (coinSize + 10); % Horizontal position | ||
|
||
% Calculate the distance and the number of steps needed for animation | ||
distance = yEnd - yStart; | ||
steps = round(distance / yStep); | ||
|
||
% Animate the new coin floating down in steps | ||
for x = 1:steps | ||
drawScreen(system, t, color); | ||
totalCount(system, correctTrials); | ||
|
||
% Redraw the static coins during each frame of the animation | ||
for c = 1:(correctTrials - 1) | ||
row = floor((c - 1) / coins_per_row); | ||
col = mod((c - 1), coins_per_row); | ||
xPos = xPos_start + col * (coinSize + 10); % Horizontal position | ||
yPos = yPos_start - row * row_spacing; % Vertical position | ||
|
||
% Draw the static coins | ||
Screen('DrawTexture', system.w, system.tex.starcoin, [], [xPos, yPos, xPos + coinSize, yPos + coinSize]); | ||
end | ||
|
||
% Animate the floating coin down smoothly | ||
yPositionFloating = yStart + (yEnd - yStart) * (x / steps); % Linear interpolation | ||
|
||
% Draw the floating coin at its current position | ||
Screen('DrawTexture', system.w, system.tex.starcoin, [], [xPosNewCoin, yPositionFloating, xPosNewCoin + coinSize, yPositionFloating + coinSize]); | ||
|
||
% Flip the screen to show the current frame | ||
onset = Screen('Flip', system.w); | ||
|
||
% Optional: Add a small delay to control the speed of movement | ||
WaitSecs(0.02); | ||
end | ||
end |
Oops, something went wrong.