x=140; y=70 -- Player position
velx=0; vely=0; -- Player velocity
health=3
hurttimer=0
mapx=0; mapy=0 -- Current map
screenwidth=240; screenheight=136
mapwidth=30; mapheight=16
enemies = {
{ mapx=0, mapy=0, x=50, y=100, img=193, spd=0.5, alive=true },
{ mapx=30, mapy=0, x=150, y=70, img=193, spd=0.5, alive=true }
}
enemytimer=0
warps = {
{
mapxA=0, mapyA=0, xA=20*8, yA=7*8,
mapxB=0, mapyB=119, xB=6*8, yB=80
},
}
warptimer=0
bullets = {}
bullettimer=0
function GetDistance( x1, y1, x2, y2 )
return math.sqrt( ( x2 - x1 )^2 + ( y2 - y1 )^2 )
end
function TIC()
-- DRAWING STUFF ---------------------
map(mapx,mapy) -- Draw map
if hurttimer == 0 then
spr(192,x,y,0) -- Draw player
else
spr(176,x,y,0) -- Draw player
end
-- KEYBOARD INPUT / MOVEMENT ---------
if btn(0) then -- UP arrow
y=y-1 -- Move player up
velx=0; vely=-1 -- Set velocity (for bullet)
elseif btn(1) then -- DOWN arrow
y=y+1 -- Move player down
velx=0; vely=1
elseif btn(2) then -- LEFT arrow
x=x-1 -- Move player left
velx=-1; vely=0
elseif btn(3) then -- RIGHT arrow
x=x+1 -- Move player right
velx=1; vely=0
end
-- HANDLE MAP SCROLLING --------------
if x > screenwidth then
x = 0
mapx = mapx + mapwidth
elseif x < -8 then
x = screenwidth-8
mapx = mapx - mapwidth
elseif y > screenheight then
y = 0
mapy = mapy + mapheight
elseif y < -8 then
y = mapheight-8
mapy = mapy - mapheight
end
-- HANDLE ARRAY OF ENEMIES -----------
for id,en in pairs(enemies) do
if en.alive == true then
-- Only use enemy if it's on the current map
if mapx == en.mapx and mapy == en.mapy then
spr(en.img, en.x, en.y,0)
-- Chase player
if x < en.x then
en.x = en.x - en.spd
elseif x > en.x then
en.x = en.x + en.spd
elseif y < en.y then
en.y = en.y - en.spd
elseif y > en.y then
en.y = en.y + en.spd
end
-- Check for collision
if GetDistance(x,y,en.x,en.y) <= 8 then
-- Bump player
x = x + math.random(-1,1)
y = y + math.random(-1,1)
if hurttimer == 0 then
-- Player gets hurt
health = health - 1
hurttimer = 100
sfx(0,"C-4",10)
end
end
end
end
end
if hurttimer > 0 then
hurttimer = hurttimer - 1
end
-- HANDLE SPAWNING ENEMIES -----------
if enemytimer == 0 then
newenemy = {}
newenemy.mapx = mapx -- Put on current map
newenemy.mapy = mapy
newenemy.x = screenwidth
newenemy.y = math.random(0,screenheight-8)
newenemy.img = 194
newenemy.spd = 0.5
newenemy.alive = true
table.insert(enemies,newenemy)
enemytimer = 100
else
enemytimer = enemytimer - 1
end
-- DRAW HEALTH -----------------------
print(health,x,y-8,11)
-- CHECK FOR WARPS -------------------
if warptimer == 0 then
for id,wp in pairs(warps) do
-- A to B warp
if mapx==wp.mapxA and mapy==wp.mapyA then
if GetDistance(x, y, wp.xA, wp.yA) <= 7 then
-- Warp to new location
mapx = wp.mapxB; mapy = wp.mapyB
x = wp.xB; y = wp.yB
warptimer = 100
end
-- B to A warp
elseif mapx==wp.mapxB and mapy==wp.mapyB then
if GetDistance(x, y, wp.xB, wp.yB) <= 7 then
-- Warp to new location
mapx = wp.mapxA; mapy = wp.mapyA
x = wp.xA; y = wp.yA
warptimer = 100
end
end
end
elseif warptimer > 0 then
warptimer = warptimer - 1
end -- if warptimer == 0 then
-- HANDLE ARRAY OF BULLETS -----------
if btn(4) and bullettimer == 0 then
newbullet={}
newbullet.x = x
newbullet.y = y
newbullet.velx = velx
newbullet.vely = vely
newbullet.img = 208
newbullet.spd = 2
table.insert(bullets,newbullet)
bullettimer = 10
end
if bullettimer > 0 then
bullettimer = bullettimer - 1
end
for id,bul in pairs(bullets) do
-- Update bullet
bul.x = bul.x + bul.velx * bul.spd
bul.y = bul.y + bul.vely * bul.spd
-- Draw bullet
spr(bul.img,bul.x,bul.y,0)
-- Check collision against enemies
for eid, en in pairs(enemies) do
if en.mapx==mapx and en.mapy==mapy then
if GetDistance(en.x, en.y, bul.x, bul.y) <= 8 then
en.alive = false
end
end
end
end
-- CHECK FOR NO HEALTH ---------------
if health <= 0 then
map(60,30)
print("GAME OVER", 120,60,12)
end
-- DEBUG OUTPUT ----------------------
print("Player: " .. x .. "," .. y, 1, screenheight-8, 12)
--print("Map: " .. mapx .. "," .. mapy, 1, 110, 12)
print("Warptimer: " .. warptimer, 100, screenheight-8, 12)
--print("warpAmap: " .. warps[1].mapxA .. "," .. warps[1].mapyA, 100, 100, 12,false,1,true)
--print("warpApos: " .. warps[1].xA .. "," .. warps[1].yA, 100, 108, 12,false,1,true)
--print("warpBmap: " .. warps[1].mapxB .. "," .. warps[1].mapyB, 100, 116, 12,false,1,true)
--print("warpBpos: " .. warps[1].xB .. "," .. warps[1].yB, 100, 124, 12,false,1,true)
end
--
-- 000:6666666666666666666666666666666666666666666666666666666666666666
-- 001:6666666666666666666666566656656666566566665665666666666666666666
-- 002:66666666cd66cd66cccccccccd66cd66cd66cd66cccccccccd66cd66cd66cd66
-- 003:66666666cd66cd66cccccd66cd66cd66cd66cd66cccccd66cd66cd66cd66cd66
-- 004:2212222222122222221222221111111122222122222221222222212211111111
-- 005:eefeeeeeeefeeeeeeefeeeeeffffffffeeeeefeeeeeeefeeeeeeefeeffffffff
-- 006:eeeeddddeeeeddddeeeeddddeeeeddddddddeeeeddddeeeeddddeeeeddddeeee
-- 007:3444344434443444344434443444333334443444344434443444344433333444
-- 010:3333333333333333333333333333333333333333333333333333333333333333
-- 017:66666666666cc666666cc6666cc44cc66cc44cc6666cc666666cc66666666666
-- 018:cd666666cd666666cd666666cd666666cd666666cd666666cd666666cd666666
-- 019:6666cd666666cd666666cd666666cd666666cd666666cd666666cd666666cd66
-- 021:fffffffffbaffbaffaaffaaffffffffffffffffffbaffbaffaaffaafffffffff
-- 022:fffffffffbaaaaaffaaaaaaffffffffffbaaaaaffaaaaaaffaaaaaafffffffff
-- 026:3333333333333333222222222222222222222222221111222211112222111122
-- 027:3333333333333333222222222222222222222222221111112211111122111111
-- 028:3333333333333333222222222222222222222222111111111111111111111111
-- 029:3333333333333333222222222222222222222222111111221111112211111122
-- 033:6667766666777766667777666772777667777776777777777777727777777777
-- 034:6dddddd6ddffffddfddddddfeffffffefefeeeefeffffffefeeeefef6ffffff6
-- 035:2222222223223332233322322222222223233232232332322323323222222222
-- 036:3333333333333333333333333333344333333443333333333333333333333333
-- 037:aaaaaaaaaaaaaaaaaaaaaaaaaaaaa44aaaaaa44aaaaaaaaaaaaaaaaaaaaaaaaa
-- 038:1111111111111111111111111111144111111441111111111111111111111111
-- 049:6663366666633666666336666663366666633666666336666663366666666666
-- 064:6666666666666669666666996666699966669999666999996699999969999999
-- 065:6666666696666666996666669996666699996666999996669999996699999996
-- 066:999999999999999999a999999a9a99999999999999999a999999a9a999999999
-- 080:6999999966999999666999996666999966666999666666996666666966666666
-- 081:9999999699999966999996669999666699966666996666669666666666666666
-- 082:2333233323332333233323332333233323332333233323332222222211111111
-- 096:666666666666666e666666ee66666eee6666eeee666eeeee66eeeeee6eeeeeee
-- 097:66666666e6666666ee666666eee66666eeee6666eeeee666eeeeee66eeeeeee6
-- 098:eeeeeeeeeeeeeeeeeedeeeeeeeeeeeeeeeeeeeeeeeeeeedeeeeeeeeeeeeeeeee
-- 112:6eeeeeee66eeeeee666eeeee6666eeee66666eee666666ee6666666e66666666
-- 113:eeeeeee6eeeeee66eeeee666eeee6666eee66666ee666666e666666666666666
-- 176:0220022002222220029229200222222000022000222222220002200000200200
-- 192:0cc00cc00cccccc00c9cc9c00cccccc0000cc000cccccccc000cc00000c00c00
-- 193:0022220002222220222222222224422222444422ccf44fcc4044440440000004
-- 194:007777000777777077777777777bb77777bbbb77ccfbbfccb0bbbb0bb000000b
-- 208:b000000b0b0000b0000bb00000b44b0000b44b00000bb0000b0000b0b000000b
-- 240:1111111111111111111111111111111111111111111111111111111111111111
-- 241:2222222222222222222222222222222222222222222222222222222222222222
-- 242:3333333333333333333333333333333333333333333333333333333333333333
-- 243:4444444444444444444444444444444444444444444444444444444444444444
-- 244:5555555555555555555555555555555555555555555555555555555555555555
-- 245:6666666666666666666666666666666666666666666666666666666666666666
-- 246:7777777777777777777777777777777777777777777777777777777777777777
-- 247:8888888888888888888888888888888888888888888888888888888888888888
-- 248:9999999999999999999999999999999999999999999999999999999999999999
-- 249:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-- 250:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
-- 251:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-- 252:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
-- 253:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
-- 254:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
--
--
--
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
--
--
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
--
--
-- 000:100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--
--
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
--