|
Post by tsh73 on Nov 14, 2020 17:05:18 GMT
So minimal that without lower$(Inkey$), comments and indents it actually fits in 1k See libertybasiccom.proboards.com/thread/1340/space-invaders-1k'space invaders inspired game 'tsh73, Nov 2020 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
open "Hack Invaders" for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher #m "place ";e;" ";r 'array of aliens for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " else s$=s$+" " 'bit-coded. Used BASIC! next #m "\";s$ next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying
o=int((w-r)/c+2):p=int((q-e+c+2)/c) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice "WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+5*c>y)_ 'so you can be crushed by descending enemy or((u>=y)and(x-10<t)and(t<x+40))then notice "DEAD!":goto[q] 'OR be hit by the bomb
if u>=y then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' if c$="w" then q=x+c:w=y-c 'fire key is 'c'. It effectively cancels old flying rocket wait
[q] close #m end
|
|
|
Post by B+ on Nov 14, 2020 19:18:31 GMT
Yes very nice, I was trying this out myself today.
|
|
|
Post by B+ on Nov 14, 2020 21:20:57 GMT
I dislike WASD how do you like this little mod?
'space invaders inspired game 'tsh73, Nov 2020 b+ mouse 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
open "Hack Invaders" for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];when mouseMove [m];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher #m "place ";e;" ";r 'array of aliens for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " else s$=s$+" " 'bit-coded. Used BASIC! next #m "\";s$ next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying
o=int((w-r)/c+2):p=int((q-e+c+2)/c) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice "WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+5*c>y)_ 'so you can be crushed by descending enemy or((u>=y)and(x-10<t)and(t<x+40))then notice "DEAD!":goto[q] 'OR be hit by the bomb
if u>=y then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' if c$="w" then q=x+c:w=y-c 'fire key is 'c'. It effectively cancels old flying rocket wait [m] x=MouseX wait [q] close #m end
|
|
|
Post by tsh73 on Nov 15, 2020 20:19:22 GMT
Well, problem not in WASD but in keyboard delay which is impossible to avoid in JB. So saying "A" one should say "B" Now rocket fires at left button click. Possible future: bomb is so big it just asks for being shot by rocket. It is not canon, but it just asks for it.
'space invaders inspired game 'tsh73, Nov 2020 b+ mouse 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
open "Hack Invaders" for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];when mouseMove [m];when leftButtonDown [f];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher #m "place ";e;" ";r 'array of aliens for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " else s$=s$+" " 'bit-coded. Used BASIC! next #m "\";s$ next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying
o=int((w-r)/c+2):p=int((q-e+c+2)/c) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice "WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+5*c>y)_ 'so you can be crushed by descending enemy or((u>=y)and(x-10<t)and(t<x+40))then notice "DEAD!":goto[q] 'OR be hit by the bomb
if u>=y then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' if c$="w" then q=x+c:w=y-c 'fire key is 'w'. It effectively cancels old flying rocket wait [m] x=MouseX 'control by mouse wait [f] q=x+c:w=y-c 'fire by mouse button wait [q] close #m end
|
|
|
Post by B+ on Nov 15, 2020 20:36:02 GMT
Oh yes! and can recover all those bytes used for Key presses!
|
|
|
Post by cundo on Nov 16, 2020 16:25:20 GMT
We should do a Galaxian or maybe Galaga ha.
|
|
|
Post by tsh73 on Nov 17, 2020 20:17:16 GMT
Fixes: * you can shoot the bomb (it just asked for it). .. (But it will not give you points.) * bomb is dropped by the alien, not by piece of clear sky * if you eliminate row of aliens, that row will not counted as landed * you can go left and appear from the right (not sure Invaders did that. Galaxians sure did.) . . - of course you cannot do that with a mouse (probably should fiddle with collision detection more - I found that at least on this computer character takes 14 pixels while I asked for 15) 'space invaders inspired game 'tsh73, Nov 2020 b+ mouse 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
t$="Hack Invaders"+chr$(13) open t$ for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];when mouseMove [m];when leftButtonDown [f];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher '#m "place ";e;" ";r-c 'debug. And it shows letter occupy 14 pixels, not 15 - ??? '#m "north;turn 90;go ";c-1;";up;go ";c-1;";down": for i=1 to 7: #m "go ";c-1;";up;go ";c-1;";down": next
#m "place ";e;" ";r 'array of aliens f=int(rnd(0)*(41-k)) 'which alien will fire for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " 'bit-coded. Used BASIC! f=f-1:if f=0 then g=i:h=j 'which alien will fire else s$=s$+" " end if next if trim$(s$)<>"" then #m "\";s$ 'this prevents overwriting launcher by eliminated (empty) alien lines next for i = 5 to 1 step -1: if s(i) then l=i: exit for 'bottom non-empty row of aliens next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying 'if w>0 then #m "place ";q;" ";w:#m "\!":w=w-1 'debug
o=int((w-r)/c+2):p=int((q-e+c+2)/c) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice t$;"You WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+l*c>y) then notice t$;"Aliens landed. GAME OVER!":goto[q] 'so you can be crushed by descending enemy if (u>=y)and(x-10<t)and(t<x+40)then notice t$;"You are DEAD!":goto[q] 'OR be hit by the bomb
'if u>=y or u<0 then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u>=y or u<0 then t=h*2*(c-1)+e:u=r+g*c 'new bomb - from selected alien
'allow to hit the bomb 'rocket q w bomb t u Set u to -50, because if >y triggers bomb hit if (abs(q-t)<6) and (abs(w-u)<9) then #m "place ";t;" ";u:#m "\*":u=-50:w=0
if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling 'if u<y then #m "place ";t;" ";u:#m "\o":u=u+1 'debug wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' if x>300 then x=0-c if x <-30 then x = 300-c 'c$=lower$(Inkey$):x=x-(c$="a")*1+(c$="d")*1 'debug with single pixel if c$="w" then q=x+c:w=y-c 'fire key is 'w'. It effectively cancels old flying rocket wait [m] x=MouseX 'control by mouse wait [f] q=x+c:w=y-c 'fire by mouse button wait [q] close #m end
|
|
|
Post by B+ on Nov 17, 2020 21:28:57 GMT
You should not say cannot ;-))
Move mouse up and down:
'space invaders inspired game 'tsh73, Nov 2020 b+ mouse 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
t$="Hack Invaders"+chr$(13) open t$ for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];when mouseMove [m];when leftButtonDown [f];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher '#m "place ";e;" ";r-c 'debug. And it shows letter occupy 14 pixels, not 15 - ??? '#m "north;turn 90;go ";c-1;";up;go ";c-1;";down": for i=1 to 7: #m "go ";c-1;";up;go ";c-1;";down": next
#m "place ";e;" ";r 'array of aliens f=int(rnd(0)*(41-k)) 'which alien will fire for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " 'bit-coded. Used BASIC! f=f-1:if f=0 then g=i:h=j 'which alien will fire else s$=s$+" " end if next if trim$(s$)<>"" then #m "\";s$ 'this prevents overwriting launcher by eliminated (empty) alien lines next for i = 5 to 1 step -1: if s(i) then l=i: exit for 'bottom non-empty row of aliens next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying 'if w>0 then #m "place ";q;" ";w:#m "\!":w=w-1 'debug
o=int((w-r)/c+2):p=int((q-e+c+2)/c) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice t$;"You WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+l*c>y) then notice t$;"Aliens landed. GAME OVER!":goto[q] 'so you can be crushed by descending enemy if (u>=y)and(x-10<t)and(t<x+40)then notice t$;"You are DEAD!":goto[q] 'OR be hit by the bomb
'if u>=y or u<0 then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u>=y or u<0 then t=h*2*(c-1)+e:u=r+g*c 'new bomb - from selected alien
'allow to hit the bomb 'rocket q w bomb t u Set u to -50, because if >y triggers bomb hit if (abs(q-t)<6) and (abs(w-u)<9) then #m "place ";t;" ";u:#m "\*":u=-50:w=0
if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling 'if u<y then #m "place ";t;" ";u:#m "\o":u=u+1 'debug wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' if x>300 then x=0-c if x <-30 then x = 300-c 'c$=lower$(Inkey$):x=x-(c$="a")*1+(c$="d")*1 'debug with single pixel if c$="w" then q=x+c:w=y-c 'fire key is 'w'. It effectively cancels old flying rocket wait [m] x=(MouseX - 50 + MouseY) mod 300 'control by mouse wait [f] q=x+c:w=y-c 'fire by mouse button wait [q] close #m end
|
|
|
Post by tsh73 on Nov 18, 2020 4:33:35 GMT
You should not say cannot ;-)) Move mouse up and down: (...) Yes, I should know better. Nice touch!
|
|
|
Post by tsh73 on Nov 18, 2020 8:12:34 GMT
Fixed collision with aliens for actual character size (14 pix) Increased vertical span for bomb to rocket collision, because pretty often rocked passed through bomb.
'space invaders inspired game 'tsh73, Nov 2020 b+ mouse 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i = 1 to 5:s(i)=255:next
t$="Hack Invaders"+chr$(13) open t$ for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y c1=c-1 'it looks like actual char size is 14 #m "font courier_new ";c;" ";c #m "down;trapclose [q];when characterInput [c];when mouseMove [m];when leftButtonDown [f];setfocus" timer 100,[t]:wait
[t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\<|>" 'rocket launcher '#m "place ";e;" ";r-c 'debug. And it shows letter occupy 14 pixels, not 15 - ??? '#m "north;turn 90": for i=1 to 8: #m "go ";c-1;";up;go ";c-1;";down": next
#m "place ";e;" ";r 'array of aliens f=int(rnd(0)*(41-k)) 'which alien will fire for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("BASIC",i,1);" " 'bit-coded. Used BASIC! f=f-1:if f=0 then g=i:h=j 'which alien will fire else s$=s$+" " end if next if trim$(s$)<>"" then #m "\";s$ 'this prevents overwriting launcher by eliminated (empty) alien lines next for i = 5 to 1 step -1: if s(i) then l=i: exit for 'bottom non-empty row of aliens next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving
if w>0 then #m "place ";q;" ";w:#m "\!":w=w-c 'rocket flying 'if w>0 then #m "place ";q;" ";w:#m "\!":w=w-1 'debug
o=int((w-r)/c+2):p=int((q-e+7)/c1) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then notice t$;"You WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if
if(r+l*c>y) then notice t$;"Aliens landed. GAME OVER!":goto[q] 'so you can be crushed by descending enemy if (u>=y)and(x-10<t)and(t<x+40)then notice t$;"You are DEAD!":goto[q] 'OR be hit by the bomb
'if u>=y or u<0 then t=rnd(0)*14*c+e:u=r+5*c 'new bomb if u>=y or u<0 then t=h*2*c1+e:u=r+g*c 'new bomb - from selected alien
'allow to hit the bomb 'rocket q w bomb t u Set u to -50, because if >y triggers bomb hit if (abs(q-t)<6) and (u-w<9) and (w-u<c) then #m "place ";t;" ";u:#m "\*":u=-50:w=0
if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling 'if u<y then #m "place ";t;" ";u:#m "\o":u=u+1 'debug wait
[c] c$=lower$(Inkey$):x=x-(c$="a")*5+(c$="d")*5 'left/right key is 'a' 'd' 'c$=lower$(Inkey$):x=x-(c$="a")*1+(c$="d")*1 'debug with single pixel if x>300 then x=0-c if x <-30 then x = 300-c if c$="w" then q=x+c:w=y-c 'fire key is 'w'. It effectively cancels old flying rocket wait [m] x=(MouseX - 50 + MouseY) mod 300 'control by mouse wait [f] q=x+c:w=y-c 'fire by mouse button wait [q] close #m end
|
|
|
Post by B+ on Nov 18, 2020 19:38:47 GMT
Hey tsh73, You have this working so well, the ship doesn't need to enter from opposite side, it is easier to position ship without that trick BUT now I get down to that last invader and am barraged by bombs from it, I cannot get a missile through ;-)) So maybe we can set up some parabolic paths for missiles or... throw a net over it and take it to Area 51.
|
|
|
Post by tsh73 on Nov 18, 2020 19:52:16 GMT
Well, since it fires at next moment bomb is shot and bomb falls from the alien... It's kind of logical (and inevitable). But sure it is bad kind of inevitable.
Original game has no such problem because bombs and rockets don't interact.
So how to circumvent it still staying logical?
|
|
|
Post by B+ on Nov 19, 2020 2:34:54 GMT
Oh you can hit the last alien by anticipating where it's going: 'space invaders inspired game 'tsh73, Nov 2020 b+ 11-18 minor mods 'for a challenge 'fit space invaders in 1k' look at 'https://libertybasiccom.proboards.com/thread/1340/space-invaders-1k nomainwin dim s(5):for i=1 to 5:s(i)=255:next t$="Hack Invaders"+chr$(13) open t$ for graphics_nsb_nf as #m c=15:y=300:x=y/2:e=6:r=50:u=y c1=c-1 'it looks like actual char size is 14 #m "font courier_new ";c;" ";c #m "down;trapclose [q];when mouseMove [m];when leftButtonDown [f];setfocus" timer 100,[t]:wait [t] #m "cls;place 9 9 ;\\";k 'score #m "place ";x;" ";y;";\=I=" 'rocket launcher #m "place ";e;" ";r 'array of aliens f=int(rnd(0)*(41-k)) 'which alien will fire for i=1 to 5 s$="" for j = 0 to 7 if s(i)and(2^j) then s$=s$+mid$("ALIEN",i,1);" " 'bit-coded. Used BASIC! f=f-1:if f=0 then g=i:h=j 'which alien will fire else s$=s$+" " end if next if trim$(s$)<>"" then #m "\";s$ 'this prevents overwriting launcher by eliminated (empty) alien lines next for i = 5 to 1 step -1: if s(i) then l=i: exit for 'bottom non-empty row of aliens next e=e+(1-2*de):if (e<0)+(e>70) then de=1-de:r=r+5 'aliens moving if w>0 then #m "place ";q;" ";w:#m "\.":#m "\|":w=w-c 'rocket flying o=int((w-r)/c+2):p=int((q-e+7)/c1) 'collision detection, kind of if (o>0)and(o<6)and(p>=0)and(p<15) then if p mod 2=0 then a=2^(p/2) if s(o)and a then s(o)=s(o)xor a:w=0:k=k+1:if k=40 then m$="You WIN!":goto[q] 'so you win by killing all 5*8 aliens end if end if end if if(r+l*c>y) then m$="Aliens landed. GAME OVER!":goto[q] 'so you can be crushed by descending enemy if (u>=y)and(x-10<t)and(t<x+40)then m$="U R Bombed!":goto[q] 'OR be hit by the bomb if u>=y or u<0 then t=h*2*c1+e:u=r+g*c 'new bomb - from selected alien if (abs(q-t)<6) and (u-w<9) and (w-u<c) then #m "place ";t;" ";u:#m "\*":u=-50:w=0 if u<y then #m "place ";t;" ";u:#m "\o":u=u+4 'bomb falling wait [m] x=MouseX:wait [f] q=x+c:w=y-c:wait [q] notice t$;m$ close #m:end
|
|
|
Post by tsh73 on Nov 19, 2020 17:01:29 GMT
Nice. You can have new line in graphic printing, like this
#m "\.\|"
|
|
|
Post by B+ on Nov 19, 2020 17:43:12 GMT
Nice. You can have new line in graphic printing, like this #m "\.\|" Thanks this is nice little game
|
|