This is a variant of an ancient computer game - aliens descend from space, while player operates laser gun and
tries to destroy as many of invaders as possible. Gun rotates covering 180
degrees - in the field above you
can try it, moving the mouse to aim and clicking it to fire.
You'll see even if laser shots cross with some of the invaders, nothing happens: the program lacks the functionality to detect "hit". It's what you need to create.
The code should be written in Lua
, but luckily it is very small code so you won't find it difficult and may
even have fun intentionally reporting wrong hits to create funny visual effects (this however won't be accepted
when submitted).
Remember we have a Quick intro to Lua which will allow you to master
the language enough for this task in about 10
minutes.
So your program will input 3
pieces of data:
You should read in all these data according to example below and output X
coordinates of aliens which
are hit (if any), preceded with word hits
. This code is executed repeatedly say 20
times per second, as the
game situation evolves. When there are hits reported, corresponding aliens are removed, you'll see.
Example
input:
2 105 302 555 98
7
5 100 300 250 400 400 220 550 100 700 330
answer:
hits 100 550
The first and third lines of the inputs are lists of coordinates (beams and aliens respectively). Every list
starts with single value, meaning how many coordinate pairs are following. So here are 2
beams and 5
aliens at the moment in the field. Tolerance is 7
which means hit is registered if X
and Y
coordinates of
some unlucky alien differ no more than 7
from coordinates of some lucky shot.
Minimal program looks like this:
print('hits')
Note: animation may not work properly if the line doesn't have newline at the end, sorry for inconvenience.
However, if you don't want to waste your time on the input with Lua
use the half-cooked code found
by this link
- you'll only need to enrich it with hit-detection lines, while "framework" is already created for you.
You are recommended to debug your code using the sample input below (clicking "Lua" and verifying the answer
as usual). When you think it is ready, press reload code
button below the game field and try playing. If
it actually works - press Submit
.
Note: all the experiments were conducted with green inflatable fake targets. No real aliens were ever hurt.