0% found this document useful (0 votes)
22 views11 pages

Pacman Game Sound Management Code

Uploaded by

mrhattrick061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Pacman Game Sound Management Code

Uploaded by

mrhattrick061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class StandardOutput {

void print(object message) {


__context.log(message);
}

void println(object message) {


message = message + "\n";
[Link](message);
}
}

class System {
static StandardOutput out = new StandardOutput();
}

class Sounds {
static Sounds _instance;
static Sounds instance() {
if (Sounds._instance == null) {
Sounds._instance = new Sounds();
}
return Sounds._instance;
}
Sound pacmanDeath = __context.sound("/themes/default/sounds/pacman_death.wav");
Sound eatGhost =
__context.sound("/themes/default/sounds/pacman_eat_ghost.wav");
Sound eatPellet =
__context.sound("/themes/default/sounds/pacman_eat_pellet.wav");
Sound intro =
__context.sound("[Link]
mario_sounds/Super_Mario_Bros_melody.wav");
Sound collectLeaf =
__context.sound("[Link]
mario_sounds/[Link]");
Sound jump =
__context.sound("[Link]
mario_sounds/[Link]");
Sound shot =
__context.sound("[Link]
mario_sounds/[Link]");
Sound levelFinished =
__context.sound("[Link]
mario_sounds/Level_finished.wav");
Sound gameOver =
__context.sound("[Link]
mario_sounds/[Link]");

class Character {
static boolean isGhostScared = false;
static BoardTile healer;
static boolean isIntroStarted = false;
static boolean isLevelFinishedSoundStarted = false;

Board _board;
BoardTile _player;
ContextPlayer _clara;
String[] _inputs;
String _debugName;
int inputIndex;

private boolean isRemoved = false;

void playCollectLeafSound() {
[Link]().[Link]();
}

void playJumpSound() {
[Link]().[Link]();
}

void playShotSound() {
[Link]().[Link]();
}

void playLevelFinishedSound() {
isLevelFinishedSoundStarted = true;
[Link]().[Link]();
}

void playGameOverSound() {
[Link]().[Link]();
}

void turnLeft() {
this._board.rotateLeft(this._player);
}

void turnRight() {
this._board.rotateRight(this._player);
}

void putLeaf() {
this._board.step();
if (this._board.getSprite(this._player.row, this._player.column) == null) {
this._board.addTileAt(this._player.row, this._player.column,
[Link]());
} else {
//throw new Error("You cannot put leaf here!");
}
return __db.wait();
}

void putDot() {
this._board.step();
if (this._board.getSprite(this._player.row, this._player.column) == null) {
this._board.addTileAt(this._player.row, this._player.column,
[Link]());
} else {
throw new Error("You cannot put a dot here!");
}
return __db.wait();
}

void removeDot() {
this._board.step();
BoardTile dot = this._board.getSprite(this._player.row,
this._player.column);
if (dot != null && [Link] == [Link]) {
this._board.removeTile(dot);
} else {
throw new Error("There is no dot to remove!");
}
return __db.wait();
}

void removeLeaf() {
this._board.step();
BoardTile leaf = this._board.getSprite(this._player.row,
this._player.column);
if (leaf != null && [Link] == [Link]) {
this._board.removeTile(leaf);
} else {
throw new Error("There is no leaf to remove!");
}
return __db.wait();
}

private void changeDeadFlag(boolean inDead)


{
// mark the tile as "dead"
for (int i = 0; i < __context.[Link]; i++)
{
ContextPlayer currentPlayer = __context.players[i];

if ([Link] == this._player)
[Link]._isDead = inDead;
}
}

boolean mushroomFront() {
return this._board.isFront(this._player, [Link]());
}

boolean treeLeft() {
return this._board.isLeft(this._player, [Link]());
}

boolean treeRight() {
return this._board.isRight(this._player, [Link]());
}

private boolean earthLeft() {


return this._board.isLeft(this._player, [Link]());
}

private boolean earthRight() {


return this._board.isRight(this._player, [Link]());
}

boolean onLeaf() {
return this._board.isOnTile(this._player, [Link]());
}

boolean onTree() {
return this._board.isOnTile(this._player, [Link]());
}

boolean onEarth() {
return this._board.isOnTile(this._player, [Link]());
}

Tile getTileByName(String name) {


try {
return this._board.getTileByName(name);
} catch (Exception ex) {
return this._board.[Link](name);
}
}

// helper methods
static String LeafTileName = "Leaf";
Tile _leafTile;
Tile getLeafTile() {
if (this._leafTile == null) {
this._leafTile = [Link]([Link]);
}
return this._leafTile;
}

// helper methods
static String DotTileName = "Dot";
Tile _dotTile;
Tile getDotTile() {
if (this._dotTile == null) {
this._dotTile = [Link]([Link]);
}
return this._dotTile;
}

static String TreeTileName = "Tree";


Tile _treeTile;
Tile getTreeTile() {
if (this._treeTile == null) {
this._treeTile = [Link]([Link]);
}
return this._treeTile;
}

static String EarthTileName = "Earth";


Tile _earthTile;
Tile getEarthTile() {
if (this._earthTile == null) {
this._earthTile = [Link]([Link]);
}
return this._earthTile;
}

static String MushroomTileName = "Mushroom";


Tile _mushroomTile;
Tile getMushroomTile() {
if (this._mushroomTile == null) {
this._mushroomTile = [Link]([Link]);
}
return this._mushroomTile;
}

// specific pacman code


void move(int pixels) {
if (pixels == 0) {
throw new Error("Cannot move! Please specify speed!");
}
this._board.moveByPixels(this._player, pixels);
}

boolean onMushroom() {
return this._board.isOnTile(this._player, [Link]());
}

boolean earthFront() {
try {
boolean isFront = this._board.isFront(this._player,
[Link]());
if (isFront) {
float width = this._player.[Link];
float tileSize = this._board.tileSize;
float margin = (this._board.tileSize - width) / 2;
int column = this._player.column;
int row = this._player.row;

// has to be almost in the middle


switch (this._player.direction) {
case 0:
if ([Link](this._player.[Link]) > [Link](row
* tileSize + margin)) {
return false;
}
break;
case 1:
if ([Link](this._player.[Link] + width) <
[Link]((column + 1) * tileSize - margin)) {
return false;
}
break;
case 2:
if ([Link](this._player.[Link] + width) <
[Link]((row + 1) * tileSize - margin)) {
return false;
}
break;
case 3:
if ([Link](this._player.[Link]) >
[Link](column * tileSize + margin)) {
return false;
}
break;
}

// if there is no obstacle and we are changing direction accross


axes, we first center the tile
try {
this._player.moveTo((int) (column * tileSize + margin), (int)
(row * tileSize + margin));
} catch (Exception ex) {
this._player.[Link](column * tileSize + margin, row *
tileSize + margin);
}

return true;
//[Link](this.__player.prop.x() + ' ' +
this.__player.prop.y());
//[Link](this.__player.[Link]() / 0.8);
}
} catch (Exception ex) {
// do nothing
}
return false;
}

boolean treeFront() {
try {
boolean isFront = this._board.isFront(this._player,
[Link]());
if (isFront) {
float width = this._player.[Link];
float tileSize = this._board.tileSize;
float margin = (this._board.tileSize - width) / 2;
int column = this._player.column;
int row = this._player.row;

// has to be almost in the middle


switch (this._player.direction) {
case 0:
if ([Link](this._player.[Link]) > [Link](row
* tileSize + margin)) {
return false;
}
break;
case 1:

if ([Link](this._player.[Link] + width) <


[Link]((column + 1) * tileSize - margin)) {
return false;
}
break;
case 2:
if ([Link](this._player.[Link] + width) <
[Link]((row + 1) * tileSize - margin)) {
return false;
}
break;
case 3:
if ([Link](this._player.[Link]) >
[Link](column * tileSize + margin)) {
return false;
}
break;
}

// if there is no obstacle and we are changing direction accross


axes, we first center the tile
try {
this._player.moveTo((int) (column * tileSize + margin), (int)
(row * tileSize + margin));
} catch (Exception ex) {
this._player.[Link](column * tileSize + margin, row *
tileSize + margin);
}

return true;
//[Link](this.__player.prop.x() + ' ' +
this.__player.prop.y());
//[Link](this.__player.[Link]() / 0.8);
}
} catch (Exception ex) {
// do nothing
}
return false;
}

String getDirection() {
return _board.getDirection(this._player.direction);
}

void setDirection(String direction) {


switch (direction) {
case "up":
this._board.setDirection(this._player, 0, true);
break;
case "down":
this._board.setDirection(this._player, 2, true);
break;
case "left":
this._board.setDirection(this._player, 3, true);
break;
case "right":
this._board.setDirection(this._player, 1, true);
break;
}
}

boolean isIntroStillPlaying() {
if (!isIntroStarted)
return false;

return ![Link]().[Link]();
}

boolean isLevelFinishedSoundStillPlaying() {
if (!isLevelFinishedSoundStarted)
return false;

return ![Link]().[Link]();
}

void wrapAroundWorld() {
int row = this._player.row;
int column = this._player.column;

int wrappedRow = this._board.wrapRow(row);


int wrappedColumn = this._board.wrapColumn(column);
if (row != wrappedRow || column != wrappedColumn) {
this._board.moveTo(this._player, wrappedRow, wrappedColumn);
}
}

@Async
void act() {}

@Async
void waitAsync() {
return __db.waitTime(1000 / 30);
}

@Async
void actAsync() {
return [Link]();
}

@Async
void runAsync() {
// init keyboard
[Link]();

// notify board
while (__context.isRunning) {
// calls method "act" on this
// __context.paintFrameAsync(this, 1000 / 30);
[Link]();
[Link]();
}
}

boolean treeAbove() {
return [Link](0);
}

boolean earthAbove() {
return [Link](0);
}

boolean treeBelow() {
return [Link](2);
}

boolean earthBelow() {
return [Link](2);
}

boolean treeToLeft() {
return [Link](3);
}

boolean earthToLeft() {
return [Link](3);
}

boolean treeToRight() {
return [Link](1);
}

boolean earthToRight() {
return [Link](1);
}

boolean treeAtPosition(int direction) {


int temp = this._player.direction;
this._player.direction = direction;
boolean isTree = this._board.isFront(this._player, [Link]());
this._player.direction = temp;
return isTree;
}

boolean earthAtPosition(int direction) {


int temp = this._player.direction;
this._player.direction = direction;
boolean isEarth = this._board.isFront(this._player, [Link]());
this._player.direction = temp;
return isEarth;
}

boolean isAboveMe(BoardTile who) {


return this._player.row > [Link];
}

boolean isBelowMe(BoardTile who) {


return this._player.row < [Link];
}

boolean isToMyLeft(BoardTile who) {


return this._player.column > [Link];
}

boolean isToMyRight(BoardTile who) {


return this._player.column < [Link];
}

boolean intersects(BoardTile who) {


return this._player.column == [Link] &&
this._player.row == [Link];
}

boolean intersectsWithName(String who)


{
boolean retVal = false;

for (int i = 0; i < __context.[Link]; i++)


{
ContextPlayer foundPlayer = __context.players[i];

// ignore those marked as "dead"


if ([Link]._isDead == true)
continue;

if ( [Link] == who )
{
if (this._player.column == [Link] &&
this._player.row == [Link])
retVal = true;
}
}

return retVal;

void animate() {
this._board.animate(this._player, "normal");
}

void animateDead() {
this._board.animate(this._player, "dead");
}

void animateInvisible() {
this._board.animate(this._player, "invisible");
}

void makeClaraDead() {
this._findClara();
this._clara.instance._isDead = true;
}

void playGhostEatenSound() {
[Link]().[Link]();
}

void _findClara() {
if (this._clara == null) {
for (int i = 0; i < __context.[Link]; i++) {
if (__context.players[i].[Link] == "Player") {
this._clara = __context.players[i];
break;
}
}
}
}

BoardTile getClara() {
this._findClara();
if (this._clara != null) {
return this._clara.tile;
}
else {
[Link]("There is no Clara tile");
}
return null;
}

void moveToClara() {
BoardTile clara = getClara();

this._board.moveTo(this._player, [Link], [Link]);


//this._player.column = [Link];
//this._player.row = [Link];
}
}

You might also like