Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Star Wars Game
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Benjamin LEROUX
Star Wars Game
Commits
debbb0e7
Commit
debbb0e7
authored
Feb 19, 2021
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JoyStick + Thread + Petite Animation + View
parent
307c95c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
196 additions
and
65 deletions
+196
-65
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-2
JoyStick.java
app/src/main/java/com/imtm1/starwarsgame/JoyStick.java
+65
-1
MainActivity.java
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
+51
-0
activity_main.xml
app/src/main/res/layout/activity_main.xml
+78
-62
No files found.
app/src/main/AndroidManifest.xml
View file @
debbb0e7
...
@@ -4,9 +4,9 @@
...
@@ -4,9 +4,9 @@
<application
<application
android:allowBackup=
"true"
android:allowBackup=
"true"
android:icon=
"@
mipmap/ic_launcher
"
android:icon=
"@
drawable/asteroid1
"
android:label=
"@string/app_name"
android:label=
"@string/app_name"
android:roundIcon=
"@
mipmap/ic_launcher_round
"
android:roundIcon=
"@
drawable/asteroid1
"
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/Theme.StarWarsGame"
>
android:theme=
"@style/Theme.StarWarsGame"
>
<activity
android:name=
".MainActivity"
>
<activity
android:name=
".MainActivity"
>
...
...
app/src/main/java/com/imtm1/starwarsgame/JoyStick.java
View file @
debbb0e7
package
com
.
imtm1
.
starwarsgame
;
package
com
.
imtm1
.
starwarsgame
;
public
class
JoyStick
{
import
android.content.Context
;
import
android.view.Gravity
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
class
JoyStickView
{
int
xDelta
;
int
yDelta
;
ViewGroup
mainLayout
;
Context
context
;
JoyStickView
(
ViewGroup
mainLayout
,
Context
context
)
{
this
.
mainLayout
=
mainLayout
;
this
.
context
=
context
;
}
final
View
.
OnTouchListener
touchListener
=
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
final
int
x
=
(
int
)
event
.
getRawX
();
final
int
y
=
(
int
)
event
.
getRawY
();
FrameLayout
framelayout
=
new
FrameLayout
(
context
);
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_DOWN
:
FrameLayout
.
LayoutParams
laParams
=
(
FrameLayout
.
LayoutParams
)
v
.
getLayoutParams
();
xDelta
=
x
-
laParams
.
leftMargin
;
yDelta
=
y
-
laParams
.
topMargin
;
break
;
case
MotionEvent
.
ACTION_MOVE
:
FrameLayout
.
LayoutParams
lParams
=
(
FrameLayout
.
LayoutParams
)
v
.
getLayoutParams
();
lParams
.
leftMargin
=
x
-
xDelta
;
lParams
.
topMargin
=
y
-
yDelta
;
lParams
.
rightMargin
=
0
;
lParams
.
bottomMargin
=
0
;
v
.
setLayoutParams
(
lParams
);
break
;
case
MotionEvent
.
ACTION_UP
:
FrameLayout
.
LayoutParams
layParams
=
(
FrameLayout
.
LayoutParams
)
v
.
getLayoutParams
();
Toast
.
makeText
(
context
,
"I'm here!"
,
Toast
.
LENGTH_SHORT
).
show
();
layParams
.
gravity
=
Gravity
.
CENTER
;
break
;
default
:
return
false
;
}
mainLayout
.
invalidate
();
return
true
;
}
};
}
}
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
View file @
debbb0e7
package
com
.
imtm1
.
starwarsgame
;
package
com
.
imtm1
.
starwarsgame
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.animation.ObjectAnimator
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Path
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.animation.PathInterpolator
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
ImageView
padExte
;
ImageView
padCenter
;
ViewGroup
mainLayout
;
ImageView
asteroid1
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
padExte
=
findViewById
(
R
.
id
.
padExte
);
padCenter
=
findViewById
(
R
.
id
.
padCenter
);
mainLayout
=
findViewById
(
R
.
id
.
main
);
asteroid1
=
findViewById
(
R
.
id
.
asteroid1
);
Path
path
=
new
Path
();
path
.
arcTo
(
0
f
,
0
f
,
1000
f
,
1000
f
,
270
f
,
-
180
f
,
true
);
ObjectAnimator
animator
=
ObjectAnimator
.
ofFloat
(
asteroid1
,
View
.
X
,
View
.
Y
,
path
);
animator
.
setDuration
(
20000
);
animator
.
start
();
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
JoyStickView
joyStickView
=
new
JoyStickView
(
mainLayout
,
MainActivity
.
this
);
padCenter
.
setOnTouchListener
(
joyStickView
.
touchListener
);
}
};
Thread
threadJS
=
new
Thread
(
runnable
);
threadJS
.
start
();
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
debbb0e7
...
@@ -6,72 +6,88 @@
...
@@ -6,72 +6,88 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".MainActivity"
>
tools:context=
".MainActivity"
>
<
ImageView
<
RelativeLayout
android:
id=
"@+id/imageView4
"
android:
layout_width=
"match_parent
"
android:layout_
width=
"wrap_cont
ent"
android:layout_
height=
"match_par
ent"
android:
layout_height=
"wrap_content
"
android:
id=
"@+id/main
"
android:layout_marginBottom=
"
16
dp"
android:layout_marginBottom=
"
4
dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:srcCompat=
"@drawable/etoilefond"
/>
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintStart_toStartOf=
"parent"
>
<ImageView
<ImageView
android:id=
"@+id/imageView5"
android:id=
"@+id/fond"
android:layout_width=
"100dp"
android:layout_width=
"wrap_content"
android:layout_height=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"27dp"
android:layout_marginEnd=
"0dp"
android:layout_marginLeft=
"27dp"
android:layout_marginRight=
"0dp"
android:layout_marginTop=
"25dp"
android:layout_marginBottom=
"0dp"
android:layout_marginBottom=
"448dp"
app:srcCompat=
"@drawable/etoilefond"
/>
app:layout_constraintBottom_toTopOf=
"@+id/imageView7"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/asteroid1"
/>
<ImageView
<FrameLayout
android:id=
"@+id/imageView6"
android:layout_width=
"match_parent"
android:layout_width=
"63dp"
android:layout_height=
"199dp"
android:layout_height=
"114dp"
android:layout_alignParentStart=
"true"
android:layout_marginTop=
"143dp"
android:layout_alignParentLeft=
"true"
android:layout_marginEnd=
"46dp"
android:layout_alignParentBottom=
"true"
android:layout_marginRight=
"46dp"
android:layout_marginStart=
"0dp"
app:layout_constraintEnd_toEndOf=
"parent"
android:layout_marginLeft=
"0dp"
app:layout_constraintTop_toTopOf=
"parent"
android:layout_marginBottom=
"0dp"
>
app:srcCompat=
"@drawable/asteroid2"
/>
<ImageView
<ImageView
android:id=
"@+id/imageView7"
android:id=
"@+id/padCenter"
android:layout_width=
"135dp"
android:layout_width=
"168dp"
android:layout_height=
"0dp"
android:layout_height=
"102dp"
android:layout_marginTop=
"548dp"
android:layout_gravity=
"center"
android:layout_marginEnd=
"21dp"
app:srcCompat=
"@drawable/pad_center"
/>
android:layout_marginRight=
"21dp"
android:layout_marginBottom=
"55dp"
app:layout_constraintBottom_toTopOf=
"@+id/imageView8"
app:layout_constraintEnd_toEndOf=
"@+id/imageView8"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/tie"
/>
<ImageView
<ImageView
android:id=
"@+id/imageView8
"
android:id=
"@+id/padExte
"
android:layout_width=
"wrap_content
"
android:layout_width=
"179dp
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"31dp
"
android:layout_gravity=
"center
"
app:layout_constraintBottom_toBottomOf=
"parent
"
android:adjustViewBounds=
"false
"
app:layout_constraintEnd_toEndOf=
"parent
"
android:cropToPadding=
"false
"
app:layout_constraintStart_toStartOf=
"parent
"
android:keepScreenOn=
"false
"
app:layout_constraintTop_toBottomOf=
"@+id/imageView7
"
android:visibility=
"visible
"
app:srcCompat=
"@drawable/pad_exterior"
/>
app:srcCompat=
"@drawable/pad_exterior"
/>
<ImageView
</FrameLayout>
android:id=
"@+id/imageView9"
android:layout_width=
"106dp"
<FrameLayout
android:layout_height=
"0dp"
android:layout_width=
"match_parent"
android:layout_marginTop=
"10dp"
android:layout_height=
"525dp"
android:layout_marginBottom=
"10dp"
android:layout_alignParentTop=
"true"
app:layout_constraintBottom_toBottomOf=
"@+id/imageView8"
android:layout_marginTop=
"0dp"
>
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
<ImageView
app:layout_constraintTop_toTopOf=
"@+id/imageView8"
android:id=
"@+id/tie"
app:srcCompat=
"@drawable/pad_center"
/>
android:layout_width=
"110dp"
android:layout_height=
"55dp"
android:layout_marginStart=
"150dp"
android:layout_marginLeft=
"50dp"
android:layout_marginTop=
"450dp"
android:layout_marginRight=
"180dp"
app:srcCompat=
"@drawable/tie"
/>
<ImageView
android:id=
"@+id/asteroid2"
android:layout_width=
"138dp"
android:layout_height=
"113dp"
android:layout_marginStart=
"50dp"
android:layout_marginLeft=
"80dp"
android:layout_marginTop=
"150dp"
app:srcCompat=
"@drawable/asteroid2"
/>
<ImageView
android:id=
"@+id/asteroid1"
android:layout_width=
"93dp"
android:layout_height=
"79dp"
android:layout_marginTop=
"60dp"
android:layout_marginEnd=
"100dp"
android:layout_marginRight=
"100dp"
app:srcCompat=
"@drawable/asteroid1"
/>
</FrameLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment