Created
October 16, 2019 15:58
-
-
Save commander-trashdin/725f1d89b1022f3164bb69605c523049 to your computer and use it in GitHub Desktop.
mah upgrad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; You probably wan to add some types to all of this. But later. | |
(defun check-collision (item-a item-b) | |
(and | |
(< (gamekit:x (pos item-a)) (+ (gamekit:x (pos item-b)) (gamekit:x (size item-b)))) | |
(< (gamekit:y (pos item-a)) (+ (gamekit:y (pos item-b)) (gamekit:y (size item-b)))) | |
(> (+ (gamekit:x (pos item-a)) (gamekit:x (size item-a))) (gamekit:x (pos item-b))) | |
(> (+ (gamekit:y (pos item-a)) (gamekit:y (size item-a))) (gamekit:y (pos item-b))))) | |
(defun check-collision-all (item) | |
(setf *collides* (find-if (lambda (elem) (check-collision item elem)) *blocks*))) | |
; objects | |
;; TODO: collision area vec4 | |
(defclass block-item () ;;types of the objects? | |
((src :accessor src) | |
(pos :accessor pos) | |
(size :accessor size) | |
(draw-pos :reader draw-pos))) | |
(defmethod draw-pos ((object block-item)) | |
(gamekit:vec2 (- (gamekit:x (pos object)) 10) (gamekit:y (pos object)))) | |
(defvar *player* (make-instance 'block-item)) | |
(setf (src *player*) nil | |
(pos *player*) (gamekit:vec2 400 100) | |
(size *player*) (gamekit:vec2 30 1)) | |
(defvar *ground* (make-instance 'block-item)) | |
(setf (src *ground*) :blank | |
(pos *ground*) (gamekit:vec2 0 0) | |
(size *ground*) (gamekit:vec2 800 100)) | |
;; TODO: move these into a loop | |
(defvar *block-a* (make-instance 'block-item)) | |
(setf (src *block-a*) :block | |
(pos *block-a*) (gamekit:vec2 200 150) | |
(size *block-a*) (gamekit:vec2 60 30)) | |
(defvar *block-b* (make-instance 'block-item)) | |
(setf (src *block-b*) :block | |
(pos *block-b*) (gamekit:vec2 300 200) | |
(size *block-b*) (gamekit:vec2 60 30)) | |
(defvar *block-c* (make-instance 'block-item)) | |
(setf (src *block-c*) :block | |
(pos *block-c*) (gamekit:vec2 400 250) | |
(size *block-c*) (gamekit:vec2 60 30)) | |
(defvar *block-d* (make-instance 'block-item)) | |
(setf (src *block-d*) :block | |
(pos *block-d*) (gamekit:vec2 550 250) | |
(size *block-d*) (gamekit:vec2 60 30)) | |
(defvar *blocks* (make-array 5 :element-type 'block-item | |
:initial-contents (list *ground* *block-a* *block-b* *block-c* *block-d*))) | |
; Game logic | |
(defmethod gamekit:draw ((app :moppu)) | |
(case *game-state* | |
(0 | |
(gamekit:draw-image (gamekit:vec2 0 0) :menu-bg) | |
(gamekit:draw-image (gamekit:vec2 310 520) :under-text) | |
(gamekit:draw-image (gamekit:vec2 *letter-padding* (moving-height 400 0)) :letter-m) | |
(gamekit:draw-image (gamekit:vec2 (+ *letter-padding* 110) (moving-height 390 20)) :letter-o) | |
(gamekit:draw-image (gamekit:vec2 (+ *letter-padding* 180) (moving-height 360 40)) :letter-p) | |
(gamekit:draw-image (gamekit:vec2 (+ *letter-padding* 250) (moving-height 360 10)) :letter-p) | |
(gamekit:draw-image (gamekit:vec2 (+ *letter-padding* 320) (moving-height 390 50)) :letter-u) | |
(gamekit:draw-image (gamekit:vec2 0 (moving-height -20 10)) :menu-f-1) | |
(gamekit:draw-image (gamekit:vec2 0 (moving-height -30 20)) :menu-f-2) | |
(gamekit:draw-image (gamekit:vec2 0 (moving-height -10 10)) :menu-f-3)) | |
(1 | |
(gamekit:draw-image (gamekit:vec2 0 0) :background) | |
(gamekit:draw-image (gamekit:vec2 *clouds-one-pos-x* 430) :clouds) | |
(gamekit:draw-image (gamekit:vec2 *clouds-two-pos-x* 430) :clouds) | |
(case *move-dir* | |
(1 (gamekit:draw-image (draw-pos *player*) :player-right)) | |
(-1 (gamekit:draw-image (draw-pos *player*) :player-left)) | |
(0 (gamekit:draw-image (draw-pos *player*) :player-front))) | |
(loop | |
:for elem :across *blocks* | |
:do (gamekit:draw-image (pos elem) (src elem)))) | |
(2 ())) | |
(gamekit:draw-rect (gamekit:vec2 0 0) 800 600 :fill-paint (gamekit:vec4 0 0 0 *alpha*)) | |
(when *debug* | |
(gamekit:print-text (format nil "Grounded: ~a" *grounded*) 10 580) | |
(gamekit:print-text (format nil "Velocity: ~3a" *velocity*) 10 560) | |
(gamekit:print-text (format nil "Collides: ~a" (check-collision-all *player*)) 10 540))) | |
(defmethod gamekit:act ((app :moppu)) | |
(case *game-state* | |
(0 | |
(setf *letter-move* (* 2 (real-time-seconds))) | |
(when *transitioning* | |
(incf *alpha* 0.02)) | |
(when (>= *alpha* 1) | |
(setf *game-state* 1))) | |
(1 | |
(when *transitioning* | |
(decf *alpha* 0.02)) | |
(when (<= *alpha* 0) | |
(setf *transitioning* nil)) | |
(when (and (< *velocity* 0) (check-collision-all *player*)) | |
(setf *grounded* t | |
*velocity* 0) | |
(incf (gamekit:x (pos *player*)) 0.2)) | |
(unless (check-collision-all *player*) | |
(setf *grounded* nil)) | |
(unless *grounded* | |
(decf *velocity* 0.2) | |
(setf *speed* 2)) | |
(when *grounded* | |
(setf *speed* 1)) | |
(update-position) | |
(when (< *clouds-one-pos-x* -800) | |
(setf *clouds-one-pos-x* 0)) | |
(decf *clouds-one-pos-x* 0.2) | |
(when (< *clouds-two-pos-x* 0) | |
(setf *clouds-two-pos-x* 800)) | |
(decf *clouds-two-pos-x* 0.2)) | |
(2 ()))) | |
; testing | |
(gamekit:bind-button :right :repeating | |
(lambda () (incf (gamekit:x (pos *block-a*)) 2))) | |
(gamekit:bind-button :left :repeating | |
(lambda () (decf (gamekit:x (pos *block-a*)) 2))) | |
(gamekit:bind-button :up :repeating | |
(lambda () (incf (gamekit:y (pos *block-a*)) 2))) | |
(gamekit:bind-button :down :repeating | |
(lambda () (decf (gamekit:y (pos *block-a*)) 2))) | |
; Input bindings | |
(gamekit:bind-button :a :pressed | |
(lambda () (setf *move-dir* -1))) | |
(gamekit:bind-button :a :released | |
(lambda () (setf *move-dir* 0))) | |
(gamekit:bind-button :d :pressed | |
(lambda () (setf *move-dir* 1))) | |
(gamekit:bind-button :d :released | |
(lambda () (setf *move-dir* 0))) | |
(gamekit:bind-button :space :pressed | |
(lambda () | |
(case *game-state* | |
(0 | |
(setf *transitioning* t)) | |
(1 | |
(when *grounded* | |
(setf *velocity* 7 | |
*grounded* nil))) | |
(2 ())))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment