Computer Science / Game Programming
#BlueJ class context comment0.params=targets\ gameLevel comment0.target=void\ initializeTargetArray(comp1022p.assignment.Target[][],\ int) comment0.text=\r\n\ Initializes\ a\ 2D\ target\ array\ with\ m\ rows\ and\ n\ columns\ of\ Target\ objects\ according\ to\ the\ game\ level.\ You\ can\ assume\ that\ the\ 2D\ array\ itself\ (but\ not\ the\ Target\ objects\ inside)\ is\ already\ initialized.\r\n\ \r\n\ Game\ level\ 1\:\r\n\ All\ targets\ are\ stationary.\r\n\ \r\n\ Game\ level\ 2\:\r\n\ For\ even\ numbered\ rows,\ targets\ at\ even\ numbered\ columns\ are\ stationary,\ targets\ at\ odd\ numbered\ columns\ are\ movable.\r\n\ For\ odd\ numbered\ rows,\ targets\ at\ odd\ numbered\ columns\ are\ stationary,\ targets\ at\ even\ numbered\ columns\ are\ movable.\r\n\ \r\n\ Game\ level\ 3\:\r\n\ All\ targets\ are\ movable.\r\n\ \r\n\ @param\ targets\ \ \ The\ m\ x\ n\ 2D\ target\ array.\r\n\ @param\ gameLevel\ The\ game\ level\ of\ the\ game.\r\n comment1.params=depthImages\ initialStep\ currentStep\ finalStep\ initialScale\ finalScale comment1.target=comp1022p.ColorImage\ generateIntermediateBulletImage(comp1022p.ColorImage[],\ int,\ int,\ int,\ double,\ double) comment1.text=\r\n\ Generates\ an\ intermediate\ bullet\ ColorImage\ for\ the\ shooting\ animation\ according\ to\ the\ current\ step\ of\ the\ animation.\r\n\ \r\n\ As\ the\ current\ step\ approaches\ the\ final\ step,\ the\ intermediate\ bullet\ image\ should\ appear\ farther\ away\ and\ smaller\ in\ size.\r\n\ This\ method\ selects\ a\ bullet\ image\ of\ the\ correct\ depth\ from\ an\ array\ of\ pre-generated\ depth\ images\ (ordered\ from\ closer\ to\ farther\ away)\ and\ set\ it\ to\ the\ correct\ scale\ according\ to\ the\ current\ step\ of\ the\ animation.\r\n\ In\ order\ to\ select\ the\ correct\ depth\ image\ from\ the\ array\ and\ to\ set\ its\ scale\ to\ a\ correct\ value,\ the\ technique\ of\ linear\ interpolation\ should\ be\ used.\r\n\ \r\n\ As\ an\ example,\ given\ the\ following\:\r\n\ s0\ -\ initial\ scale\r\n\ s1\ -\ final\ scale\r\n\ t0\ -\ initial\ step\r\n\ t1\ -\ final\ step\r\n\ t\ -\ current\ step\r\n\ \r\n\ then\ s,\ the\ current\ scale,\ can\ be\ calculated\ by\ the\ following\ formula\:\r\n\ \r\n\ s\ \=\ s0\ +\ (s1\ -\ s0)\ *\ (t\ -\ t0)\ /\ (t1\ -\ t0)\r\n\ \r\n\ Reference\:\ http\://en.wikipedia.org/wiki/Linear_interpolation\r\n\ \r\n\ @param\ depthImages\ \ \ An\ array\ of\ bullet\ images\ of\ different\ depths,\ ordered\ from\ closer\ to\ farther\ away.\ \r\n\ @param\ initialStep\ \ \ The\ initial\ step\ of\ the\ shooting\ animation.\r\n\ @param\ currentStep\ \ \ The\ current\ step\ of\ the\ shooting\ animation.\r\n\ @param\ finalStep\ \ \ \ \ The\ final\ step\ of\ the\ shooting\ animation.\r\n\ @param\ initialScale\ \ The\ initial\ scale\ of\ the\ intermediate\ bullet\ image.\r\n\ @param\ finalScale\ \ \ \ The\ final\ scale\ of\ the\ intermediate\ bullet\ image.\r\n\ \r\n\ @return\ The\ intermediate\ bullet\ image\ for\ the\ shooting\ animation.\r\n comment2.params=bulletImage\ initialStep\ currentStep\ finalStep\ initialX\ finalX\ initialY\ finalY comment2.target=void\ moveBulletImage(comp1022p.ColorImage,\ int,\ int,\ int,\ int,\ int,\ int,\ int) comment2.text=\r\n\ Moves\ the\ bullet\ image\ for\ the\ shooting\ animation\ according\ to\ the\ current\ step\ of\ the\ animation.\r\n\ \r\n\ As\ the\ current\ step\ approaches\ the\ final\ step,\ the\ intermediate\ bullet\ image\ should\ move\ closer\ to\ the\ final\ x,\ y\ positions.\r\n\ This\ method\ set\ the\ x,\ y\ position\ of\ the\ bullet\ image\ to\ the\ correct\ values\ according\ to\ the\ current\ step\ of\ the\ animation.\ \r\n\ In\ order\ to\ calculate\ the\ correct\ values\ of\ x,\ y\ positions,\ the\ technique\ of\ linear\ interpolation\ should\ be\ used.\r\n\ \r\n\ As\ an\ example,\ given\ the\ following\:\r\n\ y0\ -\ initial\ y\ position\r\n\ y1\ -\ final\ y\ position\r\n\ t0\ -\ initial\ step\r\n\ t1\ -\ final\ step\r\n\ t\ -\ current\ step\r\n\ \r\n\ then\ y,\ the\ current\ y\ position,\ can\ be\ calculated\ by\ the\ following\ formula\:\r\n\ \r\n\ y\ \=\ y0\ +\ (y1\ -\ y0)\ *\ (t\ -\ t0)\ /\ (t1\ -\ t0)\r\n\ \r\n\ Reference\:\ http\://en.wikipedia.org/wiki/Linear_interpolation\r\n\ \r\n\ @param\ bulletImage\ \ \ The\ bullet\ image\ to\ be\ moved.\ \r\n\ @param\ initialStep\ \ \ The\ initial\ step\ of\ the\ shooting\ animation.\r\n\ @param\ currentStep\ \ \ The\ current\ step\ of\ the\ shooting\ animation.\r\n\ @param\ finalStep\ \ \ \ \ The\ final\ step\ of\ the\ shooting\ animation.\r\n\ @param\ initialX\ \ \ \ \ \ The\ initial\ x\ position\ of\ the\ intermediate\ bullet\ image.\r\n\ @param\ finalX\ \ \ \ \ \ \ \ The\ final\ x\ position\ of\ the\ intermediate\ bullet\ image.\r\n\ @param\ initialY\ \ \ \ \ \ The\ initial\ y\ position\ of\ the\ intermediate\ bullet\ image.\r\n\ @param\ finalY\ \ \ \ \ \ \ \ The\ final\ y\ position\ of\ the\ intermediate\ bullet\ image.\r\n comment3.params=targets comment3.target=void\ updateTargetPositions(comp1022p.assignment.Target[][]) comment3.text=\r\n\ Updates\ the\ position\ of\ movable\ targets.\r\n\ \r\n\ This\ method\ checks\ each\ of\ the\ targets\ in\ the\ 2D\ array\ and\ update\ its\ position\ by\ the\ following\ rules\:\r\n\ \r\n\ 1.\ Targets\ that\ are\ stationary\ should\ not\ be\ moved.\r\n\ 2.\ Targets\ that\ are\ movable\ should\ be\ moved\ to\ an\ adjacent\ position\ (horizontally,\ vertically\ and\ diagonally)\ by\ some\ chance,\ GIVEN\ THAT\ the\ target\ in\ the\ adjacent\ position\ is\ already\ being\ hit.\r\n\ 3.\ If\ there\ are\ multiple\ adjacent\ positions\ available,\ moving\ to\ either\ one\ is\ acceptable.\r\n\ 4.\ If\ there\ are\ multiple\ targets\ that\ could\ be\ moved\ to\ the\ same\ position,\ moving\ either\ one\ is\ acceptable.\r\n\ 5.\ Each\ target\ should\ be\ moved\ ONCE\ only\ for\ each\ call\ of\ this\ method.\r\n\r\n\ @param\ targets\ \ \ The\ 2D\ array\ containing\ all\ the\ targets.\r\n numComments=4