diff --git a/Credits/Sources b/Credits/Sources
new file mode 100644
index 0000000..069057b
--- /dev/null
+++ b/Credits/Sources
@@ -0,0 +1,8 @@
+Credits:
+
+Lobby Audio:PUBG Mobile Main Menu Music Theme - Gboy Tyro Remix
+In-game Sound Effects: soundbible.org
+
+
+Code / Monogame Animation
+Oyyou Tutorials
diff --git a/Platformer/Account.cs b/Platformer/Account.cs
index f3f1044..6fe13a9 100644
--- a/Platformer/Account.cs
+++ b/Platformer/Account.cs
@@ -37,11 +37,33 @@ public Account(string userID)
}
+ // Takes in a string and a 'salt'
+ // Concatenates them to one string and returns its SHA256 hash
+ public static String GenerateHash(String password, String salt)
+ {
+ HashAlgorithm algorithm = new SHA256Managed();
+
+ byte[] b = algorithm.ComputeHash(Encoding.UTF8.GetBytes(password+salt));
+
+ StringBuilder hashed = new System.Text.StringBuilder();
+
+
+ foreach (byte Byte in b)
+ {
+ hashed.Append(Byte.ToString("x2"));
+ }
+
+ return hashed.ToString();
+
+ }
+
+
// genereate hash
// salts to be randomised
public static byte[] GenerateSaltedHash(byte[] plainText, byte[] salt)
{
HashAlgorithm algorithm = new SHA256Managed();
+
byte[] plainTextWithSaltBytes =
new byte[plainText.Length + salt.Length];
@@ -55,6 +77,9 @@ public static byte[] GenerateSaltedHash(byte[] plainText, byte[] salt)
plainTextWithSaltBytes[plainText.Length + i] = salt[i];
}
+
+
+
return algorithm.ComputeHash(plainTextWithSaltBytes);
}
diff --git a/Platformer/Animation.cs b/Platformer/Animation.cs
index d94b0a5..5e79a78 100644
--- a/Platformer/Animation.cs
+++ b/Platformer/Animation.cs
@@ -14,18 +14,26 @@ public class Animation
public int CurrFrame { get; set; }
public int FrameCount { get; private set; }
public int FrameHeight { get { return Texture.Height; } }
- public int FrameSpeed { get; set; }
+ public float FrameSpeed { get; set; }
public int FrameWidth { get { return Texture.Width / FrameCount; } }
public bool isLooping { get; set; }
+
public Texture2D Texture { get; private set; }
public Animation( Texture2D texture, int frameCount)
{
Texture = texture;
FrameCount = frameCount;
isLooping = true;
+ FrameSpeed = .75f;
- FrameSpeed = (int) 0.5f;
+ }
+ public Animation(Texture2D texture, int frameCount, float fs)
+ {
+ Texture = texture;
+ FrameCount = frameCount;
+ isLooping = true;
+ FrameSpeed = fs;
}
diff --git a/Platformer/AnimationManager.cs b/Platformer/AnimationManager.cs
index 9c590b2..3f853d8 100644
--- a/Platformer/AnimationManager.cs
+++ b/Platformer/AnimationManager.cs
@@ -6,6 +6,9 @@
using System.Text;
using System.Threading.Tasks;
+/* Modified code from https://github.com/Oyyou/MonoGame_Tutorials/
+ Credit Author: Oyyou */
+
namespace Platformer
{
public class AnimationManager
@@ -14,7 +17,9 @@ public class AnimationManager
private float _timer;
- public Vector2 Position { get; set; }
+ public int duration;
+
+ public Vector2 Position { get; set; }
public AnimationManager(Animation animation)
{
@@ -45,7 +50,7 @@ public void Play(Animation animation)
_timer = 0;
}
- public void Play(Animation animation, int time)
+ public void Play(Animation animation, int duration)
{
if (_animation == animation)
return;
@@ -54,10 +59,25 @@ public void Play(Animation animation, int time)
_animation.CurrFrame = 0;
- _timer = time;
+ _timer = duration;
}
+ // not used
+ public void PlayReverse(Animation animation, int duration)
+ {
+ if (_animation == animation)
+ return;
+
+ _animation = animation;
+
+ _animation.CurrFrame = 4;
+
+ _timer = duration;
+ }
+
+
+
public void Stop()
{
@@ -66,6 +86,8 @@ public void Stop()
_animation.CurrFrame = 0;
}
+
+ // the update methods increments frame
public void Update(GameTime gameTime)
{
_timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
@@ -80,5 +102,8 @@ public void Update(GameTime gameTime)
_animation.CurrFrame = 0;
}
}
- }
+
+
+
+ }
}
\ No newline at end of file
diff --git a/Platformer/Content/Audio/Heartbeat.wav b/Platformer/Content/Audio/Heartbeat.wav
new file mode 100644
index 0000000..f5f9cc2
Binary files /dev/null and b/Platformer/Content/Audio/Heartbeat.wav differ
diff --git a/Platformer/Content/Audio/Jump.wav b/Platformer/Content/Audio/Jump.wav
new file mode 100644
index 0000000..1dab6f5
Binary files /dev/null and b/Platformer/Content/Audio/Jump.wav differ
diff --git a/Platformer/Content/Audio/Lobby.mp3 b/Platformer/Content/Audio/Lobby.mp3
new file mode 100644
index 0000000..15f149a
Binary files /dev/null and b/Platformer/Content/Audio/Lobby.mp3 differ
diff --git a/Platformer/Content/Audio/victory.wav b/Platformer/Content/Audio/victory.wav
new file mode 100644
index 0000000..c7f014e
Binary files /dev/null and b/Platformer/Content/Audio/victory.wav differ
diff --git a/Platformer/Content/Content.mgcb b/Platformer/Content/Content.mgcb
index daf6bbe..15886d1 100644
--- a/Platformer/Content/Content.mgcb
+++ b/Platformer/Content/Content.mgcb
@@ -25,6 +25,30 @@
/processorParam:TextureFormat=Color
/build:attack.png
+#begin Audio/Heartbeat.wav
+/importer:WavImporter
+/processor:SoundEffectProcessor
+/processorParam:Quality=Best
+/build:Audio/Heartbeat.wav
+
+#begin Audio/Jump.wav
+/importer:WavImporter
+/processor:SoundEffectProcessor
+/processorParam:Quality=Best
+/build:Audio/Jump.wav
+
+#begin Audio/Lobby.mp3
+/importer:Mp3Importer
+/processor:SongProcessor
+/processorParam:Quality=Best
+/build:Audio/Lobby.mp3
+
+#begin Audio/victory.wav
+/importer:WavImporter
+/processor:SoundEffectProcessor
+/processorParam:Quality=Best
+/build:Audio/victory.wav
+
#begin background.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -37,6 +61,42 @@
/processorParam:TextureFormat=Color
/build:background.png
+#begin badlength.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:badlength.png
+
+#begin bigbackground.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:bigbackground.png
+
+#begin confirmpassword.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:confirmpassword.png
+
#begin continuewithoutsaving.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -49,6 +109,30 @@
/processorParam:TextureFormat=Color
/build:continuewithoutsaving.png
+#begin createaccount.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:createaccount.png
+
+#begin createaccountbutton.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:createaccountbutton.png
+
#begin death.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -68,6 +152,18 @@
/processorParam:TextureFormat=Compressed
/build:demo.spritefont
+#begin door.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:door.png
+
#begin enemyattackL.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -92,6 +188,30 @@
/processorParam:TextureFormat=Color
/build:enemyattackR.png
+#begin enemyidleL.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:enemyidleL.png
+
+#begin enemyidleR.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:enemyidleR.png
+
#begin enemywalkL.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -116,6 +236,18 @@
/processorParam:TextureFormat=Color
/build:enemywalkR.png
+#begin enter.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:enter.png
+
#begin exit.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -128,6 +260,25 @@
/processorParam:TextureFormat=Color
/build:exit.png
+#begin finishline.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:finishline.png
+
+#begin font.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:PremultiplyAlpha=True
+/processorParam:TextureFormat=Compressed
+/build:font.spritefont
+
#begin health.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -152,6 +303,18 @@
/processorParam:TextureFormat=Color
/build:idle.png
+#begin incorrect.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:incorrect.png
+
#begin instructions.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -164,6 +327,30 @@
/processorParam:TextureFormat=Color
/build:instructions.png
+#begin instructs.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:instructs.png
+
+#begin leaderboards.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:leaderboards.png
+
#begin left.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -176,6 +363,30 @@
/processorParam:TextureFormat=Color
/build:left.png
+#begin log.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:log.png
+
+#begin logintitle.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:logintitle.png
+
#begin multiplayer.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -200,6 +411,18 @@
/processorParam:TextureFormat=Color
/build:newgame.png
+#begin passwordtitle.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:passwordtitle.png
+
#begin returntomainmenu.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -308,3 +531,111 @@
/processorParam:TextureFormat=Color
/build:tryagain.png
+#begin usernametaken.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:usernametaken.png
+
+#begin usernametitle.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:usernametitle.png
+
+#begin viewleaderboards.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:viewleaderboards.png
+
+#begin continue.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:continue.png
+
+#begin levelcompleted.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:levelcompleted.png
+
+#begin nightbackground.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:nightbackground.png
+
+#begin gameover.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:gameover.png
+
+#begin leaderboards2.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:leaderboards2.png
+
+#begin pause.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:pause.png
+
diff --git a/Platformer/Content/badlength.png b/Platformer/Content/badlength.png
new file mode 100644
index 0000000..7ed56eb
Binary files /dev/null and b/Platformer/Content/badlength.png differ
diff --git a/Platformer/Content/bigbackground.png b/Platformer/Content/bigbackground.png
new file mode 100644
index 0000000..a400d19
Binary files /dev/null and b/Platformer/Content/bigbackground.png differ
diff --git a/Platformer/Content/confirmpassword.png b/Platformer/Content/confirmpassword.png
new file mode 100644
index 0000000..5b0dede
Binary files /dev/null and b/Platformer/Content/confirmpassword.png differ
diff --git a/Platformer/Content/continue.png b/Platformer/Content/continue.png
new file mode 100644
index 0000000..74351cb
Binary files /dev/null and b/Platformer/Content/continue.png differ
diff --git a/Platformer/Content/createaccount.png b/Platformer/Content/createaccount.png
new file mode 100644
index 0000000..e4dedd2
Binary files /dev/null and b/Platformer/Content/createaccount.png differ
diff --git a/Platformer/Content/createaccountbutton.png b/Platformer/Content/createaccountbutton.png
new file mode 100644
index 0000000..f7f4d1b
Binary files /dev/null and b/Platformer/Content/createaccountbutton.png differ
diff --git a/Platformer/Content/door.png b/Platformer/Content/door.png
new file mode 100644
index 0000000..c912c2c
Binary files /dev/null and b/Platformer/Content/door.png differ
diff --git a/Platformer/Content/enemyidleL.png b/Platformer/Content/enemyidleL.png
new file mode 100644
index 0000000..9d6bc9c
Binary files /dev/null and b/Platformer/Content/enemyidleL.png differ
diff --git a/Platformer/Content/enemyidleR.png b/Platformer/Content/enemyidleR.png
new file mode 100644
index 0000000..418553a
Binary files /dev/null and b/Platformer/Content/enemyidleR.png differ
diff --git a/Platformer/Content/enter.png b/Platformer/Content/enter.png
new file mode 100644
index 0000000..af68a9f
Binary files /dev/null and b/Platformer/Content/enter.png differ
diff --git a/Platformer/Content/finishline.png b/Platformer/Content/finishline.png
new file mode 100644
index 0000000..fc30d47
Binary files /dev/null and b/Platformer/Content/finishline.png differ
diff --git a/Platformer/Content/font.spritefont b/Platformer/Content/font.spritefont
new file mode 100644
index 0000000..bd33ecf
--- /dev/null
+++ b/Platformer/Content/font.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Arial
+
+
+ 12
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/Platformer/Content/gameover.png b/Platformer/Content/gameover.png
new file mode 100644
index 0000000..1f590ed
Binary files /dev/null and b/Platformer/Content/gameover.png differ
diff --git a/Platformer/Content/gameplaybar1.png b/Platformer/Content/gameplaybar1.png
new file mode 100644
index 0000000..a563199
Binary files /dev/null and b/Platformer/Content/gameplaybar1.png differ
diff --git a/Platformer/Content/incorrect.png b/Platformer/Content/incorrect.png
new file mode 100644
index 0000000..d31f5b3
Binary files /dev/null and b/Platformer/Content/incorrect.png differ
diff --git a/Platformer/Content/instructs.png b/Platformer/Content/instructs.png
new file mode 100644
index 0000000..d7875e6
Binary files /dev/null and b/Platformer/Content/instructs.png differ
diff --git a/Platformer/Content/leaderboards.png b/Platformer/Content/leaderboards.png
new file mode 100644
index 0000000..119d592
Binary files /dev/null and b/Platformer/Content/leaderboards.png differ
diff --git a/Platformer/Content/leaderboards2.png b/Platformer/Content/leaderboards2.png
new file mode 100644
index 0000000..ce3a5ef
Binary files /dev/null and b/Platformer/Content/leaderboards2.png differ
diff --git a/Platformer/Content/levelcompleted.png b/Platformer/Content/levelcompleted.png
new file mode 100644
index 0000000..ca78ca3
Binary files /dev/null and b/Platformer/Content/levelcompleted.png differ
diff --git a/Platformer/Content/localm.png b/Platformer/Content/localm.png
new file mode 100644
index 0000000..08b2e1d
Binary files /dev/null and b/Platformer/Content/localm.png differ
diff --git a/Platformer/Content/log.png b/Platformer/Content/log.png
new file mode 100644
index 0000000..b20778b
Binary files /dev/null and b/Platformer/Content/log.png differ
diff --git a/Platformer/Content/logintitle.png b/Platformer/Content/logintitle.png
new file mode 100644
index 0000000..5cb3f57
Binary files /dev/null and b/Platformer/Content/logintitle.png differ
diff --git a/Platformer/Content/melee enemy walk.png b/Platformer/Content/melee enemy walk.png
new file mode 100644
index 0000000..e5764a7
Binary files /dev/null and b/Platformer/Content/melee enemy walk.png differ
diff --git a/Platformer/Content/mult.png b/Platformer/Content/mult.png
new file mode 100644
index 0000000..d49d629
Binary files /dev/null and b/Platformer/Content/mult.png differ
diff --git a/Platformer/Content/nightbackground.png b/Platformer/Content/nightbackground.png
new file mode 100644
index 0000000..a8343ad
Binary files /dev/null and b/Platformer/Content/nightbackground.png differ
diff --git a/Platformer/Content/options.png b/Platformer/Content/options.png
new file mode 100644
index 0000000..18e7dbf
Binary files /dev/null and b/Platformer/Content/options.png differ
diff --git a/Platformer/Content/passwordtitle.png b/Platformer/Content/passwordtitle.png
new file mode 100644
index 0000000..2613ff1
Binary files /dev/null and b/Platformer/Content/passwordtitle.png differ
diff --git a/Platformer/Content/pause.png b/Platformer/Content/pause.png
new file mode 100644
index 0000000..1d61ce4
Binary files /dev/null and b/Platformer/Content/pause.png differ
diff --git a/Platformer/Content/settings.png b/Platformer/Content/settings.png
new file mode 100644
index 0000000..3b5eae2
Binary files /dev/null and b/Platformer/Content/settings.png differ
diff --git a/Platformer/Content/textbig.spritefont b/Platformer/Content/textbig.spritefont
new file mode 100644
index 0000000..77afbac
--- /dev/null
+++ b/Platformer/Content/textbig.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Comic Sans MS
+
+
+ 46
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/Platformer/Content/textsmall.spritefont b/Platformer/Content/textsmall.spritefont
new file mode 100644
index 0000000..5769ec3
--- /dev/null
+++ b/Platformer/Content/textsmall.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Comic Sans MS
+
+
+ 24
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/Platformer/Content/usernametaken.png b/Platformer/Content/usernametaken.png
new file mode 100644
index 0000000..d57799d
Binary files /dev/null and b/Platformer/Content/usernametaken.png differ
diff --git a/Platformer/Content/usernametitle.png b/Platformer/Content/usernametitle.png
new file mode 100644
index 0000000..3de5efe
Binary files /dev/null and b/Platformer/Content/usernametitle.png differ
diff --git a/Platformer/Content/viewleaderboards.png b/Platformer/Content/viewleaderboards.png
new file mode 100644
index 0000000..1625201
Binary files /dev/null and b/Platformer/Content/viewleaderboards.png differ
diff --git a/Platformer/CreateAccount.cs b/Platformer/CreateAccount.cs
new file mode 100644
index 0000000..e306eec
--- /dev/null
+++ b/Platformer/CreateAccount.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Platformer
+{
+ class CreateAccount
+ {
+
+ public CreateAccount(String username, String password)
+ {
+
+ }
+
+ }
+}
diff --git a/Platformer/DatabaseQueries.cs b/Platformer/DatabaseQueries.cs
index 7c8a2ea..f326886 100644
--- a/Platformer/DatabaseQueries.cs
+++ b/Platformer/DatabaseQueries.cs
@@ -1,239 +1,354 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MySql.Data.MySqlClient;
-
-namespace UnitTestProject1
-{
- public class ConnectDB
- {
- private static MySqlConnection connection;
- private static string server;
- private static string database;
- private static string uid;
- private static string password;
-
-
- //Initialize values
- private static void Initialize()
- {
- server = "sql181.main-hosting.eu";
- database = "u628890082_theo";
- uid = "u628890082_theo";
- password = "6sEHJuOgsfTr";
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" +
- database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";Allow User Variables=True;";
-
- connection = new MySqlConnection(connectionString);
- }
-
- //open connection to database
- private static bool OpenConnection()
- {
- try
- {
- connection.Open();
- return true;
- }
- catch (MySqlException ex)
- {
- //When handling errors, you can your application's response based
- //on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- switch (ex.Number)
- {
- case 0:
- Console.Write("Cannot connect to server. Contact administrator");
- break;
-
- case 1045:
- Console.Write("Invalid username/password, please try again");
- break;
- }
- return false;
- }
- }
-
- //Close connection
- private static bool CloseConnection()
- {
- try
- {
- connection.Close();
- return true;
- }
- catch (MySqlException ex)
- {
- Console.Write(ex.Message);
- return false;
- }
- }
-
- public static void createAccount(string username, string email, string password)
- {
- string query = "INSERT INTO player VALUES('" + username + "','" + email + "','" + password + "',0);";
-
- //open connection
- if (OpenConnection() == true)
- {
- //create command and assign the query and connection from the constructor
- MySqlCommand cmd = new MySqlCommand(query, connection);
-
- //Execute command
- cmd.ExecuteNonQuery();
-
- //close connection
- CloseConnection();
- }
- }
-
- public static void resetPassword(string username, string email, string newPassword)
- {
- string query = "UPDATE player SET password='" + newPassword + "' WHERE user='" + username + "';";
-
- //Open connection
- if (OpenConnection() == true)
- {
- //create mysql command
- MySqlCommand cmd = new MySqlCommand();
- //Assign the query using CommandText
- cmd.CommandText = query;
- //Assign the connection using Connection
- cmd.Connection = connection;
-
- //Execute query
- cmd.ExecuteNonQuery();
-
- //close connection
- CloseConnection();
- }
- }
-
- public static void login(string username, string password)
- {
- string query = "SELECT username FROM player WHERE username='" + username + "' AND password='" + password + "';";
- if (OpenConnection() == true)
- {
- MySqlCommand myCommand = new MySqlCommand(query, connection);
- MySqlDataReader myReader;
- myReader = myCommand.ExecuteReader();
- // Always call Read before accessing data.
- while (myReader.Read())
- {
- Console.WriteLine(myReader[0]);
- }
- // always call Close when done reading.
- myReader.Close();
- }
- CloseConnection();
- }
-
- public static void viewLeaderboards(int level)
- {
- string query = "SELECT user, ranking, score FROM leaderboard WHERE level=" + level + " ORDER BY score DESC;";
- if (OpenConnection() == true)
- {
- MySqlCommand myCommand = new MySqlCommand(query, connection);
- MySqlDataReader myReader;
- myReader = myCommand.ExecuteReader();
- // Always call Read before accessing data.
- while (myReader.Read())
- {
- Console.WriteLine(myReader[1] + ", " + myReader[0] + ", " + myReader[2]);
- }
- // always call Close when done reading.
- myReader.Close();
- }
- CloseConnection();
- }
-
- public static void continueGame(string user)
- {
- string query = "SELECT last_level_completed FROM player WHERE username='" + user + "';";
- if (OpenConnection() == true)
- {
- MySqlCommand myCommand = new MySqlCommand(query, connection);
- MySqlDataReader myReader;
- myReader = myCommand.ExecuteReader();
- // Always call Read before accessing data.
- while (myReader.Read())
- {
- Console.WriteLine(myReader[0] + ", " + myReader[1] + ", " + myReader[2] + ", " + myReader[3]);
- }
- // always call Close when done reading.
- myReader.Close();
- }
- CloseConnection();
- }
-
- public static void completeLevelForFirstTime(int level, string user, int score)
- {
- string query = "SET @rank := (SELECT COUNT(*)+1 FROM leaderboard WHERE score > " + score + " AND level = " + level + "); INSERT INTO leaderboard VALUES(" + level + ", @rank, '" + user + "', " + score + "); UPDATE leaderboard SET ranking = CASE WHEN score < " + score + " THEN ranking+1 ELSE ranking END WHERE level = " + level + ";";
-
- //Open connection
- if (OpenConnection() == true)
- {
- //create mysql command
- MySqlCommand cmd = new MySqlCommand();
- //Assign the query using CommandText
- cmd.CommandText = query;
- //Assign the connection using Connection
- cmd.Connection = connection;
-
- //Execute query
- cmd.ExecuteNonQuery();
-
- //close connection
- CloseConnection();
- }
- }
-
- public static void updateHighScore(string user, int level, int score)
- {
- string query = "SET @rank := (SELECT COUNT(*)+1 FROM leaderboard WHERE score > " + score + " AND level = " + level + "); UPDATE leaderboard SET score=" + score + ", ranking=@rank WHERE user='" + user + "' AND level=" + level + "; UPDATE leaderboard SET ranking = CASE WHEN score < " + score + " THEN ranking+1 ELSE ranking END WHERE level = " + level + ";";
- //Open connection
- if (OpenConnection() == true)
- {
- //create mysql command
- MySqlCommand cmd = new MySqlCommand();
- //Assign the query using CommandText
- cmd.CommandText = query;
- //Assign the connection using Connection
- cmd.Connection = connection;
-
- //Execute query
- cmd.ExecuteNonQuery();
-
- //close connection
- CloseConnection();
- }
- }
-
- public static void saveGame(string user, int level)
- {
- string query = "UPDATE player SET last_level_completed=" + level + " WHERE username='" + user + "';";
- //Open connection
- if (OpenConnection() == true)
- {
- //create mysql command
- MySqlCommand cmd = new MySqlCommand();
- //Assign the query using CommandText
- cmd.CommandText = query;
- //Assign the connection using Connection
- cmd.Connection = connection;
-
- //Execute query
- cmd.ExecuteNonQuery();
-
- //close connection
- CloseConnection();
- }
- }
- }
-}
+/* Template from Code Project
+ * URL: https://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
+
+namespace Platformer
+{
+ public class ConnectDB
+ {
+ private static MySqlConnection connection;
+ private static string server;
+ private static string database;
+ private static string uid;
+ private static string password;
+
+ public ConnectDB()
+ {
+
+ }
+
+
+
+ //Initialize values
+ public void Initialize()
+ {
+ server = "sql181.main-hosting.eu";
+ database = "u628890082_theo";
+ uid = "u628890082_theo";
+ password = "6sEHJuOgsfTr";
+ string connectionString;
+ connectionString = "SERVER=" + server + ";" + "DATABASE=" +
+ database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";Allow User Variables=True;";
+
+ connection = new MySqlConnection(connectionString);
+ }
+
+ //open connection to database
+ private static bool OpenConnection()
+ {
+ try
+ {
+ connection.Open();
+ return true;
+ }
+ catch (MySqlException ex)
+ {
+ //When handling errors, you can your application's response based
+ //on the error number.
+ //The two most common error numbers when connecting are as follows:
+ //0: Cannot connect to server.
+ //1045: Invalid user name and/or password.
+ switch (ex.Number)
+ {
+ case 0:
+ Console.Write("Cannot connect to server. Contact administrator");
+ break;
+
+ case 1045:
+ Console.Write("Invalid username/password, please try again");
+ break;
+ }
+ return false;
+ }
+ }
+
+ //Close connection
+ private static bool CloseConnection()
+ {
+ try
+ {
+ connection.Close();
+ return true;
+ }
+ catch (MySqlException ex)
+ {
+ Console.Write(ex.Message);
+ return false;
+ }
+ }
+
+ public bool createAccount(string username, string password)
+ {
+ string query = "INSERT INTO player VALUES('" + username + "','" + password + "',0);";
+ string query2 = "SELECT username FROM player WHERE username='" + username + "';"; // checks to see if the username already exists
+ //open connection
+ if (OpenConnection() == true)
+ {
+ //create command and assign the query and connection from the constructor
+ MySqlCommand cmd = new MySqlCommand(query, connection);
+ MySqlCommand cmd2 = new MySqlCommand(query2, connection);
+ //Execute command
+ MySqlDataReader myReader;
+ myReader = cmd2.ExecuteReader();
+ // Always call Read before accessing data.
+ if (myReader.Read())
+ {
+ if ((string)myReader[0] == username)
+ {
+ Console.WriteLine("Username already exists");
+ CloseConnection();
+ myReader.Close();
+ return false;
+ }
+ }
+ myReader.Close();
+ if ((username.Length < 3 || username.Length > 40) && (password.Length < 8 || password.Length > 64))
+ {
+ Console.WriteLine("Username must be 3-40 characters long. Password must be 8-20 characters long");
+
+ }
+ else if (username.Length < 3 || username.Length > 40)
+ {
+ Console.WriteLine("Username must be 3-40 characters long.");
+ }
+ else if (password.Length < 8 || password.Length > 64)
+ {
+ Console.WriteLine("Password must be 8-20 characters long");
+ }
+ else
+ {
+ cmd.ExecuteNonQuery();
+
+ }
+ //close connection
+ CloseConnection();
+ return true;
+ }
+ return true;
+ }
+
+ public bool login(string username, string password)
+ {
+ string query = "SELECT Username FROM player WHERE Username='" + username + "' AND Password='" + password + "';";
+ if (OpenConnection() == true)
+ {
+ MySqlCommand myCommand = new MySqlCommand(query, connection);
+ MySqlDataReader myReader;
+ myReader = myCommand.ExecuteReader();
+ // Always call Read before accessing data.
+ if (myReader.Read())
+ {
+ if((string)myReader[0] == username)
+ {
+ System.Diagnostics.Debug.WriteLine("Hello " + username);
+ CloseConnection();
+ return true;
+ }
+
+ }
+ else
+ {
+ Console.WriteLine("Incorrect login information");
+ //myReader.Close();
+ CloseConnection();
+ return false;
+ }
+ // always call Close when done reading.
+ myReader.Close();
+ }
+ CloseConnection();
+
+ return false;
+ }
+
+ public List[] viewLeaderboards(int level)
+ {
+ string query = "SELECT user, ranking, score FROM leaderboard WHERE level=" + level + " ORDER BY score DESC;";
+ List[] list = new List[3];
+ list[0] = new List();
+ list[1] = new List();
+ list[2] = new List();
+
+ if (OpenConnection() == true)
+ {
+ MySqlCommand myCommand = new MySqlCommand(query, connection);
+ MySqlDataReader myReader;
+ myReader = myCommand.ExecuteReader();
+ // Always call Read before accessing data.
+ while (myReader.Read())
+ {
+ list[0].Add(myReader[0] + "");
+ list[1].Add(myReader[1] + "");
+ list[2].Add(myReader[2] + "");
+ //Console.WriteLine(list[1].ToString() + ", " + list[0].ToString() + ", " + list[2].ToString());
+
+ }
+ // always call Close when done reading.
+
+
+ myReader.Close();
+ CloseConnection();
+ /* for (int i = 0; i < list.Length; i++)
+ {
+ for (int j = 0; j < list[i].; j++)
+ {
+ Console.WriteLine(list[i][j].ToString());
+ }
+ }*/
+ //Console.WriteLine(list[0][0]);
+ //Console.WriteLine(list[0][0].ToString());
+ return list;
+ }
+ else
+ {
+ return list;
+ }
+ }
+
+ public List[] continueGame(string user)
+ {
+ string query = "SELECT last_level_completed+1 FROM player WHERE username='" + user + "';";
+ List[] level = new List[1];
+ level[0] = new List();
+
+ if (OpenConnection() == true)
+ {
+ MySqlCommand myCommand = new MySqlCommand(query, connection);
+ MySqlDataReader myReader;
+ myReader = myCommand.ExecuteReader();
+ // Always call Read before accessing data.
+ while (myReader.Read())
+ {
+ level[0].Add(myReader[0] + "");
+ }
+ // always call Close when done reading.
+ myReader.Close();
+ CloseConnection();
+
+ return level;
+ }
+ else {
+ return level;
+ }
+ }
+
+ public void newGame(string user)
+ {
+ string query = "UPDATE player SET last_level_completed=0 WHERE username='" + user + "';";
+ //Open connection
+ if (OpenConnection() == true)
+ {
+ //create mysql command
+ MySqlCommand cmd = new MySqlCommand();
+ //Assign the query using CommandText
+ cmd.CommandText = query;
+ //Assign the connection using Connection
+ cmd.Connection = connection;
+
+ //Execute query
+ cmd.ExecuteNonQuery();
+
+ //close connection
+ CloseConnection();
+ }
+ }
+
+ public void completeLevelForFirstTime(int level, string user, int score)
+ {
+ string query = "SET @rank := (SELECT COUNT(*)+1 FROM leaderboard WHERE score > " + score + " AND level = " + level + "); INSERT INTO leaderboard VALUES(" + level + ", @rank, '" + user + "', " + score + "); UPDATE leaderboard SET ranking = CASE WHEN score < " + score + " THEN ranking+1 ELSE ranking END WHERE level = " + level + ";";
+ string query2 = "SELECT user FROM leaderboard WHERE user='" + user + "' AND level=" + level + ";";
+ //Open connection
+ if (OpenConnection() == true)
+ {
+ MySqlCommand myCommand = new MySqlCommand(query2, connection);
+ MySqlDataReader myReader;
+ myReader = myCommand.ExecuteReader();
+ // Always call Read before accessing data.
+ while (myReader.Read())
+ {
+ if ((string) myReader[0] == user)
+ {
+ myReader.Close();
+ CloseConnection();
+ updateHighScore(user, level, score);
+ return;
+ }
+ }
+ // always call Close when done reading.
+ myReader.Close();
+ //create mysql command
+ MySqlCommand cmd = new MySqlCommand();
+ //Assign the query using CommandText
+ cmd.CommandText = query;
+ //Assign the connection using Connection
+ cmd.Connection = connection;
+
+ //Execute query
+ cmd.ExecuteNonQuery();
+
+ //close connection
+ CloseConnection();
+ }
+ }
+
+ public void updateHighScore(string user, int level, int score)
+ {
+
+ string query = "SET @rank := (SELECT COUNT(*)+1 FROM leaderboard WHERE score>" + score + " AND level=" + level + "); " +
+ "SET @old := (SELECT ranking FROM leaderboard WHERE user='" + user + "'); " +
+ "UPDATE leaderboard SET score=" + score + ", ranking=@rank WHERE user='" + user + "' AND level=" + level + " AND score < " + score + "; " +
+ "UPDATE leaderboard SET ranking=" +
+ "CASE WHEN score<" + score + " THEN ranking+1 " +
+ "ELSE ranking " +
+ "END " +
+ "WHERE level=" + level + "; " +
+ "SET @new := (SELECT ranking FROM leaderboard WHERE user='" + user + "'); " +
+ "UPDATE leaderboard SET ranking=CASE WHEN @old=@new THEN ranking-1 END WHERE level=" + level + " AND ranking>@old;";
+ //Open connection
+ if (OpenConnection() == true)
+ {
+ //create mysql command
+ MySqlCommand cmd = new MySqlCommand();
+ //Assign the query using CommandText
+ cmd.CommandText = query;
+ //Assign the connection using Connection
+ cmd.Connection = connection;
+
+ //Execute query
+ cmd.ExecuteNonQuery();
+
+ //close connection
+ CloseConnection();
+ }
+ }
+
+ public void saveGame(string user, int level)
+ {
+ string query = "UPDATE player SET last_level_completed=" + level + " WHERE username='" + user + "';";
+ //Open connection
+ if (OpenConnection() == true)
+ {
+ //create mysql command
+ MySqlCommand cmd = new MySqlCommand();
+ //Assign the query using CommandText
+ cmd.CommandText = query;
+ //Assign the connection using Connection
+ cmd.Connection = connection;
+
+ //Execute query
+ cmd.ExecuteNonQuery();
+
+ //close connection
+ CloseConnection();
+ }
+ }
+ }
+}
diff --git a/Platformer/Door.cs b/Platformer/Door.cs
new file mode 100644
index 0000000..4c7f3a6
--- /dev/null
+++ b/Platformer/Door.cs
@@ -0,0 +1,50 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Platformer
+{
+ class Door
+ {
+
+
+ public bool beingTouched = false;
+ public static Texture2D Texture { get; set; }
+ public Vector2 position;
+ public void Draw(SpriteBatch spriteBatch)
+ {
+ spriteBatch.Draw(Texture, position, Color.White);
+ }
+ public static void LoadContent(ContentManager content, int type)
+ {
+
+
+ Texture = content.Load("door");
+
+ }
+
+
+ public Door(Vector2 position)
+ {
+ this.position = position;
+ }
+
+ public void Update(float Xtrans)
+ {
+ position.X -= Xtrans * 3;
+ }
+
+
+
+ }
+
+ // blocks modification of location of blocks
+ // credit 1
+
+
+}
diff --git a/Platformer/Enemy.cs b/Platformer/Enemy.cs
index 39722bc..c8cb1fc 100644
--- a/Platformer/Enemy.cs
+++ b/Platformer/Enemy.cs
@@ -1,5 +1,9 @@
using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
+
+using Microsoft.Xna.Framework.Input;
+
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,25 +15,36 @@ namespace Platformer
class Enemy
{
+
+ #region Fields
+
SpriteEffects se;
+
protected AnimationManager _animationManager;
protected Dictionary _animations;
+
public Vector2 _position;
+ public int attack_counter; // how many times enemy has attacked the player
+
private Boolean isAttacking;
public Boolean IsAttacking { get { return isAttacking; }set { isAttacking = value; } }
public Texture2D _texture;
+ private int health;
+ public int Health { get { return health; } set { health = value; } }
+
public bool facingRight;
public int screenWidth =GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
// velocity of the enemy
public Vector2 Velocity;
+
public Vector2 Position
{
get { return _position; }
@@ -42,10 +57,33 @@ public Vector2 Position
}
}
+
+ public float Speed = 10f;
+ // public float Speed = 3f;
+
+
+
+
+ public Vector2 Acceleration = new Vector2(9.8f, 0);
+
+
+ // x co-ordinate movement
+ // using this var for moving background along with the character
+ public int Xtrans = 0;
+
+ #endregion
+ GraphicsDeviceManager graphics;
+ SpriteBatch spriteBatch;
+ Texture2D walker;
+ Rectangle walker2;
+ #region Methods
+
+
public Enemy(Dictionary animations)
{
_animations = animations;
_animationManager = new AnimationManager(_animations.First().Value);
+ health = 100;
}
public Enemy(Texture2D texture)
@@ -53,6 +91,7 @@ public Enemy(Texture2D texture)
_texture = texture;
}
+
public virtual void Draw(SpriteBatch spriteBatch)
{
if (_texture != null)
@@ -61,97 +100,213 @@ public virtual void Draw(SpriteBatch spriteBatch)
_animationManager.Draw(spriteBatch);
else throw new Exception("error animation mngr");
}
+
+
+ public virtual void Move()
+ {
+ if (Keyboard.GetState().IsKeyDown(Keys.Left) && _position.X > 50)
+ Velocity.X = -Speed;
+ if (Keyboard.GetState().IsKeyDown(Keys.Right))
+
+ {
+ Velocity.X = Speed;
+
+ }
+
+ }
+
+
protected virtual void SetAnimations()
{
if (isAttacking)
{
- if (!facingRight)
+ if (facingRight)
{
+
_animationManager.Play(_animations["enemyattackR"]);
+ // isAttacking = false;
+ attack_counter++;
+
}
- else
+ else if(!facingRight)
+
{
+
_animationManager.Play(_animations["enemyattackL"]);
+ attack_counter++;
+ // isAttacking = false;
}
}
- else if (Velocity.X > 0 &&!isAttacking)
+
+ else if (Velocity.X > 0)
_animationManager.Play(_animations["enemywalkR"]);
- else if (Velocity.X < 0 &&!isAttacking)
+ else if (Velocity.X < 0)
{
_animationManager.Play(_animations["enemywalkL"]);
+
}
- else _animationManager.Stop();
+
+
+
}
- private void RandomMove(Player player)
+
+
+ public Enemy(Dictionary animations, GraphicsDeviceManager g)
+ {
+ graphics = g;
+ _animations = animations;
+ _animationManager = new AnimationManager(_animations.First().Value);
+ }
+
+
+
+
+
+
+
+ public bool IsTouching(Tile tile, Player sprite)
+ {
+
+ return _position.X + 25f + this.Velocity.X >= tile.
+ position.X && this._position.Y < tile.position.Y && this._position.X + this.Velocity.X + 10f <= tile.
+
+
+ position.X + Tile.Texture.Width;
+
+
+
+ }
+
+ // Returns true if player is on top the tile, false otherwise
+ public bool tileTouching(Tile tile, Player player)
+ {
+ // Checks if the player is in bounds horizontally
+ if ((player._position.X >= tile.position.X) && (player._position.X <= tile.position.X + Tile.Texture.Width))
+ // Checks if the player is at the right height
+ if ((player._position.Y <= tile.position.Y))
+ return true;
+ else
+ return false;
+ else
+ return false;
+ }
+
+ #endregion
+
+
+ private void RandomMove(Player player, Dictionary soundEffects)
{
Random r = new Random();
//&& this.Position.X > screenWidth / 2 && this.Position.X > screenWidth / 3
- if (r.Next(0, 50) > 15 && !isAttacking)
+ int cap = 32;
+
+ /*
+ * reduce cap when moving further away so that
+ * he can escape
+ */
+ if (r.Next(0, 50) > cap && !isAttacking)
+
+
{
- if (player._position.X - this.Position.X > this._animations.ElementAt(0).Value.FrameWidth
- ) {
- this.Velocity.X = 1f;
- facingRight = true; }
+ if (player._position.X > this._position.X ) {
+ /*if (player._position.X > this._position.X+this._animations.ElementAt(0).Value.FrameWidth
+ ) {*/
+ if (player.isHalfway)
+ this.Velocity.X =1f;
+ else
+ {
+ this.Velocity.X =1f;
+ facingRight = true;
+ }
+ }
- else if (player._position.X - this.Position.X < 0)
+ else if (this.Position.X >player._position.X )
{
- this.Velocity.X = -1f;
- facingRight = true;
+ if (player.isHalfway)
+ this.Velocity.X = -2f;
+ else
+ {
+ this.Velocity.X = -1f;
+ facingRight = false;
+ }
}
+ }
+ else
+ {
+ this.Velocity = Vector2.Zero;
}
- if (!IsAttacking)
+
+ if (!IsAttacking&&attack_counter<1)
+ {
+ this.Attack(player, soundEffects);
+ }
+ if (attack_counter>=1)
{
- this.Attack(player);
+ this.IsAttacking = false;
}
}
- public virtual void Update(GameTime gameTime, Player player)
- {
+ public void Reset()
+ {
+ attack_counter = 0;
+ this._position = new Vector2(700, (int)((0.838) * graphics.PreferredBackBufferHeight));
+ }
+ public virtual void Update(GameTime gameTime, Player player, Dictionary soundEffects)
+ {
- if (!IsAttacking)
- {
- RandomMove(player);
+
+
+ RandomMove(player, soundEffects);
Position += Velocity;
- }
+ _animationManager.Update(gameTime);
SetAnimations();
- _animationManager.Update(gameTime);
-
-
- Velocity = Vector2.Zero;
+
+
+ Velocity = Vector2.Zero;
+
+
}
- private void Attack
- (Player player)
+
+
+
+
+ private void Attack (Player player, Dictionary soundEffects)
{
- if ((this._position.X-player._position.X)<100 && (this._position.X - player._position.X) >0&& player.IsAlive)
+
+ if ((this._position.X - player._position.X>-100) &&(this._position.X - player._position.X < 1) && !(this.Position.Y>player.Position.Y))
{
- // this.Velocity = Vector2.Zero;
- this.isAttacking=true;
- player.Health = player.Health-34;
- player.CheckHealth();
+
+ this.isAttacking = true;
+ player.Health = player.Health - 34;
+ soundEffects["Death"].Play();
+ player.CheckHealth();
}
- else if ((this._position.X - player._position.X)< 100 && (this._position.X - player._position.X) > 0 && player.IsAlive)
+
+
+ else
{
-
+ isAttacking = false;
}
}
+
}
}
diff --git a/Platformer/Game1.cs b/Platformer/Game1.cs
index 7eefa64..5a71a25 100644
--- a/Platformer/Game1.cs
+++ b/Platformer/Game1.cs
@@ -2,9 +2,11 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
using System;
-
-
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Media;
namespace Platformer
{
@@ -15,33 +17,74 @@ namespace Platformer
public class Game1 : Game
{
-
- enum GameState
+ // different states
+ // switching transfer control n displays the set state
+ private enum GameState
{
MainMenu,
+ Login,
Level1,
- Finish
+ Level2,
+ Finish,
+ Instructions,
+ CreateAccount,
+ Leaderboards,
+ LevelCompleted,
+ GameOver,
+ Pause,
+ Continue
}
GameState _state = GameState.MainMenu;
+ GameState _previousState = GameState.Level1;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
-
- // Title Screen
- Texture2D titlescreen;
+
+
+
+
+ List username = new List();
+ List password = new List();
+
+ String beingTyped = "user";
+
+ float[] colors = { 0.5f, 0.0f, 0.0f };
+
+ // Create Account
+ float[] Createcolors = { .5f, 0f, 0f, 0f };
+ List Createusername = new List();
+ List Createpassword = new List();
+ String CreatebeingTyped = "user";
+ bool Createfirst = false;
+
+ Texture2D titlescreen, gameover;
Texture2D titlescreen_a;
Scrolling scrolling1;
Scrolling scrolling2;
+ // Level 2
+ Scrolling nightscrolling1, nightscrolling2;
// List of tiles to display on platform
List tiles = new List();
+
+ List nightTiles = new List();
+
+ // exit door
+ Door finish_line;
+
+ Door finish_line2;
+
int opacDirection = 1;
- Rectangle titleScreen = new
-
+
+
+
// fit user's screen bounds
- Rectangle(0, 0, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
+ Rectangle titleScreen = new Rectangle(0, 0, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
// Title Screen //
+ MouseState mouse = Mouse.GetState();
+ bool firstboard = true;
+ List[] board;
// Heealth bar
HealthBar healthBar;
@@ -50,54 +93,888 @@ enum GameState
// sprite list
private List _sprites;
+
private Enemy enemy;
+ private Enemy enemy2;
+ private Enemy enemy3;
- Menu m;
+
+ // Database Connection
+ ConnectDB db = new ConnectDB();
+
+ Texture2D instructs;
+
+
+
// Initialize controller/keyboard
GamePadState controller = GamePad.GetState(PlayerIndex.One);
KeyboardState keyboard = Keyboard.GetState();
KeyboardState currentState;
KeyboardState previousState;
+
+
+
+
+
int select = 0;
- Texture2D continueWithoutSaving, exit, instructions, multiplayer, newGame, returnToMainMenu, saveContinue, singePlayer, startGame, tryAgain;
+
+ Texture2D paused, levelcompleted, continueWithoutSaving,Continue, createaccountbutton, viewLeaderboards, exit, instructions, multiplayer, newGame, returnToMainMenu, saveContinue, singePlayer, startGame, tryAgain;
Point buttonSize;
+ Texture2D logintitle, usernametitle, passwordtitle, enter;
+ Texture2D createaccount, confirmpassword;
+ bool firstLog = true;
+ bool enterable = false;
+ bool incorrectLogin = false;
+ bool Createenterable = false;
+
+ Texture2D incorrect;
+ Texture2D usernametaken, badlength;
+ bool BadLength = false;
+ bool usertaken = false;
+
+ Texture2D leaderboards, leaderboards2;
+ List ranks = new List();
+ List users = new List();
+ List scores = new List();
+ int leaderboardStart = 0;
+ int leaderboardLevel = 1;
+
+ // Logged in
+ bool LOGGED_IN = false;
+ String Logged_Username;
+ String Logged_Password;
+ bool firstBeaten = true;
+ int deathCounter = 0;
+ SpriteFont font;
+
//calculates and stores elapsed time since the game has started
Rectangle time= new Rectangle(700,100,200,100);
float elapsed_time;
- private SpriteFont font;
+ //private SpriteFont font;
+
+ Texture2D finishline;
+
+ // sound effects
+ // Audio credits in README file
+ Song lobby_music;
+ SoundEffect jumpSound;
+ SoundEffect deathSound;
+ SoundEffect victorySound;
+ private Dictionary soundEffects;
+
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
-
// Sets the game to 1080p fullscreen by default
graphics.PreferredBackBufferHeight = 1080;
graphics.PreferredBackBufferWidth = 1920;
- graphics.IsFullScreen = false;
+ //graphics.IsFullScreen = true;
}
+ #region Level Completed
+ public void LevelCompleted(GameTime gameTime)
+ {
+ _sprites[0].Reset();
+ deathCounter = 0;
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+ _state = GameState.MainMenu;
+ if (currentState.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter))
+ {
+
+ enemy._position.X = 2000;
+ enemy2._position.X = 1000;
+ enemy3._position.X = 1500;
+ elapsed_time = 0f;
+ _state = GameState.Level2;
+
+ }
+ GraphicsDevice.Clear(Color.Silver);
+
- protected override void Initialize()
+ spriteBatch.Begin();
+
+ spriteBatch.Draw(levelcompleted, new Rectangle(0,0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+ spriteBatch.DrawString(font, ((int)(100000f - elapsed_time/10f)).ToString(), new Vector2(graphics.PreferredBackBufferWidth / 1.85f, graphics.PreferredBackBufferHeight / 2.7f), Color.White);
+
+ spriteBatch.End();
+ }
+ #endregion
+
+ #region Leaderboards
+ public void Leaderboards(GameTime gameTime)
{
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+ {
+ firstboard = true;
+ _state = GameState.MainMenu;
+ }
+
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+ int z = 0;
+ String[] titles = { "Username", "Rank", "Score" };
+
+
+ GraphicsDevice.Clear(Color.DarkRed);
+
+ // Will only pull from database when the leaderboards page is opened
+ if (firstboard)
+ {
+
+ firstboard = false;
+
+ // Empties lists so they are no duplicates
+ users.Clear();
+ ranks.Clear();
+ scores.Clear();
+
+
+ // Gets each entry from database
+ foreach (var i in db.viewLeaderboards(leaderboardLevel))
+ {
+
+ int y = 0;
+ Console.WriteLine(titles[z]);
+ foreach (var j in i)
+ {
+ switch(z)
+ {
+ case 0:
+ users.Add(i[y]);
+ break;
+ case 1:
+ ranks.Add(i[y]);
+ break;
+ case 2:
+ scores.Add(i[y]);
+ break;
+ default:
+ break;
+ }
+
+ y++;
+ }
+ Console.WriteLine();
+ z++;
+ }
+
+
+ }
+
+
+
+ spriteBatch.Begin();
+ // DIsplays which level of the leaderboard is loaded
+ if(leaderboardLevel == 1)
+ spriteBatch.Draw(leaderboards, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+ else
+ spriteBatch.Draw(leaderboards2, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+
+ int len = ranks.Count;
+ // Scrolls through leaderboards with arrow keys
+ if (currentState.IsKeyDown(Keys.Down) && previousState.IsKeyUp(Keys.Down))
+ {
+ if (leaderboardStart < len - 1)
+ leaderboardStart++;
+ }
+ // Scrolls through leaderboards with arrow keys
+ if (currentState.IsKeyDown(Keys.Up) && previousState.IsKeyUp(Keys.Up))
+ {
+ if (leaderboardStart > 0)
+ leaderboardStart--;
+ }
+ // Scrolls through leaderboards with arrow keys
+ if(currentState.IsKeyDown(Keys.Right))
+ {
+ leaderboardLevel = 2;
+ firstboard = true;
+ }
+ // Scrolls through leaderboards with arrow keys
+ if(currentState.IsKeyDown(Keys.Left))
+ {
+ leaderboardLevel = 1;
+ firstboard = true;
+ }
+ // Rank
+ for (int i = leaderboardStart; i < len; i++)
+ spriteBatch.DrawString(font, ranks[i].ToString(), new Vector2(graphics.PreferredBackBufferWidth / 10, (graphics.PreferredBackBufferHeight / (2.5f)) + (graphics.PreferredBackBufferHeight * (i - leaderboardStart) /20f)), Color.White);
+ // Username
+ for (int i = leaderboardStart; i < len; i++)
+ spriteBatch.DrawString(font, users[i], new Vector2(graphics.PreferredBackBufferWidth / 2.5f, (graphics.PreferredBackBufferHeight / (2.5f)) + (graphics.PreferredBackBufferHeight * (i - leaderboardStart) / 20f)), Color.White);
+ // Score
+ for (int i = leaderboardStart; i < len; i++)
+ spriteBatch.DrawString(font, scores[i], new Vector2(graphics.PreferredBackBufferWidth / 1.2f, (graphics.PreferredBackBufferHeight / (2.5f)) + (graphics.PreferredBackBufferHeight * (i - leaderboardStart) / 20f)), Color.White);
+
+
+
+ spriteBatch.End();
+
+
+
+
+ base.Update(gameTime);
+
+ }
+
+
+
+ #endregion
+
+ #region Pause
+ public void Pause(GameTime gameTime)
+ {
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ // Escape allows takes user to main menu
+ if (currentState.IsKeyDown(Keys.Escape) && previousState.IsKeyUp(Keys.Escape))
+ _state = GameState.MainMenu;
+ // enter takes user to previous screen
+ if (currentState.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter))
+ _state = _previousState;
+ spriteBatch.Begin();
+ spriteBatch.Draw(paused, new Rectangle(0,0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+ spriteBatch.End();
+
+ base.Update(gameTime);
+ }
+ #endregion
+
+
+ #region Instructions
+ public void Instructions(GameTime gameTime)
+ {
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+ _state = GameState.MainMenu;
+
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ GraphicsDevice.Clear(Color.DarkRed);
+ spriteBatch.Begin();
+ spriteBatch.Draw(instructs, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+ spriteBatch.End();
+
+ base.Update(gameTime);
+ }
+ #endregion
+ // Creates a new account on the server
+ #region Create Account
+ public void CreateAccount(GameTime gameTime)
+ {
+ String USERNAME;
+ String PASSWORD;
+
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+ _state = GameState.MainMenu;
+
+ // Updates keyboard states for typing recognition
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ if (Createfirst)
+ {
+ if (currentState.GetPressedKeys().Length == 0)
+ {
+ CreatebeingTyped = "user";
+ Createfirst = false;
+ }
+ }
+
+ int height = graphics.PreferredBackBufferHeight;
+ int width = graphics.PreferredBackBufferWidth;
+
+
+ GraphicsDevice.Clear(Color.DarkRed);
+ spriteBatch.Begin();
+
+ Keys c;
+
+ // User is entering username
+ if (CreatebeingTyped == "user")
+ {
+ // Makes sure a key is being pressed
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+
+ if (previousState.GetPressedKeys().Length > 0)
+ {
+ if (previousState.GetPressedKeys()[0] != c)
+
+ {
+ // If backspace is being pressed, last entry in list is removed
+ if (c == Keys.Back)
+ {
+ if (Createusername.Count != 0)
+ Createusername.RemoveAt(Createusername.Count - 1);
+ }
+ else if (c == Keys.OemSemicolon)
+ {
+ ;
+ }
+ // No special character was pressed, character is added to list
+ else
+ {
+ c.ToString()[c.ToString().Length - 1].ToString();
+ Createusername.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+ }
+
+ }
+ else
+ {
+ // If backspace is being pressed, last entry in list is removed
+ if (c == Keys.Back)
+ {
+ if (Createusername.Count != 0)
+ Createusername.RemoveAt(Createusername.Count - 1);
+ }
+ // Tab is pressed, tpying selection goes to password field
+ else if (c == Keys.Tab)
+ {
+ Createcolors[0] = 0f;
+ Createcolors[1] = .5f;
+ Createcolors[2] = 0f;
+ Createcolors[3] = 0f;
+
+ CreatebeingTyped = "password";
+ }
+ // Special buttons ignored
+ else if (c == Keys.Right || c == Keys.Left || c == Keys.Up || c == Keys.LeftShift || c == Keys.RightShift)
+ {
+
+ ;
+ }
+ // enter is pressed, enter button is selected
+ else if (c == Keys.Enter)
+ {
+ CreatebeingTyped = "enter";
+ Createcolors[0] = 0f;
+ Createcolors[1] = 0f;
+ Createcolors[2] = 0f;
+ Createcolors[3] = 0.5f;
+ // enterable = true;
+ }
+
+ // down is pressed, typing selection goes to password entry
+ else if (c == Keys.Down)
+ {
+ beingTyped = "enter";
+ Createcolors[0] = 0f;
+ Createcolors[1] = 0.5f;
+ Createcolors[2] = 0;
+ Createcolors[3] = 0f;
+
+ CreatebeingTyped = "password";
+ }
+ // no special character was pressed, character is added to list
+ else
+ {
+ Createusername.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+
+ }
+
+
+ }
+ }
+
+ // password entry is selected
+ if (CreatebeingTyped == "password")
+ {
+ // makes sure a key is pressed
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+
+ if (previousState.GetPressedKeys().Length > 0)
+ {
+ if (previousState.GetPressedKeys()[0] != c)
+
+ {
+ // backspace is pressed, last character is removed from list
+ if (c == Keys.Back)
+ {
+ if (Createpassword.Count != 0)
+ Createpassword.RemoveAt(Createpassword.Count - 1);
+ }
+
+ // character is added to list
+ else
+ {
+
+ Createpassword.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+ }
+
+ }
+ else
+ {
+ // backspace is pressed, last character is removed from list
+ if (c == Keys.Back)
+ {
+ if (Createpassword.Count != 0)
+ Createpassword.RemoveAt(Createpassword.Count - 1);
+ }
+ // up is pressed, selection is changed to username being typed
+ else if (c == Keys.Up)
+ {
+ Createcolors[0] = 0.5f;
+ Createcolors[1] = 0f;
+ Createcolors[2] = 0f;
+ Createcolors[3] = 0f;
+
+ CreatebeingTyped = "user";
+ }
+ // ignores special characters
+ else if (c == Keys.Right || c == Keys.Left || c == Keys.Up || c == Keys.Tab || c == Keys.Down || c==Keys.LeftShift || c==Keys.RightShift)
+ {
+
+ ;
+ }
+ // enter is pressed, enter button is selected
+ else if (c == Keys.Enter)
+ {
+ CreatebeingTyped = "enter";
+ Createcolors[0] = 0f;
+ Createcolors[1] = 0f;
+ Createcolors[2] = 0f;
+ Createcolors[3] = 0.5f;
+
+ }
+
+
+ // character is added to list
+ else
+ {
+ Createpassword.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+
+ }
+ }
+ }
+
+
+ // enter button is selected
+ if (CreatebeingTyped == "enter")
+ {
+ c = Keys.None;
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+ }
+ // up is pressed, username field is selected for entry
+ if (c == Keys.Up)
+ {
+ CreatebeingTyped = "user";
+ Createcolors[0] = 0.5f;
+ Createcolors[1] = 0f;
+ Createcolors[2] = 0f;
+ Createcolors[3] = 0f;
+ Createenterable = false;
+ }
+
+ if (currentState.GetPressedKeys().Length == 0)
+ Createenterable = true;
+ if (Createenterable)
+ {
+ if (currentState.IsKeyDown(Keys.Enter))
+ {
+
+ USERNAME = String.Join(String.Empty, Createusername.ToArray());
+ PASSWORD = String.Join(String.Empty, Createpassword.ToArray());
+ // Checks that a valid username and password are given
+ if ((USERNAME.Length >= 3 && USERNAME.Length <= 40) && (PASSWORD.Length >= 8 && PASSWORD.Length <= 20))
+ {
+
+ // Code to create account
+ // Front end hashes the password with the username as a salt and stores it in database
+ if (db.createAccount(USERNAME, Account.GenerateHash(PASSWORD, USERNAME)))
+ {
+
+ _state = GameState.MainMenu;
+
+ }
+ else
+ {
+ BadLength = false;
+ usertaken = true;
+ }
+ }
+ else
+ {
+ usertaken = false;
+ BadLength = true;
+ }
+
+ }
+ }
+ }
+
+
+
+
+ string drawPassword = "";
+ for (int i = 0; i < String.Join(String.Empty, Createpassword.ToArray()).Length; i++)
+ drawPassword += "*";
+
+ spriteBatch.DrawString(font, String.Join(String.Empty, Createusername.ToArray()), new Vector2(width / 2, height / 16 + buttonSize.Y * 3), Color.White);
+ spriteBatch.DrawString(font, drawPassword, new Vector2(width / 2, height / 16 + buttonSize.Y * 5), Color.White);
+
+ spriteBatch.Draw(createaccount, new Rectangle(new Point(width / 2 - buttonSize.X, height / 16), new Point(buttonSize.X * 2, buttonSize.Y * 3)), Color.White);
+ spriteBatch.Draw(usernametitle, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 2), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + Createcolors[0]));
+ spriteBatch.Draw(passwordtitle, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 4), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + Createcolors[1]));
+
+ spriteBatch.Draw(enter, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 6), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + Createcolors[3]));
+ if(usertaken)
+ spriteBatch.Draw(usernametaken, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 8), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White );
+ if(BadLength)
+ spriteBatch.Draw(badlength, new Rectangle(new Point(width - buttonSize.X * 2, height / 16 + buttonSize.Y * 5), new Point(buttonSize.X * 2, buttonSize.Y * 4)), Color.White);
+
+
+
+
+
+ spriteBatch.End();
+ }
+ #endregion
+
+ // Logs the user in to the server
+ #region Login
+ public void Login(GameTime gameTime)
+ {
+ String USERNAME;
+ String PASSWORD;
+
+ int height = graphics.PreferredBackBufferHeight;
+ int width = graphics.PreferredBackBufferWidth;
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+ _state = GameState.MainMenu;
+
+ // Updates keyboard states for typing recognition
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ GraphicsDevice.Clear(Color.DarkRed);
+ spriteBatch.Begin(); //
+
+
+
+ // Checks if its the first time running this function, sets the selection to username input if so
+ if(firstLog)
+ {
+ if (currentState.GetPressedKeys().Length == 0)
+ {
+ beingTyped = "user";
+ firstLog = false;
+ }
+ }
+
+
+ Keys c;
+
+ // User is entering username
+ if (beingTyped == "user")
+ {
+ // Makes sure a key is being pressed
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+
+ if (previousState.GetPressedKeys().Length > 0)
+ {
+ if (previousState.GetPressedKeys()[0] != c)
+
+ {
+ // If backspace is being pressed, last entry in list is removed
+ if (c == Keys.Back)
+ {
+ if (username.Count != 0)
+ username.RemoveAt(username.Count - 1);
+ }
+
+ else if (c == Keys.OemSemicolon)
+ {
+ ;
+ }
+ // No special character was pressed, character is added to list
+ else
+ {
+ username.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+ }
+
+ }
+ else
+ {
+ // If backspace is being pressed, last entry in list is removed
+ if (c == Keys.Back)
+ {
+ if (username.Count != 0)
+ username.RemoveAt(username.Count - 1);
+ }
+ // Tab is pressed, tpying selection goes to password field
+ else if (c == Keys.Tab)
+ {
+ colors[0] = 0f;
+ colors[1] = .5f;
+ colors[2] = 0f;
+
+ beingTyped = "password";
+ }
+ // Special buttons ignored
+ else if (c == Keys.Right || c == Keys.Left || c == Keys.Up || c == Keys.Escape || c == Keys.RightShift || c == Keys.LeftShift || c == Keys.OemSemicolon)
+ {
+
+ ;
+ }
+ // enter is pressed, enter button is selected
+ else if (c == Keys.Enter)
+ {
+ beingTyped = "enter";
+ colors[0] = 0f;
+ colors[1] = 0f;
+ colors[2] = 0.5f;
+
+ }
+
+ // down is pressed, typing selection goes to password entry
+ else if (c == Keys.Down)
+ {
+ colors[0] = 0f;
+ colors[1] = .5f;
+ colors[2] = 0f;
+
+ beingTyped = "password";
+ }
+ // no special character was pressed, character is added to list
+ else
+ {
+ username.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+
+ }
+
+
+ }
+ }
+
+
+ // User is entering password
+ if (beingTyped == "password") {
+ // makes sure a key is pressed
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+
+ if (previousState.GetPressedKeys().Length > 0)
+ {
+ if (previousState.GetPressedKeys()[0] != c)
+
+ {
+ // backspace is pressed, last character is removed from list
+ if (c == Keys.Back)
+ {
+ if (password.Count != 0)
+ password.RemoveAt(password.Count - 1);
+ }
+
+ // character is added to list
+ else
+ {
+ password.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+ }
+
+ }
+ else
+ {
+ // backspace is pressed, last character is removed from list
+ if (c == Keys.Back)
+ {
+ if (password.Count != 0)
+ password.RemoveAt(password.Count - 1);
+ }
+ // ignores special characters
+ else if (c == Keys.Tab)
+ {
+ ;
+ }
+
+ // ignores special characters
+ else if (c == Keys.Right || c == Keys.Left || c == Keys.Down || c == Keys.Escape || c == Keys.RightShift || c == Keys.LeftShift || c == Keys.OemSemicolon)
+ ;
+ // up is pressed, selection is changed to username being typed
+ else if (c == Keys.Up)
+ {
+
+ colors[0] = 0.5f;
+ colors[1] = 0f;
+ colors[2] = 0f;
+
+ beingTyped = "user";
+
+ }
+ // enter is pressed, enter button is selected
+ else if (c == Keys.Enter )
+ {
+ beingTyped = "enter";
+ colors[0] = 0f;
+ colors[1] = 0f;
+ colors[2] = 0.5f;
+ }
+ // character is added to list
+ else
+ {
+ password.Add(c.ToString()[c.ToString().Length - 1].ToString());
+ }
+ }
+
+
+ }
+ }
+ // enter button is selected
+ if (beingTyped == "enter")
+ {
+ c = Keys.None;
+ if (currentState.GetPressedKeys().Length > 0)
+ {
+ c = currentState.GetPressedKeys()[0];
+ }
+ // up is pressed, username field is selected for entry
+ if (c == Keys.Up)
+ {
+ beingTyped = "user";
+ colors[0] = 0.5f;
+ colors[1] = 0f;
+ colors[2] = 0f;
+ enterable = false;
+ }
+
+ if (currentState.GetPressedKeys().Length == 0)
+ enterable = true;
+ if(enterable)
+ {
+ if (currentState.IsKeyDown(Keys.Enter))
+ {
+ USERNAME = String.Join(String.Empty, username.ToArray());
+ PASSWORD = String.Join(String.Empty, password.ToArray());
+ // Code to Log in
+ if (db.login(USERNAME, Account.GenerateHash(PASSWORD,USERNAME)))
+ {
+
+ LOGGED_IN = true;
+ Logged_Username = USERNAME;
+
+ _state = GameState.MainMenu;
+
+
+ }
+ else
+ {
+ incorrectLogin = true;
+ }
+
+ }
+ }
+ }
+
+ if (incorrectLogin)
+ {
+ spriteBatch.Draw(incorrect, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 8), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White);
+
+ }
+
+
+ if(LOGGED_IN)
+ _state = GameState.MainMenu;
+
+
+ string drawPassword = "";
+ for (int i = 0; i < String.Join(String.Empty, password.ToArray()).Length; i++)
+ drawPassword += "*";
+
+ spriteBatch.DrawString(font, String.Join(String.Empty, username.ToArray()), new Vector2(width / 2, height / 16 + buttonSize.Y * 3), Color.White);
+ spriteBatch.DrawString(font,drawPassword, new Vector2(width / 2, height / 16 + buttonSize.Y * 5), Color.White);
+
+ spriteBatch.Draw(logintitle, new Rectangle(new Point(width / 2 - buttonSize.X, height / 16), new Point(buttonSize.X * 2, buttonSize.Y * 3)), Color.White);
+ spriteBatch.Draw(usernametitle, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 2), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + colors[0]));
+ spriteBatch.Draw(passwordtitle, new Rectangle(new Point(width/ 2 - buttonSize.X*2, height/16+buttonSize.Y*4), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + colors[1]));
+
+ spriteBatch.Draw(enter, new Rectangle(new Point(width / 2 - buttonSize.X * 2, height / 16 + buttonSize.Y * 6), new Point(buttonSize.X * 2, buttonSize.Y * 2)), Color.White * (.5f + colors[2]));
+
+
+ spriteBatch.End();
+
+
+
+
+ base.Update(gameTime);
+ }
+ #endregion
+ // Called when program is first started
+ protected override void Initialize()
+ {
CreateTiles();
+ CreateNightTiles();
base.Initialize();
+ db.Initialize();
}
-
+ #region LoadContent
protected override void LoadContent()
{
+ // load sound effect
+ lobby_music = Content.Load("Audio/Lobby");
+
+
+ jumpSound = Content.Load("Audio/Jump");
+ deathSound = Content.Load("Audio/Heartbeat");
+ victorySound = Content.Load("Audio/victory");
+ soundEffects = new Dictionary();
+
+
+ soundEffects.Add("Jump", jumpSound);
+ soundEffects.Add("Death", deathSound);
+ soundEffects.Add("Victory", victorySound);
+ MediaPlayer.Volume = 0.99f;
+
+ MediaPlayer.Play(lobby_music);
+
+ paused = Content.Load("pause");
+ buttonSize = new Point(graphics.PreferredBackBufferWidth * 5 / 32, graphics.PreferredBackBufferHeight * 5/72);
+ gameover = Content.Load("gameover");
+ font = Content.Load("font");
+ levelcompleted = Content.Load("levelcompleted");
+ // Login Page
+ usernametitle = Content.Load("usernametitle");
+ passwordtitle = Content.Load("passwordtitle");
+ logintitle = Content.Load("logintitle");
+ enter = Content.Load("enter");
+
+ leaderboards = Content.Load("leaderboards");
+ leaderboards2 = Content.Load("leaderboards2");
+
+ createaccount = Content.Load("createaccount");
+ confirmpassword = Content.Load("confirmpassword");
+
int screenWidth = graphics.PreferredBackBufferWidth;
int screenHeight = graphics.PreferredBackBufferHeight;
buttonSize = new Point(graphics.PreferredBackBufferWidth * 5 / 32, graphics.PreferredBackBufferHeight * 5/72);
@@ -106,25 +983,39 @@ protected override void LoadContent()
titlescreen = Content.Load("titlescreen");
titlescreen_a = Content.Load("titlescreen(1)");
+ instructs = Content.Load("instructs");
// Buttons
+ createaccountbutton = Content.Load("createaccountbutton");
continueWithoutSaving = Content.Load("continuewithoutsaving");
exit = Content.Load("exit");
instructions = Content.Load("instructions");
- multiplayer = Content.Load("multiplayer");
+ multiplayer = Content.Load("log");
newGame = Content.Load("newgame");
+ Continue = Content.Load("continue");
returnToMainMenu = Content.Load("returntomainmenu");
saveContinue = Content.Load("savecontinue");
singePlayer = Content.Load("singleplayer");
+ viewLeaderboards = Content.Load("viewleaderboards");
startGame = Content.Load("startgame");
tryAgain = Content.Load("tryagain");
healthBar = new HealthBar(Content.Load("Health"),new Vector2(400,400),100);
healthTexture = Content.Load("Health");
+
+ incorrect = Content.Load("incorrect");
+ badlength = Content.Load("badlength");
+ usernametaken = Content.Load("usernametaken");
+
font = Content.Load("demo");
// background
// so once we scroll through one background we go onto the next
- scrolling1 = new Scrolling(Content.Load("background"), new Rectangle(0, 0, screenWidth, screenHeight));
- scrolling2 = new Scrolling(Content.Load("background"), new Rectangle(screenWidth, 0, screenWidth, screenHeight));
+ scrolling1 = new Scrolling(Content.Load("bigbackground"), new Rectangle(0, 0, screenWidth, screenHeight));
+ scrolling2 = new Scrolling(Content.Load("bigbackground"), new Rectangle(screenWidth, 0, screenWidth, screenHeight));
+
+ nightscrolling1 = new Scrolling(Content.Load("nightbackground"), new Rectangle(0, 0, screenWidth, screenHeight));
+ nightscrolling2 = new Scrolling(Content.Load("nightbackground"), new Rectangle(screenWidth, 0, screenWidth, screenHeight));
+
+ finishline = Content.Load("finishline");
// loading tile textures here
@@ -132,12 +1023,16 @@ protected override void LoadContent()
{
Tile.LoadContent(Content, 0);
}
-
+ foreach(var _TILE in nightTiles)
+ {
+ Tile.LoadContent(Content, 0);
+ }
+ Door.LoadContent(Content,0);
- // initiating menu
- m = new Menu(GraphicsDevice);
+
+
// adding animation set
// will not be using idle
@@ -148,7 +1043,7 @@ protected override void LoadContent()
{ "WalkLeft", new Animation(Content.Load("left"),8)},
{ "Idle", new Animation(Content.Load("idle"),5)},
{ "Death", new Animation(Content.Load("death"),8)},
- { "attack",new Animation(Content.Load("attack"),6)}
+ { "attack",new Animation(Content.Load("attack"),7)}
};
var _enemy_animations = new Dictionary()
{ // enemy melee attacks
@@ -159,47 +1054,70 @@ protected override void LoadContent()
{ "enemyattackL", new Animation(Content.Load("enemyattackL"),5) }
};
+
_sprites = new List();
- Player main_player = new Player(animations) { Position = new Vector2((int)(.0732 * screenWidth)
+
+ Player main_player = new Player(animations,graphics) { Position = new Vector2((int)(0)
, (int)((0.858) * screenHeight)), };
+
+
+
_sprites.Add(main_player);
- enemy = new Enemy(_enemy_animations)
+ // initializes enemies positions
+ enemy = new Enemy(_enemy_animations,graphics)
{
- Position = new Vector2(1000,(int)((0.818) * screenHeight))
+ Position = new Vector2(700,(int)((0.838) * screenHeight))
};
-
+ enemy2 = new Enemy(_enemy_animations, graphics)
+ {
+ Position = new Vector2(1200, (int)((0.838) * screenHeight))
+
+ };
- //
+ enemy3 = new Enemy(_enemy_animations, graphics)
+ {
+ Position = new Vector2(2000, (int)((0.838) * screenHeight))
+
+ };
+
+
currentState = Keyboard.GetState();
previousState = currentState;
}
+ #endregion
-
+ // used to remove content from RAM, we do not need to do this for our game
protected override void UnloadContent()
{
}
+
+ #region Main Menu
+ // Displays the main menu
public void menu()
{
// Sets the background color
GraphicsDevice.Clear(Color.Silver);
-
- float[] selected = new float[4];
+
+ // List to set opacity of each menu object
+ float[] selected = new float[6];
+
+ // up is pressed, menu selection moves up
if (previousState.IsKeyUp(Keys.Up) && currentState.IsKeyDown(Keys.Up))
{
select--;
}
-
+ // down is pressed, menu selection moves down
if (previousState.IsKeyUp(Keys.Down) && currentState.IsKeyDown(Keys.Down))
{
select++;
@@ -207,12 +1125,13 @@ public void menu()
-
- if (select > 3)
+ // keeps menu selection within bounds, circular connection
+ if (select > 5)
select = 0;
if (select < 0)
- select = 3;
+ select = 5;
+ // sets opacities based on menu selection
switch (select)
{
case 0:
@@ -220,60 +1139,201 @@ public void menu()
selected[1] = .5f;
selected[2] = .5f;
selected[3] = .5f;
+ selected[4] = .5f;
+ selected[5] = .5f;
break;
case 1:
selected[0] = .5f;
selected[1] = 1f;
selected[2] = .5f;
selected[3] = .5f;
+ selected[4] = .5f;
+ selected[5] = .5f;
break;
case 2:
selected[0] = .5f;
selected[1] = .5f;
- selected[2] = 1f;
+ selected[2] = 1f;
+ selected[3] = .5f;
+ selected[4] = .5f;
+ selected[5] = .5f;
+ break;
+ case 3:
+ selected[0] = .5f;
+ selected[1] = .5f;
+ selected[2] = .5f;
+ selected[3] = 1f;
+ selected[4] = .5f;
+ selected[5] = .5f;
+ break;
+ case 4:
+ selected[0] = .5f;
+ selected[1] = .5f;
+ selected[2] = .5f;
selected[3] = .5f;
+ selected[4] = 1f;
+ selected[5] = .5f;
break;
- case 3:
+ case 5:
selected[0] = .5f;
selected[1] = .5f;
selected[2] = .5f;
- selected[3] = 1f;
+ selected[3] = .5f;
+ selected[4] = .5f;
+ selected[5] = 1f;
break;
}
-
int height = graphics.PreferredBackBufferHeight;
int width = graphics.PreferredBackBufferWidth;
int initial = height /5;
- spriteBatch.Draw(titlescreen, new Rectangle(width / 2 - width/4, height/12, width/2, height/2), Color.White);
+
+ // enter is pressed, does action depending on which menu item is selected
+ if (previousState.IsKeyUp(Keys.Enter) && currentState.IsKeyDown(Keys.Enter))
+ {
+
+
+ if (select == 1)
+ _state = GameState.Login;
+ if (select == 2)
+ {
+ CreatebeingTyped = "user";
+ Createusername.Clear();
+ Createpassword.Clear();
+ Createenterable = false;
+ _state = GameState.CreateAccount;
+ }
+ if (select == 3)
+ _state = GameState.Leaderboards;
+ if (select == 4)
+ _state = GameState.Instructions;
+ if (select == 5)
+ Exit();
+ }
+
+
+
+
+ // Draws the game title
+ spriteBatch.Draw(titlescreen, new Rectangle(width / 4, height/12, width/2, height/2), Color.White);
+ // Draws the menu options
+ spriteBatch.Draw(singePlayer, new Rectangle(new Point(width / 2 - buttonSize.X/2, initial + buttonSize.Y + height/20), buttonSize), Color.White * selected[0]);
+
+ // not logged in, shows all menu options
+ if(!LOGGED_IN)
+ {
+ spriteBatch.Draw(multiplayer, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 2+height/19), buttonSize), Color.White * selected[1]);
+ spriteBatch.Draw(createaccountbutton, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 3 + height / 18), buttonSize), Color.White * selected[2]);
+ spriteBatch.Draw(viewLeaderboards, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 4 + height / 17), buttonSize), Color.White * selected[3]);
+ spriteBatch.Draw(instructions, new Rectangle(new Point(width/ 2 - buttonSize.X / 2, initial + buttonSize.Y * 5+height/16), buttonSize), Color.White * selected[4]);
+ spriteBatch.Draw(exit, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y *6+ height/15), buttonSize), Color.White * selected[5]);
+
+ }
+ // logged in, does NOT show "Log in" or "create account" button
+ else
+ {
+ // adjust menu selection for missing entries
+ if(select==1)
+ select = 3;
+ if(select == 2)
+ select = 0;
- spriteBatch.Draw(singePlayer, new Rectangle(new Point(width / 2 - 150, initial + buttonSize.Y + height/20), buttonSize), Color.White * selected[0]);
- spriteBatch.Draw(multiplayer, new Rectangle(new Point(width / 2 - 150, initial + buttonSize.Y * 2+height/18), buttonSize), Color.White * selected[1]);
- spriteBatch.Draw(instructions, new Rectangle(new Point(width/ 2 - 150, initial + buttonSize.Y * 3+height/16), buttonSize), Color.White * selected[2]);
- spriteBatch.Draw(exit, new Rectangle(new Point(width / 2 - 150, initial + buttonSize.Y *4+ height/15), buttonSize), Color.White * selected[3]);
+
+ spriteBatch.Draw(viewLeaderboards, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 2 + height / 19), buttonSize), Color.White * selected[3]);
+ spriteBatch.Draw(instructions, new Rectangle(new Point(width/ 2 - buttonSize.X / 2, initial + buttonSize.Y * 3+height/18), buttonSize), Color.White * selected[4]);
+ spriteBatch.Draw(exit, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y *4+ height/17), buttonSize), Color.White * selected[5]);
+ }
}
+ #endregion
- private void CreateTiles()
+
+ // Creates tiles for level 2
+ private void CreateNightTiles()
+ {
+ nightTiles.Clear();
+ int screenWidth = graphics.PreferredBackBufferWidth;
+ int screenHeight = graphics.PreferredBackBufferHeight;
+
+ int i = 1;
+ for (; i < 21; i++)
+ {
+ nightTiles.Add(new Tile(new Vector2(screenWidth *0.1f*i, (float)(screenHeight * 0.75))));
+ }
+ finish_line2 = new Door(new Vector2(screenWidth * 0.1f * (i+1), (float)(screenHeight * 0.814)));
+
+ }
+
+ // called when user dies
+ public void Gameover(GameTime gameTime)
{
+ //resets tiles and finish line
+ CreateNightTiles();
+ CreateTiles();
+ finish_line = new Door(new Vector2(graphics.PreferredBackBufferWidth * 0.2f * (10 + 1), (float)(graphics.PreferredBackBufferHeight * 0.814)));
+ finish_line2 = new Door(new Vector2(graphics.PreferredBackBufferWidth * 0.1f * (20 + 1), (float)(graphics.PreferredBackBufferHeight * 0.814)));
+
+ // resets all enemies and player values
+ deathCounter = 0;
+ _sprites[0].Reset();
+ enemy.Reset();
+ enemy2.Reset();
+ enemy3.Reset();
+ enemy._position.X = 2000;
+ enemy2._position.X = 1000;
+ elapsed_time = 0f;
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ // pressing escape takes user back to main menu
+ if((currentState.IsKeyDown(Keys.Escape) && (previousState.IsKeyUp(Keys.Escape))))
+ _state = GameState.MainMenu;
+
+ GraphicsDevice.Clear(Color.White);
+ spriteBatch.Begin();
+
+ spriteBatch.Draw(gameover, new Rectangle(0,0,graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
+
+ spriteBatch.End();
+
+ base.Draw(gameTime);
+ }
+
+ // creates tiles for level 1
+ private void CreateTiles()
+ {
+ tiles.Clear();
int screenWidth = graphics.PreferredBackBufferWidth;
int screenHeight = graphics.PreferredBackBufferHeight;
- // float xPosition = Shared.random.Next(200, screenWidth/2+200);
- tiles.Add(new Tile(new Vector2(200, (float)(screenHeight*0.75))));
- tiles.Add(new Tile(new Vector2(500, (float)(screenHeight*0.75))));
- tiles.Add(new Tile(new Vector2(900, (float)(screenHeight*0.75))));
+ int i = 0;
+ for (; i < 10; i++)
+ {
+ tiles.Add(new Tile(new Vector2(screenWidth *0.2f*i, (float)(screenHeight * 0.75))));
+ }
+ finish_line = new Door(new Vector2(screenWidth * 0.2f * (i+1), (float)(screenHeight * 0.814)));
+
}
protected override void Update(GameTime gameTime)
{
+ if (_state!=GameState.MainMenu)
+ {
+ MediaPlayer.Pause();
+ }
+ if (_state == GameState.MainMenu && MediaPlayer.State==MediaState.Paused)
+ {
+ MediaPlayer.Resume();
+ }
+
+ base.Update(gameTime);
+ mouse = Mouse.GetState();
- base.Update(gameTime);
switch (_state)
{
case GameState.MainMenu:
@@ -282,164 +1342,553 @@ protected override void Update(GameTime gameTime)
case GameState.Level1:
UpdateLevel1(gameTime);
break;
+ case GameState.Login:
+ Login(gameTime);
+ break;
}
}
- public float drawTitle(float i)
- {
-
- spriteBatch.Draw(titlescreen, titleScreen, Color.White);
- spriteBatch.Draw(titlescreen_a, titleScreen, Color.White * i);
- if (i > 1f || i < 0f)
- opacDirection *= -1;
-
- return i + .01f * opacDirection;
-
- }
+
+ // draws the main menu
protected void DrawMainMenu(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(); //
-
+
menu();
spriteBatch.End(); //
}
+
+ // draws level 1
protected void DrawLevel1(GameTime gameTime)
{
+ _previousState = GameState.Level1;
+ GraphicsDevice.Clear(Color.Transparent);
+
+ int finish = 400;
spriteBatch.Begin();
+
scrolling1.Draw(spriteBatch);
scrolling2.Draw(spriteBatch);
spriteBatch.Draw(healthTexture, healthRectangle, Color.DarkSlateBlue);
- // spriteBatch.DrawString(font, elapsed_time.ToString,time,Color.White);
+
foreach (var sprite in _sprites)
sprite.Draw(spriteBatch);
+
foreach (var tl in tiles)
{
tl.Draw(spriteBatch);
}
+ finish_line.Draw(spriteBatch);
enemy.Draw(spriteBatch);
-
+ enemy2.Draw(spriteBatch);
+ spriteBatch.DrawString(font, "time: " + Math.Round((elapsed_time/1000),1) + "",
+ new Vector2((float)(graphics.PreferredBackBufferWidth*0.8), (float)(graphics.PreferredBackBufferHeight * 0.05)), Color.Beige);
spriteBatch.End();
+
base.Draw(gameTime);
}
void UpdateMainMenu(GameTime gameTime)
{
- // menu control
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- if (Keyboard.GetState().IsKeyDown(Keys.Enter) && select == 0)
- _state = GameState.Level1;
+
+
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ // Single player is selected, all values are set to initial values for gameplay
+ if (currentState.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter)&& select == 0)
+ {
+ _sprites[0].Reset();
+ enemy.Reset();
+ enemy2.Reset();
+ enemy._position.X = 2000;
+ enemy2._position.X = 1000;
+ elapsed_time = 0f;
+ deathCounter = 0;
+
+ CreateNightTiles();
+ CreateTiles();
+ finish_line = new Door(new Vector2(graphics.PreferredBackBufferWidth * 0.2f * (10 + 1), (float)(graphics.PreferredBackBufferHeight * 0.814)));
+ finish_line2 = new Door(new Vector2(graphics.PreferredBackBufferWidth * 0.1f * (20 + 1), (float)(graphics.PreferredBackBufferHeight * 0.814)));
+
+ // user is not logged in, taken straigt to gameplay
+ if (!LOGGED_IN)
+ _state = GameState.Level1;
+ // user is logged in, taken to continue/new game page
+ else
+ {
+ _state = GameState.Continue;
+ }
+ }
+
+
+
controller = GamePad.GetState(PlayerIndex.One);
keyboard = Keyboard.GetState();
- previousState = currentState;
- currentState = Keyboard.GetState();
+
+
base.Update(gameTime);
+
}
+ // asks user to continue or start new game if logged in
+ public void ContinueGame(GameTime gameTime)
+ {
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ if(currentState.IsKeyDown(Keys.Escape) && previousState.IsKeyUp(Keys.Escape))
+ _state = GameState.MainMenu;
+
+ // used for menu item opacities
+ float[] selected = new float[2];
+
+ // up is pressed, menu selection moves up
+ if (previousState.IsKeyUp(Keys.Up) && currentState.IsKeyDown(Keys.Up))
+ {
+ select--;
+ }
+ // down is pressed, menu item moves down
+ if (previousState.IsKeyUp(Keys.Down) && currentState.IsKeyDown(Keys.Down))
+ {
+ select++;
+ }
+ // keeps seletion within bounds
+ if (select < 0)
+ select = 1;
+ if (select >1 )
+ select = 0;
+
+ // sets opacity
+ if(select == 0)
+ {
+ selected[0] = 1f;
+ selected[1] = .5f;
+ }
+ if(select == 1)
+ {
+ selected[0] = .5f;
+ selected[1] = 1f;
+ }
+
+ // enter is pressed
+ if (currentState.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter))
+ {
+ // Continue
+ if (select == 0)
+ {
+ string level = db.continueGame(Logged_Username)[0][0];
+ switch(level) {
+
+ case "1":
+ _state = GameState.Level1;
+ break;
+ case "2":
+ enemy3._position.X = 1500;
+ _state = GameState.Level2;
+ break;
+ default:
+ _state = GameState.Level1;
+ break;
+ }
+ }
+
+ // New game
+ else{
+ db.newGame(Logged_Username);
+ _state = GameState.Level1;
+ }
+ }
+
+ int width = graphics.PreferredBackBufferWidth;
+ int height = graphics.PreferredBackBufferHeight;
+ int initial = height / 5;
+ GraphicsDevice.Clear(Color.DarkGray);
+ spriteBatch.Begin();
+
+ spriteBatch.Draw(Continue, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 2+height/19), buttonSize), Color.White*selected[0]);
+ spriteBatch.Draw(newGame, new Rectangle(new Point(width / 2 - buttonSize.X / 2, initial + buttonSize.Y * 3 + height / 18), buttonSize), Color.White * selected[1]);
+
+
+ spriteBatch.End();
+
+ base.Update(gameTime);
+ }
+
+ // updates level 1 values
void UpdateLevel1(GameTime gameTime)
{
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
// level 1 action
// enemies & objects
- elapsed_time = gameTime.TotalGameTime.Seconds;
- Console.WriteLine(elapsed_time);
+ if (_sprites[0].Health < 100)
+ {
+ deathCounter++;
+ if (deathCounter >= 30)
+ _state = GameState.GameOver;
+ }
+
+ // player finishes level
+ if (_sprites[0].hasEntered(finish_line,soundEffects))
+ {
+ // score is recored if logged in
+ if(LOGGED_IN && firstBeaten)
+ {
+ db.completeLevelForFirstTime(1, Logged_Username, (int)(100000f - elapsed_time/10f));
+ db.saveGame(Logged_Username, 1);
+ firstBeaten = false;
+ }
+ // taken to level completed screen
+ _state = GameState.LevelCompleted;
+
+ }
+
+ int touchCount = 0;
+
+ elapsed_time += gameTime.ElapsedGameTime.Milliseconds;
+
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
+
+ if ((currentState.IsKeyDown(Keys.Escape) && (previousState.IsKeyUp(Keys.Escape))))
+ _state = GameState.Pause;
{
-
+ touchCount = 0;
- foreach (var tile in tiles)
+ // Background scroll
+ for (int i = 0; i < 10; i++)
{
-
-
- _sprites[0].Update(gameTime, _sprites);
- enemy.Update(gameTime,_sprites[0]);
scrolling1.Update((int)_sprites[0].Xtrans);
scrolling2.Update((int)_sprites[0].Xtrans);
- tile.Update(_sprites[0].Xtrans);
- if (scrolling1.rectangle.X + scrolling1.rectangle.Width <= 0)
+ }
+ finish_line.Update(_sprites[0].Xtrans*3);
+ foreach (var tile in tiles)
+ {
+
+ // updates player and enemy positions
+ if(_sprites[0].Health == 100)
+ _sprites[0].Update(gameTime, _sprites,soundEffects);
+ enemy.Update(gameTime,_sprites[0], soundEffects);
+ enemy2.Update(gameTime, _sprites[0], soundEffects);
+
+
+ healthBar.health = _sprites[0].Health;
+ if (_sprites[0].Health < 100)
+ _sprites[0].Xtrans = 0;
{
- scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.rectangle.Width;
+ tile.Update(_sprites[0].Xtrans);
+ // user is halfway, tiles and enemies move faster to make it more smooth
+ if (_sprites[0].isHalfway && _sprites[0].Health == 100)
+ {
+ tile.Update(_sprites[0].Xtrans);
+ tile.Update(_sprites[0].Xtrans);
+
+ // Adjusts enemies better
+ enemy._position.X -= .75f;
+ enemy2._position.X-=.75f;
+
+
+
+ }
+
+ // Scrolls the background with player movement
+ if (scrolling1.rectangle.X + scrolling1.rectangle.Width <= 0)
+ {
+ scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.rectangle.Width;
+ }
+ if (scrolling2.rectangle.X + scrolling2.rectangle.Width <= 0)
+ {
+ scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.rectangle.Width;
+ }
}
- if (scrolling2.rectangle.X + scrolling2.rectangle.Width <= 0)
+
+ // Used for attacking (NOT USED IN OUR GAME)
+ if (Keyboard.GetState().IsKeyDown(Keys.E))
{
- scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.rectangle.Width;
+ _sprites[0].Attack(enemy);
}
+
+ // user is on a tile
if (_sprites[0].IsTouching(tile, _sprites[0]))
{
-
- Console.Write("Check");
- Vector2 vec = new Vector2(1, tile.position.Y -160f);
- // _sprites[0].Velocity
- // = vec;
-
- _sprites[0]._position.Y = tile.position.Y - 56f;
-
+ touchCount++;
}
- /* sprite._position.Y = tile.position.Y + sprite._texture.Height;
- if (!sprite.IsTouching(tile))
- {
+
- tile.Update(sprite.Xtrans);
- }
- else
- {
- }*/
+ // Checks if player is hitting anything
+ // If not, he fails
+ if (_sprites[0].jumping == false)
+ {
+ if (_sprites[0].Contact == false)
+ // fall speed
+ _sprites[0]._position.Y += graphics.PreferredBackBufferHeight/600f;
+ }
+
+ // player is on a tile, doesnt fall past tile
+ if (touchCount > 0)
+ if (_sprites[0]._position.Y > graphics.PreferredBackBufferHeight * .7f)
+ {
+ _sprites[0]._position.Y = graphics.PreferredBackBufferHeight * .7f;
+ _sprites[0].grounded = true;
+ }
+ // Player must stop falling when he reaches the ground
+ if (_sprites[0].Position.Y > graphics.PreferredBackBufferHeight * .87f)
+ {
+ _sprites[0]._position.Y = graphics.PreferredBackBufferHeight * .87f;
+ _sprites[0].grounded = true;
+ }
+
}
+
healthRectangle = new Rectangle(150,50,healthBar.health,60);
}
+
+
+
base.Update(gameTime);
}
+ public void Level2(GameTime gameTime)
+ {
+ // Updates Keyboards
+ previousState = currentState;
+ currentState = Keyboard.GetState();
+
+ elapsed_time += gameTime.ElapsedGameTime.Milliseconds;
+
+ // Sets state that the pause menu will return to
+ _previousState = GameState.Level2;
+
+ if (currentState.IsKeyDown(Keys.Escape) && previousState.IsKeyUp(Keys.Escape))
+ _state = GameState.Pause;
+
+ GraphicsDevice.Clear(Color.Transparent);
+
+ // Player enters the finish line
+ if (_sprites[0].hasEntered(finish_line2, soundEffects))
+ {
+ CreateNightTiles();
+ enemy._position.X = 2000;
+ enemy2._position.X = 1000;
+ enemy3._position.X = 1500;
+
+ _state = GameState.Level2;
+
+
+ // Logs score to leaderboard if player is logged in
+ if (LOGGED_IN && firstBeaten)
+ {
+ db.completeLevelForFirstTime(2, Logged_Username, (int)(100000f - elapsed_time / 10f));
+ db.saveGame(Logged_Username, 2);
+ firstBeaten = false;
+
+ }
+ _state = GameState.LevelCompleted;
+ spriteBatch.Begin();
+ spriteBatch.End();
+ }
+
+ // Player takes damage, dies
+ if (_sprites[0].Health < 100)
+ _state = GameState.GameOver;
+
+ int touchCount = 0;
+ // Updates the player and enemies movement
+ for(int i = 0; i < 10; i++)
+ {
+ _sprites[0].Update(gameTime, _sprites, soundEffects);
+ enemy.Update(gameTime, _sprites[0], soundEffects);
+ enemy2.Update(gameTime, _sprites[0], soundEffects);
+ enemy3.Update(gameTime, _sprites[0], soundEffects);
+ }
+ // Scrolls the background
+ for (int i = 0; i < 10; i++)
+ {
+ nightscrolling1.Update((int)_sprites[0].Xtrans);
+ nightscrolling2.Update((int)_sprites[0].Xtrans);
+ }
+ finish_line2.Update(_sprites[0].Xtrans * 3);
+
+ foreach (var tile in nightTiles)
+ {
+
+ // Player jumps onto platform
+ if (_sprites[0].IsTouching(tile, _sprites[0]))
+ {
+ touchCount++;
+ }
+
+ // Player is halfway in the screen
+ // enemies and tiles move a bit faster to make it more smooth
+ if (_sprites[0].isHalfway && _sprites[0].Health == 100)
+ {
+ tile.Update(_sprites[0].Xtrans);
+
+ enemy._position.X -= .75f/2;
+ enemy2._position.X-=.75f/2;
+ enemy3._position.X-= .75f/2;
+
+
+ }
+
+
+
+ healthBar.health = _sprites[0].Health;
+
+ tile.Update(_sprites[0].Xtrans);
+ if (_sprites[0].isHalfway)
+ {
+ tile.Update(_sprites[0].Xtrans);
+ tile.Update(_sprites[0].Xtrans);
+
+ }
+ if (nightscrolling1.rectangle.X + nightscrolling1.rectangle.Width <= 0)
+ {
+ nightscrolling1.rectangle.X = nightscrolling2.rectangle.X + nightscrolling2.rectangle.Width;
+ }
+ if (nightscrolling2.rectangle.X + nightscrolling2.rectangle.Width <= 0)
+ {
+ nightscrolling2.rectangle.X = nightscrolling1.rectangle.X + nightscrolling1.rectangle.Width;
+ }
+
+ // gravity doesnt affect player while he is jumping
+ if (_sprites[0].jumping == false)
+ {
+ if (_sprites[0].Contact == false)
+ // fall speed
+ _sprites[0]._position.Y += graphics.PreferredBackBufferHeight/1200f;
+ }
+
+ // player is on a tile
+ if (touchCount > 0)
+ if (_sprites[0]._position.Y > graphics.PreferredBackBufferHeight * .7f)
+ {
+ _sprites[0]._position.Y = graphics.PreferredBackBufferHeight * .7f;
+ _sprites[0].grounded = true;
+ }
+
+ // Player must stop falling when he reaches the ground
+ if (_sprites[0].Position.Y > graphics.PreferredBackBufferHeight * .87f)
+ {
+ _sprites[0]._position.Y = graphics.PreferredBackBufferHeight * .87f;
+ _sprites[0].grounded = true;
+ }
+
+
+ }
+
+
+ spriteBatch.Begin();
+
+ nightscrolling1.Draw(spriteBatch);
+ nightscrolling2.Draw(spriteBatch);
+
+ spriteBatch.Draw(healthTexture, healthRectangle, Color.DarkSlateBlue);
+
+ foreach (var sprite in _sprites)
+ sprite.Draw(spriteBatch);
+
+ foreach (var tl in nightTiles)
+ {
+ tl.Draw(spriteBatch);
+ }
+ finish_line2.Draw(spriteBatch);
+ enemy.Draw(spriteBatch);
+ enemy2.Draw(spriteBatch);
+ enemy3.Draw(spriteBatch);
+ spriteBatch.DrawString(font, "time: " + Math.Round((elapsed_time/1000),1) + "",
+ new Vector2((float)(graphics.PreferredBackBufferWidth*0.8), (float)(graphics.PreferredBackBufferHeight * 0.05)), Color.Beige);
+
+ spriteBatch.End();
+
+
+
+ base.Draw(gameTime);
+
+
+ }
+
+ // Main function that draws/run the current state
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
switch (_state)
{
case GameState.MainMenu:
- DrawMainMenu(gameTime);
+ DrawMainMenu(gameTime);
+ break;
+ case GameState.Login:
+ Login(gameTime);
+ break;
+ case GameState.CreateAccount:
+ CreateAccount(gameTime);
+ break;
+ case GameState.Leaderboards:
+ Leaderboards(gameTime);
break;
case GameState.Level1:
DrawLevel1(gameTime);
break;
+ case GameState.Level2:
+ Level2(gameTime);
+ break;
+ case GameState.Instructions:
+ Instructions(gameTime);
+ break;
case GameState.Finish:
// DrawFinish(gameTime);
break;
+ case GameState.LevelCompleted:
+ LevelCompleted(gameTime);
+ break;
+ case GameState.GameOver:
+ Gameover(gameTime);
+ break;
+ case GameState.Pause:
+ Pause(gameTime);
+ break;
+ case GameState.Continue:
+ ContinueGame(gameTime);
+ break;
+
}
}
+
+
}
}
diff --git a/Platformer/Menu.cs b/Platformer/Menu.cs
index 11d1d2c..090785e 100644
--- a/Platformer/Menu.cs
+++ b/Platformer/Menu.cs
@@ -31,10 +31,5 @@ public Menu(GraphicsDevice g)
spritebatch = new SpriteBatch(g);
}
- public void draw()
- {
- // spritebatch.Draw(singleplayer, new Rectangle(0, 0, 100, 100), Color.AliceBlue);
- }
-
}
}
diff --git a/Platformer/Platformer.csproj b/Platformer/Platformer.csproj
index bbe9555..b594c6a 100644
--- a/Platformer/Platformer.csproj
+++ b/Platformer/Platformer.csproj
@@ -1,5 +1,5 @@
-
+
Debug
@@ -13,10 +13,10 @@
Platformer
512
Windows
- v4.5
+ v4.6.1
false
- C:\Users\Adam\Desktop\
+ C:\Users\austi\Desktop\HERE YOU GO BRO\
true
Disk
false
@@ -62,8 +62,13 @@
false
+
+ true
+
+
+
@@ -74,13 +79,33 @@
+
+
+ ..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll
+
+
+ ..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll
+
+
$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll
+
+ ..\packages\MySql.Data.8.0.16\lib\net452\MySql.Data.dll
+
+
+
+
+
+
+
+
+
+
@@ -90,6 +115,7 @@
+
diff --git a/Platformer/Player.cs b/Platformer/Player.cs
index d5692bc..19d54d3 100644
--- a/Platformer/Player.cs
+++ b/Platformer/Player.cs
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
@@ -13,11 +14,20 @@ class Player
{
#region Fields
- protected AnimationManager _animationManager;
- protected Dictionary _animations;
+ GraphicsDeviceManager graphics; // dimensions & scaling
- public Vector2 _position;
+ public AnimationManager _animationManager; // manage animation
+
+ public Dictionary _animations; //store dict if animations accessed by key
+
+ public Vector2 _position ;
+
+ private Boolean isAttacking;
+
+ public Boolean IsAttacking { get { return isAttacking; } set { isAttacking = value; } }
+
+ public bool Contact = false;
protected Vector2 _prevPos;
@@ -28,13 +38,17 @@ class Player
#region Properties
private int health;
+
+ private int totalDistance;
+
+ public float TotalDistance { get { return totalDistance; }set { value = totalDistance; } }
public int Health { get { return health; } set { health = value; } }
public int Lives { get; set; }
private bool isAlive;
public bool IsAlive { get { return isAlive; } set { isAlive = value; } }
- public bool IsAttacking { get; set; }
+
@@ -49,25 +63,39 @@ public Vector2 Position
if (_animationManager != null)
_animationManager.Position = _position;
}
+
}
+ public float Speed = 1f;
- public float Speed = 2f;
public Vector2 Velocity;
+ public Vector2 Acceleration = new Vector2(9.8f,0);
+
Boolean hasJumped = false;
+ public Boolean jumping = false;
+ int jumpCount = 0;
+
+ Boolean falling = false;
+
+ public bool grounded = false;
// x co-ordinate movement
// using this var for moving background along with the character
- public int Xtrans = 0;
+ public float Xtrans = 0;
+
+ public bool isHalfway = false;
#endregion
#region Methods
+
+
+ // draw player on screen
public virtual void Draw(SpriteBatch spriteBatch)
{
if (_texture != null)
@@ -77,14 +105,11 @@ public virtual void Draw(SpriteBatch spriteBatch)
else throw new Exception("error animation mngr");
}
- public virtual void Move()
+ public virtual void Move(Dictionary soundEffects)
{
- if(Keyboard.GetState().IsKeyDown(Keys.E))
- {
-
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Left) && _position.X > 50)
+
+ if (Keyboard.GetState().IsKeyDown(Keys.Left)&&Position.X>this._animations.ElementAt(0).Value.FrameWidth)
Velocity.X = -Speed;
if (Keyboard.GetState().IsKeyDown(Keys.Right) )
@@ -93,71 +118,67 @@ public virtual void Move()
}
- if (Keyboard.GetState().IsKeyDown(Keys.Space) && hasJumped == false)
+ // Jump
+ if (Keyboard.GetState().IsKeyDown(Keys.Space) && grounded)
{
- Velocity.X = 15f;
- _position.Y -= 170f;
- Velocity.Y = 3f*10;
+
+ if (jumpCount == 0)
+ jumpCount = 150;
+ jumping = true;
+ grounded = false;
hasJumped = true;
+ soundEffects["Jump"].Play();
+
}
- if (hasJumped == true)
+ if (jumpCount > 0)
{
- float i = 10;
- Velocity.Y += 0.25f * i;
+
+ jumpCount--;
+ // jump speed
+ _position.Y -= graphics.PreferredBackBufferHeight/600f;
+
+ if (jumpCount == 0)
+ {
+
+ hasJumped = false;
+ jumping = false;
+ }
+ }
-
-
-
- }
- if (_position.Y > (0.858) * GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)
- {
- hasJumped = false;
- }
- if (hasJumped == false)
- {
- Velocity.Y = 0f;
- //Velocity.X = 0f;
-
-
- }
-
- //else if (Keyboard.GetState().IsKeyDown(Keys.Down))
- // Velocity.Y = Speed
+
+
+
}
protected virtual void SetAnimations()
{
- if (Velocity.X > 0)
- _animationManager.Play(_animations["WalkRight"]);
- /* else if (Velocity.X < 0)
- _animationManager.Play(_animations["WalkLeft"]);
- else if (Velocity.Y > 0)
- _animationManager.Play(_animations["WalkDown"]);
- else if (Velocity.Y < 0)
- _animationManager.Play(_animations["WalkUp"]);*/
+
+ if (IsAttacking)
+ {
+ _animationManager.Play(_animations["attack"]);
+ IsAttacking = false;
+ }
+ else if (Velocity.X > 0)
+ _animationManager.Play(_animations["WalkRight"]);
+
else if (Velocity.X < 0)
{
_animationManager.Play(_animations["WalkLeft"]);
}
-
- else if (IsAttacking)
- {
- _animationManager.Play(_animations["attack"]);
-
- }
else _animationManager.Stop();
}
- public Player(Dictionary animations)
+ public Player(Dictionary animations, GraphicsDeviceManager g)
{
+ graphics = g;
_animations = animations;
_animationManager = new AnimationManager(_animations.First().Value);
health = 100;
@@ -170,35 +191,52 @@ public Player(Texture2D texture)
}
-
- public virtual void Update(GameTime gameTime, List sprites)
- {
-
- Move();
+ public virtual void Update(GameTime gameTime, List sprites, Dictionary soundEffects)
+ {
+
+
+ Move(soundEffects);
+
+ SetAnimations();
- SetAnimations();
+ _animationManager.Update(gameTime);
- _animationManager.Update(gameTime);
-
- Position += Velocity;
+
+ Position += Velocity;
- Xtrans = (int)Velocity.X;
+
+ Xtrans = Velocity.X;
+ TotalDistance += Xtrans;
_prevPos = Position;
- if (_position.X > GraphicsDeviceManager.DefaultBackBufferWidth)
+
+ if (_position.X > graphics.PreferredBackBufferWidth/2 )
{
- _position.X= (float)(GraphicsDeviceManager.DefaultBackBufferWidth / 2);
+
+ Xtrans = _position.X- graphics.PreferredBackBufferWidth / 2;
+ _position.X = (float)(graphics.PreferredBackBufferWidth * 0.5);
+ isHalfway = true;
+
+
+
}
+ else if (_position.X < 0)
+ {
+ Xtrans = 0;
+ _position.X = 0;
- Velocity = Vector2.Zero;
+ }
+ else
+ {
+ isHalfway = false;
+ }
-
- }
+ Velocity = Vector2.Zero;
+ }
- public bool IsTouching(Tile tile,Player sprite
- )
+ public bool IsTouching(Tile tile,Player sprite)
{
return _position.X +25f +this.Velocity.X >= tile.
@@ -206,10 +244,26 @@ public bool IsTouching(Tile tile,Player sprite
position.X+Tile.Texture.Width;
+
}
+
+ // Returns true if player is on top the tile, false otherwise
+ public bool tileTouching(Tile tile, Player player)
+ {
+ // Checks if the player is in bounds horizontally
+ if ((player._position.X >= tile.position.X) && (player._position.X <= tile.position.X + Tile.Texture.Width))
+ // Checks if the player is at the right height
+ if ((player._position.Y <= tile.position.Y))
+ return true;
+ else
+ return false;
+ else
+ return false;
+ }
+
public void CheckHealth()
{
if (this.Health <= 0)
@@ -218,7 +272,43 @@ public void CheckHealth()
}
}
+ public void Attack(Enemy enemy)
+ {
+ if ((this._position.X - enemy._position.X) <= 170
+ & (this._position.X - enemy._position.X) > -70 )
+ {
+ // this.Velocity = Vector2.Zero;
+ this.isAttacking = true;
+ enemy.Health -= 34;
+
+ }
+
+ else
+ {
+ isAttacking = false;
+ }
+
+ }
#endregion
+ // checks if player is near door
+ // cannot be above the door for level promotion
+ public bool hasEntered(Door door, Dictionary soundEffects)
+ {
+ if (this._position.X > door.position.X && this._position.X < door.position.X + Door.Texture.Width && (this._position.Y > door.position.Y)
+ ) {
+ this.Health = 300;
+ soundEffects["Victory"].Play();
+ return true;
+ }
+ return false;
+ }
+ // setting default values for new level/spawn
+ public void Reset()
+ {
+ this.Health = 100;
+ this.TotalDistance = 0;
+ this.Position = new Vector2(0, (int)((0.858) * graphics.PreferredBackBufferHeight));
+ }
}
}
\ No newline at end of file
diff --git a/Platformer/Program.cs b/Platformer/Program.cs
index b2a8330..c28977c 100644
--- a/Platformer/Program.cs
+++ b/Platformer/Program.cs
@@ -1,7 +1,23 @@
-using System;
+/*
+ * Authors
+ *
+ *
+ * Austin Cultra
+ * Adam Passanissi
+ * Deepak Damera
+ *
+ * Project for CS496
+ *
+ */
+
+using System;
namespace Platformer
{
+
+
+
+
#if WINDOWS || LINUX
///
/// The main class.
@@ -20,8 +36,7 @@ static void Main()
game.Run();
- //Account a = new Account("youtube","c2lone");
-
+
}
}
#endif
diff --git a/Platformer/Tile.cs b/Platformer/Tile.cs
index 4669215..def39e8 100644
--- a/Platformer/Tile.cs
+++ b/Platformer/Tile.cs
@@ -11,7 +11,7 @@ namespace Platformer
{
class Tile
{
-
+ public bool beingTouched = false;
public static Texture2D Texture { get; set; }
public Vector2 position;
public void Draw(SpriteBatch spriteBatch)
@@ -26,6 +26,7 @@ public static void LoadContent(ContentManager content, int type)
}
+
public Tile(Vector2 position)
{
this.position = position;
@@ -33,7 +34,7 @@ public Tile(Vector2 position)
public void Update(float Xtrans)
{
- position.X -= Xtrans;
+ position.X -= Xtrans*3;
}
diff --git a/Platformer/app.config b/Platformer/app.config
index 51278a4..3dbff35 100644
--- a/Platformer/app.config
+++ b/Platformer/app.config
@@ -1,3 +1,3 @@
-
+
diff --git a/Platformer/packages.config b/Platformer/packages.config
new file mode 100644
index 0000000..a1ada4f
--- /dev/null
+++ b/Platformer/packages.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Theokoles.zip b/Theokoles.zip
new file mode 100644
index 0000000..dd21eeb
Binary files /dev/null and b/Theokoles.zip differ