diff --git a/app/src/main/java/com/example/ellegadodepintia/ListaMinijuegos.kt b/app/src/main/java/com/example/ellegadodepintia/ListaMinijuegos.kt index 629b0148bc3ecb6f970f301dfffe5801b7152fae..81630ab7c46f8dbb0d6f9989f63944c7c1c52876 100644 --- a/app/src/main/java/com/example/ellegadodepintia/ListaMinijuegos.kt +++ b/app/src/main/java/com/example/ellegadodepintia/ListaMinijuegos.kt @@ -54,6 +54,8 @@ class ListaMinijuegos : AppCompatActivity(){ val repararLayout = findViewById<FrameLayout>(R.id.minijuegoReparar) repararLayout.setOnClickListener { val intent = Intent(this, MinijuegoReparacion::class.java) + val flag = true + intent.putExtra("FLAG_KEY", flag) startActivity(intent) } } diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/ResumenAdapter.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/ResumenAdapter.kt index 2af6cb8ce897e4fbe403236e69f4c8f6afad5769..11e5b45dce5d7aabf9173500f5570fd63e3695e0 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/ResumenAdapter.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/ResumenAdapter.kt @@ -26,8 +26,8 @@ class ResumenAdapter(private val resumenList: MutableList<ObjetoDeValor>) : override fun onBindViewHolder(holder: ResumenViewHolder, position: Int) { val resumen = resumenList[position] resumen.nombre.also { holder.textoObjeto.text = it } - ": 20".also { holder.textoPrecio.text = it } - holder.imagen.setBackgroundResource(resumen.imagen) + (" :" + resumen.coste.toString()).also { holder.textoPrecio.text = it } + holder.imagen.setImageResource(resumen.imagen) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GeneradorDeEventos.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GeneradorDeEventos.kt index 46292b080da7df448164b51318bd6b08b959c8dc..f0b47f6ea624beeabb31a58e1d8fd9b77dd1c4a3 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GeneradorDeEventos.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GeneradorDeEventos.kt @@ -50,7 +50,7 @@ object GeneradorDeEventos { val drawable = imagenEvento.drawable - if (drawable is AnimationDrawable) { + if (drawable is AnimationDrawable && eventoSeleccionado is EventoCombate) { drawable.start() } diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GestorDeEventos.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GestorDeEventos.kt index 37342e4f77f800296b8551645a2217e03b9e2b34..c10f9d71d1bdae5554aee0d2789dbe50dc2ab7cf 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GestorDeEventos.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/GestorDeEventos.kt @@ -12,7 +12,6 @@ import androidx.core.content.res.ResourcesCompat import com.example.ellegadodepintia.R import com.example.ellegadodepintia.exploradoresDePintia.Resumen import com.example.ellegadodepintia.exploradoresDePintia.model.GameState.context -import com.example.ellegadodepintia.exploradoresDePintia.model.eventoFactory.EventoTienda object GestorDeEventos{ @@ -71,7 +70,7 @@ object GestorDeEventos{ LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ).apply { - if ((index == 0 || index == 1) && GameState.eventoActual !is EventoTienda) { + if ((index == 0 || index == 1) && GameState.eventoActual.opciones.size == 4) { marginEnd = (14 * context!!.resources.displayMetrics.density).toInt() } if (index == 1 || index == 3) { diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/TipoEvento.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/TipoEvento.kt index 63df53e31a03f77ca88326c3c99502693f7dcb4b..41b62f9b94168f9144e5914b7ac1e470b5a983e3 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/TipoEvento.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/TipoEvento.kt @@ -5,6 +5,7 @@ enum class TipoEvento { Combate, Tienda, Trampa, + Riesgo, /*Trampa, Aliado, Misterio, diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoDestruir.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoDestruir.kt index affefb4c6eb312ade9ac7a09141190d287dd0cda..29abe3f7142e428b8d93a46c6c665812aa10d792 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoDestruir.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoDestruir.kt @@ -8,6 +8,7 @@ import com.example.ellegadodepintia.R import com.example.ellegadodepintia.exploradoresDePintia.model.GameState import com.example.ellegadodepintia.exploradoresDePintia.model.GameState.context import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.ObjetoDeValor //TODO() Agregar inventario con restos de la reliquia class EfectoDestruir(probabilidadExito: Int) : Efecto(probabilidadExito) { @@ -29,11 +30,19 @@ class EfectoDestruir(probabilidadExito: Int) : Efecto(probabilidadExito) { val ataque = GameState.jugador.atributos[Atributo.Ataque]!! GameState.eventoActual.actualizarResistencia(-ataque) - if(GameState.eventoActual.resistenciaActual > 0){ + if (GameState.eventoActual.resistenciaActual > 0) { "¡Cuidado, parece que la reliquia se está quebrando!" - }else{ + } else { GameState.eventoActual.actualizarFinalizado(true) - "¡Qué has hecho, la reliquia se ha roto por completo!" + GameState.jugador.conseguirObjeto( + ObjetoDeValor( + nombre = "Fragmento de reliquia", + descripcion = "Los restos de una reliquia. Hay algunos comerciantes que los buscan. Tiene un valor de 5 monedas.", + imagen = R.drawable.asi_fragmento_reliquia, + coste = 5 + ) + ) + "¡Qué has hecho, la reliquia se ha roto por completo!. Has conseguido un fragmento de la reliquia" } } else { "La reliquia ha resistido el golpe con éxito." diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoReparar.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoReparar.kt index fd5054e1b4dac2b736c1c716710065827f50cf58..92c3fea6ffd9388ca82fdc4985e9fcb981066b8f 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoReparar.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoReparar.kt @@ -1,6 +1,7 @@ package com.example.ellegadodepintia.exploradoresDePintia.model.efecto import android.animation.ObjectAnimator +import android.content.Intent import android.graphics.drawable.AnimationDrawable import android.os.Handler import android.os.Looper @@ -10,6 +11,7 @@ import com.example.ellegadodepintia.exploradoresDePintia.model.GameState import com.example.ellegadodepintia.exploradoresDePintia.model.GameState.context import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.Objeto +import com.example.ellegadodepintia.minijuegoReparacion.MinijuegoReparacion class EfectoReparar(probabilidadExito: Int, private val stringReparado: String, private val stringFallo: String, private val valorPerdido: Int, private val objeto: Objeto) : Efecto(probabilidadExito) { override fun ejecutar(): String { @@ -37,6 +39,9 @@ class EfectoReparar(probabilidadExito: Int, private val stringReparado: String, GameState.eventoActual.actualizarResistencia(1) if(GameState.eventoActual.resistenciaActual == GameState.eventoActual.resistenciaMax){ + val intent = Intent(context, MinijuegoReparacion::class.java) + context!!.startActivityForResult(intent, 100) + GameState.eventoActual.actualizarFinalizado(true) stringReparado + "\n" + GameState.jugador.conseguirObjeto(objeto) + "." }else{ diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoRiesgo.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoRiesgo.kt new file mode 100644 index 0000000000000000000000000000000000000000..0f002c1bff85210537dd7077ea5109de246d6281 --- /dev/null +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/efecto/EfectoRiesgo.kt @@ -0,0 +1,47 @@ +package com.example.ellegadodepintia.exploradoresDePintia.model.efecto + +import android.graphics.drawable.AnimationDrawable +import android.widget.ImageView +import com.example.ellegadodepintia.R +import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo +import com.example.ellegadodepintia.exploradoresDePintia.model.GameState +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.Objeto +import com.example.ellegadodepintia.exploradoresDePintia.model.GameState.context + +class EfectoRiesgo(private val objetoRecompensa : Objeto, private val dmgRiesgo: Int, private val mensajeRecomensa : String, private val mensajeRiesgo : String) : Efecto(100) { + + override fun ejecutar(): String { + val resultado = (1..100).random() + + val imageView: ImageView = context!!.findViewById(R.id.imagenEvento) + val animationDrawable = imageView.drawable as? AnimationDrawable + + val animationDuration = animationDrawable?.let { anim -> + var totalDuration = 0 + for (i in 0 until anim.numberOfFrames) { + totalDuration += anim.getDuration(i) + } + totalDuration + } ?: 0 + + animationDrawable?.start() + + imageView.postDelayed({ + animationDrawable?.let { anim -> + anim.stop() + anim.selectDrawable(anim.numberOfFrames - 1) + } + }, animationDuration.toLong() - 150) + + if (resultado <= 50) { + GameState.jugador.conseguirObjeto(objetoRecompensa) + GameState.eventoActual.actualizarFinalizado(true) + return mensajeRecomensa + } else { + GameState.jugador.actualizarAtributo(Atributo.Vida, -dmgRiesgo) + GameState.eventoActual.actualizarFinalizado(true) + return mensajeRiesgo + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoFactorySelector.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoFactorySelector.kt index 057684f5a091d42c2f4d245bf4784c9d9f4dd37a..6054dee6245284a52dff2eeb77415e964717ed50 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoFactorySelector.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoFactorySelector.kt @@ -10,6 +10,7 @@ object EventoFactorySelector { TipoEvento.Combate -> CombateFactory() TipoEvento.Tienda -> TiendaFactory() TipoEvento.Trampa -> TrampaFactory() + TipoEvento.Riesgo -> RiesgoFactory() } } } diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoRiesgo.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoRiesgo.kt new file mode 100644 index 0000000000000000000000000000000000000000..60890734e5adbe5247618a1679a533302df2da7c --- /dev/null +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/EventoRiesgo.kt @@ -0,0 +1,11 @@ +package com.example.ellegadodepintia.exploradoresDePintia.model.eventoFactory + +import com.example.ellegadodepintia.exploradoresDePintia.model.Opcion + +class EventoRiesgo( + override val descripcion: String, + override val dificultad: Int, + override val opciones: MutableList<Opcion>, + override val imagen: Int, resistenciaMax: Int, + override var finalizado: Boolean, +) : Evento(descripcion, dificultad, opciones, imagen, resistenciaMax, resistenciaMax, finalizado) \ No newline at end of file diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/ReliquiaFactory.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/ReliquiaFactory.kt index 7b7caab4e0718c9a9b149d3892b0cd2582953527..93f0c1e3fa45e88d175dd919d5e88afd6a5c1ade 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/ReliquiaFactory.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/ReliquiaFactory.kt @@ -8,7 +8,6 @@ import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo import com.example.ellegadodepintia.exploradoresDePintia.model.Opcion import com.example.ellegadodepintia.exploradoresDePintia.model.efecto.EfectoIgnorar import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.ObjetoDeValor -import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.efectoObjeto.EfectoVender class ReliquiaFactory : EventoFactory { private val reliquiasMap = mapOf( @@ -33,7 +32,7 @@ class ReliquiaFactory : EventoFactory { ObjetoDeValor( nombre = "Vasito de barro cocido", descripcion = "Objeto de gran valor. Se convierte en 20 monedas si consigues completar la partida.", - efecto = EfectoVender(20), + coste = 20, imagen = R.drawable.asi_exploradores_vasito ) @@ -73,7 +72,7 @@ class ReliquiaFactory : EventoFactory { ObjetoDeValor( nombre = "Jabonera de cerámica", descripcion = "Objeto de gran valor. Se convierte en 20 monedas si consigues completar la partida.", - efecto = EfectoVender(20), + coste = 20, imagen = R.drawable.asi_exploradores_jabonera ) ) @@ -111,7 +110,7 @@ class ReliquiaFactory : EventoFactory { ObjetoDeValor( nombre = "Copa negra con inscripciones", descripcion = "Objeto de gran valor. Se convierte en 20 monedas si consigues completar la partida.", - efecto = EfectoVender(20), + coste = 20, imagen = R.drawable.asi_minijuego_3_copa_negra_brunida ) ) @@ -149,7 +148,7 @@ class ReliquiaFactory : EventoFactory { ObjetoDeValor( nombre = "Tapadera de cerámica zoomorfa", descripcion = "Objeto de gran valor. Se convierte en 20 monedas si consigues completar la partida.", - efecto = EfectoVender(20), + coste = 20, imagen = R.drawable.asi_minijuego_3_tapadera_zoomorfo ) ) diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/RiesgoFactory.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/RiesgoFactory.kt new file mode 100644 index 0000000000000000000000000000000000000000..af802fb1b5261c8846fd6dc542f229fd794c84fd --- /dev/null +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/eventoFactory/RiesgoFactory.kt @@ -0,0 +1,63 @@ +package com.example.ellegadodepintia.exploradoresDePintia.model.eventoFactory + +import com.example.ellegadodepintia.R +import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo +import com.example.ellegadodepintia.exploradoresDePintia.model.Opcion +import com.example.ellegadodepintia.exploradoresDePintia.model.efecto.EfectoIgnorar +import com.example.ellegadodepintia.exploradoresDePintia.model.efecto.EfectoRiesgo +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.ObjetoEquipable +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.efectoObjeto.EfectoEquipableAumento + + +class RiesgoFactory : EventoFactory { + private val riesgoMap = mapOf( + "En un claro junto al rÃo Duero, encuentras un viejo cofre de madera decorado con espigas de trigo y motivos solares. " to Pair( + R.drawable.cofre_open_animation, listOf( + Opcion( + descripcion = "Abrir el cofre", + atributoRequerida = Atributo.Investigacion, + EfectoRiesgo( + ObjetoEquipable( + nombre = "Espada de Hierro", + descripcion = "Una espada de hierro sencilla y confiable perfecta para un aventurero novato.", + efecto = EfectoEquipableAumento(1, Atributo.Ataque), + imagen = R.drawable.asi_objeto_espadadefault + ), + dmgRiesgo = 2, + mensajeRecomensa = "Dentro del cofre encuentras una espada de hierro vaccea. Está en buen estado y tiene un brillo sobrenatural", + mensajeRiesgo = "Una nube de polvo tóxico se libera, causandote 2 de daño", + ) + ), Opcion( + descripcion = "Ignorar", + atributoRequerida = Atributo.Nula, + EfectoIgnorar(100) + ) + ) + ), + ) + + override fun generarDescripcion(): String { + return riesgoMap.keys.random() + } + + override fun generarOpciones(descripcion: String): MutableList<Opcion> { + return riesgoMap[descripcion]?.second?.toMutableList() + ?: mutableListOf() + } + + override fun generarImagen(descripcion: String): Int { + return riesgoMap[descripcion]?.first!! + } + + override fun generarEvento(): EventoRiesgo { + val descripcion = generarDescripcion() + return EventoRiesgo( + descripcion = descripcion, + dificultad = 0, + opciones = generarOpciones(descripcion), + imagen = generarImagen(descripcion), + resistenciaMax = (2..8).random(), + finalizado = false + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/objeto/ObjetoDeValor.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/objeto/ObjetoDeValor.kt index ecd6bcbb3c2f3075da3ee56795dcdeb19c9f0345..176b7f0e11fcd36d6dc111ba2f59e87e24340580 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/objeto/ObjetoDeValor.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/objeto/ObjetoDeValor.kt @@ -1,13 +1,16 @@ package com.example.ellegadodepintia.exploradoresDePintia.model.objeto -import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.efectoObjeto.EfectoObjeto +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.efectoObjeto.EfectoVender class ObjetoDeValor( nombre: String, descripcion: String, - val efecto: EfectoObjeto, imagen: Int, + imagen: Int, + val coste: Int ) : Objeto(nombre, descripcion, imagen) { + private val efecto: EfectoVender = EfectoVender(coste) + override fun usar() { efecto.ejecutar() } diff --git a/app/src/main/java/com/example/ellegadodepintia/minijuego1/Minijuego1.kt b/app/src/main/java/com/example/ellegadodepintia/minijuego1/Minijuego1.kt index a440fac44394306df00bb82e9257f20e8c238b60..133e68c18b57592c641428b0d6d7eb47b607b3cf 100644 --- a/app/src/main/java/com/example/ellegadodepintia/minijuego1/Minijuego1.kt +++ b/app/src/main/java/com/example/ellegadodepintia/minijuego1/Minijuego1.kt @@ -4,6 +4,7 @@ import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ObjectAnimator import android.content.Intent +import android.graphics.drawable.AnimationDrawable import android.os.Bundle import android.os.CountDownTimer import android.os.Handler @@ -16,6 +17,7 @@ import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.example.ellegadodepintia.R +import com.example.ellegadodepintia.soundManager.SoundManager import kotlin.random.Random class Minijuego1 : AppCompatActivity() { @@ -24,6 +26,7 @@ class Minijuego1 : AppCompatActivity() { private lateinit var frameLayout: FrameLayout private lateinit var puntajeTextView: TextView private lateinit var tiempoTextView: TextView + private lateinit var soundManager: SoundManager // Instancia de SoundManager private var puntaje = 0 private var tiempoRestante = 30 private var fuera = false @@ -37,13 +40,14 @@ class Minijuego1 : AppCompatActivity() { frameLayout = findViewById(R.id.frameLayout) puntajeTextView = findViewById(R.id.puntajeTextView) tiempoTextView = findViewById(R.id.tiempoTextView) - + soundManager = SoundManager(this) iniciarJuego() iniciarContador() } // Función principal para iniciar el juego private fun iniciarJuego() { + soundManager.playSoundLoop(R.raw.sound_cueva) handler.postDelayed(object : Runnable { override fun run() { agregarBoton() @@ -110,7 +114,7 @@ class Minijuego1 : AppCompatActivity() { object : CountDownTimer(30 * 1000L, 1000) { override fun onTick(millisUntilFinished: Long) { tiempoRestante = (millisUntilFinished / 1000).toInt() - tiempoTextView.text = "Tiempo: $tiempoRestante s" + tiempoTextView.text = "Tiempo: $tiempoRestante" if (tiempoRestante == 1) { handler.removeCallbacksAndMessages(null) } @@ -144,52 +148,73 @@ class Minijuego1 : AppCompatActivity() { super.onPause() fuera = true handler.removeCallbacksAndMessages(null) + soundManager.stopSound() } override fun onDestroy() { super.onDestroy() handler.removeCallbacksAndMessages(null) + soundManager.stopSound() } - // Mostrar partÃculas en la posición del botón tocado + // Mostrar partÃculas o animación en la posición del botón tocado private fun mostrarParticulas(x: Float, y: Float, esHueso: Boolean) { - val cantidadParticulas = Random.nextInt(5, 11) - for (i in 0 until cantidadParticulas) { - val particula = ImageView(this) - particula.setImageResource( - if (esHueso) R.drawable.asi_minijuego_1_hueso else R.drawable.asi_minijuego_1_bomba - ) - particula.layoutParams = FrameLayout.LayoutParams( - if (esHueso) 25 else 35, - if (esHueso) 25 else 35 - ) - - frameLayout.addView(particula) - particula.x = x - particula.y = y - - val animX = ObjectAnimator.ofFloat(particula, "translationX", x + Random.nextInt(-200, 200)) - val animY = ObjectAnimator.ofFloat(particula, "translationY", y + Random.nextInt(-200, 200)) - val alphaAnim = ObjectAnimator.ofFloat(particula, "alpha", 1f, 0f) - - animX.duration = Random.nextLong(300, 800) - animY.duration = animX.duration - alphaAnim.duration = animX.duration - - val interpolator = AccelerateDecelerateInterpolator() - animX.interpolator = interpolator - animY.interpolator = interpolator - alphaAnim.interpolator = interpolator - - animX.start() - animY.start() - alphaAnim.start() - - alphaAnim.addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - frameLayout.removeView(particula) - } - }) + if (esHueso) { + soundManager.playSound(R.raw.sound_huesito) // Usando el SoundManager + // Mostrar partÃculas si es un hueso + val cantidadParticulas = Random.nextInt(5, 11) + for (i in 0 until cantidadParticulas) { + val particula = ImageView(this) + particula.setImageResource(R.drawable.asi_minijuego_1_hueso) + particula.layoutParams = FrameLayout.LayoutParams(25, 25) + frameLayout.addView(particula) + particula.x = x + particula.y = y + + val animX = ObjectAnimator.ofFloat(particula, "translationX", x + Random.nextInt(-200, 200)) + val animY = ObjectAnimator.ofFloat(particula, "translationY", y + Random.nextInt(-200, 200)) + val alphaAnim = ObjectAnimator.ofFloat(particula, "alpha", 1f, 0f) + + animX.duration = Random.nextLong(300, 800) + animY.duration = animX.duration + alphaAnim.duration = animX.duration + + val interpolator = AccelerateDecelerateInterpolator() + animX.interpolator = interpolator + animY.interpolator = interpolator + alphaAnim.interpolator = interpolator + + animX.start() + animY.start() + alphaAnim.start() + + alphaAnim.addListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + frameLayout.removeView(particula) + } + }) + } + } else { + val explosionView = ImageView(this) + soundManager.playSound(R.raw.sound_bomba) // Usando el SoundManager + explosionView.setBackgroundResource(R.drawable.effect_reparar_animation) + val params = FrameLayout.LayoutParams(300, 300) + params.leftMargin = x.toInt() - 150 + params.topMargin = y.toInt() - 150 + explosionView.layoutParams = params + frameLayout.addView(explosionView) + + // Iniciar la animación + handler.postDelayed({ + (explosionView.background as? AnimationDrawable)?.start() + explosionView.animate() + .alpha(0f) + .setDuration(1000L) + .withEndAction { + frameLayout.removeView(explosionView) + } + .start() + }, 0) } } } diff --git a/app/src/main/java/com/example/ellegadodepintia/minijuego2/Minijuego2.kt b/app/src/main/java/com/example/ellegadodepintia/minijuego2/Minijuego2.kt index bd7d4feb78b692552535b1284bdc92f92a90d4e7..73ac82dc98f59c1eed6300e15a212822a0c1c089 100644 --- a/app/src/main/java/com/example/ellegadodepintia/minijuego2/Minijuego2.kt +++ b/app/src/main/java/com/example/ellegadodepintia/minijuego2/Minijuego2.kt @@ -13,6 +13,7 @@ import kotlin.random.Random import android.graphics.drawable.AnimationDrawable import android.view.animation.AnimationUtils import com.example.ellegadodepintia.R +import com.example.ellegadodepintia.soundManager.SoundManager class Minijuego2 : AppCompatActivity() { @@ -26,6 +27,7 @@ class Minijuego2 : AppCompatActivity() { private lateinit var fondo1: ImageView private lateinit var fondo2: ImageView private lateinit var nube: ImageView + private lateinit var soundManager: SoundManager private var puntuacion = 0 private var gravedad = 1f @@ -51,6 +53,7 @@ class Minijuego2 : AppCompatActivity() { } private fun inicializarComponentes() { + soundManager = SoundManager(this) botonIniciar = findViewById(R.id.boton_iniciar) protagonista = findViewById(R.id.protagonista) layout = findViewById(R.id.layout) @@ -98,6 +101,7 @@ class Minijuego2 : AppCompatActivity() { } private fun iniciarJuego() { + soundManager.playSoundLoop(R.raw.sound_nubes) ocultarElementosInicioYMostrarProtagonista() inicializarJuego() iniciarBucleJuego() @@ -115,6 +119,7 @@ class Minijuego2 : AppCompatActivity() { protagonista.setElevation(10f) nube.setElevation(10f) botonReinicio.setElevation(10f) + puntuacionTextView.setElevation(10f) } private fun inicializarJuego() { @@ -241,6 +246,8 @@ class Minijuego2 : AppCompatActivity() { private fun detenerJuego() { jugando = false + soundManager.stopSound() + soundManager.playSound(R.raw.sound_over) protagonista.clearAnimation() val animacionMuerte = AnimationUtils.loadAnimation(this, R.anim.caida) obstacleTimer?.let { handler.removeCallbacks(it) } // Detener el temporizador de obstáculos diff --git a/app/src/main/java/com/example/ellegadodepintia/minijuegoReparacion/MinijuegoReparacion.kt b/app/src/main/java/com/example/ellegadodepintia/minijuegoReparacion/MinijuegoReparacion.kt index c53ce8584587917efbb34e24cc712f9a18f3875d..e13ad4ce8ceacedf990ccd1fd9288b5db6dbc542 100644 --- a/app/src/main/java/com/example/ellegadodepintia/minijuegoReparacion/MinijuegoReparacion.kt +++ b/app/src/main/java/com/example/ellegadodepintia/minijuegoReparacion/MinijuegoReparacion.kt @@ -1,9 +1,12 @@ package com.example.ellegadodepintia.minijuegoReparacion +import android.app.Activity +import android.content.Intent import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Rect import android.graphics.drawable.AnimationDrawable +import android.graphics.drawable.Drawable import android.os.Bundle import android.widget.ImageView import android.widget.RelativeLayout @@ -12,6 +15,7 @@ import com.example.ellegadodepintia.R import android.os.Handler import android.os.Looper import android.view.animation.LinearInterpolator +import com.example.ellegadodepintia.exploradoresDePintia.model.GameState import kotlin.random.Random class MinijuegoReparacion : AppCompatActivity() { @@ -26,7 +30,14 @@ class MinijuegoReparacion : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_minijuego_reparacion) - val imagenOriginal = cargarImagen(R.drawable.asi_exploradores_jabonera) + var imagenOriginal: Bitmap? = null + val flag = intent.getBooleanExtra("FLAG_KEY", false) + if(flag){ + imagenOriginal = cargarImagen(R.drawable.asi_exploradores_jabonera) + }else{ + imagenOriginal = cargarImagen(GameState.eventoActual.imagen) + } + fragmentos = dividirImagen(imagenOriginal, filas, columnas) val relativeLayout = findViewById<RelativeLayout>(R.id.relativeLayoutFragmentos) @@ -172,6 +183,11 @@ class MinijuegoReparacion : AppCompatActivity() { handler.removeCallbacks(this) val relativeLayout = findViewById<RelativeLayout>(R.id.relativeLayoutFragmentos) mostrarNubesDePolvo(relativeLayout,100) + + val resultIntent = Intent() + resultIntent.putExtra("resultado", "Reparación completada") + setResult(Activity.RESULT_OK, resultIntent) + finish() return } mostrarQTE(paloImageView, ruleImageView) diff --git a/app/src/main/java/com/example/ellegadodepintia/soundManager/SoundManager.kt b/app/src/main/java/com/example/ellegadodepintia/soundManager/SoundManager.kt new file mode 100644 index 0000000000000000000000000000000000000000..a3b416251252282e83d353d9f6f8849e3ae09b73 --- /dev/null +++ b/app/src/main/java/com/example/ellegadodepintia/soundManager/SoundManager.kt @@ -0,0 +1,40 @@ +package com.example.ellegadodepintia.soundManager + +import android.content.Context +import android.media.MediaPlayer + +class SoundManager(private val context: Context) { + private var mediaPlayer: MediaPlayer? = null + + // Método para reproducir un sonido + fun playSound(soundResource: Int) { + // Inicializa un nuevo MediaPlayer con el recurso de sonido + mediaPlayer = MediaPlayer.create(context, soundResource) + mediaPlayer?.start() // Comienza la reproducción + } + + // Método para reproducir un sonido en bucle + fun playSoundLoop(soundResource: Int) { + // Inicializa un nuevo MediaPlayer con el recurso de sonido + mediaPlayer = MediaPlayer.create(context, soundResource) + mediaPlayer?.apply { + isLooping = true // Hacer que el sonido se repita en bucle + start() // Comienza la reproducción + } + } + + // Método para detener el sonido actual + fun stopSound() { + mediaPlayer?.let { + if (it.isPlaying) { + it.stop() + } + } + } + + // Método para liberar recursos cuando ya no se necesiten más + fun release() { + mediaPlayer?.release() + mediaPlayer = null + } +} diff --git a/app/src/main/res/drawable/asi_fragmento_reliquia.png b/app/src/main/res/drawable/asi_fragmento_reliquia.png new file mode 100644 index 0000000000000000000000000000000000000000..807c32c7a0ce3efa9f314bd330f40ae6911f6ee2 Binary files /dev/null and b/app/src/main/res/drawable/asi_fragmento_reliquia.png differ diff --git a/app/src/main/res/drawable/cofre_madera_00.png b/app/src/main/res/drawable/cofre_madera_00.png new file mode 100644 index 0000000000000000000000000000000000000000..ddfa7099a4eab7df9365c90de9a3225bbe5cc207 Binary files /dev/null and b/app/src/main/res/drawable/cofre_madera_00.png differ diff --git a/app/src/main/res/drawable/cofre_madera_01.png b/app/src/main/res/drawable/cofre_madera_01.png new file mode 100644 index 0000000000000000000000000000000000000000..1828f69fc64898e93fbf7d3256af31963d06d916 Binary files /dev/null and b/app/src/main/res/drawable/cofre_madera_01.png differ diff --git a/app/src/main/res/drawable/cofre_madera_02.png b/app/src/main/res/drawable/cofre_madera_02.png new file mode 100644 index 0000000000000000000000000000000000000000..ebe13e8f63ae470ec5e0e2db16dc7239042d14fb Binary files /dev/null and b/app/src/main/res/drawable/cofre_madera_02.png differ diff --git a/app/src/main/res/drawable/cofre_madera_03.png b/app/src/main/res/drawable/cofre_madera_03.png new file mode 100644 index 0000000000000000000000000000000000000000..3758126601556e18052c2eb44012557b63207613 Binary files /dev/null and b/app/src/main/res/drawable/cofre_madera_03.png differ diff --git a/app/src/main/res/drawable/cofre_madera_04.png b/app/src/main/res/drawable/cofre_madera_04.png new file mode 100644 index 0000000000000000000000000000000000000000..d2278293892099f3e0030293c211fd9465f856a9 Binary files /dev/null and b/app/src/main/res/drawable/cofre_madera_04.png differ diff --git a/app/src/main/res/drawable/cofre_open_animation.xml b/app/src/main/res/drawable/cofre_open_animation.xml new file mode 100644 index 0000000000000000000000000000000000000000..b5a78b0da5ef8670349e8dabdc28ba82cd8b59a7 --- /dev/null +++ b/app/src/main/res/drawable/cofre_open_animation.xml @@ -0,0 +1,11 @@ +<!-- res/drawable/idle_animation.xml --> +<animation-list xmlns:android="http://schemas.android.com/apk/res/android" + android:oneshot="false"> + + <item android:drawable="@drawable/cofre_madera_00" android:duration="150" /> + <item android:drawable="@drawable/cofre_madera_01" android:duration="150" /> + <item android:drawable="@drawable/cofre_madera_02" android:duration="150" /> + <item android:drawable="@drawable/cofre_madera_03" android:duration="150" /> + <item android:drawable="@drawable/cofre_madera_04" android:duration="150" /> + +</animation-list> \ No newline at end of file diff --git a/app/src/main/res/raw/sound_bomba.wav b/app/src/main/res/raw/sound_bomba.wav new file mode 100644 index 0000000000000000000000000000000000000000..c0c322860f9acb9ca712be706244a85c127c8497 Binary files /dev/null and b/app/src/main/res/raw/sound_bomba.wav differ diff --git a/app/src/main/res/raw/sound_cueva.mp3 b/app/src/main/res/raw/sound_cueva.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..ee8c0a839e62b9c828fff59fe7717bfb6f27ea79 Binary files /dev/null and b/app/src/main/res/raw/sound_cueva.mp3 differ diff --git a/app/src/main/res/raw/sound_huesito.mp3 b/app/src/main/res/raw/sound_huesito.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..893deb23063f96ecdd118ebe05f7bb44e7b56a78 Binary files /dev/null and b/app/src/main/res/raw/sound_huesito.mp3 differ diff --git a/app/src/main/res/raw/sound_nubes.mp3 b/app/src/main/res/raw/sound_nubes.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d4271e28045298d51586afac7e5b784ad3145a8d Binary files /dev/null and b/app/src/main/res/raw/sound_nubes.mp3 differ diff --git a/app/src/main/res/raw/sound_over.mp3 b/app/src/main/res/raw/sound_over.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..b03955fca91d4eb7813a310165be7b5ed34d9104 Binary files /dev/null and b/app/src/main/res/raw/sound_over.mp3 differ