# What can i change for my lava lake code?

``````

#hitbox = 3.5 in each dir
while True:
item = hero.findNearestItem()

e=hero.opponent
dir=e.direction
if hero.distanceTo(e)<=20:
if e:
if hero.x>e.x:
hero.turn("right")
hero.fire()
elif hero.x<e.x:
hero.turn("left")
hero.fire()

mx=hero.x+e.x
my=hero.y+e.y

hero.throw(e.x, e.y)

if item:

x = (item.x-hero.x) / 4
y = (item.y-hero.y) / 4
x2  = Math.round(x)
y2 = Math.round(y)
X = x2 * 4
Y = y2 * 4
X += hero.x
Y += hero.y

if  hero.x > item.x:

x = (hero.x-item.x) / 4
x2  = Math.round(x)
if hero.lavaAtXY(hero.x-x2/2, hero.y)!=0:

if x2/2!=1 and x2/2!=0:
hero.moveLeft((x2/2)-1)
hero.turn("left")

hero.jump(0.5)

if x2!=0:

hero.turn("left")
hero.moveForward(x2/2)

elif hero.x < item.x:
x = (item.x-hero.x) / 4
x2  = Math.round(x)
if hero.lavaAtXY(hero.x+x2/2, hero.y)!=0:
if x2/2!=1 and x2/2!=0:
hero.moveRight((x2/2)-1)

hero.turn("right")

hero.jump(0.5)

if x2!=0:

hero.turn("right")
hero.moveForward(x2/2)

if  hero.y < item.y:
y=(item.y-hero.y)/4
y2= Math.round(y)
if hero.lavaAtXY(hero.x, hero.y+y2/2)!=0:

if y2/2!=1 and y2/2!=0:
hero.moveUp((y2/2)-1)
hero.turn("up")

hero.jump(0.5)

if y2!=0:

hero.turn("up")
hero.moveForward(y2)

elif hero.y > item.y:
y=(hero.y-item.y)/4
y2= Math.round(y)
if hero.lavaAtXY(hero.x, hero.y-y2/2)!=0:

if y2/2!=1 and y2/2!=0:
hero.moveDown((y2/2)-1)
hero.turn("down")

hero.jump(0.5)
if y2!=0:

hero.turn("down")
hero.moveForward(y2)

#please do not copy. If you do, you will be shamy shamed by the comunity
``````
1 Like

pls help @Learned or anyone pls

I would but tbh I donâ€™t do much coding lately since I have no motivation for anything whatsoever

how should i find the nearest item (without using nearest Item) (for testing purposes)

check distance to item and check which item has the smallest distance? (use hero.pos with vector.distance for hero.distanceTo)

I donâ€™t have anything specific to point out (The code that works for my program may not work for you). However, I can point out some good strategies that have helped me monumentally.

1. Find a way to dodge enemy fireballs. I have noticed that almost everyone tries to attack using fireballs, and a way to avoid them has helped me against a lot of opponents. To start, you would need to find if your opponent has fired a fireball. The easiest way to do this would be recording whether or not your opponent is ready to fire a fireball in a variable at the end of your while loop. At the start of your while loop, compare said variable to whether or not your opponent can fire a fireball. If your opponent cannot fire a fireball, but the variable you saved says that they can, that means that they have launched a fireball after you saved the variable. If you do detect a fireball, you can find the area the fireball would cover and avoid that part of the map. Hopefully, this can point you in the right direction.

2. Another good way to beat your opponent is to collect items more efficiently than they do. I myself used the algorithm from the level â€śDiamond Dozenâ€ť in the desert campaign of Code Combat and compared the value and distance of items clustered together to find the best cluster of items.

Hope this helps and good luck with the competition.

2 Likes

how would i find where a fireball has been launched?

The fireball will have been launched from your opponentâ€™s coordinates.