mirror of
https://github.com/Skysamara/airshot_a.git
synced 2025-12-06 06:16:05 +00:00
random shots
This commit is contained in:
commit
b38a9655e7
27
app/src/main/AndroidManifest.xml
Normal file
27
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="ru.panorobot.airshot">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Airshot"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
69
app/src/main/java/ru/panorobot/airshot/Draw2D.kt
Normal file
69
app/src/main/java/ru/panorobot/airshot/Draw2D.kt
Normal file
@ -0,0 +1,69 @@
|
||||
//https://developer.alexanderklimov.ru/android/simplepaint.php
|
||||
|
||||
package ru.panorobot.airshot
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.view.View
|
||||
import kotlin.random.Random
|
||||
|
||||
class Draw2D(context: Context?) : View(context) {
|
||||
private val paint: Paint = Paint()
|
||||
private val shots:Shots = Shots()
|
||||
|
||||
override fun setOnClickListener(l: OnClickListener?) {
|
||||
super.setOnClickListener(l)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas?) {
|
||||
super.onDraw(canvas)
|
||||
val screenWidth: Int = getWidth()
|
||||
val screenHeight: Int = getHeight()
|
||||
|
||||
drawTarget(canvas)
|
||||
shots.draw(canvas,screenWidth, screenHeight)
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun drawTarget(canvas: Canvas?) {
|
||||
paint.apply {
|
||||
style = Paint.Style.FILL // стиль Заливка
|
||||
color = Color.WHITE // закрашиваем холст белым цветом
|
||||
}
|
||||
canvas?.drawPaint(paint)
|
||||
|
||||
paint.apply {
|
||||
isAntiAlias = true
|
||||
color = Color.BLACK
|
||||
}
|
||||
|
||||
val screenWidth: Int = getWidth()
|
||||
val screenHeight: Int = getHeight()
|
||||
val centerX = width / 2
|
||||
val centerY = height / 2
|
||||
|
||||
var radiusSun: Int = (screenWidth + screenHeight) / 30
|
||||
canvas!!.drawCircle(centerX.toFloat(), centerY.toFloat(), radiusSun.toFloat(), paint)
|
||||
|
||||
paint.apply {
|
||||
style = Paint.Style.STROKE
|
||||
}
|
||||
var radius = radiusSun * 2
|
||||
canvas!!.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)
|
||||
|
||||
radius = radiusSun * 3
|
||||
canvas!!.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)
|
||||
|
||||
radius = radiusSun * 4
|
||||
canvas!!.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)
|
||||
|
||||
radius = radiusSun * 5
|
||||
canvas!!.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
app/src/main/java/ru/panorobot/airshot/MainActivity.kt
Normal file
13
app/src/main/java/ru/panorobot/airshot/MainActivity.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package ru.panorobot.airshot
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// setContentView(R.layout.activity_main)
|
||||
val draw2D = Draw2D(this)
|
||||
setContentView(draw2D)
|
||||
}
|
||||
}
|
||||
6
app/src/main/java/ru/panorobot/airshot/Shot.kt
Normal file
6
app/src/main/java/ru/panorobot/airshot/Shot.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package ru.panorobot.airshot
|
||||
|
||||
class Shot(x: Int = 0, y: Int = 0) {
|
||||
var x = x
|
||||
var y = y
|
||||
}
|
||||
45
app/src/main/java/ru/panorobot/airshot/Shots.kt
Normal file
45
app/src/main/java/ru/panorobot/airshot/Shots.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package ru.panorobot.airshot
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import kotlin.random.Random
|
||||
|
||||
class Shots {
|
||||
private var arrayOfShots: Array<Shot> = arrayOf(
|
||||
Shot(50,70),
|
||||
Shot(200,100),
|
||||
Shot(50,50),
|
||||
Shot(70,300),
|
||||
Shot(10,20),
|
||||
)
|
||||
|
||||
private fun randomizeShots(screenWidth: Int, screenHeight: Int){
|
||||
for (shot in arrayOfShots) {
|
||||
shot.x = Random.nextInt(0, screenWidth)
|
||||
shot.y = Random.nextInt(0, screenHeight)
|
||||
}
|
||||
}
|
||||
|
||||
fun draw(canvas: Canvas?, screenWidth: Int, screenHeight: Int){
|
||||
val paint: Paint = Paint()
|
||||
paint.apply {
|
||||
style = Paint.Style.FILL // стиль Заливка
|
||||
color = Color.WHITE // белая кайма вокруг
|
||||
}
|
||||
|
||||
randomizeShots(screenWidth, screenHeight)
|
||||
for (shot in arrayOfShots){
|
||||
val x = shot.x
|
||||
val y = shot.y
|
||||
var radius: Int = (screenWidth + screenHeight) / 100
|
||||
canvas!!.drawCircle(x.toFloat(), y.toFloat(), radius.toFloat(), paint)
|
||||
|
||||
paint.apply {
|
||||
color = Color.BLACK // закрашиваем холст белым цветом
|
||||
}
|
||||
radius = (screenWidth + screenHeight) / 120
|
||||
canvas.drawCircle(x.toFloat(), y.toFloat(), radius.toFloat(), paint)
|
||||
}
|
||||
}
|
||||
}
|
||||
18
app/src/main/res/layout/activity_main.xml
Normal file
18
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
x
Reference in New Issue
Block a user