Added Some Documentation...
This commit is contained in:
parent
f3c3997fe3
commit
b2777bbf68
20 changed files with 688 additions and 551 deletions
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -6,7 +6,17 @@
|
||||||
</artifacts-to-build>
|
</artifacts-to-build>
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="aa440324-95db-4232-b779-41095ebcca0f" name="Default" comment="" />
|
<list default="true" id="aa440324-95db-4232-b779-41095ebcca0f" name="Default" comment="">
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/out/artifacts/Astroids2D_jar/Astroids2D.jar" afterPath="$PROJECT_DIR$/out/artifacts/Astroids2D_jar/Astroids2D.jar" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Engine/GameEngine.java" afterPath="$PROJECT_DIR$/src/Engine/GameEngine.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/GamePanels/GamePanel.java" afterPath="$PROJECT_DIR$/src/GamePanels/GamePanel.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Sprites/Astroid.java" afterPath="$PROJECT_DIR$/src/Sprites/Astroid.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Sprites/Fog.java" afterPath="$PROJECT_DIR$/src/Sprites/Fog.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Sprites/LaserBlast.java" afterPath="$PROJECT_DIR$/src/Sprites/LaserBlast.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Sprites/Ship.java" afterPath="$PROJECT_DIR$/src/Sprites/Ship.java" />
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Sprites/Sprite.java" afterPath="$PROJECT_DIR$/src/Sprites/Sprite.java" />
|
||||||
|
</list>
|
||||||
<ignored path="Astroids2D.iws" />
|
<ignored path="Astroids2D.iws" />
|
||||||
<ignored path=".idea/workspace.xml" />
|
<ignored path=".idea/workspace.xml" />
|
||||||
<ignored path="$PROJECT_DIR$/out/" />
|
<ignored path="$PROJECT_DIR$/out/" />
|
||||||
|
@ -27,21 +37,15 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="FileEditorManager">
|
<component name="FileEditorManager">
|
||||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||||
<file leaf-file-name="GameEngine.java" pinned="false" current-in-tab="true">
|
<file leaf-file-name="GameEngine.java" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="2.1241474">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="276" column="12" selection-start-line="276" selection-start-column="12" selection-end-line="278" selection-end-column="13" />
|
<caret line="130" column="29" selection-start-line="130" selection-start-column="29" selection-end-line="130" selection-end-column="29" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -61,7 +65,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="14" column="54" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="54" />
|
<caret line="21" column="7" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="54" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -73,7 +77,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="13" column="31" selection-start-line="13" selection-start-column="31" selection-end-line="13" selection-end-column="31" />
|
<caret line="20" column="26" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -85,7 +89,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="91" column="17" selection-start-line="91" selection-start-column="17" selection-end-line="91" selection-end-column="17" />
|
<caret line="146" column="7" selection-start-line="146" selection-start-column="7" selection-end-line="146" selection-end-column="7" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -97,12 +101,8 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
<caret line="51" column="0" selection-start-line="51" selection-start-column="0" selection-end-line="51" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -119,14 +119,12 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="GamePanel.java" pinned="false" current-in-tab="false">
|
<file leaf-file-name="GamePanel.java" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/src/GamePanels/GamePanel.java">
|
<entry file="file://$PROJECT_DIR$/src/GamePanels/GamePanel.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="1.7435198">
|
||||||
<caret line="74" column="43" selection-start-line="74" selection-start-column="43" selection-end-line="74" selection-end-column="43" />
|
<caret line="76" column="43" selection-start-line="76" selection-start-column="43" selection-end-line="76" selection-end-column="43" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -135,7 +133,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/LaserBlast.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/LaserBlast.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="12" column="50" selection-start-line="12" selection-start-column="50" selection-end-line="12" selection-end-column="50" />
|
<caret line="19" column="13" selection-start-line="19" selection-start-column="13" selection-end-line="19" selection-end-column="13" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -152,6 +150,9 @@
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
<component name="GradleLocalSettings">
|
<component name="GradleLocalSettings">
|
||||||
<option name="externalProjectsViewState">
|
<option name="externalProjectsViewState">
|
||||||
<projects_view />
|
<projects_view />
|
||||||
|
@ -173,9 +174,9 @@
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectFrameBounds">
|
<component name="ProjectFrameBounds">
|
||||||
<option name="x" value="51" />
|
<option name="x" value="67" />
|
||||||
<option name="y" value="27" />
|
<option name="y" value="27" />
|
||||||
<option name="width" value="1869" />
|
<option name="width" value="1853" />
|
||||||
<option name="height" value="1053" />
|
<option name="height" value="1053" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||||
|
@ -203,7 +204,7 @@
|
||||||
<foldersAlwaysOnTop value="true" />
|
<foldersAlwaysOnTop value="true" />
|
||||||
</navigator>
|
</navigator>
|
||||||
<panes>
|
<panes>
|
||||||
<pane id="PackagesPane" />
|
<pane id="Scope" />
|
||||||
<pane id="ProjectPane">
|
<pane id="ProjectPane">
|
||||||
<subPane>
|
<subPane>
|
||||||
<PATH>
|
<PATH>
|
||||||
|
@ -310,8 +311,8 @@
|
||||||
</PATH>
|
</PATH>
|
||||||
</subPane>
|
</subPane>
|
||||||
</pane>
|
</pane>
|
||||||
|
<pane id="PackagesPane" />
|
||||||
<pane id="Scratches" />
|
<pane id="Scratches" />
|
||||||
<pane id="Scope" />
|
|
||||||
</panes>
|
</panes>
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
|
@ -604,7 +605,7 @@
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="51" y="27" width="1869" height="1053" extended-state="6" />
|
<frame x="67" y="27" width="1853" height="1053" extended-state="6" />
|
||||||
<editor active="true" />
|
<editor active="true" />
|
||||||
<layout>
|
<layout>
|
||||||
<window_info id="Palette	" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Palette	" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
|
@ -621,14 +622,14 @@
|
||||||
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.12904997" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.12853186" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13754228" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13754228" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
|
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32890365" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32890365" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="combo" />
|
|
||||||
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="combo" />
|
||||||
</layout>
|
</layout>
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.UiProperties">
|
<component name="Vcs.Log.UiProperties">
|
||||||
|
@ -647,7 +648,7 @@
|
||||||
<breakpoints>
|
<breakpoints>
|
||||||
<line-breakpoint enabled="true" type="java-line">
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
<url>file://$PROJECT_DIR$/src/Engine/GameEngine.java</url>
|
<url>file://$PROJECT_DIR$/src/Engine/GameEngine.java</url>
|
||||||
<line>270</line>
|
<line>371</line>
|
||||||
<properties />
|
<properties />
|
||||||
<option name="timeStamp" value="2" />
|
<option name="timeStamp" value="2" />
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
|
@ -661,20 +662,42 @@
|
||||||
<option name="FILTER_TARGETS" value="false" />
|
<option name="FILTER_TARGETS" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="editorHistoryManager">
|
<component name="editorHistoryManager">
|
||||||
|
<entry file="file://$PROJECT_DIR$/src/Engine/CollisionUtil.java">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state vertical-scroll-proportion="0.0">
|
||||||
|
<caret line="47" column="5" selection-start-line="47" selection-start-column="5" selection-end-line="48" selection-end-column="5" />
|
||||||
|
<folding>
|
||||||
|
<element signature="imports" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/src/GamePanels/GamePanel.java">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state vertical-scroll-proportion="0.0">
|
||||||
|
<caret line="74" column="43" selection-start-line="74" selection-start-column="43" selection-end-line="74" selection-end-column="43" />
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/src/Sprites/LaserBlast.java">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state vertical-scroll-proportion="0.0">
|
||||||
|
<caret line="12" column="50" selection-start-line="12" selection-start-column="50" selection-end-line="12" selection-end-column="50" />
|
||||||
|
<folding>
|
||||||
|
<element signature="imports" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -721,11 +744,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -743,9 +762,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -765,14 +782,8 @@
|
||||||
<caret line="135" column="49" selection-start-line="135" selection-start-column="49" selection-end-line="135" selection-end-column="49" />
|
<caret line="135" column="49" selection-start-line="135" selection-start-column="49" selection-end-line="135" selection-end-column="49" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -819,11 +830,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -841,9 +848,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -863,14 +868,8 @@
|
||||||
<caret line="135" column="49" selection-start-line="135" selection-start-column="49" selection-end-line="135" selection-end-column="49" />
|
<caret line="135" column="49" selection-start-line="135" selection-start-column="49" selection-end-line="135" selection-end-column="49" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -917,11 +916,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -939,9 +934,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
<caret line="79" column="0" selection-start-line="79" selection-start-column="0" selection-end-line="79" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -961,14 +954,8 @@
|
||||||
<caret line="40" column="51" selection-start-line="40" selection-start-column="51" selection-end-line="40" selection-end-column="51" />
|
<caret line="40" column="51" selection-start-line="40" selection-start-column="51" selection-end-line="40" selection-end-column="51" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -1015,11 +1002,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="28" column="13" selection-start-line="28" selection-start-column="13" selection-end-line="28" selection-end-column="13" />
|
<caret line="28" column="13" selection-start-line="28" selection-start-column="13" selection-end-line="28" selection-end-column="13" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -1027,9 +1010,7 @@
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -1060,7 +1041,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="13" column="31" selection-start-line="13" selection-start-column="31" selection-end-line="13" selection-end-column="31" />
|
<caret line="20" column="26" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -1075,7 +1056,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="91" column="17" selection-start-line="91" selection-start-column="17" selection-end-line="91" selection-end-column="17" />
|
<caret line="146" column="7" selection-start-line="146" selection-start-column="7" selection-end-line="146" selection-end-column="7" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -1085,12 +1066,8 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="61" column="0" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
|
<caret line="51" column="0" selection-start-line="51" selection-start-column="0" selection-end-line="51" selection-end-column="0" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="e#2181#2182#0" expanded="true" />
|
|
||||||
<element signature="e#2220#2221#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -1114,7 +1091,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/LaserBlast.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/LaserBlast.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="12" column="50" selection-start-line="12" selection-start-column="50" selection-end-line="12" selection-end-column="50" />
|
<caret line="19" column="13" selection-start-line="19" selection-start-column="13" selection-end-line="19" selection-end-column="13" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -1124,7 +1101,7 @@
|
||||||
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="14" column="54" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="54" />
|
<caret line="21" column="7" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="54" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -1139,31 +1116,23 @@
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/src/GamePanels/GamePanel.java">
|
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="0.0">
|
<state vertical-scroll-proportion="0.0">
|
||||||
<caret line="74" column="43" selection-start-line="74" selection-start-column="43" selection-end-line="74" selection-end-column="43" />
|
<caret line="130" column="29" selection-start-line="130" selection-start-column="29" selection-end-line="130" selection-end-column="29" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
|
<element signature="e#3584#3585#0" expanded="true" />
|
||||||
|
<element signature="e#3611#3612#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/src/Engine/GameEngine.java">
|
<entry file="file://$PROJECT_DIR$/src/GamePanels/GamePanel.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state vertical-scroll-proportion="2.1241474">
|
<state vertical-scroll-proportion="1.7435198">
|
||||||
<caret line="276" column="12" selection-start-line="276" selection-start-column="12" selection-end-line="278" selection-end-column="13" />
|
<caret line="76" column="43" selection-start-line="76" selection-start-column="43" selection-end-line="76" selection-end-column="43" />
|
||||||
<folding>
|
<folding />
|
||||||
<element signature="imports" expanded="true" />
|
|
||||||
<element signature="method#initFogs#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#startNewGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#initGame#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#setupLives#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#update#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="method#collisionHandler#0;class#GameEngine#0" expanded="false" />
|
|
||||||
<element signature="e#9718#9719#0" expanded="true" />
|
|
||||||
<element signature="e#9756#9757#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -22,12 +22,12 @@ import java.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
public class GameEngine implements KeyListener {
|
public class GameEngine implements KeyListener {
|
||||||
private final int LARGE=100, MEDIUM=50, SMALL=25, NUM_OF_LIVES = 3, LASER_SPEED = 10, ASTROID_SPEED = 3;
|
private final int LARGE=100, MEDIUM=50, SMALL=25, NUM_OF_LIVES = 3, LASER_SPEED = 10, ASTROID_SPEED = 3, FOG_COUNT = 4, MINI_SHIP_SIZE = 30;
|
||||||
private final int STOP=0, UP=1, DOWN=-1;
|
private final int STOP=0, UP=1, DOWN=-1; //Movement directions
|
||||||
public boolean gameOn,fireLock, gameOver, isFirstGame;
|
public boolean gameOn,fireLock, gameOver, isFirstGame;
|
||||||
private Ship player;
|
private Ship player;
|
||||||
private Vector<Sprite> astroidsSprites,laserSprites;
|
private Vector<Sprite> astroidsSprites,laserSprites; //will save all laser shots and asteroids which are currently on the screen.
|
||||||
private int pWidth, pHeight;
|
private int pWidth, pHeight; //panel dimensions
|
||||||
private Timer astroidTimer, fireTimer, startTime;
|
private Timer astroidTimer, fireTimer, startTime;
|
||||||
private Random r;
|
private Random r;
|
||||||
private int score, countDown;
|
private int score, countDown;
|
||||||
|
@ -40,6 +40,8 @@ public class GameEngine implements KeyListener {
|
||||||
private final URL themeURL= getClass().getResource("/Sounds/theme.wav");
|
private final URL themeURL= getClass().getResource("/Sounds/theme.wav");
|
||||||
|
|
||||||
public GameEngine(int width, int height){
|
public GameEngine(int width, int height){
|
||||||
|
|
||||||
|
//initialize variables and load audio\image files.
|
||||||
this.isFirstGame = true;
|
this.isFirstGame = true;
|
||||||
this.gameOver = true;
|
this.gameOver = true;
|
||||||
this.pWidth = width;
|
this.pWidth = width;
|
||||||
|
@ -56,16 +58,23 @@ public class GameEngine implements KeyListener {
|
||||||
fogs = new Vector<>();
|
fogs = new Vector<>();
|
||||||
r = new Random();
|
r = new Random();
|
||||||
sceneImage = new BufferedImage(width, height, Image.SCALE_SMOOTH);
|
sceneImage = new BufferedImage(width, height, Image.SCALE_SMOOTH);
|
||||||
initFogs();
|
|
||||||
|
initFogs(); //create fog sprites moving on screen.
|
||||||
startNewGame();
|
startNewGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates FOG_COUNT amount of fog sprites to roam the screen. (currently set to 4)
|
||||||
|
*/
|
||||||
private void initFogs(){
|
private void initFogs(){
|
||||||
for(int i = 0 ; i < 4 ; i++){
|
for(int i = 0 ; i < FOG_COUNT ; i++){
|
||||||
fogs.add(new Fog((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,1,"Fog.png",r.nextInt(360),pWidth));
|
fogs.add(new Fog((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,1,"Fog.png",r.nextInt(360),pWidth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize and reset vars and timers to "new game" configuration.
|
||||||
|
*/
|
||||||
private void startNewGame(){
|
private void startNewGame(){
|
||||||
score = 0;
|
score = 0;
|
||||||
lives = new Vector<>();
|
lives = new Vector<>();
|
||||||
|
@ -77,6 +86,9 @@ public class GameEngine implements KeyListener {
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clears asteroid and laser arrays, creates new asteroids, starts timers and repositions ship in center of screen.
|
||||||
|
*/
|
||||||
private void initGame(){
|
private void initGame(){
|
||||||
this.countDown = 3;
|
this.countDown = 3;
|
||||||
astroidsSprites = new Vector<>();
|
astroidsSprites = new Vector<>();
|
||||||
|
@ -90,32 +102,53 @@ public class GameEngine implements KeyListener {
|
||||||
createAstroid();
|
createAstroid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates requested amount of ships to "Lives" array (Mini ships to be presented at corner of the screen).
|
||||||
|
* @param num
|
||||||
|
* number of wanted "Lives".
|
||||||
|
*/
|
||||||
private void setupLives(int num){
|
private void setupLives(int num){
|
||||||
int size = 30;
|
|
||||||
for(int i = 0 ; i < num ; i++){
|
for(int i = 0 ; i < num ; i++){
|
||||||
lives.add(new Ship(pWidth - ((i+1)*size), 15, pWidth, pHeight, size));
|
lives.add(new Ship(pWidth - ((i+1)*MINI_SHIP_SIZE), 15, pWidth, pHeight, MINI_SHIP_SIZE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns score
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
public int getScore(){
|
public int getScore(){
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns gameOver flag
|
||||||
|
* @return
|
||||||
|
* boolean
|
||||||
|
*/
|
||||||
public boolean isGameOver(){
|
public boolean isGameOver(){
|
||||||
return this.gameOver;
|
return this.gameOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns countDown
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
public int getCountDown(){
|
public int getCountDown(){
|
||||||
return countDown;
|
return countDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new asteroid on a random position.
|
||||||
|
*/
|
||||||
private void createAstroid(){
|
private void createAstroid(){
|
||||||
astroidsSprites.add(new Astroid((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,ASTROID_SPEED,"astroid.png",r.nextInt(360),LARGE));
|
astroidsSprites.add(new Astroid((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,ASTROID_SPEED,"astroid.png",r.nextInt(360),LARGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent keyEvent) {
|
public void keyTyped(KeyEvent keyEvent) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent keyEvent) {
|
public void keyPressed(KeyEvent keyEvent) {
|
||||||
|
@ -128,15 +161,16 @@ public class GameEngine implements KeyListener {
|
||||||
player.setDirection(DOWN);
|
player.setDirection(DOWN);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_LEFT:
|
case KeyEvent.VK_LEFT:
|
||||||
player.turnShip(DOWN);
|
player.turnShip(DOWN); //Left
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_RIGHT:
|
case KeyEvent.VK_RIGHT:
|
||||||
player.turnShip(UP);
|
player.turnShip(UP); //Right
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_SPACE:
|
case KeyEvent.VK_SPACE: //Fire
|
||||||
if (!fireLock && countDown <= 0) {
|
if (!fireLock && countDown <= 0) {
|
||||||
if(laserAudioClip != null)
|
if(laserAudioClip != null)
|
||||||
laserAudioClip.loop();
|
laserAudioClip.play(); //Play audio file
|
||||||
|
//create a new laser from ship towards ship direction.
|
||||||
laserSprites.add(new LaserBlast((int) player.getLocX() + (player.getImageWidth() / 2),
|
laserSprites.add(new LaserBlast((int) player.getLocX() + (player.getImageWidth() / 2),
|
||||||
(int) player.getLocY() + (player.getImageHeight() / 2),
|
(int) player.getLocY() + (player.getImageHeight() / 2),
|
||||||
pWidth,
|
pWidth,
|
||||||
|
@ -145,11 +179,11 @@ public class GameEngine implements KeyListener {
|
||||||
"laser2.gif",
|
"laser2.gif",
|
||||||
player.getAngle(),
|
player.getAngle(),
|
||||||
SMALL));
|
SMALL));
|
||||||
fireLock = true;
|
fireLock = true; //lock for delay in fire speed
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_F2:
|
case KeyEvent.VK_F2: //new game
|
||||||
this.isFirstGame = false;
|
this.isFirstGame = false;
|
||||||
gameOver = false;
|
gameOver = false;
|
||||||
startNewGame();
|
startNewGame();
|
||||||
|
@ -165,6 +199,7 @@ public class GameEngine implements KeyListener {
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent keyEvent) {
|
public void keyReleased(KeyEvent keyEvent) {
|
||||||
if(gameOn){
|
if(gameOn){
|
||||||
|
//stop all movement activity
|
||||||
switch (keyEvent.getKeyCode()){
|
switch (keyEvent.getKeyCode()){
|
||||||
case KeyEvent.VK_UP:
|
case KeyEvent.VK_UP:
|
||||||
case KeyEvent.VK_DOWN:
|
case KeyEvent.VK_DOWN:
|
||||||
|
@ -174,9 +209,9 @@ public class GameEngine implements KeyListener {
|
||||||
case KeyEvent.VK_LEFT:
|
case KeyEvent.VK_LEFT:
|
||||||
player.turnShip(STOP);
|
player.turnShip(STOP);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_SPACE:
|
// case KeyEvent.VK_SPACE:
|
||||||
laserAudioClip.stop();
|
// laserAudioClip.stop();
|
||||||
break;
|
// break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -185,7 +220,9 @@ public class GameEngine implements KeyListener {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Update all sprites, including collision handling.
|
||||||
|
*/
|
||||||
public void update(){
|
public void update(){
|
||||||
for (Sprite sprite : fogs) {
|
for (Sprite sprite : fogs) {
|
||||||
sprite.update();
|
sprite.update();
|
||||||
|
@ -205,18 +242,29 @@ public class GameEngine implements KeyListener {
|
||||||
sprite.update();
|
sprite.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for collisions
|
||||||
collisionHandler();
|
collisionHandler();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a collision has occurred.
|
||||||
|
* in case of missile hitting an asteroid - they are both removed.
|
||||||
|
* in case of asteroid hitting the ship - round over.
|
||||||
|
*/
|
||||||
private void collisionHandler(){
|
private void collisionHandler(){
|
||||||
|
|
||||||
Vector<Sprite> newAstroids = new Vector<>();
|
Vector<Sprite> newAstroids = new Vector<>();
|
||||||
Vector<Sprite> removeLasers = new Vector<>();
|
Vector<Sprite> removeLasers = new Vector<>();
|
||||||
Vector<Sprite> removeAstroids = new Vector<>();
|
Vector<Sprite> removeAstroids = new Vector<>();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check for "Laser vs Asteroid" collisions
|
||||||
|
* in case of collision both missile and asteroid are removed,
|
||||||
|
* and 2 smaller asteroids are created (if needed).
|
||||||
|
*/
|
||||||
for (int i = 0; i<laserSprites.size(); i++){
|
for (int i = 0; i<laserSprites.size(); i++){
|
||||||
for (int j = 0; j<astroidsSprites.size(); j++){
|
for (int j = 0; j<astroidsSprites.size(); j++){
|
||||||
|
|
||||||
|
@ -240,6 +288,11 @@ public class GameEngine implements KeyListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* check for "Asteroid vs Ship" collisions.
|
||||||
|
* if last live - game over
|
||||||
|
* else - 1 less life and reset vars for next round
|
||||||
|
*/
|
||||||
|
|
||||||
for(int i = 0 ; i < astroidsSprites.size() ; i++){
|
for(int i = 0 ; i < astroidsSprites.size() ; i++){
|
||||||
if(CollisionUtil.collidesWith(astroidsSprites.get(i), player)){
|
if(CollisionUtil.collidesWith(astroidsSprites.get(i), player)){
|
||||||
|
@ -250,23 +303,33 @@ public class GameEngine implements KeyListener {
|
||||||
if(lives.size() > 0)
|
if(lives.size() > 0)
|
||||||
lives.remove(lives.size()-1);
|
lives.remove(lives.size()-1);
|
||||||
initGame();
|
initGame();
|
||||||
System.out.println("==============GAME OVER==============");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add new asteroids and remove collisions.
|
||||||
|
|
||||||
astroidsSprites.addAll(newAstroids);
|
astroidsSprites.addAll(newAstroids);
|
||||||
|
|
||||||
laserSprites.removeAll(removeLasers);
|
laserSprites.removeAll(removeLasers);
|
||||||
astroidsSprites.removeAll(removeAstroids);
|
astroidsSprites.removeAll(removeAstroids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render buffered image.
|
||||||
|
* @param panel
|
||||||
|
* JPanel
|
||||||
|
*/
|
||||||
public void render(JPanel panel){
|
public void render(JPanel panel){
|
||||||
sceneImage = new BufferedImage(this.pWidth, this.pHeight, Image.SCALE_FAST);
|
sceneImage = new BufferedImage(this.pWidth, this.pHeight, Image.SCALE_FAST);
|
||||||
renderScene(sceneImage.getGraphics(), panel);
|
renderScene(sceneImage.getGraphics(), panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws all sprites
|
||||||
|
* @param g
|
||||||
|
* Graphics
|
||||||
|
* @param panel
|
||||||
|
* Jpanel
|
||||||
|
*/
|
||||||
public void renderScene(Graphics g, JPanel panel){
|
public void renderScene(Graphics g, JPanel panel){
|
||||||
if(!gameOver)
|
if(!gameOver)
|
||||||
player.drawSprite(g, panel);
|
player.drawSprite(g, panel);
|
||||||
|
@ -289,20 +352,31 @@ public class GameEngine implements KeyListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private class astroidTimerListener implements ActionListener{
|
* creates an new asteroid each 5 seconds *
|
||||||
|
*/
|
||||||
|
private class astroidTimerListener implements ActionListener{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
createAstroid();
|
createAstroid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class fireTimerListener implements ActionListener{
|
|
||||||
|
/**
|
||||||
|
* Limits fire speed to 1 second.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private class fireTimerListener implements ActionListener{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
fireLock = false;
|
fireLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre game countdown.
|
||||||
|
*
|
||||||
|
*/
|
||||||
private class countDownListener implements ActionListener{
|
private class countDownListener implements ActionListener{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
@ -311,6 +385,11 @@ private class fireTimerListener implements ActionListener{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns sceneImage
|
||||||
|
* @return
|
||||||
|
* BufferedImage
|
||||||
|
*/
|
||||||
public BufferedImage getScene(){
|
public BufferedImage getScene(){
|
||||||
return this.sceneImage;
|
return this.sceneImage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,20 @@ import Engine.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
//import java.awt.image.BufferedImage;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sagi on 12/18/15.
|
* Created by sagi on 12/18/15.
|
||||||
*/
|
*/
|
||||||
public class GamePanel extends JPanel implements Runnable{
|
public class GamePanel extends JPanel implements Runnable{
|
||||||
// private final String BASE_PATH = System.getProperty("user.dir") + File.separator +"src"+ File.separator;
|
|
||||||
|
|
||||||
// private final String bgPath = BASE_PATH + "Images" + File.separator + "bg.gif";
|
|
||||||
// private final String gameOverPath = BASE_PATH + "Images" + File.separator + "gameOver.png";
|
|
||||||
// private final String startPath = BASE_PATH + "Images" + File.separator + "start.png";
|
|
||||||
|
|
||||||
private final URL bgURL= getClass().getResource("/Images/bg2.gif");
|
private final URL bgURL= getClass().getResource("/Images/bg2.gif");
|
||||||
private final URL gameOverURL= getClass().getResource("/Images/gameOver.png");
|
private final URL gameOverURL= getClass().getResource("/Images/gameOver.png");
|
||||||
private final URL startURL= getClass().getResource("/Images/start.png");
|
private final URL startURL= getClass().getResource("/Images/start.png");
|
||||||
|
|
||||||
|
|
||||||
private int width, height;
|
// private int width, height;
|
||||||
private GameEngine engine;
|
private GameEngine engine;
|
||||||
private JLabel lbl_score, lbl_countDown, lbl_gameOver, lbl_bg, lbl_start;
|
private JLabel lbl_score, lbl_countDown, lbl_gameOver, lbl_bg, lbl_start;
|
||||||
|
|
||||||
|
@ -30,23 +25,30 @@ public class GamePanel extends JPanel implements Runnable{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Constructor.
|
||||||
|
* initializes all objects on panel and creates gameEngine
|
||||||
|
*/
|
||||||
public GamePanel(int width, int height){
|
public GamePanel(int width, int height){
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
this.width = width;
|
// this.width = width;
|
||||||
this.height = height;
|
// this.height = height;
|
||||||
this.engine = new GameEngine(width, height);
|
this.engine = new GameEngine(width, height);
|
||||||
this.addKeyListener(engine);
|
this.addKeyListener(engine);
|
||||||
this.setFocusable(true);
|
this.setFocusable(true);
|
||||||
this.requestFocus();
|
this.requestFocus();
|
||||||
|
|
||||||
|
//set score label at top left corner
|
||||||
this.lbl_score = new JLabel("");
|
this.lbl_score = new JLabel("");
|
||||||
lbl_score.setBounds(15,15,width,30);
|
lbl_score.setBounds(15,15,width,30);
|
||||||
|
|
||||||
|
//set countDown label at center
|
||||||
this.lbl_countDown = new JLabel("");
|
this.lbl_countDown = new JLabel("");
|
||||||
lbl_countDown.setBounds(width/2,0,width,height);
|
lbl_countDown.setBounds(width/2,0,width,height);
|
||||||
System.out.println("URL = " +bgURL);
|
System.out.println("URL = " +bgURL);
|
||||||
|
|
||||||
|
//set background
|
||||||
img_bg = new ImageIcon(bgURL);
|
img_bg = new ImageIcon(bgURL);
|
||||||
Image tmp_BG = img_bg.getImage();
|
Image tmp_BG = img_bg.getImage();
|
||||||
bg_image = tmp_BG.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
|
bg_image = tmp_BG.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
|
||||||
|
@ -83,6 +85,7 @@ public class GamePanel extends JPanel implements Runnable{
|
||||||
while(engine.gameOn){
|
while(engine.gameOn){
|
||||||
engine.update();
|
engine.update();
|
||||||
|
|
||||||
|
//check if game is over and draw labels accordingly
|
||||||
if(engine.isGameOver()){
|
if(engine.isGameOver()){
|
||||||
this.lbl_countDown.setVisible(false);
|
this.lbl_countDown.setVisible(false);
|
||||||
if(!engine.isFirstGame)
|
if(!engine.isFirstGame)
|
||||||
|
@ -95,16 +98,20 @@ public class GamePanel extends JPanel implements Runnable{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//render graphics
|
||||||
engine.render(this);
|
engine.render(this);
|
||||||
repaint();
|
|
||||||
|
//sleep to slow down game
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(5);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
|
//sleep for other processes to take control
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(20);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -124,6 +131,7 @@ public class GamePanel extends JPanel implements Runnable{
|
||||||
|
|
||||||
g.drawImage(bg_image, 0, 0, this); //draw the background
|
g.drawImage(bg_image, 0, 0, this); //draw the background
|
||||||
g2d.drawImage(engine.getScene(),0,0,this); //Draw the scene
|
g2d.drawImage(engine.getScene(),0,0,this); //Draw the scene
|
||||||
|
|
||||||
//Some labels - Score & countDown
|
//Some labels - Score & countDown
|
||||||
lbl_score.setText("SCORE : " + engine.getScore());
|
lbl_score.setText("SCORE : " + engine.getScore());
|
||||||
if(engine.getCountDown() > 0){
|
if(engine.getCountDown() > 0){
|
||||||
|
|
|
@ -19,6 +19,9 @@ public class Astroid extends Sprite {
|
||||||
rotationSpeed = ((r.nextDouble()*10) % 3) + 0.01;
|
rotationSpeed = ((r.nextDouble()*10) % 3) + 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates sprite location according to movement speed and angle.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||||
|
@ -27,6 +30,9 @@ public class Astroid extends Sprite {
|
||||||
selfAngle+=rotationSpeed;
|
selfAngle+=rotationSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw sprite with rotation according to sprite angle
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void drawSprite(Graphics g, JPanel p) {
|
public void drawSprite(Graphics g, JPanel p) {
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
|
|
@ -22,6 +22,9 @@ public class Fog extends Sprite {
|
||||||
alphaChannel = r.nextFloat()-0.04f;
|
alphaChannel = r.nextFloat()-0.04f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates sprite location according to movement speed and angle.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||||
|
@ -30,6 +33,9 @@ public class Fog extends Sprite {
|
||||||
selfAngle+=rotationSpeed;
|
selfAngle+=rotationSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw sprite with rotation according to sprite angle
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void drawSprite(Graphics g, JPanel p) {
|
public void drawSprite(Graphics g, JPanel p) {
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
|
|
@ -14,6 +14,9 @@ public class LaserBlast extends Sprite {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates sprite location according to movement speed and angle.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||||
|
@ -21,6 +24,9 @@ public class LaserBlast extends Sprite {
|
||||||
outOfScreeFix();
|
outOfScreeFix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw sprite with rotation according to sprite angle
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void drawSprite(Graphics g, JPanel p) {
|
public void drawSprite(Graphics g, JPanel p) {
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package Sprites;
|
package Sprites;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
//import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.geom.AffineTransform;
|
//import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.AffineTransformOp;
|
//import java.awt.image.AffineTransformOp;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sagi on 12/18/15.
|
* Created by sagi on 12/18/15.
|
||||||
|
@ -28,6 +28,9 @@ public class Ship extends Sprite {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates sprite location according to movement speed and angle.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
setSpeed();
|
setSpeed();
|
||||||
|
@ -35,9 +38,23 @@ public class Ship extends Sprite {
|
||||||
locX += selfAccel * Math.cos(Math.toRadians(angle));
|
locX += selfAccel * Math.cos(Math.toRadians(angle));
|
||||||
locY -= selfAccel * (-1 * Math.sin(Math.toRadians(angle)));
|
locY -= selfAccel * (-1 * Math.sin(Math.toRadians(angle)));
|
||||||
outOfScreeFix();
|
outOfScreeFix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw sprite with rotation according to sprite angle
|
||||||
|
*/
|
||||||
|
public void drawSprite(Graphics g, JPanel panel) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.rotate(Math.toRadians(angle), locX + (bImage.getWidth()/2), locY + (bImage.getHeight()/2));
|
||||||
|
g2d.drawImage(bImage, (int)locX, (int)locY, panel);
|
||||||
|
g2d.rotate(-1*Math.toRadians(angle), locX + (bImage.getWidth()/2), locY + (bImage.getHeight()/2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets movement speed according to movement direction.
|
||||||
|
* if ship is not "moved" - it will slow down by slowing factor.
|
||||||
|
*/
|
||||||
private void setSpeed(){
|
private void setSpeed(){
|
||||||
if (direction == UP && !(selfAccel > MAX_SPEED)){
|
if (direction == UP && !(selfAccel > MAX_SPEED)){
|
||||||
selfAccel+=SLOWING_FACTOR*2;
|
selfAccel+=SLOWING_FACTOR*2;
|
||||||
|
@ -61,18 +78,21 @@ public class Ship extends Sprite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set movement direction
|
||||||
|
* @param direction
|
||||||
|
* int
|
||||||
|
*/
|
||||||
public void setDirection(int direction){
|
public void setDirection(int direction){
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public void drawSprite(Graphics g, JPanel panel) {
|
* set turning direction
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
* @param direction
|
||||||
g2d.rotate(Math.toRadians(angle), locX + (bImage.getWidth()/2), locY + (bImage.getHeight()/2));
|
* int
|
||||||
g2d.drawImage(bImage, (int)locX, (int)locY, panel);
|
*/
|
||||||
g2d.rotate(-1*Math.toRadians(angle), locX + (bImage.getWidth()/2), locY + (bImage.getHeight()/2));
|
|
||||||
|
|
||||||
}
|
|
||||||
public void turnShip(int direction){
|
public void turnShip(int direction){
|
||||||
turnDirection=direction;
|
turnDirection=direction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
//import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
//import java.net.URL;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Sprite {
|
public abstract class Sprite {
|
||||||
|
@ -18,7 +18,7 @@ public abstract class Sprite {
|
||||||
protected int pWidth, pHeight, size; // panel's dimensions
|
protected int pWidth, pHeight, size; // panel's dimensions
|
||||||
|
|
||||||
protected double angle;
|
protected double angle;
|
||||||
private final String BASE_PATH = System.getProperty("user.dir") + File.separator +"src"+ File.separator;
|
// private final String BASE_PATH = System.getProperty("user.dir") + File.separator +"src"+ File.separator;
|
||||||
|
|
||||||
|
|
||||||
public Sprite(int x, int y, int w, int h, int acc, String imgName, double angle, int size)
|
public Sprite(int x, int y, int w, int h, int acc, String imgName, double angle, int size)
|
||||||
|
@ -29,19 +29,24 @@ public abstract class Sprite {
|
||||||
acceleration = acc;
|
acceleration = acc;
|
||||||
pWidth = w;
|
pWidth = w;
|
||||||
pHeight = h;
|
pHeight = h;
|
||||||
try {///home/sagi/Development/JCE/Astroids2D/src/Images/ship.gif
|
this.angle = angle;
|
||||||
|
|
||||||
|
//load image from source files
|
||||||
|
try {
|
||||||
bImage = ImageIO.read(getClass().getResource("/Images/"+imgName));
|
bImage = ImageIO.read(getClass().getResource("/Images/"+imgName));
|
||||||
}catch (IOException pin){
|
}catch (IOException pin){
|
||||||
pin.printStackTrace();
|
pin.printStackTrace();
|
||||||
bImage = null;
|
bImage = null;
|
||||||
}
|
}
|
||||||
this.angle = angle;
|
|
||||||
|
|
||||||
setImageDimensions();
|
setImageDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setImageDimensions()
|
/*
|
||||||
|
* resizes image to a set size
|
||||||
|
*/
|
||||||
|
private void setImageDimensions()
|
||||||
{
|
{
|
||||||
Image tmp = bImage.getScaledInstance(size,size, Image.SCALE_SMOOTH);
|
Image tmp = bImage.getScaledInstance(size,size, Image.SCALE_SMOOTH);
|
||||||
BufferedImage bi = new BufferedImage(size,size, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage bi = new BufferedImage(size,size, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
@ -52,44 +57,82 @@ public abstract class Sprite {
|
||||||
bImage = bi;
|
bImage = bi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract method to update sprite.
|
||||||
|
*/
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
|
|
||||||
// public Rectangle getBoundingBox()
|
/**
|
||||||
// {
|
* returns sprite x position
|
||||||
// return new Rectangle(getLocX(), getLocY(), imageWidth, imageHeight);
|
* @return
|
||||||
// }
|
* double
|
||||||
|
*/
|
||||||
|
public double getLocX() {return locX;}
|
||||||
|
|
||||||
public double getLocX() {
|
/**
|
||||||
return locX;
|
* returns sprite y position
|
||||||
|
* @return
|
||||||
|
* double
|
||||||
|
*/
|
||||||
|
public double getLocY() {return locY;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns sprite acceleration
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
|
public int getAcceleration() {return acceleration;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns sprite size
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
|
public BufferedImage getbImage() {return bImage;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns image width
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
|
public int getImageWidth() {return imageWidth;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns image height
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
|
public int getImageHeight() {return imageHeight;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns sprite angle
|
||||||
|
* @return
|
||||||
|
* double
|
||||||
|
*/
|
||||||
|
public double getAngle() {return angle;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns sprite size
|
||||||
|
* @return
|
||||||
|
* int
|
||||||
|
*/
|
||||||
|
public int getSize() {return size;}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns shape location and dimensions as a Rectangle.
|
||||||
|
* @return
|
||||||
|
* Rectangle
|
||||||
|
*/
|
||||||
|
public Rectangle getBounds() {
|
||||||
|
return new Rectangle((int)locX, (int)locY, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLocY() {
|
|
||||||
return locY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAcceleration(){
|
/**
|
||||||
return acceleration;
|
* its not a bug it's a feature. actually it just moves a shape that goes beyond the screen to the other side.
|
||||||
}
|
*/
|
||||||
|
protected void outOfScreeFix(){
|
||||||
public BufferedImage getbImage()
|
|
||||||
{
|
|
||||||
return bImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getImageWidth() {
|
|
||||||
return imageWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getImageHeight()
|
|
||||||
{
|
|
||||||
return imageHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAngle(){
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void outOfScreeFix(){ //its not a bug it's a feature
|
|
||||||
if(locX < 0 - size)
|
if(locX < 0 - size)
|
||||||
locX = pWidth;
|
locX = pWidth;
|
||||||
else if (locX > pWidth+size)
|
else if (locX > pWidth+size)
|
||||||
|
@ -101,17 +144,11 @@ public abstract class Sprite {
|
||||||
locY = 0-size ;
|
locY = 0-size ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle getBounds() {
|
/**
|
||||||
Rectangle r = new Rectangle((int)locX, (int)locY, size, size);
|
* abstract method for drawing sprite.
|
||||||
return r;
|
* @param g
|
||||||
}
|
* @param p
|
||||||
|
*/
|
||||||
public int getSize(){
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract void drawSprite(Graphics g, JPanel p);
|
public abstract void drawSprite(Graphics g, JPanel p);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue