-
Notifications
You must be signed in to change notification settings - Fork 0
/
riptromino.rkt
54 lines (42 loc) · 1.24 KB
/
riptromino.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#lang racket
(provide riptromino%)
(provide (struct-out block))
(struct block (color))
(define riptromino%
(class object%
(super-new)
(init-field color)
(init-field rotations)
;; replace ones with colored blocks
(for-each
(lambda (rotation)
(for-each
(lambda (row)
(for ([b (in-range 0 (vector-length row))])
(when (equal? (vector-ref row b) 1)
(vector-set! row b (block color))))) rotation)) rotations)
(define rotation-index 0)
(define x 0)
(define y 0)
(define/public (get-x) x)
(define/public (get-y) y)
(define/public (tick)
;; collision detection where
(set! y (+ y 1)))
(define/public (move-left)
;; collision detection where
(set! x (- x 1)))
(define/public (move-right)
;; collision detection where
(set! x (+ x 1)))
(define/public (move-down)
;; collision detection where
(set! y (+ y 1)))
(define/public (rotate)
;; collision detection where
(set! rotation-index
(cond
[(equal? rotation-index (- (length rotations) 1)) 0]
[else (+ rotation-index 1)])))
(define/public (blocks)
(list-ref rotations rotation-index))))