Git Product home page Git Product logo

asteroids's People

Contributors

andyhd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asteroids's Issues

Underflow issue?

Playing around a bit (and giving myself more powerups ;) I got this:

The value 32791 is not of type (SIGNED-BYTE 16).
   [Condition of type TYPE-ERROR]

Restarts:
  0: [RETRY] Retry SLIME REPL evaluation request.
  1: [*ABORT] Return to SLIME's top level.
  2: [ABORT] Abort thread (#<THREAD "repl-thread" RUNNING {10076B3693}>)

Backtrace:
  0: (LISPBUILDER-SDL::GFX-DRAW-CIRCLE-* 32791 21087 3 :SURFACE NIL :COLOR #<COLOR {1004DD6703}> :AA NIL)
  1: (DRAW-CIRCLE-* 32791 21087 3 :SURFACE NIL :COLOR #<COLOR {1004DD6703}> :ALPHA NIL :AA NIL :GFX-LOADED-P T)
  2: (DRAW-CIRCLE #(32791 21087) 3 :SURFACE NIL :COLOR #<COLOR {1004DD6703}> :ALPHA NIL :AA NIL :GFX-LOADED-P NIL)
  3: ((SB-PCL::FAST-METHOD RENDER (BULLET)) #<unused argument> #<unused argument> #<BULLET {100A958313}>)
  4: ((SB-PCL::FAST-METHOD RENDER-WORLD (WORLD T)) #<unused argument> #<unused argument> #<WORLD {1008C590E3}> NIL)
  5: ((LAMBDA () :IN MAIN))
  6: ((SB-PCL::FAST-METHOD LISPBUILDER-SDL::PROCESS-TIMESTEP (LISPBUILDER-SDL::FPS-MANAGER T)) #<unused argument> #<unused argument> #<unused argume
  7: ((SB-PCL::EMF LISPBUILDER-SDL::PROCESS-TIMESTEP) #<unused argument> #<unused argument> #<FPS-FIXED {1008C4C383}> #<CLOSURE (LAMBDA # :IN MAIN)
  8: ((SB-PCL::FAST-METHOD LISPBUILDER-SDL::PROCESS-TIMESTEP :AROUND (LISPBUILDER-SDL::FPS-MANAGER T)) ..)
  9: (MAIN)

I thought you might be interested.

Possible tweaks

Just some suggestions

diff --git a/asteroids.lisp b/asteroids.lisp
index 5087dda..f358870 100644
--- a/asteroids.lisp
+++ b/asteroids.lisp
@@ -57,8 +57,7 @@
          :y (+ (* radius (cos (deg->rad angle))) (y p))))

 (defun get-ticks ()
-  (let ((ticks *ticks*))
-    (setf *ticks* (sdl-get-ticks))
+  (let ((ticks (shiftf *ticks* (sdl-get-ticks))))
     (- *ticks* ticks)))

 ;;; represents an object on the game map
@@ -115,10 +114,13 @@
 (defmethod collide ((mob mob) (other mob) (world world)) t)

 (defmethod map-coords ((mob mob))
-  (multiple-value-bind (x y) (values-list (pos mob))
+  (destructuring-bind (x y) (pos mob)
     (point :x (round (* x *map-width*))
            :y (round (* y *map-height*)))))

+(defun relative-coords (x y)
+  (list (/ x *map-width*) (/ y *map-height*)))
+
 (defmethod map-radius ((mob mob))
   (round (* (radius mob) *map-width*)))

@@ -205,11 +207,10 @@
            *powerup-max-age*)
     (remove-from-world world powerup)))

-(defmethod add-score ((world world) score)
-  (when (numberp score)
-    (setf (high-score world)
-          (max (incf (score world) score)
-               (high-score world)))))
+(defmethod add-score ((world world) (score number))
+  (setf (high-score world)
+   (max (incf (score world) score)
+        (high-score world))))

 (defmethod add-score ((world world) (powerup powerup))
   (add-score world (* (level world) 10)))
@@ -395,7 +396,7 @@
         (vector-sum (pos bullet)
                     (vector-scale (velocity bullet)
                                   time-delta)))
-  (multiple-value-bind (x y) (values-list (pos bullet))
+  (destructuring-bind (x y) (pos bullet)
     (when (or (not (< 0 x *map-width*))
               (not (< 0 y *map-height*)))
       (remove-from-world world bullet)))
@@ -527,7 +528,7 @@
                                      :color *green*)))))

 (defun calc-angle (a b)
-  (multiple-value-bind (x y) (values-list (vector-subtract b a))
+  (destructuring-bind (x y) (vector-subtract b a)
     (rad->deg (atan x y))))

 (defun main ()
@@ -546,18 +547,13 @@
         (:mouse-motion-event (:x x :y y)
           (when (ship world)
             (setf (facing (ship world))
-                  (calc-angle (pos (ship world))
-                              `(,(/ x *map-width*) ,(/ y *map-height*))))))
+                  (calc-angle (pos (ship world)) (relative-coords x y)))))
         (:mouse-button-down-event (:x x :y y)
           (when (and (> (level world) 0)
                      (ship world)
                      (not paused))
-            (shoot-at (ship world)
-                      `(,(/ x *map-width*) ,(/ y *map-height*))
-                      world)
-            (thrust-at (ship world)
-                       `(,(/ x *map-width*)
-                         ,(/ y *map-height*)))))
+            (shoot-at (ship world) (relative-coords x y)  world)
+            (thrust-at (ship world) (relative-coords x y))))
         (:mouse-button-up-event ()
           (when (and (> (level world) 0)
                      (ship world))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.