2009-09-28 08:57:29 +00:00
|
|
|
;; p l a n t e y e s [ copyright (c) 2009 foam vzw : gpl v3 ]
|
|
|
|
|
2009-08-04 08:06:14 +00:00
|
|
|
#lang scheme
|
2009-09-28 08:57:29 +00:00
|
|
|
(require scheme/class
|
|
|
|
fluxus-016/fluxus
|
|
|
|
"logic.ss"
|
|
|
|
"view.ss"
|
|
|
|
"controller.ss"
|
|
|
|
"client.ss"
|
|
|
|
"jabberer.ss"
|
|
|
|
"list-utils.ss")
|
|
|
|
|
2009-08-04 08:06:14 +00:00
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
(define-struct player-info (jid pass tex pos col))
|
|
|
|
|
|
|
|
(define gui-game-mode%
|
|
|
|
(class object%
|
|
|
|
(init-field
|
|
|
|
(seed-obs '()))
|
|
|
|
|
|
|
|
(field
|
|
|
|
(players (list
|
|
|
|
(make-player-info "plant0000001@fo.am" "plant0000001"
|
2009-08-15 08:03:28 +00:00
|
|
|
"textures/plant0000001.png" (list-ref (list-ref seed-obs 0) 2)
|
2009-09-25 16:19:48 +00:00
|
|
|
(vector 0.5 0.5 0.5))
|
2009-08-04 08:06:14 +00:00
|
|
|
(make-player-info "plant0000002@fo.am" "plant0000002"
|
2009-08-15 08:03:28 +00:00
|
|
|
"textures/plant0000002.png" (list-ref (list-ref seed-obs 1) 2)
|
2009-09-25 16:19:48 +00:00
|
|
|
(vector 0.25 0.25 0.25))
|
2009-08-04 08:06:14 +00:00
|
|
|
(make-player-info "plant0000003@fo.am" "plant0000003"
|
2009-08-15 08:03:28 +00:00
|
|
|
"textures/plant0000003.png" (list-ref (list-ref seed-obs 2) 2)
|
2009-09-25 16:19:48 +00:00
|
|
|
(vector 0.7 0.7 0.7))
|
2009-08-04 08:06:14 +00:00
|
|
|
(make-player-info "plant0000004@fo.am" "plant0000004"
|
2009-08-15 08:03:28 +00:00
|
|
|
"textures/plant0000004.png" (list-ref (list-ref seed-obs 3) 2)
|
2009-09-25 16:19:48 +00:00
|
|
|
(vector 0.75 0.75 0.75))
|
2009-08-04 08:06:14 +00:00
|
|
|
(make-player-info "plant0000005@fo.am" "plant0000005"
|
2009-08-15 08:03:28 +00:00
|
|
|
"textures/plant0000005.png" (list-ref (list-ref seed-obs 4) 2)
|
2009-09-25 16:19:48 +00:00
|
|
|
(vector 0.1 0.1 0.1))
|
2009-08-04 08:06:14 +00:00
|
|
|
))
|
|
|
|
(seeds '())
|
|
|
|
(clicked -1))
|
|
|
|
|
|
|
|
(define/public (get-player-info)
|
|
|
|
(list-ref players clicked))
|
2009-09-25 16:19:48 +00:00
|
|
|
|
|
|
|
(define/public (get-players)
|
|
|
|
players)
|
2009-08-04 08:06:14 +00:00
|
|
|
|
|
|
|
(define/public (setup)
|
|
|
|
(let ((c 0))
|
|
|
|
(set! seeds (map
|
|
|
|
(lambda (pi)
|
|
|
|
(with-state
|
|
|
|
(translate (vmul (vector (sin (* 2 3.141 (/ c (length players))))
|
|
|
|
(cos (* 2 3.141 (/ c (length players)))) 0) 4))
|
|
|
|
;(texture (load-texture (player-info-tex pi)))
|
|
|
|
(colour (player-info-col pi))
|
|
|
|
(set! c (+ c 1))
|
|
|
|
;(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(load-primitive "meshes/seed.obj")))
|
|
|
|
players))))
|
|
|
|
|
|
|
|
(define/public (update t d)
|
|
|
|
(for-each
|
|
|
|
(lambda (seed)
|
|
|
|
(with-primitive seed
|
|
|
|
(rotate (vector 0 1 0))))
|
|
|
|
seeds)
|
|
|
|
(cond
|
|
|
|
((mouse-button 1)
|
|
|
|
(let ((o (mouse-over)))
|
|
|
|
(cond
|
|
|
|
(o
|
|
|
|
(set! clicked (which-element o seeds 0))
|
|
|
|
(when clicked
|
|
|
|
(for-each
|
|
|
|
(lambda (seed)
|
|
|
|
(destroy seed))
|
|
|
|
seeds))
|
|
|
|
(if clicked #t #f))
|
|
|
|
(else
|
|
|
|
#f))))
|
|
|
|
(else
|
|
|
|
#f)))
|
|
|
|
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
|
|
|
|
(define main-game-mode%
|
|
|
|
(class object%
|
|
|
|
(init-field
|
|
|
|
(world-list '()))
|
|
|
|
|
|
|
|
(field
|
|
|
|
(gl (make-object game-logic%))
|
|
|
|
(gv (make-object game-view%))
|
|
|
|
(c (make-object controller% gv))
|
|
|
|
(cl #f)
|
|
|
|
(tick-time 0)
|
|
|
|
(player #f)
|
|
|
|
(logic-tick 0.5)) ; time between logic updates
|
|
|
|
|
2009-09-25 16:19:48 +00:00
|
|
|
(define/public (setup pi players)
|
2009-08-04 08:06:14 +00:00
|
|
|
(set! cl (make-object client% (player-info-jid pi) (player-info-pass pi)))
|
|
|
|
(set! player (make-object plant-logic%
|
|
|
|
(player-info-jid pi)
|
|
|
|
(player-info-pos pi)
|
|
|
|
(player-info-col pi)
|
2009-09-25 16:19:48 +00:00
|
|
|
(player-info-tex pi)
|
|
|
|
#t))
|
2009-08-04 08:06:14 +00:00
|
|
|
(send c set-player-plant player)
|
|
|
|
(send gl add-player player)
|
2009-09-25 16:19:48 +00:00
|
|
|
|
|
|
|
; add the other players...
|
|
|
|
(for-each
|
|
|
|
(lambda (player)
|
|
|
|
(when (not (eq? player pi))
|
|
|
|
(send gl add-plant (make-object plant-logic%
|
|
|
|
(player-info-jid player)
|
|
|
|
(player-info-pos player)
|
|
|
|
(player-info-col player)
|
|
|
|
(player-info-tex player)))))
|
|
|
|
players)
|
|
|
|
|
2009-08-04 08:06:14 +00:00
|
|
|
(send c setup)
|
|
|
|
(send gv setup world-list)
|
|
|
|
(send gl setup world-list)
|
|
|
|
(send cl setup))
|
|
|
|
|
|
|
|
(define/public (update t d)
|
|
|
|
(when (< tick-time t)
|
|
|
|
|
|
|
|
|
2009-09-25 16:19:48 +00:00
|
|
|
(let ((messages (send gl update t d)))
|
2009-08-04 08:06:14 +00:00
|
|
|
; pass the messages to the network client
|
|
|
|
(send gv update t d (send cl update messages gl))) ; and the game view
|
|
|
|
|
|
|
|
(set! tick-time (+ t logic-tick)))
|
|
|
|
|
|
|
|
(send gv update t d '())
|
|
|
|
(send c update t d))
|
|
|
|
|
|
|
|
(super-new)))
|