Skip to content

Commit

Permalink
Movimiento del enemigo y test
Browse files Browse the repository at this point in the history
  • Loading branch information
Miranda-03 committed Nov 4, 2024
1 parent d717c70 commit 154bad8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 35 deletions.
73 changes: 49 additions & 24 deletions enemigos.wlk
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
class Enemigo1{
var property position = game.at(4,16)
var lado = 0
var property valor = "e_brocoli.png"
method image() = valor
import miscelaneos.*

class Enemigo1 inherits ObjetoVisible{
//var lado = 0
var property vida
var property position = game.center()
var property velocidad = 700
var property apariencia = "piopio.png"
method image() = apariencia

var property vector_movimiento = [0, 1, 0, 0]

method movimiento(){
game.onTick(velocidad, self, {self.moverse()})
}

method cambiar_vector_movimiento() {
const elemento = vector_movimiento.get(0)
vector_movimiento.remove(vector_movimiento.get(0))
vector_movimiento.addAll([elemento])
}

method detectar_colisiones() {
game.onCollideDo(self, {elemento =>
if(elemento.soyBloque()){
self.volver()
self.cambiar_vector_movimiento()
}
})
}

method volver() {
position = position.left(vector_movimiento.get(0) * -1)
.down(vector_movimiento.get(1) * -1)
.right(vector_movimiento.get(2) * -1)
.up(vector_movimiento.get(3) * -1)
}

method moverseH(limite1, limite2){
game.onTick(500, self, {self.muevete(limite1, limite2)})
method moverse(){
position = position.left(vector_movimiento.get(0))
.down(vector_movimiento.get(1))
.right(vector_movimiento.get(2))
.up(vector_movimiento.get(3))
}

method muevete(limite1, limite2){
if(self.position().x() == limite2){
lado = 1
}
if(self.position().x() == limite1){
lado = 0
}
if(lado == 0 && self.position().x()<limite2){
position = game.at(self.position().x()+1, 16)
}
if(lado == 1 && self.position().x()>limite1){
position = game.at(self.position().x()-1, 16)
}
method activar_enemigo() {
game.addVisual(self)
self.movimiento()
self.detectar_colisiones()
}

method limpiarEnemigos(){
Expand All @@ -30,14 +56,13 @@ class Enemigo1{
}

object lineaEnemiga{
var property enemigo = new Enemigo1()
var property enemigo = new Enemigo1(vida = 100)

method imagen(imagen){
enemigo.valor(imagen)
enemigo.apariencia(imagen)
}
method activar(){
game.addVisual(enemigo)
enemigo.moverseH(4,13)
enemigo.activar_enemigo()
}
}

Expand Down
6 changes: 4 additions & 2 deletions jugador.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import menus.menuPerdiste

import movimiento.*

import miscelaneos.*

object jugador inherits FiguraConMovimiento(position = game.at(1, 1)) {

method jugador() = true
override method jugador() = true

method posicionate(){
self.position(game.at(1, 1))
Expand All @@ -22,7 +24,7 @@ object jugador inherits FiguraConMovimiento(position = game.at(1, 1)) {
}
}

object points{
object points inherits ObjetoVisible{
var puntosObtenidos = 0
method sumarPuntos(){
puntosObtenidos += 1
Expand Down
6 changes: 6 additions & 0 deletions miscelaneos.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ object finDelJuego{
method image() = "PP_final.png"
}

mixin ObjetoVisible {
method soyBloque() = false
method esFruta() = false
method jugador() = false
}

//IMAGENES DE SELECCION
object marcoDeSeleccion{
var property position = game.at(2,5)
Expand Down
3 changes: 2 additions & 1 deletion movimiento.wlk
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import muros.*
import miscelaneos.*



class FiguraConMovimiento{
class FiguraConMovimiento inherits ObjetoVisible{
var position
method position() = position

Expand Down
10 changes: 8 additions & 2 deletions muros.wlk
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import niveles.*
class Bloque{
import miscelaneos.*

class Bloque inherits ObjetoVisible{
var property position = game.center()
method image() = visual.valor()
method ubicarYDibujar(x,y){
Expand All @@ -8,15 +10,19 @@ class Bloque{
escenario.enlistarBloque(self)
}
method quitarBloque() = game.removeVisual(self)

override method soyBloque() = true
}
class BloqueSuperior{
class BloqueSuperior inherits ObjetoVisible{
var property position = game.center()
method image() = visualSuperior.valor()
method ubicarYDibujar(x,y){
self.position(game.at(x,y))
game.addVisual(self)
}
method quitarBloque() = game.removeVisual(self)

//override method soyBloque() = true
}

object visual{
Expand Down
40 changes: 36 additions & 4 deletions pruebas.wtest
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import pepita.*
import muros.*
import wollok.game.*
import jugador.*
import puntos.*
import niveles.*
import miscelaneos.*
import menus.*
import enemigos.*

describe "group of tests for pepita" {
describe "Group of test for the enemy" {

test "pepita has initial energy" {
assert.equals(100, pepita.energy())
method initialize(){
game.clear()
game.cellSize(40)
game.height(18)
game.width(18)
game.start()
}

test "Should move"{
const enemy = new Enemigo1(vida = 100, position = game.at(1, 2), velocidad = 0)
game.addVisual(enemy)
enemy.moverse()
assert.equals(game.at(1, 1), enemy.position())
}

test "Should rotate direction" {
const enemy = new Enemigo1(vida = 100, position = game.at(1, 1), velocidad = 0)
game.addVisual(enemy)
enemy.cambiar_vector_movimiento()
assert.equals(1, enemy.vector_movimiento().get(0))
}

test "Should turn back"{
const enemy = new Enemigo1(vida = 100, position = game.at(1, 2), velocidad = 0)
game.addVisual(enemy)
enemy.moverse()
enemy.volver()
assert.equals(game.at(1, 2), enemy.position())
}
}
6 changes: 4 additions & 2 deletions puntos.wlk
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import muros.*
class Fruta{
import miscelaneos.*

class Fruta inherits ObjetoVisible{
var property position = posicionAleatoria.generarPosicionAleatoria()
var valor = spawn.puntos().get(0)

method jugador() = false
override method esFruta() = true

method image(){
return valor
Expand Down

0 comments on commit 154bad8

Please sign in to comment.