Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Challenge: 2D Tank

Name: Anonymous 2010-05-14 15:43

The Challenge:
|---->Program a 2d tank application in the language of your choice that adheres to the following:

#-The tank must rotate using the left and right directional keys.
#-The tank must loosely resemble a tank.
#-The tank must move forward or backward respectively from the direction it is facing using the up and down directional keys.
#-Pressing spacebar must fire a 'shot' in the direction the tank is facing.
#-The perspective of the user must be fixed and facing down at the tank.
#-The tank, shot, and ground must each have their own color. (all shots may have the same color)


<------You have 24 hours!------>
GET TO WORK!

Name: Anonymous 2010-05-15 7:37

2D is PIG DISGUSTING

fluxus is superior


(define-struct tank ((pos #:mutable) (rot #:mutable)))

(define player (make-tank (vector 0 0 0) (vector 0 0 0)))

(define shell null)

(define timefired 0)

(define ground-texture (load-texture "green.png"))

(define (draw-ground)
  (with-state
   (translate (vector 0 -2 0))
   (scale (vector 60 60 60))
   (rotate (vector 90 0 0))
   (texture ground-texture)
   (draw-plane)))

(define (tank-paint tank)
  (with-state
   (colour (vector 0.0 0.3 0.0))
   (translate (tank-pos tank))
   (rotate (tank-rot tank))
   (scale (vector 2.0 1.0 2.0))
   (draw-cube)
   (with-state
    (translate (vector 0.0 0.0 -1.0))
    (scale (vector 0.3 0.3 1.0))
    (draw-cube))
   (translate (vector 0.0 -1.0 0.0))
   (scale (vector 1.5 1.0 2.0))
   (draw-cube)))

(define (handle-input)
  (when (key-special-pressed 100)
    (tank-turn player (* 100 (delta))))
  (when (key-special-pressed 102)
    (tank-turn player (* -100 (delta))))
  (when (key-special-pressed 101)
    (tank-drive player (* 4 (delta))))
  (when (key-special-pressed 103)
    (tank-drive player (* -4 (delta))))
  (when (key-special-pressed 8)
    (shoot)))

(define (shoot)
  (cond ((null? shell)
         (set! shell (make-tank (tank-pos player) (tank-rot player)))
         (set! timefired (time))
         (tank-drive shell 3))))

(define (handle-shell)
  (cond ((> (- (time) timefired) 1)
         (set! shell null))
        ((not (null? shell))
         (tank-drive shell (* 30 (delta)))
         (paint-shell))))

(define (paint-shell)
  (with-state
   (colour (vector 1.0 0.0 0.0))
   (translate (tank-pos shell))
   (scale (vector 0.3 0.3 0.3))
   (draw-sphere)))

(every-frame (begin
               (draw-ground)
               (handle-input)
               (handle-shell)
               (tank-paint player)))

(define (tank-turn tank degrees)
  (set-tank-rot! tank (vadd (tank-rot tank) (vector 0 degrees 0))))

(define (tank-drive tank distance)
  (set-tank-pos! tank
                 (vadd
                  (tank-pos tank)
                  (vtransform
                   (vector 0 0 (- distance))
                   (mrotate (tank-rot tank))))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List