Permalink
Browse files

Working on Sprite movement.

  • Loading branch information...
1 parent 14cae87 commit e07a2ee288d945015f0d038f68554f139fd4cc19 Matthew Grigajtis committed Dec 24, 2011
Showing with 43 additions and 12 deletions.
  1. +43 −12 Malibu.js
View
@@ -1,30 +1,29 @@
// default function for the Malibu Game Engine
function Malibu(GameName) {
- // each game has a name
+ // Each game has a name
this.GameName = GameName;
- // each game has sprites (an array of sprites)
+ // Each game has sprites (an array of sprites)
this.Sprites = [];
}
-// create the width and height of the game field
+// Create the width and height of the game field
Malibu.prototype.CreateGameField = function (GameField, width, height) {
this.GameField = GameField;
this.GameField.width = width;
this.GameField.height = height;
+ this.GameField.Context = this.GameField.getContext("2d");
};
-// set the background color for the game field
+// Set the background color for the game field
Malibu.prototype.SetGameFieldColor = function (x, y, z) {
- var context = this.GameField.getContext("2d");
-
// set the background color
var color = "rgb(" + x + "," + y + "," + z + ")";
- context.fillStyle = color;
- context.fillRect(0, 0, this.GameField.width, this.GameField.height);
+ this.GameField.Context.fillStyle = color;
+ this.GameField.Context.fillRect(0, 0, this.GameField.width, this.GameField.height);
};
-// creates a sprite and adds it to the Sprite array
+// Creates a sprite and adds it to the Sprite array
// the developer should never access the Sprite Class directly. This should
// all be done through the game engine class
Malibu.prototype.CreateSprite = function (SpriteName, SpriteImage, width, height, x, y) {
@@ -34,6 +33,31 @@ Malibu.prototype.CreateSprite = function (SpriteName, SpriteImage, width, height
this.Sprites.push(sprite);
};
+// Moves a sprite to the specified x y coordinate
+Malibu.prototype.MoveSpriteRight = function (SpriteNumber, x) {
+ this.Sprites[SpriteNumber].MoveSpriteRight(this.GameField, x);
+};
+
+// Set the sprite state
+Malibu.prototype.SetSpriteState = function (SpriteNumber, SpriteState) {
+ this.Sprites[SpriteNumber].SpriteState = SpriteState;
+};
+
+// Get the sprite state
+Malibu.prototype.GetSpriteState = function (SpriteNumber) {
+ return this.Sprites[SpriteNumber].SpriteState;
+};
+
+// Get the current X coordinate
+Malibu.prototype.GetSpriteX = function (SpriteNumber) {
+ return this.Sprites[SpriteNumber].x;
+};
+
+// Get the current Y coordinate
+Malibu.prototype.GetSpriteY = function (SpriteNumber) {
+ return this.Sprites[SpriteNumber].y;
+};
+
// default function for the sprite object
function Sprite(SpriteName, width, height, x, y) {
// each sprite has a name
@@ -61,7 +85,14 @@ Sprite.prototype.SetImage = function (ImageFile) {
// function to draw the sprite in a stationary location
Sprite.prototype.DrawSprite = function (GameField) {
- var context = GameField.getContext("2d");
- context.drawImage(this.SpriteImage, this.x, this.y);
- context.stroke();
+ GameField.Context.beginPath();
+ GameField.Context.drawImage(this.SpriteImage, this.x, this.y);
+ GameField.Context.closePath();
+};
+
+Sprite.prototype.MoveSpriteRight = function (GameField, x) {
+ for (i=0; i<x; i++) {
+ this.x = this.x + 1;
+ this.DrawSprite(GameField);
+ }
};

0 comments on commit e07a2ee

Please sign in to comment.