저는 Perlenspiel을 사용하여 퍼즐 게임을 만들고 Javascript를 Sublime Text와 함께 사용하고 있습니다. 이 게임은 달팽이를 제어하는 플레이어에 관한 것이며 플레이어가 통과 할 수없는 녹색 점액 흔적을 남깁니다. 목표는 흰 점액을 녹색 점액으로 덮는 것입니다. 나는 대부분의 게임을 설정했고 게임을 끝내고 녹색 점액으로 그 지역을 덮은 다음 다음 레벨을 올리는 방법을 알아내는 데 도움이 필요합니다.퍼즐 게임 제작에 도움이 필요합니다.
저는 Javascript와 Perlenspiel을 사용하여 새로운 기능을 제공하며 작동 방법을 잘 모릅니다. 이 많은 이유에 대한 잘못된 접근 인 반면
// Put your global variables after this line
var GRIDWIDTH, GRIDHEIGHT;
GRIDWIDTH = 11;
GRIDHEIGHT = 11;
var player = new Object();
player.x = 0;
player.y = 0;
// Put your function definitions after this line
function drawPlayer(x, y) {
PS.color(x, y, PS.COLOR_GREEN);
PS.glyphColor(x, y, PS.COLOR_WHITE);
PS.glyph(x, y, "ඬ");
player.x = x;
player.y = y;
}
function drawSlime(x, y, dir) {
PS.color(x, y, PS.COLOR_GREEN);
PS.data(x, y, dir);
PS.data(x, y, "wall")
}
function removePlayer(x, y) {
PS.glyph(x, y, 0);
}
function isInGrid(x, y) {
if (x < 0) return false;
else if (x >= GRIDWIDTH) return false;
else if (y < 0) return false;
else if (y >= GRIDHEIGHT) return false;
else return true;
}
// PS.init(system, options)
// Initializes the game
PS.init = function(system, options) {
"use strict";
// Use PS.gridSize(x, y) to set the grid to
// the initial dimensions you want (32 x 32 maximum)
// Do this FIRST to avoid problems!
// Otherwise you will get the default 8x8 grid
PS.gridSize(GRIDWIDTH, GRIDHEIGHT); // replace with your own x/y values
// Add any other initialization code you need here
PS.statusText("Move:WASD Shoot:Arrow Keys")
// Walls that The Snail can't pass through
PS.color(7, 1, PS.COLOR_BLACK);
PS.data(7, 1, "wall");
PS.color(9, 1, PS.COLOR_BLACK);
PS.data(9, 1, "wall");
PS.color(10, 0, PS.COLOR_BLACK);
PS.data(10, 0, "wall");
PS.color(10, 10, PS.COLOR_BLACK);
PS.data(10, 10, "wall");
PS.color(8, 10, PS.COLOR_BLACK);
PS.data(8, 10, "wall");
PS.color(5, 4, PS.COLOR_BLACK);
PS.data(5, 4, "wall");
PS.color(10, 8, PS.COLOR_BLACK);
PS.data(10, 8, "wall");
PS.color(8, 8, PS.COLOR_BLACK);
PS.data(8, 8, "wall");
PS.color(0, 2, PS.COLOR_BLACK);
PS.data(0, 2, "wall");
PS.color(2, 3, PS.COLOR_BLACK);
PS.data(2, 3, "wall");
PS.color(2, 2, PS.COLOR_BLACK);
PS.data(2, 2, "wall");
PS.color(1, 0, PS.COLOR_BLACK);
PS.data(1, 0, "wall");
PS.color(0, 0, PS.COLOR_BLACK);
PS.data(0, 0, "wall");
PS.color(4, 4, PS.COLOR_BLACK);
PS.data(4, 4, "wall");
PS.color(4, 5, PS.COLOR_BLACK);
PS.data(4, 5, "wall");
PS.color(5, 5, PS.COLOR_BLACK);
PS.data(5, 5, "wall");
PS.color(10, 3, PS.COLOR_BLACK);
PS.data(10, 3, "wall");
PS.color(10, 5, PS.COLOR_BLACK);
PS.data(10, 5, "wall");
PS.color(4, 0, PS.COLOR_BLACK);
PS.data(4, 0, "wall");
PS.color(8, 5, PS.COLOR_BLACK);
PS.data(8, 5, "wall");
PS.color(3, 7, PS.COLOR_BLACK);
PS.data(3, 7, "wall");
PS.color(1, 9, PS.COLOR_BLACK);
PS.data(1, 9, "wall");
PS.color(4, 10, PS.COLOR_BLACK);
PS.data(4, 10, "wall");
PS.color(0, 5, PS.COLOR_BLACK);
PS.data(0, 5, "wall");
PS.color(1, 7, PS.COLOR_BLACK);
PS.data(1, 7, "wall");
PS.color(6, 7, PS.COLOR_BLACK);
PS.data(6, 7, "wall");
PS.color(6, 9, PS.COLOR_BLACK);
PS.data(6, 9, "wall");
// display The Snail's location
drawPlayer(5, 0);
PS.data(5, 0, "wall");
};
// PS.touch (x, y, data, options)
// Called when the mouse button is clicked on a bead, or when a bead is touched
PS.touch = function(x, y, data, options) {
"use strict";
// Uncomment the following line to inspect parameters
//PS.debug("PS.touch() @ " + x + ", " + y + "\n");
// Add code here for mouse clicks/touches over a bead
};
// PS.release (x, y, data, options)
// Called when the mouse button is released over a bead, or when a touch is lifted off a bead
PS.release = function(x, y, data, options) {
"use strict";
// Uncomment the following line to inspect parameters
// PS.debug("PS.release() @ " + x + ", " + y + "\n");
// Add code here for when the mouse button/touch is released over a bead
//PS.color(x, y, PS.COLOR_GREEN);
//PS.debug("You clicked on " + x + ", " + y + "\n");
};
// PS.enter (x, y, button, data, options)
// Called when the mouse/touch enters a bead
PS.enter = function(x, y, data, options) {
"use strict";
// Uncomment the following line to inspect parameters
// PS.debug("PS.enter() @ " + x + ", " + y + "\n");
// Add code here for when the mouse cursor/touch enters a bead
};
// PS.exit (x, y, data, options)
// Called when the mouse cursor/touch exits a bead
PS.exit = function(x, y, data, options) {
"use strict";
// Uncomment the following line to inspect parameters
// PS.debug("PS.exit() @ " + x + ", " + y + "\n");
// Add code here for when the mouse cursor/touch exits a bead
};
// PS.exitGrid (options)
// Called when the mouse cursor/touch exits the grid perimeter
PS.exitGrid = function(options) {
"use strict";
// Uncomment the following line to verify operation
// PS.debug("PS.exitGrid() called\n");
// Add code here for when the mouse cursor/touch moves off the grid
};
// PS.keyDown (key, shift, ctrl, options)
// Called when a key on the keyboard is pressed
PS.keyDown = function(key, shift, ctrl, options) {
"use strict";
// Uncomment the following line to inspect parameters
// PS.debug("PS.keyDown(): key = " + key + ", shift = " + shift + ", ctrl = " + ctrl + "\n");
// Add code here for when a key is pressed
// WASD keys to move The Snail
if (key == 119) {
//Check that up isn’t a wall
//Check that up isn’t off the screen
if (player.y - 1 >= 0) {
if (PS.data(player.x, player.y - 1) != "wall") {
//If both are true, remove player from current position
//If both are true, draw player in new position
removePlayer(player.x, player.y);
drawPlayer(player.x, player.y - 1);
drawSlime(player.x, player.y);
}
}
}
if (key == 115) {
//Check that down isn’t a wall
//Check that down isn’t off the screen
if (player.y + 1 < GRIDHEIGHT) {
if (PS.data(player.x, player.y + 1) != "wall") {
//If both are true, remove player from current position
//If both are true, draw player in new position
removePlayer(player.x, player.y);
drawPlayer(player.x, player.y + 1);
drawSlime(player.x, player.y);
}
}
}
if (key == 97) {
//Check that left isn’t a wall
//Check that left isn’t off the screen
if (player.x - 1 >= 0) {
if (PS.data(player.x - 1, player.y) != "wall") {
//If both are true, remove player from current position
//If both are true, draw player in new position
removePlayer(player.x, player.y);
drawPlayer(player.x - 1, player.y);
drawSlime(player.x, player.y);
}
}
}
if (key == 100) {
//Check that left isn’t a wall
//Check that left isn’t off the screen
if (player.x + 1 < GRIDWIDTH) {
if (PS.data(player.x + 1, player.y) != "wall") {
//If both are true, remove player from current position
//If both are true, draw player in new position
removePlayer(player.x, player.y);
drawPlayer(player.x + 1, player.y);
drawSlime(player.x, player.y);
}
}
}
// Keys to shoot the slime from the snail
if (key == PS.KEY_ARROW_UP) // shoot up
{
if (isInGrid(player.x, player.y - 1)) drawSlime(player.x, player.y - 1, "up");
}
if (key == PS.KEY_ARROW_LEFT) // shoot left
{
if (isInGrid(player.x - 1, player.y)) drawSlime(player.x - 1, player.y, "left");
}
if (key == PS.KEY_ARROW_DOWN) // shoot down
{
if (isInGrid(player.x, player.y + 1)) drawSlime(player.x, player.y + 1, "down");
}
if (key == PS.KEY_ARROW_RIGHT) // shoot right
{
if (isInGrid(player.x + 1, player.y)) drawSlime(player.x + 1, player.y, "right");
}
};
// PS.keyUp (key, shift, ctrl, options)
// Called when a key on the keyboard is released
PS.keyUp = function(key, shift, ctrl, options) {
"use strict";
// Uncomment the following line to inspect parameters
// PS.debug("PS.keyUp(): key = " + key + ", shift = " + shift + ", ctrl = " + ctrl + "\n");
// Add code here for when a key is released
};
// PS.input (sensors, options)
// Called when an input device event (other than mouse/touch/keyboard) is detected
PS.input = function(sensors, options) {
"use strict";
// Uncomment the following block to inspect parameters
/*
PS.debug("PS.input() called\n");
var device = sensors.wheel; // check for scroll wheel
if (device)
{
PS.debug("sensors.wheel = " + device + "\n");
}
*/
// Add code here for when an input event is detected
};
어떤 특정 문제가 발생합니까? 자신의 모델을 기반으로 솔루션을 완성 해달라고 요청하는 것은 충분한 조언을주지 않는 한 공정하게 들리지 않습니다. –