RuleGame Compose | #2

NumberUtils.kt

object ValueList {
val list = listOf(
0,
32,
15,
19,
4,
21,
2,
25,
17,
34,
6,
27,
13,
36,
11,
30,
8,
23,
10,
5,
24,
16,
33,
1,
20,
14,
31,
9,
22,
18,
29,
7,
28,
12,
35,
3,
26

)
}

RuleScreen.kt

import android.util.Log
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonColors
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.ruletagameexamplecompose.R
import com.example.ruletagameexamplecompose.ui.theme.Red
import com.example.ruletagameexamplecompose.utils.ValueList


@Composable
fun RuleScreen() {
var rotationValue by remember {
mutableStateOf(0f)
}
var number by remember {
mutableStateOf(0)
}
val angle: Float by animateFloatAsState(
targetValue = rotationValue,
animationSpec = tween(
durationMillis = 2000,
easing = LinearOutSlowInEasing
),
finishedListener = {
val index = (365f - (rotationValue % 360f)) / (360f / ValueList.list.size)
Log.d("MyLog", "index: ${index}")
number = ValueList.list[index.toInt()]
}
)
Log.d("MyLog", "angle: $angle")

Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.SpaceBetween
) {
Text(
text = number.toString(),
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.wrapContentWidth()
.wrapContentHeight(),
fontSize = 35.sp,
fontWeight = FontWeight.Bold,
color = Color.White
)
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()){
Image(
painter = painterResource(id = R.drawable.ruleta),
contentDescription = "Ruleta",
modifier = Modifier
.fillMaxSize()
.rotate(angle)
)
Image(
painter = painterResource(id = R.drawable.flecha),
contentDescription = "Arrow",
modifier = Modifier
.fillMaxSize()
)
}

Button(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
onClick = {
rotationValue = ((0..360).random().toFloat() + 720) + angle
},
colors = ButtonDefaults.buttonColors(backgroundColor = Red)
) {
Text(
text = "Start",
color = Color.White
)
}
}
}

Добавить комментарий

Ваш адрес email не будет опубликован.