Skip to content

Instantly share code, notes, and snippets.

@JimOfLeisure
Last active December 29, 2021 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimOfLeisure/a198321c7aac4ec03ed1ebf3f6b49909 to your computer and use it in GitHub Desktop.
Save JimOfLeisure/a198321c7aac4ec03ed1ebf3f6b49909 to your computer and use it in GitHub Desktop.
a=math b=240 c=138 d=120 e=69 f=0 g=0 h=0 i=.5 j=.2 k=.5
function l()m=d n=e o=0 p=0 q=0 r=0 end
l()
function TIC()t=a.sin(a.rad(f))u=-a.cos(a.rad(f))m=m+o n=n+p q=q+i r=r+j
if btnp(4)then m=d+t*9 n=e+u*9 o=t*2 p=u*2 end
if btn(2)then f=f-4 end
if btn(3)then f=f+4 end
cls()circ(d,e,7,8)print("*",(q-6)%b,(r-4)%c,6,true,2)circ(q%b,r%c,2,6)
if pix(m%b,n%c)==6 then g=g+1 k=k*1.2 i=k*t j=k*u l()end
print("SCORE "..g.." HI "..h,9,0)pix(m%b,n%c,15)line(d,e,d+t*9,e+u*9,15)
if a.abs(q%b-d)<9 and a.abs(r%c-e)<9 then h=g>h and g or h g=0 k=.5 i=.5 j=.2 l()end
end
--[[
Virus Defender
An Asteroids-like game in Lua for the TIC-80 fantasy computer console
Created and submitted as a game jam on Itch.io for TweetJam 4
in which entries were limited to 560 characters, the amount to fit
into two Twitter tweets.
https://jimofleisure.itch.io/virus-defender
This was made in TIC-80 v0.7 ; in v0.8 the default color palette changed so colors may be off
The pre-minified code follows
--]]
-- for extra manual minifying
m=math
screenwidth=240
screenheight=138
middlex=120
middley=69
-- starting turrent angle
angle=0
score=0
highscore=0
edx=.5
edy=.2
espeed=.5
function resetmovers()
-- init bullet x, y, dx, and dy (velocity)
bx=middlex
by=middley
dx=0
dy=0
-- init enemy
ex=0
ey=0
end
resetmovers()
function TIC()
x=m.sin(m.rad(angle))
-- negating Y because screen coords
-- and I want starting position up
-- and 0 is shorter than 180
-- only saving 1 char, though
y=-m.cos(m.rad(angle))
bx=bx+dx
by=by+dy
ex=ex+edx
ey=ey+edy
if btnp(4) then
-- pew pew
bx=middlex+x*9
by=middley+y*9
dx=x*2
dy=y*2
end
if btn(2) then
angle=angle-4
end
if btn(3) then
angle=angle+4
end
cls()
-- cell
circ(middlex,middley,7,8)
-- enemy
print("*", (ex-6)%screenwidth, (ey-4)%screenheight, 6, true, 2)
circ(ex%screenwidth,ey%screenheight,2,6)
-- bullet hit detect
if pix(bx%screenwidth,by%screenheight) == 6 then
score = score + 1
-- -- reset enemy
espeed=espeed*1.2
edx=espeed*x
edy=espeed*y
resetmovers()
end
-- score
print("SCORE "..score.." HI "..highscore,9,0)
-- bullet
pix(bx%screenwidth,by%screenheight,15)
-- turret
line(middlex,middley,middlex+x*9,middley+y*9,15)
if m.abs(ex%screenwidth-middlex)<9 and m.abs(ey%screenheight-middley)<9 then
-- game over! man. game over!
highscore = score > highscore and score or highscore
score=0
espeed=.5
edx=.5
edy=.2
resetmovers()
end
end
--[[
Copyright 2020, 2021 Jim "JimOfLeisure" Nelson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment