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>
|
||||
</component>
|
||||
<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=".idea/workspace.xml" />
|
||||
<ignored path="$PROJECT_DIR$/out/" />
|
||||
|
@ -27,21 +37,15 @@
|
|||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<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">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state vertical-scroll-proportion="2.1241474">
|
||||
<caret line="276" column="12" selection-start-line="276" selection-start-column="12" selection-end-line="278" selection-end-column="13" />
|
||||
<state vertical-scroll-proportion="0.0">
|
||||
<caret line="130" column="29" selection-start-line="130" selection-start-column="29" selection-end-line="130" selection-end-column="29" />
|
||||
<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" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -61,7 +65,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -73,7 +77,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -85,7 +89,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -97,12 +101,8 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<caret line="51" column="0" selection-start-line="51" selection-start-column="0" selection-end-line="51" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -119,14 +119,12 @@
|
|||
</provider>
|
||||
</entry>
|
||||
</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">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
<state vertical-scroll-proportion="1.7435198">
|
||||
<caret line="76" column="43" selection-start-line="76" selection-start-column="43" selection-end-line="76" selection-end-column="43" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -135,7 +133,7 @@
|
|||
<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" />
|
||||
<caret line="19" column="13" selection-start-line="19" selection-start-column="13" selection-end-line="19" selection-end-column="13" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -152,6 +150,9 @@
|
|||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="GradleLocalSettings">
|
||||
<option name="externalProjectsViewState">
|
||||
<projects_view />
|
||||
|
@ -173,9 +174,9 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="x" value="51" />
|
||||
<option name="x" value="67" />
|
||||
<option name="y" value="27" />
|
||||
<option name="width" value="1869" />
|
||||
<option name="width" value="1853" />
|
||||
<option name="height" value="1053" />
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
|
@ -203,7 +204,7 @@
|
|||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="Scope" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<PATH>
|
||||
|
@ -310,8 +311,8 @@
|
|||
</PATH>
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="Scratches" />
|
||||
<pane id="Scope" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
|
@ -604,7 +605,7 @@
|
|||
<servers />
|
||||
</component>
|
||||
<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" />
|
||||
<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" />
|
||||
|
@ -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="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="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="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="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="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="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>
|
||||
</component>
|
||||
<component name="Vcs.Log.UiProperties">
|
||||
|
@ -647,7 +648,7 @@
|
|||
<breakpoints>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<url>file://$PROJECT_DIR$/src/Engine/GameEngine.java</url>
|
||||
<line>270</line>
|
||||
<line>371</line>
|
||||
<properties />
|
||||
<option name="timeStamp" value="2" />
|
||||
</line-breakpoint>
|
||||
|
@ -661,20 +662,42 @@
|
|||
<option name="FILTER_TARGETS" value="false" />
|
||||
</component>
|
||||
<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">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<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" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -721,11 +744,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -743,9 +762,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</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" />
|
||||
<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" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -819,11 +830,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -841,9 +848,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</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" />
|
||||
<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" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -917,11 +916,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -939,9 +934,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</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" />
|
||||
<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" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -1015,11 +1002,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -1027,9 +1010,7 @@
|
|||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -1060,7 +1041,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Fog.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -1075,7 +1056,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Sprite.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -1085,12 +1066,8 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Ship.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#2181#2182#0" expanded="true" />
|
||||
<element signature="e#2220#2221#0" expanded="true" />
|
||||
</folding>
|
||||
<caret line="51" column="0" selection-start-line="51" selection-start-column="0" selection-end-line="51" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -1114,7 +1091,7 @@
|
|||
<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" />
|
||||
<caret line="19" column="13" selection-start-line="19" selection-start-column="13" selection-end-line="19" selection-end-column="13" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -1124,7 +1101,7 @@
|
|||
<entry file="file://$PROJECT_DIR$/src/Sprites/Astroid.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
|
@ -1139,31 +1116,23 @@
|
|||
</state>
|
||||
</provider>
|
||||
</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">
|
||||
<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>
|
||||
<element signature="imports" expanded="true" />
|
||||
<element signature="e#3584#3585#0" expanded="true" />
|
||||
<element signature="e#3611#3612#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</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">
|
||||
<state vertical-scroll-proportion="2.1241474">
|
||||
<caret line="276" column="12" selection-start-line="276" selection-start-column="12" selection-end-line="278" selection-end-column="13" />
|
||||
<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 vertical-scroll-proportion="1.7435198">
|
||||
<caret line="76" column="43" selection-start-line="76" selection-start-column="43" selection-end-line="76" selection-end-column="43" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</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,298 +22,377 @@ import java.util.Vector;
|
|||
|
||||
|
||||
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 STOP=0, UP=1, DOWN=-1;
|
||||
public boolean gameOn,fireLock, gameOver, isFirstGame;
|
||||
private Ship player;
|
||||
private Vector<Sprite> astroidsSprites,laserSprites;
|
||||
private int pWidth, pHeight;
|
||||
private Timer astroidTimer, fireTimer, startTime;
|
||||
private Random r;
|
||||
private int score, countDown;
|
||||
private Vector<Sprite> lives, fogs;
|
||||
private AudioClip laserAudioClip;
|
||||
private BufferedImage sceneImage;
|
||||
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; //Movement directions
|
||||
public boolean gameOn,fireLock, gameOver, isFirstGame;
|
||||
private Ship player;
|
||||
private Vector<Sprite> astroidsSprites,laserSprites; //will save all laser shots and asteroids which are currently on the screen.
|
||||
private int pWidth, pHeight; //panel dimensions
|
||||
private Timer astroidTimer, fireTimer, startTime;
|
||||
private Random r;
|
||||
private int score, countDown;
|
||||
private Vector<Sprite> lives, fogs;
|
||||
private AudioClip laserAudioClip;
|
||||
private BufferedImage sceneImage;
|
||||
|
||||
private AudioClip themeAudioClip;
|
||||
private final URL laserURL= getClass().getResource("/Sounds/laser.wav");
|
||||
private final URL themeURL= getClass().getResource("/Sounds/theme.wav");
|
||||
private AudioClip themeAudioClip;
|
||||
private final URL laserURL= getClass().getResource("/Sounds/laser.wav");
|
||||
private final URL themeURL= getClass().getResource("/Sounds/theme.wav");
|
||||
|
||||
public GameEngine(int width, int height){
|
||||
this.isFirstGame = true;
|
||||
this.gameOver = true;
|
||||
this.pWidth = width;
|
||||
this.pHeight = height;
|
||||
try {
|
||||
laserAudioClip = Applet.newAudioClip(laserURL);
|
||||
themeAudioClip = Applet.newAudioClip(themeURL);
|
||||
}catch (Exception e){
|
||||
laserAudioClip = null;
|
||||
themeAudioClip = null;
|
||||
}
|
||||
if(themeAudioClip != null)
|
||||
themeAudioClip.loop();
|
||||
fogs = new Vector<>();
|
||||
r = new Random();
|
||||
sceneImage = new BufferedImage(width, height, Image.SCALE_SMOOTH);
|
||||
initFogs();
|
||||
startNewGame();
|
||||
}
|
||||
public GameEngine(int width, int height){
|
||||
|
||||
private void initFogs(){
|
||||
for(int i = 0 ; i < 4 ; i++){
|
||||
fogs.add(new Fog((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,1,"Fog.png",r.nextInt(360),pWidth));
|
||||
}
|
||||
}
|
||||
//initialize variables and load audio\image files.
|
||||
this.isFirstGame = true;
|
||||
this.gameOver = true;
|
||||
this.pWidth = width;
|
||||
this.pHeight = height;
|
||||
try {
|
||||
laserAudioClip = Applet.newAudioClip(laserURL);
|
||||
themeAudioClip = Applet.newAudioClip(themeURL);
|
||||
}catch (Exception e){
|
||||
laserAudioClip = null;
|
||||
themeAudioClip = null;
|
||||
}
|
||||
if(themeAudioClip != null)
|
||||
themeAudioClip.loop();
|
||||
fogs = new Vector<>();
|
||||
r = new Random();
|
||||
sceneImage = new BufferedImage(width, height, Image.SCALE_SMOOTH);
|
||||
|
||||
private void startNewGame(){
|
||||
score = 0;
|
||||
lives = new Vector<>();
|
||||
setupLives(NUM_OF_LIVES);
|
||||
astroidTimer = new Timer(5000, new astroidTimerListener()) ;
|
||||
fireTimer = new Timer(500, new fireTimerListener()) ;
|
||||
startTime = new Timer(1000, new countDownListener());
|
||||
fogs.remove(fogs.size()-1);
|
||||
initGame();
|
||||
}
|
||||
initFogs(); //create fog sprites moving on screen.
|
||||
startNewGame();
|
||||
}
|
||||
|
||||
private void initGame(){
|
||||
this.countDown = 3;
|
||||
astroidsSprites = new Vector<>();
|
||||
laserSprites = new Vector<>();
|
||||
this.player = new Ship(pWidth/2, pHeight/2,pWidth,pHeight, MEDIUM);
|
||||
gameOn = true;
|
||||
fireTimer.start();
|
||||
astroidTimer.start();
|
||||
/**
|
||||
* creates FOG_COUNT amount of fog sprites to roam the screen. (currently set to 4)
|
||||
*/
|
||||
private void initFogs(){
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i =0 ; i<4 ; i++)
|
||||
createAstroid();
|
||||
}
|
||||
/**
|
||||
* initialize and reset vars and timers to "new game" configuration.
|
||||
*/
|
||||
private void startNewGame(){
|
||||
score = 0;
|
||||
lives = new Vector<>();
|
||||
setupLives(NUM_OF_LIVES);
|
||||
astroidTimer = new Timer(5000, new astroidTimerListener()) ;
|
||||
fireTimer = new Timer(500, new fireTimerListener()) ;
|
||||
startTime = new Timer(1000, new countDownListener());
|
||||
fogs.remove(fogs.size()-1);
|
||||
initGame();
|
||||
}
|
||||
|
||||
private void setupLives(int num){
|
||||
int size = 30;
|
||||
for(int i = 0 ; i < num ; i++){
|
||||
lives.add(new Ship(pWidth - ((i+1)*size), 15, pWidth, pHeight, size));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* clears asteroid and laser arrays, creates new asteroids, starts timers and repositions ship in center of screen.
|
||||
*/
|
||||
private void initGame(){
|
||||
this.countDown = 3;
|
||||
astroidsSprites = new Vector<>();
|
||||
laserSprites = new Vector<>();
|
||||
this.player = new Ship(pWidth/2, pHeight/2,pWidth,pHeight, MEDIUM);
|
||||
gameOn = true;
|
||||
fireTimer.start();
|
||||
astroidTimer.start();
|
||||
|
||||
public int getScore(){
|
||||
return score;
|
||||
}
|
||||
for (int i =0 ; i<4 ; i++)
|
||||
createAstroid();
|
||||
}
|
||||
|
||||
public boolean isGameOver(){
|
||||
return this.gameOver;
|
||||
}
|
||||
/**
|
||||
* 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){
|
||||
for(int i = 0 ; i < num ; i++){
|
||||
lives.add(new Ship(pWidth - ((i+1)*MINI_SHIP_SIZE), 15, pWidth, pHeight, MINI_SHIP_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
public int getCountDown(){
|
||||
return countDown;
|
||||
}
|
||||
/**
|
||||
* returns score
|
||||
* @return
|
||||
* int
|
||||
*/
|
||||
public int getScore(){
|
||||
return score;
|
||||
}
|
||||
|
||||
private void createAstroid(){
|
||||
astroidsSprites.add(new Astroid((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,ASTROID_SPEED,"astroid.png",r.nextInt(360),LARGE));
|
||||
}
|
||||
/**
|
||||
* returns gameOver flag
|
||||
* @return
|
||||
* boolean
|
||||
*/
|
||||
public boolean isGameOver(){
|
||||
return this.gameOver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent keyEvent) {
|
||||
}
|
||||
/**
|
||||
* returns countDown
|
||||
* @return
|
||||
* int
|
||||
*/
|
||||
public int getCountDown(){
|
||||
return countDown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
if(gameOn) {
|
||||
switch (keyEvent.getKeyCode()) {
|
||||
case KeyEvent.VK_UP:
|
||||
player.setDirection(UP);
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
player.setDirection(DOWN);
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
player.turnShip(DOWN);
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
player.turnShip(UP);
|
||||
break;
|
||||
case KeyEvent.VK_SPACE:
|
||||
if (!fireLock && countDown <= 0) {
|
||||
if(laserAudioClip != null)
|
||||
laserAudioClip.loop();
|
||||
laserSprites.add(new LaserBlast((int) player.getLocX() + (player.getImageWidth() / 2),
|
||||
(int) player.getLocY() + (player.getImageHeight() / 2),
|
||||
pWidth,
|
||||
pHeight,
|
||||
LASER_SPEED,
|
||||
"laser2.gif",
|
||||
player.getAngle(),
|
||||
SMALL));
|
||||
fireLock = true;
|
||||
}
|
||||
/**
|
||||
* Create a new asteroid on a random position.
|
||||
*/
|
||||
private void createAstroid(){
|
||||
astroidsSprites.add(new Astroid((-1)*r.nextInt(),(-1)*r.nextInt(),pWidth,pHeight,ASTROID_SPEED,"astroid.png",r.nextInt(360),LARGE));
|
||||
}
|
||||
|
||||
break;
|
||||
case KeyEvent.VK_F2:
|
||||
this.isFirstGame = false;
|
||||
gameOver = false;
|
||||
startNewGame();
|
||||
startTime.start();
|
||||
break;
|
||||
@Override
|
||||
public void keyTyped(KeyEvent keyEvent) {}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
if(gameOn) {
|
||||
switch (keyEvent.getKeyCode()) {
|
||||
case KeyEvent.VK_UP:
|
||||
player.setDirection(UP);
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
player.setDirection(DOWN);
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
player.turnShip(DOWN); //Left
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
player.turnShip(UP); //Right
|
||||
break;
|
||||
case KeyEvent.VK_SPACE: //Fire
|
||||
if (!fireLock && countDown <= 0) {
|
||||
if(laserAudioClip != null)
|
||||
laserAudioClip.play(); //Play audio file
|
||||
//create a new laser from ship towards ship direction.
|
||||
laserSprites.add(new LaserBlast((int) player.getLocX() + (player.getImageWidth() / 2),
|
||||
(int) player.getLocY() + (player.getImageHeight() / 2),
|
||||
pWidth,
|
||||
pHeight,
|
||||
LASER_SPEED,
|
||||
"laser2.gif",
|
||||
player.getAngle(),
|
||||
SMALL));
|
||||
fireLock = true; //lock for delay in fire speed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent keyEvent) {
|
||||
if(gameOn){
|
||||
switch (keyEvent.getKeyCode()){
|
||||
case KeyEvent.VK_UP:
|
||||
case KeyEvent.VK_DOWN:
|
||||
player.setDirection(STOP);
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
case KeyEvent.VK_LEFT:
|
||||
player.turnShip(STOP);
|
||||
break;
|
||||
case KeyEvent.VK_SPACE:
|
||||
laserAudioClip.stop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
case KeyEvent.VK_F2: //new game
|
||||
this.isFirstGame = false;
|
||||
gameOver = false;
|
||||
startNewGame();
|
||||
startTime.start();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent keyEvent) {
|
||||
if(gameOn){
|
||||
//stop all movement activity
|
||||
switch (keyEvent.getKeyCode()){
|
||||
case KeyEvent.VK_UP:
|
||||
case KeyEvent.VK_DOWN:
|
||||
player.setDirection(STOP);
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
case KeyEvent.VK_LEFT:
|
||||
player.turnShip(STOP);
|
||||
break;
|
||||
// case KeyEvent.VK_SPACE:
|
||||
// laserAudioClip.stop();
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Update all sprites, including collision handling.
|
||||
*/
|
||||
public void update(){
|
||||
for (Sprite sprite : fogs) {
|
||||
sprite.update();
|
||||
}
|
||||
if(!gameOver) {
|
||||
if (countDown > 0)
|
||||
return;
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
public void update(){
|
||||
for (Sprite sprite : fogs) {
|
||||
sprite.update();
|
||||
}
|
||||
if(!gameOver) {
|
||||
if (countDown > 0)
|
||||
return;
|
||||
}
|
||||
else
|
||||
return;
|
||||
player.update();
|
||||
for (Sprite sprite : astroidsSprites) {
|
||||
sprite.update();
|
||||
}
|
||||
for (Sprite sprite : laserSprites) {
|
||||
sprite.update();
|
||||
}
|
||||
|
||||
player.update();
|
||||
for (Sprite sprite : astroidsSprites) {
|
||||
sprite.update();
|
||||
}
|
||||
for (Sprite sprite : laserSprites) {
|
||||
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(){
|
||||
|
||||
}
|
||||
Vector<Sprite> newAstroids = new Vector<>();
|
||||
Vector<Sprite> removeLasers = 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 j = 0; j<astroidsSprites.size(); j++){
|
||||
|
||||
private void collisionHandler(){
|
||||
if(CollisionUtil.collidesWith(laserSprites.get(i), astroidsSprites.get(j))) {
|
||||
score+=100;
|
||||
if (astroidsSprites.get(j).getSize() == LARGE) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
newAstroids.add(new Astroid((int) astroidsSprites.get(j).getLocX(), (int) astroidsSprites.get(j).getLocY(), pWidth, pHeight, astroidsSprites.get(j).getAcceleration(), "astroid.png", r.nextInt(360), MEDIUM));
|
||||
}
|
||||
} else if (astroidsSprites.get(j).getSize() == MEDIUM) {
|
||||
for (int h = 0; h < 2; h++) {
|
||||
newAstroids.add(new Astroid((int) astroidsSprites.get(j).getLocX(), (int) astroidsSprites.get(j).getLocY(), pWidth, pHeight, astroidsSprites.get(j).getAcceleration(), "astroid.png", r.nextInt(360), SMALL));
|
||||
}
|
||||
score+=100;
|
||||
}else{
|
||||
score+=200;
|
||||
}
|
||||
|
||||
Vector<Sprite> newAstroids = new Vector<>();
|
||||
Vector<Sprite> removeLasers = new Vector<>();
|
||||
Vector<Sprite> removeAstroids = new Vector<>();
|
||||
removeLasers.add(laserSprites.get(i));
|
||||
removeAstroids.add(astroidsSprites.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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++){
|
||||
if(CollisionUtil.collidesWith(astroidsSprites.get(i), player)){
|
||||
if(lives.size() == 1){
|
||||
gameOver = true;
|
||||
fogs.add(new Fog(pWidth,0,pWidth,pHeight,1,"Fog.png",180,pWidth));
|
||||
}
|
||||
if(lives.size() > 0)
|
||||
lives.remove(lives.size()-1);
|
||||
initGame();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i<laserSprites.size(); i++){
|
||||
for (int j = 0; j<astroidsSprites.size(); j++){
|
||||
//add new asteroids and remove collisions.
|
||||
astroidsSprites.addAll(newAstroids);
|
||||
laserSprites.removeAll(removeLasers);
|
||||
astroidsSprites.removeAll(removeAstroids);
|
||||
}
|
||||
|
||||
/**
|
||||
* render buffered image.
|
||||
* @param panel
|
||||
* JPanel
|
||||
*/
|
||||
public void render(JPanel panel){
|
||||
sceneImage = new BufferedImage(this.pWidth, this.pHeight, Image.SCALE_FAST);
|
||||
renderScene(sceneImage.getGraphics(), panel);
|
||||
}
|
||||
|
||||
if(CollisionUtil.collidesWith(laserSprites.get(i), astroidsSprites.get(j))) {
|
||||
score+=100;
|
||||
if (astroidsSprites.get(j).getSize() == LARGE) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
newAstroids.add(new Astroid((int) astroidsSprites.get(j).getLocX(), (int) astroidsSprites.get(j).getLocY(), pWidth, pHeight, astroidsSprites.get(j).getAcceleration(), "astroid.png", r.nextInt(360), MEDIUM));
|
||||
}
|
||||
} else if (astroidsSprites.get(j).getSize() == MEDIUM) {
|
||||
for (int h = 0; h < 2; h++) {
|
||||
newAstroids.add(new Astroid((int) astroidsSprites.get(j).getLocX(), (int) astroidsSprites.get(j).getLocY(), pWidth, pHeight, astroidsSprites.get(j).getAcceleration(), "astroid.png", r.nextInt(360), SMALL));
|
||||
}
|
||||
score+=100;
|
||||
}else{
|
||||
score+=200;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all sprites
|
||||
* @param g
|
||||
* Graphics
|
||||
* @param panel
|
||||
* Jpanel
|
||||
*/
|
||||
public void renderScene(Graphics g, JPanel panel){
|
||||
if(!gameOver)
|
||||
player.drawSprite(g, panel);
|
||||
try {
|
||||
for (Sprite sprite : astroidsSprites) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : lives) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : laserSprites) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : fogs) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
}catch (Exception e)
|
||||
{
|
||||
|
||||
removeLasers.add(laserSprites.get(i));
|
||||
removeAstroids.add(astroidsSprites.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0 ; i < astroidsSprites.size() ; i++){
|
||||
if(CollisionUtil.collidesWith(astroidsSprites.get(i), player)){
|
||||
if(lives.size() == 1){
|
||||
gameOver = true;
|
||||
fogs.add(new Fog(pWidth,0,pWidth,pHeight,1,"Fog.png",180,pWidth));
|
||||
}
|
||||
if(lives.size() > 0)
|
||||
lives.remove(lives.size()-1);
|
||||
initGame();
|
||||
System.out.println("==============GAME OVER==============");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* creates an new asteroid each 5 seconds *
|
||||
*/
|
||||
private class astroidTimerListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
createAstroid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits fire speed to 1 second.
|
||||
*
|
||||
*/
|
||||
private class fireTimerListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
fireLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre game countdown.
|
||||
*
|
||||
*/
|
||||
private class countDownListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
countDown--;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
astroidsSprites.addAll(newAstroids);
|
||||
|
||||
laserSprites.removeAll(removeLasers);
|
||||
astroidsSprites.removeAll(removeAstroids);
|
||||
}
|
||||
|
||||
public void render(JPanel panel){
|
||||
sceneImage = new BufferedImage(this.pWidth, this.pHeight, Image.SCALE_FAST);
|
||||
renderScene(sceneImage.getGraphics(), panel);
|
||||
}
|
||||
|
||||
public void renderScene(Graphics g, JPanel panel){
|
||||
if(!gameOver)
|
||||
player.drawSprite(g, panel);
|
||||
try {
|
||||
for (Sprite sprite : astroidsSprites) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : lives) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : laserSprites) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
for (Sprite sprite : fogs) {
|
||||
sprite.drawSprite(g, panel);
|
||||
}
|
||||
}catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class astroidTimerListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
createAstroid();
|
||||
}
|
||||
}
|
||||
private class fireTimerListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
fireLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
private class countDownListener implements ActionListener{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
countDown--;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getScene(){
|
||||
return this.sceneImage;
|
||||
}
|
||||
/**
|
||||
* returns sceneImage
|
||||
* @return
|
||||
* BufferedImage
|
||||
*/
|
||||
public BufferedImage getScene(){
|
||||
return this.sceneImage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,25 +3,20 @@ import Engine.*;
|
|||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
//import java.awt.image.BufferedImage;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by sagi on 12/18/15.
|
||||
*/
|
||||
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 gameOverURL= getClass().getResource("/Images/gameOver.png");
|
||||
private final URL startURL= getClass().getResource("/Images/start.png");
|
||||
|
||||
|
||||
private int width, height;
|
||||
// private int width, height;
|
||||
private GameEngine engine;
|
||||
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){
|
||||
this.setLayout(null);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
// this.width = width;
|
||||
// this.height = height;
|
||||
this.engine = new GameEngine(width, height);
|
||||
this.addKeyListener(engine);
|
||||
this.setFocusable(true);
|
||||
this.requestFocus();
|
||||
|
||||
//set score label at top left corner
|
||||
this.lbl_score = new JLabel("");
|
||||
lbl_score.setBounds(15,15,width,30);
|
||||
|
||||
|
||||
//set countDown label at center
|
||||
this.lbl_countDown = new JLabel("");
|
||||
lbl_countDown.setBounds(width/2,0,width,height);
|
||||
System.out.println("URL = " +bgURL);
|
||||
|
||||
//set background
|
||||
img_bg = new ImageIcon(bgURL);
|
||||
Image tmp_BG = img_bg.getImage();
|
||||
bg_image = tmp_BG.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
|
||||
|
@ -82,7 +84,8 @@ public class GamePanel extends JPanel implements Runnable{
|
|||
public void run() {
|
||||
while(engine.gameOn){
|
||||
engine.update();
|
||||
|
||||
|
||||
//check if game is over and draw labels accordingly
|
||||
if(engine.isGameOver()){
|
||||
this.lbl_countDown.setVisible(false);
|
||||
if(!engine.isFirstGame)
|
||||
|
@ -94,17 +97,21 @@ public class GamePanel extends JPanel implements Runnable{
|
|||
lbl_start.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//render graphics
|
||||
engine.render(this);
|
||||
repaint();
|
||||
|
||||
//sleep to slow down game
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
repaint();
|
||||
|
||||
//sleep for other processes to take control
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -124,6 +131,7 @@ public class GamePanel extends JPanel implements Runnable{
|
|||
|
||||
g.drawImage(bg_image, 0, 0, this); //draw the background
|
||||
g2d.drawImage(engine.getScene(),0,0,this); //Draw the scene
|
||||
|
||||
//Some labels - Score & countDown
|
||||
lbl_score.setText("SCORE : " + engine.getScore());
|
||||
if(engine.getCountDown() > 0){
|
||||
|
|
|
@ -19,6 +19,9 @@ public class Astroid extends Sprite {
|
|||
rotationSpeed = ((r.nextDouble()*10) % 3) + 0.01;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates sprite location according to movement speed and angle.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||
|
@ -26,7 +29,10 @@ public class Astroid extends Sprite {
|
|||
outOfScreeFix();
|
||||
selfAngle+=rotationSpeed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw sprite with rotation according to sprite angle
|
||||
*/
|
||||
@Override
|
||||
public void drawSprite(Graphics g, JPanel p) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
|
|
|
@ -21,7 +21,10 @@ public class Fog extends Sprite {
|
|||
rotationSpeed = 0;
|
||||
alphaChannel = r.nextFloat()-0.04f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* updates sprite location according to movement speed and angle.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||
|
@ -30,6 +33,9 @@ public class Fog extends Sprite {
|
|||
selfAngle+=rotationSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* draw sprite with rotation according to sprite angle
|
||||
*/
|
||||
@Override
|
||||
public void drawSprite(Graphics g, JPanel p) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
|
|
|
@ -14,6 +14,9 @@ public class LaserBlast extends Sprite {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* updates sprite location according to movement speed and angle.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
locX += acceleration * Math.cos(Math.toRadians(angle));
|
||||
|
@ -21,6 +24,9 @@ public class LaserBlast extends Sprite {
|
|||
outOfScreeFix();
|
||||
}
|
||||
|
||||
/**
|
||||
* draw sprite with rotation according to sprite angle
|
||||
*/
|
||||
@Override
|
||||
public void drawSprite(Graphics g, JPanel p) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
|
|
|
@ -1,80 +1,100 @@
|
|||
package Sprites;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
//import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
//import java.awt.geom.AffineTransform;
|
||||
//import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
//import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by sagi on 12/18/15.
|
||||
*/
|
||||
public class Ship extends Sprite {
|
||||
|
||||
private final int STOP=0, UP=1, DOWN=-1, TURN_SPEED=10;
|
||||
private final double MAX_SPEED = 6, SLOWING_FACTOR = 0.1;
|
||||
private int direction, turnDirection;
|
||||
private BufferedImage bi;
|
||||
private double selfAccel;
|
||||
private final int STOP=0, UP=1, DOWN=-1, TURN_SPEED=10;
|
||||
private final double MAX_SPEED = 6, SLOWING_FACTOR = 0.1;
|
||||
private int direction, turnDirection;
|
||||
private BufferedImage bi;
|
||||
private double selfAccel;
|
||||
|
||||
|
||||
public Ship(int x, int y, int w, int h, int size) {
|
||||
super(x, y, w, h, 0, "ship2.png", 0, size);
|
||||
direction = STOP;
|
||||
turnDirection = STOP;
|
||||
selfAccel = acceleration;
|
||||
public Ship(int x, int y, int w, int h, int size) {
|
||||
super(x, y, w, h, 0, "ship2.png", 0, size);
|
||||
direction = STOP;
|
||||
turnDirection = STOP;
|
||||
selfAccel = acceleration;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
setSpeed();
|
||||
this.angle+=TURN_SPEED*turnDirection;
|
||||
locX += selfAccel * Math.cos(Math.toRadians(angle));
|
||||
locY -= selfAccel * (-1 * Math.sin(Math.toRadians(angle)));
|
||||
outOfScreeFix();
|
||||
/**
|
||||
* updates sprite location according to movement speed and angle.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
setSpeed();
|
||||
this.angle+=TURN_SPEED*turnDirection;
|
||||
locX += selfAccel * Math.cos(Math.toRadians(angle));
|
||||
locY -= selfAccel * (-1 * Math.sin(Math.toRadians(angle)));
|
||||
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));
|
||||
|
||||
private void setSpeed(){
|
||||
if (direction == UP && !(selfAccel > MAX_SPEED)){
|
||||
selfAccel+=SLOWING_FACTOR*2;
|
||||
}
|
||||
else if (direction == DOWN && (selfAccel > MAX_SPEED*(-1))){
|
||||
selfAccel-=SLOWING_FACTOR*2;
|
||||
}
|
||||
else { //slowing down
|
||||
if (selfAccel > 0) {
|
||||
selfAccel -= SLOWING_FACTOR;
|
||||
if (selfAccel < 0) {
|
||||
selfAccel = 0;
|
||||
}
|
||||
}
|
||||
if (selfAccel < 0) {
|
||||
selfAccel += SLOWING_FACTOR;
|
||||
if (selfAccel > 0) {
|
||||
selfAccel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirection(int direction){
|
||||
this.direction = direction;
|
||||
}
|
||||
/**
|
||||
* sets movement speed according to movement direction.
|
||||
* if ship is not "moved" - it will slow down by slowing factor.
|
||||
*/
|
||||
private void setSpeed(){
|
||||
if (direction == UP && !(selfAccel > MAX_SPEED)){
|
||||
selfAccel+=SLOWING_FACTOR*2;
|
||||
}
|
||||
else if (direction == DOWN && (selfAccel > MAX_SPEED*(-1))){
|
||||
selfAccel-=SLOWING_FACTOR*2;
|
||||
}
|
||||
else { //slowing down
|
||||
if (selfAccel > 0) {
|
||||
selfAccel -= SLOWING_FACTOR;
|
||||
if (selfAccel < 0) {
|
||||
selfAccel = 0;
|
||||
}
|
||||
}
|
||||
if (selfAccel < 0) {
|
||||
selfAccel += SLOWING_FACTOR;
|
||||
if (selfAccel > 0) {
|
||||
selfAccel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
/**
|
||||
* set movement direction
|
||||
* @param direction
|
||||
* int
|
||||
*/
|
||||
public void setDirection(int direction){
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
}
|
||||
public void turnShip(int direction){
|
||||
turnDirection=direction;
|
||||
}
|
||||
/**
|
||||
* set turning direction
|
||||
* @param direction
|
||||
* int
|
||||
*/
|
||||
public void turnShip(int direction){
|
||||
turnDirection=direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,114 +4,151 @@ import javax.imageio.ImageIO;
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
//import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
//import java.net.URL;
|
||||
|
||||
|
||||
public abstract class Sprite {
|
||||
protected BufferedImage bImage;
|
||||
protected int imageWidth, imageHeight; // image dimensions
|
||||
protected BufferedImage bImage;
|
||||
protected int imageWidth, imageHeight; // image dimensions
|
||||
|
||||
protected double locX, locY;
|
||||
protected int acceleration;
|
||||
protected int pWidth, pHeight, size; // panel's dimensions
|
||||
protected double locX, locY;
|
||||
protected int acceleration;
|
||||
protected int pWidth, pHeight, size; // panel's dimensions
|
||||
|
||||
protected double angle;
|
||||
private final String BASE_PATH = System.getProperty("user.dir") + File.separator +"src"+ File.separator;
|
||||
protected double angle;
|
||||
// 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)
|
||||
{
|
||||
this.size = size;
|
||||
locX = x;
|
||||
locY = y;
|
||||
acceleration = acc;
|
||||
pWidth = w;
|
||||
pHeight = h;
|
||||
try {///home/sagi/Development/JCE/Astroids2D/src/Images/ship.gif
|
||||
bImage = ImageIO.read(getClass().getResource("/Images/"+imgName));
|
||||
}catch (IOException pin){
|
||||
pin.printStackTrace();
|
||||
bImage = null;
|
||||
}
|
||||
this.angle = angle;
|
||||
public Sprite(int x, int y, int w, int h, int acc, String imgName, double angle, int size)
|
||||
{
|
||||
this.size = size;
|
||||
locX = x;
|
||||
locY = y;
|
||||
acceleration = acc;
|
||||
pWidth = w;
|
||||
pHeight = h;
|
||||
this.angle = angle;
|
||||
|
||||
setImageDimensions();
|
||||
}
|
||||
//load image from source files
|
||||
try {
|
||||
bImage = ImageIO.read(getClass().getResource("/Images/"+imgName));
|
||||
}catch (IOException pin){
|
||||
pin.printStackTrace();
|
||||
bImage = null;
|
||||
}
|
||||
|
||||
setImageDimensions();
|
||||
}
|
||||
|
||||
|
||||
public void setImageDimensions()
|
||||
{
|
||||
Image tmp = bImage.getScaledInstance(size,size, Image.SCALE_SMOOTH);
|
||||
BufferedImage bi = new BufferedImage(size,size, BufferedImage.TYPE_INT_ARGB);
|
||||
/*
|
||||
* resizes image to a set size
|
||||
*/
|
||||
private void setImageDimensions()
|
||||
{
|
||||
Image tmp = bImage.getScaledInstance(size,size, Image.SCALE_SMOOTH);
|
||||
BufferedImage bi = new BufferedImage(size,size, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics2D g2d = bi.createGraphics();
|
||||
g2d.drawImage(tmp,0,0,null);
|
||||
g2d.dispose();
|
||||
bImage = bi;
|
||||
}
|
||||
Graphics2D g2d = bi.createGraphics();
|
||||
g2d.drawImage(tmp,0,0,null);
|
||||
g2d.dispose();
|
||||
bImage = bi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method to update sprite.
|
||||
*/
|
||||
public abstract void update();
|
||||
|
||||
public abstract void update();
|
||||
/**
|
||||
* returns sprite x position
|
||||
* @return
|
||||
* double
|
||||
*/
|
||||
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;}
|
||||
|
||||
// public Rectangle getBoundingBox()
|
||||
// {
|
||||
// return new Rectangle(getLocX(), getLocY(), imageWidth, imageHeight);
|
||||
// }
|
||||
|
||||
/**
|
||||
* returns shape location and dimensions as a Rectangle.
|
||||
* @return
|
||||
* Rectangle
|
||||
*/
|
||||
public Rectangle getBounds() {
|
||||
return new Rectangle((int)locX, (int)locY, size, size);
|
||||
}
|
||||
|
||||
public double getLocX() {
|
||||
return locX;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(){
|
||||
if(locX < 0 - size)
|
||||
locX = pWidth;
|
||||
else if (locX > pWidth+size)
|
||||
locX = 0-size;
|
||||
|
||||
public double getLocY() {
|
||||
return locY;
|
||||
}
|
||||
|
||||
public int getAcceleration(){
|
||||
return acceleration;
|
||||
}
|
||||
|
||||
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)
|
||||
locX = pWidth;
|
||||
else if (locX > pWidth+size)
|
||||
locX = 0-size;
|
||||
|
||||
if(locY < 0 - size)
|
||||
locY = pHeight;
|
||||
else if(locY > pHeight+size)
|
||||
locY = 0-size ;
|
||||
}
|
||||
|
||||
public Rectangle getBounds() {
|
||||
Rectangle r = new Rectangle((int)locX, (int)locY, size, size);
|
||||
return r;
|
||||
}
|
||||
|
||||
public int getSize(){
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
public abstract void drawSprite(Graphics g, JPanel p);
|
||||
if(locY < 0 - size)
|
||||
locY = pHeight;
|
||||
else if(locY > pHeight+size)
|
||||
locY = 0-size ;
|
||||
}
|
||||
|
||||
/**
|
||||
* abstract method for drawing sprite.
|
||||
* @param g
|
||||
* @param p
|
||||
*/
|
||||
public abstract void drawSprite(Graphics g, JPanel p);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue