Skip to content

Commit

Permalink
Began work on animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlinde committed May 9, 2012
1 parent 9920148 commit abb716d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Game.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@
(glTranslatef (get-field xpos (get-field player world)) (get-field ypos (get-field player world)) 0)
(glMatrixMode GL_PROJECTION)
(glPushMatrix)
(glBindTexture GL_TEXTURE_2D (gl-vector-ref char-texture-list 0))

(glBindTexture GL_TEXTURE_2D (gl-vector-ref char-texture-list (get-field animation-state (get-field player world))))
(glColor3f 1 1 1)
(glBegin GL_TRIANGLE_STRIP)
(glTexCoord2i 0 0)
Expand Down
31 changes: 29 additions & 2 deletions Player.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
((up) 0)
((right) 90)
((down) 180)))
(gait-state #t)
(animation-state (case dir
((left) 0)
((up) 1)
((right) 2)
((down) 3)))
(transitstate 0)
(targetx xpos)
(targety ypos)
Expand Down Expand Up @@ -197,9 +203,30 @@
(vector-ref keys up)
(vector-ref keys down))
(eq? dir facing))
(set! in-transit #t)))
(set! in-transit #t)
(case dir
((up) (set! animation-state 4))
((right) (set! animation-state 8))
((down) (set! animation-state 12))
((left) (set! animation-state 16)))))
(when in-transit
(move! dir ticks)))
(when (eq? (remainder ticks speed) 0)
(if gait-state
(case animation-state
((4) (set! animation-state 5))
((5) (set! animation-state 6))
((6) (set! animation-state 7)
(set! gait-state #f)))
(case animation-state
((7) (set! animation-state 6))
((5) (set! animation-state 4)
(set! gait-state #t))
((6) (set! animation-state 5)))))




(move! dir ticks)))

;-------- Check the tile triggers ------
(let ((tile (send (get-field current-map world) gettile gridx gridy)))
Expand Down
Binary file modified images/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 25 additions & 4 deletions setuptextures.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
(image->gl-vector "images/door1.png"))
(list
(image->gl-vector "images/newtile.png"))))

(define (chartexloop filename i number-of-textures)
(if (eq? i number-of-textures)
'()
(cons (bitmaparea->gl-vector (make-object bitmap% filename 'png/alpha #f) (* i 32) 0 32 64) (chartexloop filename (+ i 1) number-of-textures))))
(define char-texs (list
(list (image->gl-vector "images/player.png"))
(chartexloop "images/player.png" 0 20)
(list (image->gl-vector "images/monster.png"))
(list (image->gl-vector "images/Eiresmile.png"))))

Expand All @@ -36,7 +39,7 @@

(set! tile-texture-list (glGenTextures (* (length tile-texs) 16)))

(set! char-texture-list (glGenTextures (* (length char-texs) 16)))
(set! char-texture-list (glGenTextures (* (length char-texs) 20)))
(set! text-texture-list (glGenTextures 70))
(set! thing-texture-list (glGenTextures 10))
(set! texture-list (glGenTextures 4))
Expand Down Expand Up @@ -88,7 +91,25 @@
tile-texs))
(let ((i 0)
(j 0))

(for-each (lambda (char-list)
(if (eq? (length char-list) 20)
(for-each (lambda (tex)
(glBindTexture GL_TEXTURE_2D (gl-vector-ref char-texture-list (+ (* i 20) j)))
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR)
(glTexImage2D GL_TEXTURE_2D
0
4
(list-ref (list-ref (list-ref char-texs i) j) 0)
(list-ref (list-ref (list-ref char-texs i) j) 1)
0
GL_RGBA
GL_UNSIGNED_BYTE
(list-ref (list-ref (list-ref char-texs i) j) 2))
(set! j (+ j 1)))
char-list)
(begin
(glBindTexture GL_TEXTURE_2D (gl-vector-ref char-texture-list (* i 16)))
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR)
(glTexParameteri GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR)
Expand All @@ -102,7 +123,7 @@
GL_UNSIGNED_BYTE
(list-ref (list-ref (list-ref char-texs i) 0) 2))
(set! j 0)
(set! i (+ i 1)))
(set! i (+ i 1)))))
char-texs))

(let ((i 0))
Expand Down

0 comments on commit abb716d

Please sign in to comment.