-
Notifications
You must be signed in to change notification settings - Fork 0
/
riptris.rkt
62 lines (54 loc) · 1.89 KB
/
riptris.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
55
56
57
58
59
60
61
62
#lang racket/gui
(require "settings.rkt" "colors.rkt" "riptrominos.rkt" "drawing.rkt")
(define frame (new frame%
[label "riptris"]
[width WINDOW-WIDTH]
[height WINDOW-HEIGHT]))
(define falling-riptromino (t-riptromino))
;; (define fallen-blocks (make-list BOARD-HEIGHT (make-vector BOARD-WIDTH 0)))
(define fallen-blocks
(list
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 1 0 0 0)
(vector 0 0 0 1 0 0 1 0 0 0)
(vector 0 1 0 1 0 0 1 1 0 1)
(vector 1 1 1 1 1 0 1 0 1 0)))
;; convert ones to orange blocks
(for-each
(lambda (row)
(for ([i (in-range 0 (vector-length row))])
(when (equal? (vector-ref row i) 1)
(vector-set! row i (block COLOR-ORANGE))))) fallen-blocks)
(define my-canvas%
(class canvas%
(define/override (on-char event)
(define key (send event get-key-code))
(cond
([equal? key 'left] (send falling-riptromino move-left))
([equal? key 'right] (send falling-riptromino move-right))
([equal? key 'up] (send falling-riptromino rotate))
([equal? key 'down] (send falling-riptromino move-down)))
(send this refresh))
(super-new)))
(new my-canvas% [parent frame]
[paint-callback
(lambda (canvas dc)
(send canvas set-canvas-background COLOR-BACKGROUND)
(send dc set-scale 3 3)
(draw-game dc fallen-blocks falling-riptromino))])
(send frame show #t)