andyhd / asteroids Goto Github PK
View Code? Open in Web Editor NEWAsteroids game in Common Lisp
Asteroids game in Common Lisp
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.
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))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.