好吧,我正在尝试做一个迷宫游戏,吃豆人,我需要创建和渲染地图,为此,我做了一个“矢量地图”与不同的状态我需要的。
这是代码:
#lang racket
(require 2htdp/image 2htdp/universe
(only-in racket/draw
read-bitmap))
(require math/matrix)
(require math/array)
(define CELL-SIZE 20)
(define E (rectangle CELL-SIZE CELL-SIZE "solid" "black"))
(define D (circle 3 "solid" "YELLOW"))
(define W (rectangle CELL-SIZE CELL-SIZE "solid" "blue"))
(define C (rectangle CELL-SIZE CELL-SIZE "solid" "red"))
(define Initial-Map
(vector (vector W W W W W W W W W W W W W)
(vector W C D D D D D D D D D D W)
(vector W D W D W W W W W D W D W)
(vector W D W D W D D D W D W D W)
(vector W D W D D D W D D D W D W)
(vector W D W W D W W W D W W D W)
(vector E D D D D D E D D D D D E)
(vector W D W W D W W W D W W D W)
(vector W D W D D D W D D D W D W)
(vector W D W D W D W D W D W D W)
(vector W D W D D D W D D D W D W)
(vector W D W D W D D D W D W D W)
(vector W D D C W D W D W D D D W)
(vector W W W W W W W W W W W W W)))
(define EMPTY (rectangle CELL-SIZE CELL-SIZE "solid" "black")) ; Empty
(define DOT (circle 3 "solid" "white")) ; DOT
(define WALL (rectangle CELL-SIZE CELL-SIZE "solid" "blue")) ; Wall
(define Scene (empty-scene 400 400 "black"))
(define (paintWorld mundo) (place-image (vector*->matrix Initial-Map) 100 100 Scene))
(big-bang 4
;(on-key changePacmanM)
;(on-tick automaticMovePacman 0.2)
(to-draw paintWorld)
(state true)
(name "Pacman - Racket"))
这是问题
初始地图是地图矢量。 我怎样才能为大爆炸创造宇宙函数渲染它?
我尝试使用 vector * - >矩阵将矢量转换为矩阵,以便将其传递给place-image
:
(place-image (vector*->matrix Initial-Map) 100 100 Scene)
但是我收到以下错误:
place-image:期望图像作为第一个参数,给定(mutable-array#[#[(object:image%...)(object:image%...)(object:image%...) (object:image%...)(object:image%...)