From 9837c31d1165557867a50bf9cfdbabe434129b73 Mon Sep 17 00:00:00 2001 From: Anneliese Doerfler Date: Sun, 15 Mar 2020 21:07:47 -0700 Subject: [PATCH 1/3] jumping changed from S to Spacebar --- Enjine/keyboardInput.js | 11 ++-- code/character.js | 138 ++++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/Enjine/keyboardInput.js b/Enjine/keyboardInput.js index 8205a53..091b47e 100755 --- a/Enjine/keyboardInput.js +++ b/Enjine/keyboardInput.js @@ -33,29 +33,30 @@ Enjine.Keys = { Left: 37, Up: 38, Right: 39, - Down: 40 + Down: 40, + Spacebar: 32 }; Enjine.KeyboardInput = { Pressed: new Array(), - + Initialize: function() { var self = this; document.onkeydown = function(event) { self.KeyDownEvent(event); } document.onkeyup = function(event) { self.KeyUpEvent(event); } }, - + IsKeyDown: function(key) { if (this.Pressed[key] != null) return this.Pressed[key]; return false; }, - + KeyDownEvent: function(event) { this.Pressed[event.keyCode] = true; this.PreventScrolling(event); }, - + KeyUpEvent: function(event) { this.Pressed[event.keyCode] = false; this.PreventScrolling(event); diff --git a/code/character.js b/code/character.js index 853c771..a156e8e 100755 --- a/code/character.js +++ b/code/character.js @@ -12,7 +12,7 @@ Mario.Character = function() { this.LevelString = "none"; this.GroundInertia = 0.89; this.AirInertia = 0.89; - + //non static variables in Notch's code this.RunTime = 0; this.WasOnGround = false; @@ -24,23 +24,23 @@ Mario.Character = function() { this.XJumpSpeed = 0; this.YJumpSpeed = 0; this.CanShoot = false; - + this.Width = 4; this.Height = 24; - + //Level scene this.World = null; this.Facing = 0; this.PowerUpTime = 0; - + this.XDeathPos = 0; this.YDeathPos = 0; this.DeathTime = 0; this.WinTime = 0; this.InvulnerableTime = 0; - + //Sprite this.Carried = null; - + this.LastLarge = false; this.LastFire = false; this.NewLarge = false; @@ -54,7 +54,7 @@ Mario.Character.prototype.Initialize = function(world) { this.X = 32; this.Y = 0; this.PowerUpTime = 0; - + //non static variables in Notch's code this.RunTime = 0; this.WasOnGround = false; @@ -66,23 +66,23 @@ Mario.Character.prototype.Initialize = function(world) { this.XJumpSpeed = 0; this.YJumpSpeed = 0; this.CanShoot = false; - + this.Width = 4; this.Height = 24; - + //Level scene this.World = world; this.Facing = 0; this.PowerUpTime = 0; - + this.XDeathPos = 0; this.YDeathPos = 0; this.DeathTime = 0; this.WinTime = 0; this.InvulnerableTime = 0; - + //Sprite this.Carried = null; - + this.SetLarge(this.Large, this.Fire); }; @@ -93,28 +93,28 @@ Mario.Character.prototype.SetLarge = function(large, fire) { if (!large) { fire = false; } - + this.LastLarge = this.Large; this.LastFire = this.Fire; this.Large = large; this.Fire = fire; this.NewLarge = this.Large; this.NewFire = this.Fire; - + this.Blink(true); }; Mario.Character.prototype.Blink = function(on) { this.Large = on ? this.NewLarge : this.LastLarge; this.Fire = on ? this.NewFire : this.LastFire; - + if (this.Large) { if (this.Fire) { this.Image = Enjine.Resources.Images["fireMario"]; } else { this.Image = Enjine.Resources.Images["mario"]; } - + this.XPicO = 16; this.YPicO = 31; this.PicWidth = this.PicHeight = 32; @@ -133,7 +133,7 @@ Mario.Character.prototype.Move = function() { this.Ya = 0; return; } - + if (this.DeathTime > 0) { this.DeathTime++; if (this.DeathTime < 11) { @@ -148,7 +148,7 @@ Mario.Character.prototype.Move = function() { this.Y += this.Ya; return; } - + if (this.PowerUpTime !== 0) { if (this.PowerUpTime > 0) { this.PowerUpTime--; @@ -157,24 +157,24 @@ Mario.Character.prototype.Move = function() { this.PowerUpTime++; this.Blink((((-this.PowerUpTime / 3) | 0) & 1) === 0); } - + if (this.PowerUpTime === 0) { this.World.Paused = false; } - + this.CalcPic(); return; } - + if (this.InvulnerableTime > 0) { this.InvulnerableTime--; } - + this.Visible = (((this.InvulerableTime / 2) | 0) & 1) === 0; - + this.WasOnGround = this.OnGround; var sideWaysSpeed = Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A) ? 1.2 : 0.6; - + if (this.OnGround) { if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Down) && this.Large) { this.Ducking = true; @@ -182,15 +182,15 @@ Mario.Character.prototype.Move = function() { this.Ducking = false; } } - + if (this.Xa > 2) { this.Facing = 1; } if (this.Xa < -2) { this.Facing = -1; } - - if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S) || (this.JumpTime < 0 && !this.OnGround && !this.Sliding)) { + + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Spacebar) || (this.JumpTime < 0 && !this.OnGround && !this.Sliding)) { if (this.JumpTime < 0) { this.Xa = this.XJumpSpeed; this.Ya = -this.JumpTime * this.YJumpSpeed; @@ -221,7 +221,7 @@ Mario.Character.prototype.Move = function() { } else { this.JumpTime = 0; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Left) && !this.Ducking) { if (this.Facing === 1) { this.Sliding = false; @@ -231,7 +231,7 @@ Mario.Character.prototype.Move = function() { this.Facing = -1; } } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Right) && !this.Ducking) { if (this.Facing === -1) { this.Sliding = false; @@ -241,66 +241,66 @@ Mario.Character.prototype.Move = function() { this.Facing = 1; } } - + if ((!Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Left) && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Right)) || this.Ducking || this.Ya < 0 || this.OnGround) { - this.Sliding = false; + this.Sliding = false; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A) && this.CanShoot && this.Fire && this.World.FireballsOnScreen < 2) { Enjine.Resources.PlaySound("fireball"); this.World.AddSprite(new Mario.Fireball(this.World, this.X + this.Facing * 6, this.Y - 20, this.Facing)); } - + this.CanShoot = !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A); - this.MayJump = (this.OnGround || this.Sliding) && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S); + this.MayJump = (this.OnGround || this.Sliding) && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Spacebar); this.XFlip = (this.Facing === -1); this.RunTime += Math.abs(this.Xa) + 5; - + if (Math.abs(this.Xa) < 0.5) { this.RunTime = 0; this.Xa = 0; } - + this.CalcPic(); - + if (this.Sliding) { this.World.AddSprite(new Mario.Sparkle(this.World, ((this.X + Math.random() * 4 - 2) | 0) + this.Facing * 8, ((this.Y + Math.random() * 4) | 0) - 24, Math.random() * 2 - 1, Math.random(), 0, 1, 5)); this.Ya *= 0.5; } - + this.OnGround = false; this.SubMove(this.Xa, 0); this.SubMove(0, this.Ya); if (this.Y > this.World.Level.Height * 16 + 16) { this.Die(); } - + if (this.X < 0) { this.X = 0; this.Xa = 0; } - + if (this.X > this.World.Level.ExitX * 16) { this.Win(); } - + if (this.X > this.World.Level.Width * 16) { this.X = this.World.Level.Width * 16; this.Xa = 0; } - + this.Ya *= 0.85; if (this.OnGround) { this.Xa *= this.GroundInertia; } else { this.Xa *= this.AirInertia; } - + if (!this.OnGround) { this.Ya += 3; } - + if (this.Carried !== null) { this.Carried.X *= this.X + this.Facing * 8; this.Carried.Y *= this.Y - 2; @@ -313,7 +313,7 @@ Mario.Character.prototype.Move = function() { Mario.Character.prototype.CalcPic = function() { var runFrame = 0, i = 0; - + if (this.Large) { runFrame = ((this.RunTime / 20) | 0) % 4; if (runFrame === 3) { @@ -352,19 +352,19 @@ Mario.Character.prototype.CalcPic = function() { } } } - + if (this.OnGround && ((this.Facing === -1 && this.Xa > 0) || (this.Facing === 1 && this.Xa < 0))) { if (this.Xa > 1 || this.Xa < -1) { runFrame = this.Large ? 9 : 7; } - + if (this.Xa > 3 || this.Xa < -3) { for (i = 0; i < 3; i++) { this.World.AddSprite(new Mario.Sparkle(this.World, (this.X + Math.random() * 8 - 4) | 0, (this.Y + Math.random() * 4) | 0, Math.random() * 2 - 1, Math.random() * -1, 0, 1, 5)); } } } - + if (this.Large) { if (this.Ducking) { runFrame = 14; @@ -373,13 +373,13 @@ Mario.Character.prototype.CalcPic = function() { } else { this.Height = 12; } - + this.XPic = runFrame; }; Mario.Character.prototype.SubMove = function(xa, ya) { var collide = false; - + while (xa > 8) { if (!this.SubMove(8, 0)) { return false; @@ -404,7 +404,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } ya += 8; } - + if (ya > 0) { if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, 0)) { collide = true; @@ -425,7 +425,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { collide = true; } } - + if (xa > 0) { this.Sliding = true; if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya - this.Height, xa, ya)) { @@ -433,13 +433,13 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya - ((this.Height / 2) | 0), xa, ya)) { collide = true; } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya, xa, ya)) { collide = true; } else { @@ -453,20 +453,20 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya - ((this.Height / 2) | 0), xa, ya)) { collide = true; } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, ya)) { collide = true; } else { this.Sliding = false; } } - + if (collide) { if (xa < 0) { this.X = (((this.X - this.Width) / 16) | 0) * 16 + this.Width; @@ -485,7 +485,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { this.Y = (((this.Y - 1) / 16 + 1) | 0) * 16 - 1; this.OnGround = true; } - + return false; } else { this.X += xa; @@ -496,15 +496,15 @@ Mario.Character.prototype.SubMove = function(xa, ya) { Mario.Character.prototype.IsBlocking = function(x, y, xa, ya) { var blocking = false, block = 0, xx = 0, yy = 0; - + x = (x / 16) | 0; y = (y / 16) | 0; if (x === ((this.X / 16) | 0) && y === ((this.Y / 16) | 0)) { return false; } - + block = this.World.Level.GetBlock(x, y); - + if (((Mario.Tile.Behaviors[block & 0xff]) & Mario.Tile.PickUpable) > 0) { this.GetCoin(); Enjine.Resources.PlaySound("coin"); @@ -515,7 +515,7 @@ Mario.Character.prototype.IsBlocking = function(x, y, xa, ya) { } } } - + blocking = this.World.Level.IsBlocking(x, y, xa, ya); if (blocking && ya < 0) { this.World.Bump(x, y, this.Large); @@ -529,12 +529,12 @@ Mario.Character.prototype.Stomp = function(object) { if (this.DeathTime > 0 || this.World.Paused) { return; } - + targetY = object.Y - object.Height / 2; this.SubMove(0, targetY - this.Y); - + if (object instanceof Mario.Enemy || object instanceof Mario.BulletBill) { - + Enjine.Resources.PlaySound("kick"); this.XJumpSpeed = 0; this.YJumpSpeed = -1.9; @@ -567,7 +567,7 @@ Mario.Character.prototype.GetHurt = function() { if (this.InvulnerableTime > 0) { return; } - + if (this.Large) { this.World.Paused = true; this.PowerUpTime = -18; @@ -604,7 +604,7 @@ Mario.Character.prototype.GetFlower = function() { if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (!this.Fire) { this.World.Paused = true; this.PowerUpTime = 18; @@ -620,7 +620,7 @@ Mario.Character.prototype.GetMushroom = function() { if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (!this.Large) { this.World.Paused = true; this.PowerUpTime = 18; @@ -636,7 +636,7 @@ Mario.Character.prototype.Kick = function(shell) { if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A)) { this.Carried = shell; shell.Carried = true; From 41a4cd232ce3b7d67a1e0862236dcc1c7b7adc23 Mon Sep 17 00:00:00 2001 From: Isaac Martin Date: Mon, 16 Mar 2020 13:25:47 -0700 Subject: [PATCH 2/3] Limited the height difference between platforms to be 4, which is mario's jump height --- code/levelGenerator.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/levelGenerator.js b/code/levelGenerator.js index 38dbaf4..b749fa5 100755 --- a/code/levelGenerator.js +++ b/code/levelGenerator.js @@ -161,7 +161,7 @@ Mario.LevelGenerator.prototype = { return length; }, - BuildHillStraight: function(level, xo, maxLength) { + BuildHillStraight: function (level, xo, maxLength) { var length = ((Math.random() * 10) | 0) + 10, floor = this.Height - 1 - (Math.random() * 4) | 0, x = 0, y = 0, h = floor, keepGoing = true, l = 0, xxo = 0, occupied = [], xx = 0, yy = 0; @@ -181,6 +181,9 @@ Mario.LevelGenerator.prototype = { while (keepGoing) { h = h - 2 - (Math.random() * 3) | 0; + if (h < 4) { + h = 7; + } if (h <= 0) { keepGoing = false; } else { From bc285ceb186570bb2531fffbba66aa43714ca043 Mon Sep 17 00:00:00 2001 From: dharma-prime <59862800+dharma-prime@users.noreply.github.com> Date: Mon, 16 Mar 2020 16:33:33 -0700 Subject: [PATCH 3/3] Score/Point Implementation Adds running point total to levels. Points can be earned by: - Stomping enemies - Stomping shells - Collecting coins - Finishing a level with remaining time - Getting powerups - Getting 1-ups Points are lost when the player dies. --- code/character.js | 158 +++++++++++++++++++++++++-------------------- code/enemy.js | 95 +++++++++++++-------------- code/levelState.js | 2 +- 3 files changed, 136 insertions(+), 119 deletions(-) diff --git a/code/character.js b/code/character.js index 853c771..26f1a62 100755 --- a/code/character.js +++ b/code/character.js @@ -9,10 +9,11 @@ Mario.Character = function() { this.Fire = false; this.Coins = 0; this.Lives = 3; + this.Score = 0; this.LevelString = "none"; this.GroundInertia = 0.89; this.AirInertia = 0.89; - + //non static variables in Notch's code this.RunTime = 0; this.WasOnGround = false; @@ -24,23 +25,23 @@ Mario.Character = function() { this.XJumpSpeed = 0; this.YJumpSpeed = 0; this.CanShoot = false; - + this.Width = 4; this.Height = 24; - + //Level scene this.World = null; this.Facing = 0; this.PowerUpTime = 0; - + this.XDeathPos = 0; this.YDeathPos = 0; this.DeathTime = 0; this.WinTime = 0; - this.InvulnerableTime = 0; - + this.nerableTime = 0; + //Sprite this.Carried = null; - + this.LastLarge = false; this.LastFire = false; this.NewLarge = false; @@ -54,7 +55,7 @@ Mario.Character.prototype.Initialize = function(world) { this.X = 32; this.Y = 0; this.PowerUpTime = 0; - + //non static variables in Notch's code this.RunTime = 0; this.WasOnGround = false; @@ -66,23 +67,23 @@ Mario.Character.prototype.Initialize = function(world) { this.XJumpSpeed = 0; this.YJumpSpeed = 0; this.CanShoot = false; - + this.Width = 4; this.Height = 24; - + //Level scene this.World = world; this.Facing = 0; this.PowerUpTime = 0; - + this.XDeathPos = 0; this.YDeathPos = 0; this.DeathTime = 0; this.WinTime = 0; - this.InvulnerableTime = 0; - + this.nerableTime = 0; + //Sprite this.Carried = null; - + this.SetLarge(this.Large, this.Fire); }; @@ -93,28 +94,28 @@ Mario.Character.prototype.SetLarge = function(large, fire) { if (!large) { fire = false; } - + this.LastLarge = this.Large; this.LastFire = this.Fire; this.Large = large; this.Fire = fire; this.NewLarge = this.Large; this.NewFire = this.Fire; - + this.Blink(true); }; Mario.Character.prototype.Blink = function(on) { this.Large = on ? this.NewLarge : this.LastLarge; this.Fire = on ? this.NewFire : this.LastFire; - + if (this.Large) { if (this.Fire) { this.Image = Enjine.Resources.Images["fireMario"]; } else { this.Image = Enjine.Resources.Images["mario"]; } - + this.XPicO = 16; this.YPicO = 31; this.PicWidth = this.PicHeight = 32; @@ -133,7 +134,7 @@ Mario.Character.prototype.Move = function() { this.Ya = 0; return; } - + if (this.DeathTime > 0) { this.DeathTime++; if (this.DeathTime < 11) { @@ -148,7 +149,7 @@ Mario.Character.prototype.Move = function() { this.Y += this.Ya; return; } - + if (this.PowerUpTime !== 0) { if (this.PowerUpTime > 0) { this.PowerUpTime--; @@ -157,24 +158,24 @@ Mario.Character.prototype.Move = function() { this.PowerUpTime++; this.Blink((((-this.PowerUpTime / 3) | 0) & 1) === 0); } - + if (this.PowerUpTime === 0) { this.World.Paused = false; } - + this.CalcPic(); return; } - + if (this.InvulnerableTime > 0) { this.InvulnerableTime--; } - - this.Visible = (((this.InvulerableTime / 2) | 0) & 1) === 0; - + + this.Visible = (((this.InvulnerableTime / 2) | 0) & 1) === 0; + this.WasOnGround = this.OnGround; var sideWaysSpeed = Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A) ? 1.2 : 0.6; - + if (this.OnGround) { if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Down) && this.Large) { this.Ducking = true; @@ -182,14 +183,14 @@ Mario.Character.prototype.Move = function() { this.Ducking = false; } } - + if (this.Xa > 2) { this.Facing = 1; } if (this.Xa < -2) { this.Facing = -1; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S) || (this.JumpTime < 0 && !this.OnGround && !this.Sliding)) { if (this.JumpTime < 0) { this.Xa = this.XJumpSpeed; @@ -221,7 +222,7 @@ Mario.Character.prototype.Move = function() { } else { this.JumpTime = 0; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Left) && !this.Ducking) { if (this.Facing === 1) { this.Sliding = false; @@ -231,7 +232,7 @@ Mario.Character.prototype.Move = function() { this.Facing = -1; } } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Right) && !this.Ducking) { if (this.Facing === -1) { this.Sliding = false; @@ -241,66 +242,66 @@ Mario.Character.prototype.Move = function() { this.Facing = 1; } } - + if ((!Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Left) && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Right)) || this.Ducking || this.Ya < 0 || this.OnGround) { - this.Sliding = false; + this.Sliding = false; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A) && this.CanShoot && this.Fire && this.World.FireballsOnScreen < 2) { Enjine.Resources.PlaySound("fireball"); this.World.AddSprite(new Mario.Fireball(this.World, this.X + this.Facing * 6, this.Y - 20, this.Facing)); } - + this.CanShoot = !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A); this.MayJump = (this.OnGround || this.Sliding) && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S); this.XFlip = (this.Facing === -1); this.RunTime += Math.abs(this.Xa) + 5; - + if (Math.abs(this.Xa) < 0.5) { this.RunTime = 0; this.Xa = 0; } - + this.CalcPic(); - + if (this.Sliding) { this.World.AddSprite(new Mario.Sparkle(this.World, ((this.X + Math.random() * 4 - 2) | 0) + this.Facing * 8, ((this.Y + Math.random() * 4) | 0) - 24, Math.random() * 2 - 1, Math.random(), 0, 1, 5)); this.Ya *= 0.5; } - + this.OnGround = false; this.SubMove(this.Xa, 0); this.SubMove(0, this.Ya); if (this.Y > this.World.Level.Height * 16 + 16) { this.Die(); } - + if (this.X < 0) { this.X = 0; this.Xa = 0; } - + if (this.X > this.World.Level.ExitX * 16) { this.Win(); } - + if (this.X > this.World.Level.Width * 16) { this.X = this.World.Level.Width * 16; this.Xa = 0; } - + this.Ya *= 0.85; if (this.OnGround) { this.Xa *= this.GroundInertia; } else { this.Xa *= this.AirInertia; } - + if (!this.OnGround) { this.Ya += 3; } - + if (this.Carried !== null) { this.Carried.X *= this.X + this.Facing * 8; this.Carried.Y *= this.Y - 2; @@ -313,7 +314,7 @@ Mario.Character.prototype.Move = function() { Mario.Character.prototype.CalcPic = function() { var runFrame = 0, i = 0; - + if (this.Large) { runFrame = ((this.RunTime / 20) | 0) % 4; if (runFrame === 3) { @@ -352,19 +353,19 @@ Mario.Character.prototype.CalcPic = function() { } } } - + if (this.OnGround && ((this.Facing === -1 && this.Xa > 0) || (this.Facing === 1 && this.Xa < 0))) { if (this.Xa > 1 || this.Xa < -1) { runFrame = this.Large ? 9 : 7; } - + if (this.Xa > 3 || this.Xa < -3) { for (i = 0; i < 3; i++) { this.World.AddSprite(new Mario.Sparkle(this.World, (this.X + Math.random() * 8 - 4) | 0, (this.Y + Math.random() * 4) | 0, Math.random() * 2 - 1, Math.random() * -1, 0, 1, 5)); } } } - + if (this.Large) { if (this.Ducking) { runFrame = 14; @@ -373,13 +374,13 @@ Mario.Character.prototype.CalcPic = function() { } else { this.Height = 12; } - + this.XPic = runFrame; }; Mario.Character.prototype.SubMove = function(xa, ya) { var collide = false; - + while (xa > 8) { if (!this.SubMove(8, 0)) { return false; @@ -404,7 +405,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } ya += 8; } - + if (ya > 0) { if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, 0)) { collide = true; @@ -425,7 +426,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { collide = true; } } - + if (xa > 0) { this.Sliding = true; if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya - this.Height, xa, ya)) { @@ -433,13 +434,13 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya - ((this.Height / 2) | 0), xa, ya)) { collide = true; } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya, xa, ya)) { collide = true; } else { @@ -453,20 +454,20 @@ Mario.Character.prototype.SubMove = function(xa, ya) { } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya - ((this.Height / 2) | 0), xa, ya)) { collide = true; } else { this.Sliding = false; } - + if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, ya)) { collide = true; } else { this.Sliding = false; } } - + if (collide) { if (xa < 0) { this.X = (((this.X - this.Width) / 16) | 0) * 16 + this.Width; @@ -485,7 +486,7 @@ Mario.Character.prototype.SubMove = function(xa, ya) { this.Y = (((this.Y - 1) / 16 + 1) | 0) * 16 - 1; this.OnGround = true; } - + return false; } else { this.X += xa; @@ -496,15 +497,15 @@ Mario.Character.prototype.SubMove = function(xa, ya) { Mario.Character.prototype.IsBlocking = function(x, y, xa, ya) { var blocking = false, block = 0, xx = 0, yy = 0; - + x = (x / 16) | 0; y = (y / 16) | 0; if (x === ((this.X / 16) | 0) && y === ((this.Y / 16) | 0)) { return false; } - + block = this.World.Level.GetBlock(x, y); - + if (((Mario.Tile.Behaviors[block & 0xff]) & Mario.Tile.PickUpable) > 0) { this.GetCoin(); Enjine.Resources.PlaySound("coin"); @@ -515,7 +516,7 @@ Mario.Character.prototype.IsBlocking = function(x, y, xa, ya) { } } } - + blocking = this.World.Level.IsBlocking(x, y, xa, ya); if (blocking && ya < 0) { this.World.Bump(x, y, this.Large); @@ -525,16 +526,17 @@ Mario.Character.prototype.IsBlocking = function(x, y, xa, ya) { Mario.Character.prototype.Stomp = function(object) { var targetY = 0; + this.Score+=100; if (this.DeathTime > 0 || this.World.Paused) { return; } - + targetY = object.Y - object.Height / 2; this.SubMove(0, targetY - this.Y); - + if (object instanceof Mario.Enemy || object instanceof Mario.BulletBill) { - + Enjine.Resources.PlaySound("kick"); this.XJumpSpeed = 0; this.YJumpSpeed = -1.9; @@ -567,7 +569,7 @@ Mario.Character.prototype.GetHurt = function() { if (this.InvulnerableTime > 0) { return; } - + if (this.Large) { this.World.Paused = true; this.PowerUpTime = -18; @@ -584,6 +586,8 @@ Mario.Character.prototype.GetHurt = function() { }; Mario.Character.prototype.Win = function() { + + this.Score+=this.DeathTime; this.XDeathPos = this.X | 0; this.YDeathPos = this.Y | 0; this.World.Paused = true; @@ -592,6 +596,8 @@ Mario.Character.prototype.Win = function() { }; Mario.Character.prototype.Die = function() { + + this.Score=0; this.XDeathPos = this.X | 0; this.YDeathPos = this.Y | 0; this.World.Paused = true; @@ -601,10 +607,13 @@ Mario.Character.prototype.Die = function() { }; Mario.Character.prototype.GetFlower = function() { + + this.Score+=100; + if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (!this.Fire) { this.World.Paused = true; this.PowerUpTime = 18; @@ -617,10 +626,13 @@ Mario.Character.prototype.GetFlower = function() { }; Mario.Character.prototype.GetMushroom = function() { - if (this.DeathTime > 0 && this.World.Paused) { + + this.Score+=100; + + if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (!this.Large) { this.World.Paused = true; this.PowerUpTime = 18; @@ -636,7 +648,7 @@ Mario.Character.prototype.Kick = function(shell) { if (this.DeathTime > 0 && this.World.Paused) { return; } - + if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.A)) { this.Carried = shell; shell.Carried = true; @@ -647,6 +659,7 @@ Mario.Character.prototype.Kick = function(shell) { }; Mario.Character.prototype.Get1Up = function() { + Enjine.Resources.PlaySound("1up"); this.Lives++; if (this.Lives === 99) { @@ -655,6 +668,9 @@ Mario.Character.prototype.Get1Up = function() { }; Mario.Character.prototype.GetCoin = function() { + + this.Score+=200; + this.Coins++; if (this.Coins === 100) { this.Coins = 0; diff --git a/code/enemy.js b/code/enemy.js index 4a56d7d..d9b4838 100755 --- a/code/enemy.js +++ b/code/enemy.js @@ -18,21 +18,21 @@ Mario.Enemy = function(world, x, y, dir, type, winged) { this.FlyDeath = false; this.WingTime = 0; this.NoFireballDeath = false; - + this.X = x; this.Y = y; this.World = world; - + this.Type = type; this.Winged = winged; - + this.Image = Enjine.Resources.Images["enemies"]; - + this.XPicO = 8; this.YPicO = 31; this.AvoidCliffs = this.Type === Mario.Enemy.RedKoopa; this.NoFireballDeath = this.Type === Mario.Enemy.Spiky; - + this.YPic = this.Type; if (this.YPic > 1) { this.Height = 12; @@ -41,7 +41,7 @@ Mario.Enemy = function(world, x, y, dir, type, winged) { if (this.Facing === 0) { this.Facing = 1; } - + this.PicWidth = 16; }; @@ -51,9 +51,9 @@ Mario.Enemy.prototype.CollideCheck = function() { if (this.DeadTime !== 0) { return; } - + var xMarioD = Mario.MarioCharacter.X - this.X, yMarioD = Mario.MarioCharacter.Y - this.Y; - + if (xMarioD > -this.Width * 2 - 4 && xMarioD < this.Width * 2 + 4) { if (yMarioD > -this.Height && yMarioD < Mario.MarioCharacter.Height) { if (this.Type !== Mario.Enemy.Spiky && Mario.MarioCharacter.Ya > 0 && yMarioD <= 0 && (!Mario.MarioCharacter.OnGround || !Mario.MarioCharacter.WasOnGround)) { @@ -64,14 +64,14 @@ Mario.Enemy.prototype.CollideCheck = function() { } else { this.YPicO = 31 - (32 - 8); this.PicHeight = 8; - + if (this.SpriteTemplate !== null) { this.SpriteTemplate.IsDead = true; } - + this.DeadTime = 10; this.Winged = false; - + if (this.Type === Mario.Enemy.RedKoopa) { this.World.AddSprite(new Mario.Shell(this.World, this.X, this.Y, 0)); } else if (this.Type === Mario.Enemy.GreenKoopa) { @@ -91,7 +91,7 @@ Mario.Enemy.prototype.Move = function() { this.WingTime++; if (this.DeadTime > 0) { this.DeadTime--; - + if (this.DeadTime === 0) { this.DeadTime = 1; for (i = 0; i < 8; i++) { @@ -99,7 +99,7 @@ Mario.Enemy.prototype.Move = function() { } this.World.RemoveSprite(this); } - + if (this.FlyDeath) { this.X += this.Xa; this.Y += this.Ya; @@ -108,41 +108,41 @@ Mario.Enemy.prototype.Move = function() { } return; } - + if (this.Xa > 2) { this.Facing = 1; } if (this.Xa < -2) { this.Facing = -1; } - + this.Xa = this.Facing * sideWaysSpeed; - + this.MayJump = this.OnGround; - + this.XFlip = this.Facing === -1; - + this.RunTime += Math.abs(this.Xa) + 5; - + runFrame = ((this.RunTime / 20) | 0) % 2; - + if (!this.OnGround) { runFrame = 1; } - + if (!this.SubMove(this.Xa, 0)) { this.Facing = -this.Facing; } this.OnGround = false; this.SubMove(0, this.Ya); - + this.Ya *= this.Winged ? 0.95 : 0.85; if (this.OnGround) { this.Xa *= this.GroundInertia; } else { this.Xa *= this.AirInertia; } - + if (!this.OnGround) { if (this.Winged) { this.Ya += 0.6; @@ -152,17 +152,17 @@ Mario.Enemy.prototype.Move = function() { } else if (this.Winged) { this.Ya = -10; } - + if (this.Winged) { runFrame = ((this.WingTime / 4) | 0) % 2; } - + this.XPic = runFrame; }; Mario.Enemy.prototype.SubMove = function(xa, ya) { var collide = false; - + while (xa > 8) { if (!this.SubMove(8, 0)) { return false; @@ -187,7 +187,7 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { } ya += 8; } - + if (ya > 0) { if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, 0)) { collide = true; @@ -208,7 +208,7 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { collide = true; } } - + if (xa > 0) { if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya - this.Height, xa, ya)) { collide = true; @@ -219,7 +219,7 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { if (this.IsBlocking(this.X + xa + this.Width, this.Y + ya, xa, ya)) { collide = true; } - + if (this.AvoidCliffs && this.OnGround && !this.World.Level.IsBlocking(((this.X + this.Xa + this.Width) / 16) | 0, ((this.Y / 16) + 1) | 0, this.Xa, 1)) { collide = true; } @@ -234,12 +234,12 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { if (this.IsBlocking(this.X + xa - this.Width, this.Y + ya, xa, ya)) { collide = true; } - + if (this.AvoidCliffs && this.OnGround && !this.World.Level.IsBlocking(((this.X + this.Xa - this.Width) / 16) | 0, ((this.Y / 16) + 1) | 0, this.Xa, 1)) { collide = true; } } - + if (collide) { if (xa < 0) { this.X = (((this.X - this.Width) / 16) | 0) * 16 + this.Width; @@ -258,7 +258,7 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { this.Y = (((this.Y - 1) / 16 + 1) | 0) * 16 - 1; this.OnGround = true; } - + return false; } else { this.X += xa; @@ -270,11 +270,11 @@ Mario.Enemy.prototype.SubMove = function(xa, ya) { Mario.Enemy.prototype.IsBlocking = function(x, y, xa, ya) { x = (x / 16) | 0; y = (y / 16) | 0; - + if (x === (this.X / 16) | 0 && y === (this.Y / 16) | 0) { return false; } - + return this.World.Level.IsBlocking(x, y, xa, ya); }; @@ -282,12 +282,13 @@ Mario.Enemy.prototype.ShellCollideCheck = function(shell) { if (this.DeadTime !== 0) { return false; } - + var xd = shell.X - this.X, yd = shell.Y - this.Y; if (xd > -16 && xd < 16) { if (yd > -this.Height && yd < shell.Height) { Enjine.Resources.PlaySound("kick"); - + + Mario.MarioCharacter.Score+=100; this.Xa = shell.Facing * 2; this.Ya = -5; this.FlyDeath = true; @@ -307,16 +308,16 @@ Mario.Enemy.prototype.FireballCollideCheck = function(fireball) { if (this.DeadTime !== 0) { return false; } - + var xd = fireball.X - this.X, yd = fireball.Y - this.Y; if (xd > -16 && xd < 16) { if (yd > -this.Height && yd < fireball.Height) { if (this.NoFireballDeath) { return true; } - + Enjine.Resources.PlaySound("kick"); - + this.Xa = fireball.Facing * 2; this.Ya = -5; this.FlyDeath = true; @@ -335,10 +336,10 @@ Mario.Enemy.prototype.BumpCheck = function(xTile, yTile) { if (this.DeadTime !== 0) { return; } - + if (this.X + this.Width > xTile * 16 && this.X - this.Width < xTile * 16 + 16 && yTile === ((this.Y - 1) / 16) | 0) { Enjine.Resources.PlaySound("kick"); - + this.Xa = -Mario.MarioCharacter.Facing * 2; this.Ya = -5; this.FlyDeath = true; @@ -355,11 +356,11 @@ Mario.Enemy.prototype.SubDraw = Mario.NotchSprite.prototype.Draw; Mario.Enemy.prototype.Draw = function(context, camera) { var xPixel = 0, yPixel = 0; - + if (this.Winged) { xPixel = ((this.XOld + (this.X - this.XOld) * this.Delta) | 0) - this.XPicO; yPixel = ((this.YOld + (this.Y - this.YOld) * this.Delta) | 0) - this.YPicO; - + if (this.Type !== Mario.Enemy.RedKoopa && this.Type !== Mario.Enemy.GreenKoopa) { this.XFlip = !this.XFlip; context.save(); @@ -371,13 +372,13 @@ Mario.Enemy.prototype.Draw = function(context, camera) { this.XFlip = !this.XFlip; } } - + this.SubDraw(context, camera); - + if (this.Winged) { xPixel = ((this.XOld + (this.X - this.XOld) * this.Delta) | 0) - this.XPicO; yPixel = ((this.YOld + (this.Y - this.YOld) * this.Delta) | 0) - this.YPicO; - + if (this.Type === Mario.Enemy.RedKoopa && this.Type === Mario.Enemy.GreenKoopa) { context.save(); context.scale(this.XFlip ? -1 : 1, this.YFlip ? -1 : 1); @@ -401,4 +402,4 @@ Mario.Enemy.RedKoopa = 0; Mario.Enemy.GreenKoopa = 1; Mario.Enemy.Goomba = 2; Mario.Enemy.Spiky = 3; -Mario.Enemy.Flower = 4; \ No newline at end of file +Mario.Enemy.Flower = 4; diff --git a/code/levelState.js b/code/levelState.js index a33a03e..6378376 100755 --- a/code/levelState.js +++ b/code/levelState.js @@ -289,7 +289,7 @@ Mario.LevelState.prototype.Draw = function(context) { this.Layer.DrawExit1(context, this.Camera); this.DrawStringShadow(context, "MARIO " + Mario.MarioCharacter.Lives, 0, 0); - this.DrawStringShadow(context, "00000000", 0, 1); + this.DrawStringShadow(context, " " + Mario.MarioCharacter.Score, 0, 1); this.DrawStringShadow(context, "COIN", 14, 0); this.DrawStringShadow(context, " " + Mario.MarioCharacter.Coins, 14, 1); this.DrawStringShadow(context, "WORLD", 24, 0);