Code covered by the BSD License  

Highlights from
Stellaria (Tech Demo) - The best MATLAB shooting game ever

image thumbnail

Stellaria (Tech Demo) - The best MATLAB shooting game ever

by

 

14 May 2011 (Updated )

If you think you have played the best MATLAB game before. Think again after you try this one.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

stl_preprocessStage(thisStage)
function [thisStageTimeTable thisStageActors] = stl_preprocessStage(thisStage)

global DefaultEnemyStructs;
global DefaultNeutralObjectStructs;
global emptyEnemyStruct;
global STAGE_COLUMNS;
global STAGE_COL_SEC2FRAME_CONV;
global STAGE_NEUTRAL_COL_SEC2FRAME_CONV
global STAGE_COLUMNS_TEXT
global STAGE_COLUMNS_PICT
global FRAME_DURATION;
global FPS;

%% Enemy Types and IDS
global TYPE_ENEMY_CRAFT
global ID_EC_STACCATO
global TYPE_NEUTRAL_PICT
global TYPE_NEUTRAL_TEXT

[nEntries nCols]= size(thisStage);

thisStageTimeTable = zeros(nEntries, 1);
thisStageActors = repmat(emptyEnemyStruct, 1, nEntries);  

for i = 1:nEntries
    thisStageTimeTable(i) = thisStage{i, 1} .* FPS;
    if i >= 2
        thisStageTimeTable(i) = thisStageTimeTable(i-1) + thisStageTimeTable(i);
    end
    if thisStage{i, 2} == TYPE_ENEMY_CRAFT
        % Copy the default enemy struct
        thisStageActors(i) = DefaultEnemyStructs(thisStage{i, 3});
    elseif thisStage{i, 2} == TYPE_NEUTRAL_PICT || thisStage{i, 2} == TYPE_NEUTRAL_TEXT
        thisStageActors(i) = DefaultNeutralObjectStructs(thisStage{i, 3});
    else
        errmsg = sprintf('stl_preprocessStage(): Unrecognizable Object Type %d in line %d', thisStage{i, 2}, i);
        error(errmsg);
    end
    for iCol = 4:nCols
        
       
        if ~isempty(thisStage{i, iCol})

            if thisStage{i, 2} == TYPE_ENEMY_CRAFT 
                if STAGE_COL_SEC2FRAME_CONV(iCol) == -1
                    thisStage{i, iCol} = thisStage{i, iCol} .* FRAME_DURATION;
                elseif STAGE_COL_SEC2FRAME_CONV(iCol) == 1
                    thisStage{i, iCol} = thisStage{i, iCol} .* FPS;
                end
                thisStageActors(i).(STAGE_COLUMNS{iCol}) = thisStage{i, iCol};
            else
                 if STAGE_NEUTRAL_COL_SEC2FRAME_CONV(iCol) == -1
                    thisStage{i, iCol} = thisStage{i, iCol} .* FRAME_DURATION;
                elseif STAGE_NEUTRAL_COL_SEC2FRAME_CONV(iCol) == 1
                    thisStage{i, iCol} = thisStage{i, iCol} .* FPS;
                end
                
                if thisStage{i, 2} == TYPE_NEUTRAL_PICT
                    thisStageActors(i).(STAGE_COLUMNS_PICT{iCol}) = thisStage{i, iCol};
                else
                    thisStageActors(i).(STAGE_COLUMNS_TEXT{iCol}) = thisStage{i, iCol};
                end
            end
            
        end
    end
end

Contact us