Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moar particles

  • Loading branch information...
commit bf811bf7d448565590f925c1157bf7471b534d6b 1 parent 28fa424
Morgan Veyret authored
Showing with 96 additions and 50 deletions.
  1. +96 −50 examples/particles.lisp
View
146 examples/particles.lisp
@@ -8,56 +8,102 @@
(defmethod init-example ((it particles))
(glaw:load-asset "particle.png" :texture)
(glaw:load-asset "fire-particle.png" :texture)
+ (glaw:load-asset "smoke-particle.png" :texture)
+ (glaw:load-asset "bubble.png" :texture)
(setf (particles-view it) (glaw:create-2d-view 0 0 glaw:*display-width* glaw:*display-height*))
(loop for i below 10
- do (if (oddp i)
- ;; water thing
- (let ((syst (glaw:create-particle-system)))
- (push syst (particles-systems it))
- (glaw::add-particle-emitter syst
- (glaw::make-particle-emitter
- :delay 0.00
- :rate 1.0
- :vx '(90.0 100.0)
- :vy '(19 20)
- :lifetime 8.0
- :color (glaw:create-color 0.3 0.3 1.0 1.0)
- :width 5.0
- :height 5.0
- :x (random glaw:*display-width*)
- :y (random glaw:*display-height*)
- :texture (glaw:use-resource "particle.png")))
- (glaw::add-particle-affector syst
- (glaw::make-gravity-affector
- :strength 50))
- (glaw::add-particle-affector syst
- (glaw::make-fading-affector
- :rate 0.3)))
- ;; fire thing
- (let ((syst (glaw:create-particle-system)))
- (push syst (particles-systems it))
- (glaw::add-particle-emitter syst
- (glaw::make-particle-emitter
- :delay 0.05
- :spin (list 0 (glaw:deg->rad 60))
- :angle (list 0 (glaw:deg->rad 60))
- :rate '(1.0 10.0)
- :vx 0.0
- :vy '(100 200.0)
- :lifetime 2.0
- :color (glaw:create-color 1.0 0.4 0.15 1.0)
- :width 30.0
- :height 30.0
- :x (let ((x (random glaw:*display-width*)))
- (list (- x 20) (+ x 20)))
- :y (random glaw:*display-height*)
- :texture (glaw:use-resource "fire-particle.png")))
- (glaw::add-particle-affector syst
- (glaw::make-resistance-affector
- :value 0.5))
- (glaw::add-particle-affector syst
- (glaw::make-fading-affector
- :rate 2.0))))))
+ do (let ((syst (glaw:create-particle-system)))
+ (push syst (particles-systems it))
+ (case (mod i 4)
+ (0 ;; water thing
+ (glaw::add-particle-emitter syst
+ (glaw::make-particle-emitter
+ :rate 100.0
+ :vx '(90.0 100.0)
+ :vy '(19 20)
+ :lifetime 8.0
+ :color (glaw:create-color 0.3 0.3 1.0 1.0)
+ :width 5.0
+ :height 5.0
+ :x (random glaw:*display-width*)
+ :y (random glaw:*display-height*)
+ :texture (glaw:use-resource "particle.png")))
+ (glaw::add-particle-affector syst
+ (glaw::make-gravity-affector
+ :strength 50))
+ (glaw::add-particle-affector syst
+ (glaw::make-fading-affector
+ :rate 0.3)))
+ (1 ;; blobby thing
+ (let ((x (random glaw:*display-width*))
+ (y (random glaw:*display-height*)))
+ (glaw::add-particle-emitter syst
+ (glaw::make-particle-emitter
+ :rate 50.0
+ :vx '(-5.0 5.0)
+ :vy '(-5.0 5.0)
+ :lifetime 1.0
+ :color (glaw:create-color 0.3 0.3 1.0 0.3)
+ :width '(50.0 100.0)
+ :height '(50.0 100.0)
+ :x (list (- x 10.0) (+ x 10.0))
+ :y (list (- y 10.0) (+ y 10.0))
+ :texture (glaw:use-resource "particle.png"))))
+ (glaw::add-particle-affector syst
+ (glaw::make-fading-affector
+ :rate 0.1)))
+ (2 ;; bubble thing
+ (glaw::add-particle-emitter syst
+ (glaw::make-particle-emitter
+ :rate 3.0
+ :vx '(-5.0 5.0)
+ :vy '(19 20)
+ :lifetime 8.0
+ :color (glaw:create-color 1.0 1.0 1.0 0.7)
+ :width 5.0
+ :height 5.0
+ :x (list 0 glaw:*display-width*)
+ :y (list 0 10)
+ :texture (glaw:use-resource "bubble.png"))))
+ (3 ;; fire thing
+ (let ((x (random glaw:*display-width*))
+ (y (random glaw:*display-height*)))
+ (glaw::add-particle-emitter syst
+ (glaw::make-particle-emitter
+ :rate 65.0
+ :spin (list 0 (glaw:deg->rad 60))
+ :angle (list 0 (glaw:deg->rad 60))
+ :rate '(1.0 10.0)
+ :vx 0.0
+ :vy '(100 200.0)
+ :lifetime 2.0
+ :color (glaw:create-color 1.0 0.4 0.15 1.0)
+ :width 30.0
+ :height 30.0
+ :x (list (- x 20.0) (+ x 20.0))
+ :y y
+ :texture (glaw:use-resource "fire-particle.png")))
+ (glaw::add-particle-emitter syst
+ (glaw::make-particle-emitter
+ :rate 20.0
+ :spin (list 0 (glaw:deg->rad 60))
+ :angle (list 0 (glaw:deg->rad 60))
+ :rate '(1.0 10.0)
+ :vx 0.0
+ :vy '(100 200.0)
+ :lifetime 2.0
+ :color (glaw:create-color .3 .3 .3 1.0)
+ :width 30.0
+ :height 30.0
+ :x (list (- x 20.0) (+ x 20.0))
+ :y (+ y 50.0)
+ :texture (glaw:use-resource "smoke-particle.png"))))
+ (glaw::add-particle-affector syst
+ (glaw::make-resistance-affector
+ :value 0.5))
+ (glaw::add-particle-affector syst
+ (glaw::make-fading-affector
+ :rate 2.0)))))))
(defmethod shutdown-example ((it particles))
(glaw:dispose-asset "particle.png")
@@ -70,9 +116,9 @@
(dolist (syst (particles-systems it))
(glaw:render-particles syst)
(incf nb-particles (glaw:particle-system-nb-particles syst)))
- (glaw:set-color/rgb 1 1 1)
+ (glaw:set-color/rgb 1.0 1.0 1.0)
(glaw:with-resources ((fnt "default-font"))
- (glaw:format-at 50 80 fnt "Particles: ~a" nb-particles)
+ (glaw:format-at 50 120 fnt "Particles: ~a" nb-particles)
(glaw:format-at 50 100 fnt "FPS: ~a" (glaw:current-fps))))
(glaw:end-draw))
Please sign in to comment.
Something went wrong with that request. Please try again.