summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.scm104
-rw-r--r--images/player-bullet.pngbin138 -> 0 bytes
-rw-r--r--images/player-bullets.ase (renamed from images/player-bullet.ase)bin422 -> 523 bytes
-rw-r--r--images/player-bullets.pngbin0 -> 175 bytes
-rw-r--r--level.tmx2
5 files changed, 67 insertions, 39 deletions
diff --git a/game.scm b/game.scm
index 7d8a6a3..cf72933 100644
--- a/game.scm
+++ b/game.scm
@@ -301,7 +301,7 @@
(define context (get-context canvas "2d"))
(define image:background (load-image "images/background.png"))
(define image:player (load-image "images/player.png"))
- (define image:player-bullet (load-image "images/player-bullet.png"))
+ (define image:player-bullets (load-image "images/player-bullets.png"))
(define image:enemy-bullets (load-image "images/enemy-bullets.png"))
(define image:map (load-image "images/map.png"))
(define image:enemies (load-image "images/enemies.png"))
@@ -454,7 +454,7 @@
(type (s32-ref bullets offset))
(x (f64-ref bullets (+ offset 4)))
(y (f64-ref bullets (+ offset 12))))
- (draw-image context image (* type w) (* type h) w h
+ (draw-image context image (* type w) 0.0 w h
(- x (/ w 2.0)) (- y (/ w 2.0)) w h))))))
(define player-bullets (make-bullet-pool 200))
@@ -735,11 +735,13 @@
(define player-position (vec2 (/ game-width 2.0) (- game-height 12.0)))
(define player-velocity (vec2 0.0 0.0))
(define player-speed 2.9)
- (define player-bullet-speed 12.0)
+ (define player-focus-speed 1.5)
+ (define player-bullet-speed 12.3)
(define player-width 24.0)
(define player-height 24.0)
(define *player-fire-counter* 0)
(define player-fire-interval 3)
+ (define player-focus-fire-interval 2)
(define player-hitbox-position (vec2 0.0 0.0))
(define player-hitbox-width 2.0)
(define player-hitbox-height 2.0)
@@ -747,11 +749,11 @@
(define *player-lives* %default-lives)
(define *player-visible?* #t)
(define *player-invincible?* #f)
- ;; left, right, down, up, fire
- (define key-state (vector #f #f #f #f #f))
+ ;; left, right, down, up, fire, focus
+ (define key-state (vector #f #f #f #f #f #f))
(define (update-player-velocity!)
(match key-state
- (#(left? right? down? up? _)
+ (#(left? right? down? up? _ _)
(set-vec2-x! player-velocity
(+ (if left? -1.0 0.0)
(if right? 1.0 0.0)))
@@ -759,7 +761,10 @@
(+ (if down? 1.0 0.0)
(if up? -1.0 0.0)))
(vec2-normalize! player-velocity)
- (vec2-mul-scalar! player-velocity player-speed))))
+ (vec2-mul-scalar! player-velocity
+ (if (focusing?)
+ player-focus-speed
+ player-speed)))))
(define (set-left! pressed?)
(vector-set! key-state 0 pressed?)
(update-player-velocity!))
@@ -772,13 +777,21 @@
(define (set-up! pressed?)
(vector-set! key-state 3 pressed?)
(update-player-velocity!))
+ (define (firing?)
+ (vector-ref key-state 4))
(define (set-firing! pressed?)
(let ((was-firing? (firing?)))
(vector-set! key-state 4 pressed?)
(when (and pressed? (not was-firing?))
(set! *player-fire-counter* 0))))
- (define (firing?)
- (vector-ref key-state 4))
+ (define (focusing?)
+ (vector-ref key-state 5))
+ (define (set-focusing! pressed?)
+ (let ((was-focusing? (focusing?)))
+ (vector-set! key-state 5 pressed?)
+ (when (and pressed? (not was-focusing?))
+ (set! *player-fire-counter* 0)
+ (update-player-velocity!))))
(define (player-die!)
(unless *player-invincible?*
;; (sound-effect-play sound:player-death)
@@ -815,17 +828,26 @@
(player-die!))
(when (firing?)
(set! *player-fire-counter*
- (modulo (+ *player-fire-counter* 1) player-fire-interval))
+ (modulo (+ *player-fire-counter* 1)
+ (if (focusing?)
+ player-focus-fire-interval
+ player-fire-interval)))
(when (= *player-fire-counter* 0)
(sound-effect-play sound:player-shoot 0.2)
- (bullet-pool-add! player-bullets 0
- (- (vec2-x player-position) 6.0)
- (vec2-y player-position)
- 0.0 (- player-bullet-speed))
- (bullet-pool-add! player-bullets 0
- (+ (vec2-x player-position) 8.0)
- (vec2-y player-position)
- 0.0 (- player-bullet-speed))
+ (if (focusing?)
+ (bullet-pool-add! player-bullets 1
+ (vec2-x player-position)
+ (vec2-y player-position)
+ 0.0 (- player-bullet-speed))
+ (begin
+ (bullet-pool-add! player-bullets 0
+ (- (vec2-x player-position) 6.0)
+ (vec2-y player-position)
+ 0.0 (- player-bullet-speed))
+ (bullet-pool-add! player-bullets 0
+ (+ (vec2-x player-position) 8.0)
+ (vec2-y player-position)
+ 0.0 (- player-bullet-speed))))
(set! *player-fire-counter* 0))))
(define (draw-player)
(draw-image context image:player
@@ -872,7 +894,7 @@
(clear-rect context 0.0 0.0 *canvas-width* *canvas-height*))
(define (draw-player-bullets)
- (draw-bullets player-bullets image:player-bullet 8.0 8.0))
+ (draw-bullets player-bullets image:player-bullets 8.0 8.0))
(define (draw-enemy-bullets)
(draw-bullets enemy-bullets image:enemy-bullets 16.0 16.0))
@@ -969,6 +991,31 @@
((string-=? code "KeyZ")
(set-firing! #t)
(prevent-default! event))
+ ((string-=? code "ShiftLeft")
+ (set-focusing! #t)
+ (prevent-default! event)))))
+
+ (define (on-key-up event)
+ (let ((code (keyboard-event-code event)))
+ (cond
+ ((string-=? code "ArrowLeft")
+ (set-left! #f)
+ (prevent-default! event))
+ ((string-=? code "ArrowRight")
+ (set-right! #f)
+ (prevent-default! event))
+ ((string-=? code "ArrowDown")
+ (set-down! #f)
+ (prevent-default! event))
+ ((string-=? code "ArrowUp")
+ (set-up! #f)
+ (prevent-default! event))
+ ((string-=? code "KeyZ")
+ (set-firing! #f)
+ (prevent-default! event))
+ ((string-=? code "ShiftLeft")
+ (set-focusing! #f)
+ (prevent-default! event))
(else
(match *game-state*
('play
@@ -994,25 +1041,6 @@
(prevent-default! event))))
(_ #t))))))
- (define (on-key-up event)
- (let ((code (keyboard-event-code event)))
- (cond
- ((string-=? code "ArrowLeft")
- (set-left! #f)
- (prevent-default! event))
- ((string-=? code "ArrowRight")
- (set-right! #f)
- (prevent-default! event))
- ((string-=? code "ArrowDown")
- (set-down! #f)
- (prevent-default! event))
- ((string-=? code "ArrowUp")
- (set-up! #f)
- (prevent-default! event))
- ((string-=? code "KeyZ")
- (set-firing! #f)
- (prevent-default! event)))))
-
(define (out-of-bounds? x y w h)
(let ((padding 32.0))
(not (rect-within? x y w h (- padding) (- padding)
diff --git a/images/player-bullet.png b/images/player-bullet.png
deleted file mode 100644
index ca5cd4a..0000000
--- a/images/player-bullet.png
+++ /dev/null
Binary files differ
diff --git a/images/player-bullet.ase b/images/player-bullets.ase
index 5e7a8cf..354b729 100644
--- a/images/player-bullet.ase
+++ b/images/player-bullets.ase
Binary files differ
diff --git a/images/player-bullets.png b/images/player-bullets.png
new file mode 100644
index 0000000..7c80630
--- /dev/null
+++ b/images/player-bullets.png
Binary files differ
diff --git a/level.tmx b/level.tmx
index 94b5628..63618f5 100644
--- a/level.tmx
+++ b/level.tmx
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="15" height="40" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="14">
<tileset firstgid="1" source="tiles.tsx"/>
- <layer id="2" name="background" width="15" height="40">
+ <layer id="2" name="background" width="15" height="40" visible="0">
<data encoding="csv">
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,