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
27a3b70f
Commit
27a3b70f
authored
Feb 26, 2021
by
Benjamin LEROUX
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init ben
parent
288fded0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
4 deletions
+50
-4
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-2
JoyStick.java
app/src/main/java/com/imtm1/starwarsgame/JoyStick.java
+3
-2
MainActivity.java
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
+37
-0
attrs.xml
app/src/main/res/values/attrs.xml
+8
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
27a3b70f
...
@@ -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 @
27a3b70f
...
@@ -3,6 +3,7 @@ package com.imtm1.starwarsgame;
...
@@ -3,6 +3,7 @@ package com.imtm1.starwarsgame;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Point
;
import
android.graphics.Point
;
import
android.graphics.Rect
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.util.AttributeSet
;
import
android.util.AttributeSet
;
import
android.util.DisplayMetrics
;
import
android.util.DisplayMetrics
;
...
@@ -29,10 +30,10 @@ class JoyStickView {
...
@@ -29,10 +30,10 @@ class JoyStickView {
ViewGroup
mainLayout
;
ViewGroup
mainLayout
;
Context
context
;
Context
context
;
Boolean
joystickIsPressed
=
false
;
Boolean
joystickIsPressed
=
false
;
View
tie
;
Image
View
tie
;
public
JoyStickView
(
ViewGroup
mainLayout
,
Context
context
,
View
tie
)
public
JoyStickView
(
ViewGroup
mainLayout
,
Context
context
,
Image
View
tie
)
{
{
this
.
mainLayout
=
mainLayout
;
this
.
mainLayout
=
mainLayout
;
this
.
context
=
context
;
this
.
context
=
context
;
...
...
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
View file @
27a3b70f
...
@@ -5,10 +5,12 @@ import androidx.appcompat.app.AppCompatActivity;
...
@@ -5,10 +5,12 @@ import androidx.appcompat.app.AppCompatActivity;
import
android.animation.Animator
;
import
android.animation.Animator
;
import
android.animation.ObjectAnimator
;
import
android.animation.ObjectAnimator
;
import
android.animation.ValueAnimator
;
import
android.annotation.SuppressLint
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Path
;
import
android.graphics.Path
;
import
android.graphics.Rect
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Handler
;
...
@@ -23,6 +25,8 @@ import android.widget.ImageView;
...
@@ -23,6 +25,8 @@ import android.widget.ImageView;
import
android.widget.RelativeLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
import
android.widget.Toast
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
ImageView
padExte
;
ImageView
padExte
;
...
@@ -51,10 +55,27 @@ public class MainActivity extends AppCompatActivity {
...
@@ -51,10 +55,27 @@ public class MainActivity extends AppCompatActivity {
ObjectAnimator
animator
=
ObjectAnimator
.
ofFloat
(
asteroid1
,
View
.
X
,
View
.
Y
,
path
);
ObjectAnimator
animator
=
ObjectAnimator
.
ofFloat
(
asteroid1
,
View
.
X
,
View
.
Y
,
path
);
animator
.
setDuration
(
2000
);
animator
.
setDuration
(
2000
);
animator
.
setRepeatCount
(
Animation
.
INFINITE
);
animator
.
setRepeatCount
(
Animation
.
INFINITE
);
animator
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
@Override
public
void
onAnimationUpdate
(
ValueAnimator
animation
)
{
if
(
sontEnCollision
(
asteroid1
,
tie
)){
Log
.
i
(
"collision"
,
"true"
);
}
}
});
animator
.
start
();
animator
.
start
();
ObjectAnimator
animator2
=
ObjectAnimator
.
ofFloat
(
asteroid2
,
View
.
X
,
View
.
Y
,
path
);
ObjectAnimator
animator2
=
ObjectAnimator
.
ofFloat
(
asteroid2
,
View
.
X
,
View
.
Y
,
path
);
animator2
.
setDuration
(
5000
);
animator2
.
setDuration
(
5000
);
animator2
.
setRepeatCount
(
Animation
.
INFINITE
);
animator2
.
setRepeatCount
(
Animation
.
INFINITE
);
animator2
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
@Override
public
void
onAnimationUpdate
(
ValueAnimator
animation
)
{
if
(
sontEnCollision
(
asteroid2
,
tie
)){
Log
.
i
(
"collision2"
,
"true"
);
}
}
});
animator2
.
start
();
animator2
.
start
();
...
@@ -66,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -66,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
public
void
run
()
{
public
void
run
()
{
// tie.setTranslationX(joyStickView.xDelta);
// tie.setTranslationX(joyStickView.xDelta);
// tie.setTranslationY(joyStickView.yDelta);
// tie.setTranslationY(joyStickView.yDelta);
Log
.
i
(
"TAG"
,
"Bool:"
+
joyStickView
.
joystickIsPressed
);
Log
.
i
(
"TAG"
,
"Bool:"
+
joyStickView
.
joystickIsPressed
);
if
(
joyStickView
.
joystickIsPressed
)
{
if
(
joyStickView
.
joystickIsPressed
)
{
Toast
.
makeText
(
MainActivity
.
this
,
"joysitck is pressed"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
MainActivity
.
this
,
"joysitck is pressed"
,
Toast
.
LENGTH_SHORT
).
show
();
...
@@ -83,4 +105,19 @@ public class MainActivity extends AppCompatActivity {
...
@@ -83,4 +105,19 @@ public class MainActivity extends AppCompatActivity {
padCenter
.
setOnTouchListener
(
joyStickView
.
touchListener
);
padCenter
.
setOnTouchListener
(
joyStickView
.
touchListener
);
}
}
boolean
sontEnCollision
(
ImageView
firstView
,
ImageView
secondView
)
{
int
[]
firstPosition
=
new
int
[
2
];
int
[]
secondPosition
=
new
int
[
2
];
firstView
.
getLocationOnScreen
(
firstPosition
);
secondView
.
getLocationOnScreen
(
secondPosition
);
Rect
rectFirstView
=
new
Rect
(
firstPosition
[
0
],
firstPosition
[
1
],
firstPosition
[
0
]
+
firstView
.
getMeasuredWidth
(),
firstPosition
[
1
]
+
firstView
.
getMeasuredHeight
());
Rect
rectSecondView
=
new
Rect
(
secondPosition
[
0
],
secondPosition
[
1
],
secondPosition
[
0
]
+
secondView
.
getMeasuredWidth
(),
secondPosition
[
1
]
+
secondView
.
getMeasuredHeight
());
return
(
rectFirstView
.
intersect
(
rectSecondView
));
}
}
}
app/src/main/res/values/attrs.xml
0 → 100644
View file @
27a3b70f
<?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