1+ /*
2+ First time? Check out the tutorial game:
3+ https://sprig.hackclub.com/gallery/getting_started
4+
5+ @title : Sniper Simulator
6+ @author :
7+ @tags : []
8+ @addedOn : 2025-00-00
9+ */
10+
11+ const player = "p"
12+ const solid = "*"
13+ const target = "x"
14+ const crosshair = "+"
15+ const flash = "F"
16+ const shot = tune `
17+ 0,
18+ 37.5: C4/37.5 + D4/37.5 + E4/37.5 + F4/37.5 + G4/37.5,
19+ 37.5: F4/37.5 + E4/37.5 + D4/37.5 + G4~37.5 + C4~37.5,
20+ 0`
21+ const start = performance . now ( )
22+
23+ setLegend (
24+ [ player , bitmap `
25+ ................
26+ ................
27+ .......000......
28+ .......0.0......
29+ ......0..0......
30+ ......0...0.0...
31+ ....0003.30.0...
32+ ....0.0...000...
33+ ....0.05550.....
34+ ......0...0.....
35+ .....0....0.....
36+ .....0...0......
37+ ......000.......
38+ ......0.0.......
39+ .....00.00......
40+ ................` ] ,
41+ [ solid , bitmap `
42+ 0000000000000000
43+ 0000000000000000
44+ 0000000000000000
45+ 0000000000000000
46+ 0000000000000000
47+ 0000000000000000
48+ 0000000000000000
49+ 0000000000000000
50+ 0000000000000000
51+ 0000000000000000
52+ 0000000000000000
53+ 0000000000000000
54+ 0000000000000000
55+ 0000000000000000
56+ 0000000000000000
57+ 0000000000000000` ] ,
58+ [ crosshair , bitmap `
59+ .......33.......
60+ .....333333.....
61+ ....33333333....
62+ ...33..33..33...
63+ ..33...33...33..
64+ .33....33....33.
65+ .33....33....33.
66+ 3333333..3333333
67+ 3333333..3333333
68+ .33....33....33.
69+ .33....33....33.
70+ ..33...33...33..
71+ ...33..33..33...
72+ ....33333333....
73+ .....333333.....
74+ .......33.......` ] ,
75+ [ target , bitmap `
76+ ......6LLLL.....
77+ ......L6LLL.....
78+ ......6L6LL.....
79+ ......L6LLL.....
80+ ......6LLLL.....
81+ ......LLLLL.....
82+ .......111......
83+ .......111......
84+ ......LLLLL.....
85+ .....LLLLLLL....
86+ .....LLLLLLL....
87+ .....LLLLLLL....
88+ .....LLLLLLL....
89+ .....LLLLLLL....
90+ .....LLLLLLL....
91+ .....LLLLLLL....` ] ,
92+ [ flash , bitmap `
93+ ................
94+ ................
95+ ...999999.......
96+ ..99999999......
97+ ..9999999999....
98+ .996666999999...
99+ .9666666699999..
100+ .96666666699999.
101+ .96666666699999.
102+ .9666666699999..
103+ .996666999999...
104+ ..9999999999....
105+ ..99999999......
106+ ...999999.......
107+ ................
108+ ................` ]
109+ )
110+
111+ setSolids ( [ ] )
112+
113+ let level = 0
114+ const levels = [
115+ map `
116+ ........................................
117+ ........................................
118+ ........................................
119+ ........................................
120+ ........................................
121+ ........................................
122+ ........................................
123+ ........................................
124+ .***....................................
125+ .*****..................................
126+ .***....................................
127+ .***....................................
128+ ..*..***................................
129+ ************............................
130+ *****.***...............................
131+ ****.*..................................
132+ .***....................................
133+ *********...............................
134+ *********...............................
135+ ********................................
136+ ********................................
137+ ******..................................
138+ *****...................................
139+ ****....................................
140+ ........................................
141+ ........................................
142+ ........................................
143+ ........................................
144+ ........................................
145+ ........................................`
146+ ]
147+ const targets = [
148+ [ 20 , 10 ] , [ 32 , 24 ] , [ 37 , 20 ] , [ 28 , 6 ] , [ 25 , 15 ] , [ 35 , 11 ] , [ 23 , 25 ]
149+ ]
150+
151+ setMap ( levels [ level ] )
152+ for ( x = 0 ; x < targets . length ; x ++ ) {
153+ addSprite ( targets [ x ] [ 0 ] , targets [ x ] [ 1 ] , target )
154+ }
155+ addSprite ( 12 , 13 , crosshair )
156+ ch = getFirst ( crosshair )
157+
158+ onInput ( "w" , ( ) => {
159+ ch . y -= 1
160+ clearTile ( 12 , 13 )
161+ } )
162+ onInput ( "a" , ( ) => {
163+ ch . x -= 1
164+ clearTile ( 12 , 13 )
165+ } )
166+ onInput ( "s" , ( ) => {
167+ ch . y += 1
168+ clearTile ( 12 , 13 )
169+ } )
170+ onInput ( "d" , ( ) => {
171+ ch . x += 1
172+ clearTile ( 12 , 13 )
173+ } )
174+ onInput ( "k" , ( ) => {
175+ addSprite ( 12 , 13 , flash )
176+ playTune ( shot )
177+ var x = ch . x
178+ var y = ch . y
179+ clearTile ( ch . x , ch . y )
180+ addSprite ( x , y , crosshair )
181+ ch = getFirst ( crosshair )
182+ } )
183+
184+ afterInput ( ( ) => {
185+ if ( getAll ( target ) . length == 0 ) {
186+ const timeElapsed = ( ( performance . now ( ) - start ) / 1000 )
187+ addText ( "All targets\n eliminated.\n Time: " + timeElapsed , { x : 0 , y : 10 } )
188+ }
189+ } )
0 commit comments