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
3eab8cc5
Commit
3eab8cc5
authored
Feb 24, 2021
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avancement sur deplacement du vaisseau
parent
debbb0e7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
24 deletions
+58
-24
JoyStick.java
app/src/main/java/com/imtm1/starwarsgame/JoyStick.java
+19
-6
MainActivity.java
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
+25
-10
activity_main.xml
app/src/main/res/layout/activity_main.xml
+6
-8
attrs.xml
app/src/main/res/values/attrs.xml
+8
-0
No files found.
app/src/main/java/com/imtm1/starwarsgame/JoyStick.java
View file @
3eab8cc5
...
...
@@ -2,6 +2,9 @@ package com.imtm1.starwarsgame;
import
android.content.Context
;
import
android.os.Handler
;
import
android.util.AttributeSet
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.MotionEvent
;
import
android.view.View
;
...
...
@@ -17,11 +20,15 @@ class JoyStickView {
int
yDelta
;
ViewGroup
mainLayout
;
Context
context
;
Boolean
joystickIsPressed
=
false
;
JoyStickView
(
ViewGroup
mainLayout
,
Context
context
)
public
JoyStickView
(
ViewGroup
mainLayout
,
Context
context
)
{
this
.
mainLayout
=
mainLayout
;
this
.
context
=
context
;
}
final
View
.
OnTouchListener
touchListener
=
new
View
.
OnTouchListener
()
{
...
...
@@ -29,28 +36,33 @@ class JoyStickView {
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
final
int
x
=
(
int
)
event
.
getRawX
();
final
int
y
=
(
int
)
event
.
getRawY
();
FrameLayout
framelayout
=
new
FrameLayout
(
context
)
;
joystickIsPressed
=
false
;
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_DOWN
:
FrameLayout
.
LayoutParams
laParams
=
(
FrameLayout
.
LayoutParams
)
v
.
getLayoutParams
();
xDelta
=
x
-
laParams
.
leftMargin
;
yDelta
=
y
-
laParams
.
topMargin
;
Log
.
i
(
"tag"
,
"Hello"
);
joystickIsPressed
=
true
;
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
;
joystickIsPressed
=
true
;
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
;
//layParams.leftMargin = xDelta;
//layParams.topMargin = yDelta ;
v
.
setLayoutParams
(
layParams
);
joystickIsPressed
=
false
;
break
;
default
:
...
...
@@ -62,6 +74,7 @@ class JoyStickView {
}
};
}
...
...
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
View file @
3eab8cc5
...
...
@@ -11,9 +11,11 @@ import android.os.Build;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.animation.PathInterpolator
;
import
android.widget.FrameLayout
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
...
...
@@ -24,6 +26,7 @@ public class MainActivity extends AppCompatActivity {
ImageView
padCenter
;
ViewGroup
mainLayout
;
ImageView
asteroid1
;
ImageView
tie
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
...
...
@@ -33,9 +36,9 @@ public class MainActivity extends AppCompatActivity {
padExte
=
findViewById
(
R
.
id
.
padExte
);
padCenter
=
findViewById
(
R
.
id
.
padCenter
);
mainLayout
=
findViewById
(
R
.
id
.
main
);
mainLayout
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
main
);
asteroid1
=
findViewById
(
R
.
id
.
asteroid1
);
tie
=
findViewById
(
R
.
id
.
tie
);
Path
path
=
new
Path
();
path
.
arcTo
(
0
f
,
0
f
,
1000
f
,
1000
f
,
270
f
,
-
180
f
,
true
);
...
...
@@ -44,18 +47,30 @@ public class MainActivity extends AppCompatActivity {
animator
.
start
();
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
JoyStickView
joyStickView
=
new
JoyStickView
(
mainLayout
,
MainActivity
.
this
);
JoyStickView
joyStickView
=
new
JoyStickView
(
mainLayout
,
MainActivity
.
this
);
padCenter
.
setOnTouchListener
(
joyStickView
.
touchListener
);
Handler
handlerForMovingTie
=
new
Handler
();
Runnable
movingTie
=
new
Runnable
()
{
@Override
public
void
run
()
{
tie
.
setTranslationX
(
joyStickView
.
xDelta
);
tie
.
setTranslationY
(
joyStickView
.
yDelta
);
Log
.
i
(
"TAG"
,
"Bool:"
+
joyStickView
.
joystickIsPressed
);
if
(
joyStickView
.
joystickIsPressed
)
{
Toast
.
makeText
(
MainActivity
.
this
,
"joysitck is pressed"
,
Toast
.
LENGTH_SHORT
).
show
();
handlerForMovingTie
.
postDelayed
(
this
,
10
);
mainLayout
.
invalidate
();
}
}
}
};
handlerForMovingTie
.
post
(
movingTie
);
Thread
threadTie
=
new
Thread
(
movingTie
);
threadTie
.
start
();
Log
.
i
(
"TAG"
,
"Thread:"
+
Thread
.
currentThread
().
getName
());
Log
.
i
(
"tag"
,
"Hello"
);
padCenter
.
setOnTouchListener
(
joyStickView
.
touchListener
);
Thread
threadJS
=
new
Thread
(
runnable
);
threadJS
.
start
();
...
...
app/src/main/res/layout/activity_main.xml
View file @
3eab8cc5
<?xml version="1.0" encoding="utf-8"?>
<
androidx.constraintlayout.widget.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Relative
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
...
...
@@ -10,11 +10,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:id=
"@+id/main"
android:layout_marginBottom=
"4dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintStart_toStartOf=
"parent"
>
android:layout_marginBottom=
"4dp"
>
<ImageView
android:id=
"@+id/fond"
...
...
@@ -26,6 +22,7 @@
app:srcCompat=
"@drawable/etoilefond"
/>
<FrameLayout
android:id=
"@+id/gameSpace"
android:layout_width=
"match_parent"
android:layout_height=
"199dp"
android:layout_alignParentStart=
"true"
...
...
@@ -33,7 +30,8 @@
android:layout_alignParentBottom=
"true"
android:layout_marginStart=
"0dp"
android:layout_marginLeft=
"0dp"
android:layout_marginBottom=
"0dp"
>
android:layout_marginBottom=
"0dp"
>
<ImageView
android:id=
"@+id/padCenter"
...
...
@@ -90,4 +88,4 @@
app:srcCompat=
"@drawable/asteroid1"
/>
</FrameLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</RelativeLayout>
\ No newline at end of file
app/src/main/res/values/attrs.xml
0 → 100644
View file @
3eab8cc5
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable
name=
"JoystickView"
>
<attr
name=
"joystickIsPressed"
format=
"boolean"
/>
</declare-styleable>
</resources>
\ 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