diff --git a/AlkuIkkuna.xaml b/AlkuIkkuna.xaml
index 4f656a8..d820f67 100644
--- a/AlkuIkkuna.xaml
+++ b/AlkuIkkuna.xaml
@@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Seikkailu Laakso" Height="788" Width="1024">
diff --git a/AlkuIkkuna.xaml.cs b/AlkuIkkuna.xaml.cs
index 29910d9..c1cfd2a 100644
--- a/AlkuIkkuna.xaml.cs
+++ b/AlkuIkkuna.xaml.cs
@@ -26,6 +26,10 @@ public AlkuIkkuna()
private void Aloitetaan(object sender, RoutedEventArgs e)
{
+ new Peli().Show();
+ }
+
+ private void UkkelinMuokkaus(object sender, RoutedEventArgs e) {
new UkkelinMuokkaus().Show();
}
}
diff --git a/Peli.xaml b/Peli.xaml
index a7e9bbf..d723a97 100644
--- a/Peli.xaml
+++ b/Peli.xaml
@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:L="clr-namespace:Net.Brotherus.SeikkailuLaakso"
- Title="Peli" Height="880" Width="1000" WindowState="Maximized">
+ Title="Peli" Height="1200" Width="1600" WindowState="Normal">
@@ -13,7 +13,7 @@
diff --git a/Peli.xaml.cs b/Peli.xaml.cs
index 5de6360..e11552f 100644
--- a/Peli.xaml.cs
+++ b/Peli.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using System.Linq;
@@ -31,15 +32,19 @@ public Peli() {
// Create land if no previous content
if (this.scene.Children.Count == 0)
{
- for(int x = 0; x < 12; ++x) {
- this.scene.AddRectPolygon(900, x * 200, 200, 100);
- }
+ CreateNewLand();
}
scene.MouseMove += scene_MouseMove;
scene.MouseLeftButtonDown += scene_MouseLeftButtonDown;
scene.MouseLeftButtonUp += scene_MouseLeftButtonUp;
}
+ private void CreateNewLand() {
+ for (int x = 0; x < 24; ++x) {
+ this.scene.AddRectPolygon(1100, x * 200, 200, 100);
+ }
+ }
+
private void scene_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
scene.StartDrawing(e);
@@ -64,37 +69,41 @@ private string SaveDir
{
get
{
- return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SeikkailuMaa");
+ return Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "SeikkailuMaa");
}
}
- private void PlayGame_Click(object sender, RoutedEventArgs e)
- {
- using (var game = new SeikkailuLaaksoGame())
- {
+ public void StartGame() {
+ using (var game = new SeikkailuLaaksoGame()) {
int i = 1;
- foreach (FrameworkElement sceneItem in scene.Children)
- {
- var encoder = RenderToBitmap(sceneItem);
- string picFile = Path.Combine(SaveDir, "scene_item_" + i.ToString() + ".png");
- using (var picStream = new FileStream(picFile, FileMode.Create)) {
- encoder.Save(picStream);
+ var items = new System.Collections.ArrayList(scene.Children);
+ foreach (FrameworkElement sceneItem in items) {
+ try {
+ var encoder = RenderToBitmap(sceneItem);
+ string picFile = Path.Combine(SaveDir, "scene_item_" + i.ToString() + ".png");
+ using (var picStream = new FileStream(picFile, FileMode.Create)) {
+ encoder.Save(picStream);
+ }
+ game.AddPolygonObstacle(picFile, Canvas.GetLeft(sceneItem), Canvas.GetTop(sceneItem));
+ ++i;
+ } catch (Exception ex) {
+ Debug.WriteLine(ex);
+ scene.Children.Remove(sceneItem);
}
- game.AddPolygonObstacle(picFile, Canvas.GetLeft(sceneItem), Canvas.GetTop(sceneItem));
- ++i;
}
game.Run();
}
}
+ private void PlayGame_Click(object sender, RoutedEventArgs e)
+ {
+ StartGame();
+ }
+
[STAThread]
public static void Main()
{
- //new Application().Run(new AlkuIkkuna());
-
- new Application().Run(new Peli());
-
- //new Peli().PlayGame_Click(null, null);
+ new Application().Run(new AlkuIkkuna());
}
private static PngBitmapEncoder RenderToBitmap(FrameworkElement sceneItem)
@@ -114,7 +123,7 @@ private static PngBitmapEncoder RenderToBitmap(FrameworkElement sceneItem)
return encoder;
}
- private void MenuItem_Click(object sender, RoutedEventArgs e)
+ private void Save_Click(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(SaveDir)) Directory.CreateDirectory(SaveDir);
using (var stream = new FileStream(this.SaveFileName, FileMode.Create))
diff --git a/PeliXNA/AngleTargetLimitJoint.cs b/PeliXNA/AngleTargetLimitJoint.cs
deleted file mode 100644
index e39b85e..0000000
--- a/PeliXNA/AngleTargetLimitJoint.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using System;
-using FarseerGames.FarseerPhysics;
-using FarseerGames.FarseerPhysics.Dynamics;
-using FarseerGames.FarseerPhysics.Dynamics.Joints;
-using FarseerGames.FarseerPhysics.Factories;
-
-namespace Net.Brotherus
-{
- public class AngleTargetLimitJoint
- {
- AngleJoint _angleJoint;
- AngleLimitJoint _limitJoint;
-
- public AngleTargetLimitJoint(PhysicsSimulator physicsSimulator, Body a, Body b, double minDegrees, double targetDegrees, double maxDegrees)
- {
- _angleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, a, b);
- _angleJoint.TargetAngle = MathExt.ToRadians(targetDegrees);
- _angleJoint.Softness = 0.5f;
- _angleJoint.MaxImpulse = 3000.0f;
- _limitJoint = JointFactory.Instance.CreateAngleLimitJoint(
- physicsSimulator, a, b, MathExt.ToRadians(minDegrees), MathExt.ToRadians(maxDegrees));
- }
-
- public float MaxImpulse { set { _angleJoint.MaxImpulse = value; } }
-
- public float TargetAngleRadians
- {
- get { return _angleJoint.TargetAngle; }
- set
- {
- if ((value > _limitJoint.LowerLimit) && (value < _limitJoint.UpperLimit))
- {
- _angleJoint.TargetAngle = value;
- }
- }
- }
-
- public float TargetAngleDegrees { set { TargetAngleRadians = MathExt.ToRadians(value); } }
- }
-}
diff --git a/PeliXNA/Content/Common/background.png b/PeliXNA/Content/Common/background.png
deleted file mode 100644
index 6d1b671..0000000
Binary files a/PeliXNA/Content/Common/background.png and /dev/null differ
diff --git a/PeliXNA/Content/Common/blank.png b/PeliXNA/Content/Common/blank.png
deleted file mode 100644
index 3165c37..0000000
Binary files a/PeliXNA/Content/Common/blank.png and /dev/null differ
diff --git a/PeliXNA/Content/Common/gradient.png b/PeliXNA/Content/Common/gradient.png
deleted file mode 100644
index 1a5a0f7..0000000
Binary files a/PeliXNA/Content/Common/gradient.png and /dev/null differ
diff --git a/PeliXNA/Content/Common/logo.png b/PeliXNA/Content/Common/logo.png
deleted file mode 100644
index 3ed3d41..0000000
Binary files a/PeliXNA/Content/Common/logo.png and /dev/null differ
diff --git a/PeliXNA/Content/Content.contentproj b/PeliXNA/Content/Content.contentproj
index 4258cf1..0a0a012 100644
--- a/PeliXNA/Content/Content.contentproj
+++ b/PeliXNA/Content/Content.contentproj
@@ -42,28 +42,6 @@
False
-
-
- background
- TextureImporter
- TextureProcessor
-
-
- blank
- TextureImporter
- TextureProcessor
-
-
- gradient
- TextureImporter
- TextureProcessor
-
-
- logo
- TextureImporter
- TextureProcessor
-
-
detailsFont
diff --git a/PeliXNA/Content/Content.contentproj.user b/PeliXNA/Content/Content.contentproj.user
index 7ff3943..b875c0c 100644
--- a/PeliXNA/Content/Content.contentproj.user
+++ b/PeliXNA/Content/Content.contentproj.user
@@ -1 +1,5 @@
-
\ No newline at end of file
+
+
+ ProjectFiles
+
+
\ No newline at end of file
diff --git a/PeliXNA/DrawingSystem/LineBrush.cs b/PeliXNA/DrawingSystem/LineBrush.cs
index 6f9b8e9..4cb15c4 100644
--- a/PeliXNA/DrawingSystem/LineBrush.cs
+++ b/PeliXNA/DrawingSystem/LineBrush.cs
@@ -1,6 +1,7 @@
using FarseerGames.FarseerPhysics.Mathematics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
+using Vector2 = Microsoft.Xna.Framework.Vector2;
namespace FarseerGames.GettingStarted.DrawingSystem
{
diff --git a/PeliXNA/GameScreen.cs b/PeliXNA/GameScreen.cs
index 3ea5e50..d74a93a 100644
--- a/PeliXNA/GameScreen.cs
+++ b/PeliXNA/GameScreen.cs
@@ -10,23 +10,32 @@
using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.GettingStarted.DrawingSystem;
using Net.Brotherus.SeikkailuLaakso;
+using Vector2Fs = FarseerGames.FarseerPhysics.Mathematics.Vector2;
+using Vector2Xna = Microsoft.Xna.Framework.Vector2;
namespace Net.Brotherus
{
public class GameScreen : DrawableGameComponent
{
- private static readonly Vector2 GRAVITY = new Vector2(0, 1000);
+ private float _scrollPosition = 0.0f;
+ private float _scrollSpeed = 0.0f;
+
+
+ public static Point ScreenSize = new Point(1600, 1200);
+ private static readonly float SCROLL_MARGIN = 400.0f;
+
+ private static readonly Vector2Fs GRAVITY = new Vector2Fs(0, 1000);
private PhysicsSimulator _physicsSimulator;
private ContentManager _contentManager;
private SpriteBatch _spriteBatch;
private InputState _input = new InputState();
- private Ukkeli _ukkeli;
+ private UkkeliSimple _ukkeli;
private List _obstacles;
private LineBrush _lineBrush = new LineBrush(1, Color.Black); //used to draw spring on mouse grab
- private FixedLinearSpring _mousePickSpring;
- private Geom _pickedGeom;
+
+ private Texture2D _background;
public GameScreen(Game game) : base(game)
{
@@ -35,7 +44,7 @@ public GameScreen(Game game) : base(game)
_obstacles = new List();
}
- public void AddObstacle(string picFile, Vector2 position)
+ public void AddObstacle(string picFile, Vector2Fs position)
{
_obstacles.Add(new PolygonObstacle(position, picFile));
}
@@ -46,9 +55,10 @@ public void AddObstacle(string picFile, Vector2 position)
protected override void LoadContent()
{
// Load content belonging to the screen manager.
+ _background = Texture2D.FromFile(GraphicsDevice, "Content/taustakuvat/berkin_talo.png");
_spriteBatch = new SpriteBatch(GraphicsDevice);
_lineBrush.Load(GraphicsDevice);
- _ukkeli = new Ukkeli(new Vector2(150, 800), GraphicsDevice, _physicsSimulator);
+ _ukkeli = new UkkeliSimple(new Vector2Fs(150, 800), GraphicsDevice, _physicsSimulator);
foreach (var obstacle in _obstacles)
{
obstacle.Load(GraphicsDevice, _physicsSimulator);
@@ -58,77 +68,59 @@ protected override void LoadContent()
///
/// Unload your graphics content.
///
- protected override void UnloadContent()
- {
+ protected override void UnloadContent() {
_contentManager.Unload();
_physicsSimulator.Clear();
}
- public override void Update(GameTime gameTime)
- {
+ public override void Update(GameTime gameTime) {
// Read the keyboard and gamepad.
_input.Update();
float secondsElapsed = gameTime.ElapsedGameTime.Milliseconds * .001f;
_physicsSimulator.Update(secondsElapsed);
_ukkeli.HandleKeyboardInput(_input, gameTime);
- HandleMouseInput(_input);
+ Scroll(secondsElapsed);
}
- private void HandleMouseInput(InputState input)
- {
- Vector2 point = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y);
- if (input.LastMouseState.LeftButton == ButtonState.Released &&
- input.CurrentMouseState.LeftButton == ButtonState.Pressed)
- {
- CreateMouseSpring(point);
- }
- else if (input.LastMouseState.LeftButton == ButtonState.Pressed &&
- input.CurrentMouseState.LeftButton == ButtonState.Released)
- {
- DestroyMouseSpring();
- }
- //move anchor point
- if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && _mousePickSpring != null)
- {
- _mousePickSpring.WorldAttachPoint = point;
- }
- }
-
- private void DestroyMouseSpring()
- {
- if (_mousePickSpring != null && _mousePickSpring.IsDisposed == false)
- {
- _mousePickSpring.Dispose();
- _mousePickSpring = null;
- }
- }
-
- private void CreateMouseSpring(Vector2 point)
- {
- _pickedGeom = _physicsSimulator.Collide(point);
- if (_pickedGeom != null)
- {
- _mousePickSpring = SpringFactory.Instance.CreateFixedLinearSpring(_physicsSimulator,
- _pickedGeom.Body, _pickedGeom.Body.GetLocalPosition(point), point, 20, 10);
+ private void Scroll(float secondsElapsed) {
+ if (ManOnScreenX > ScreenSize.X - SCROLL_MARGIN) {
+ _scrollSpeed += secondsElapsed;
+ } else if (ManOnScreenX < SCROLL_MARGIN) {
+ _scrollSpeed -= secondsElapsed;
+ } else if (Math.Abs(_scrollSpeed) < 0.1f ) {
+ _scrollSpeed = 0.0f;
+ } else {
+ _scrollSpeed -= Math.Sign(_scrollSpeed) * secondsElapsed;
}
+ _scrollSpeed = _scrollSpeed.InLimits(-100.0f, 100.0f);
+ _scrollPosition += secondsElapsed * _scrollSpeed * 500.0f;
}
///
/// This is called when the screen should draw itself.
///
- public override void Draw(GameTime gameTime)
- {
+ public override void Draw(GameTime gameTime) {
_spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
- foreach (var obstacle in _obstacles) obstacle.Draw(_spriteBatch);
- _ukkeli.Draw(_spriteBatch);
- if (_mousePickSpring != null)
- {
- _lineBrush.Draw(_spriteBatch,
- _mousePickSpring.Body.GetWorldPosition(_mousePickSpring.BodyAttachPoint),
- _mousePickSpring.WorldAttachPoint);
+
+ Action drawer = (tex, pos, rot, orig) => {
+ _spriteBatch.Draw(tex, pos.ToVector2Xna(-_scrollPosition), null, Color.White, rot, orig.ToVector2Xna(), 1, SpriteEffects.None, 0);
+ };
+
+ // Background is made always only of three tiles so we must alter which ones
+ int bgIndex = Convert.ToInt32( Math.Floor(_scrollPosition / ScreenSize.X) );
+ for (int i = bgIndex - 1; i <= bgIndex + 1; ++i) {
+ var flip = i % 2 == 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
+ _spriteBatch.Draw(_background, new Rectangle((int)-_scrollPosition + ScreenSize.X * i, 0, ScreenSize.X, ScreenSize.Y), null, Color.White, 0, Vector2Xna.Zero, flip, 0.0f);
}
+
+
+ foreach (var obstacle in _obstacles) obstacle.Draw(drawer);
+ _ukkeli.Draw(drawer);
_spriteBatch.End();
}
+ private float ManOnScreenX {
+ get { return _ukkeli.Position.X - _scrollPosition; }
+ }
}
}
\ No newline at end of file
diff --git a/PeliXNA/InputState.cs b/PeliXNA/InputState.cs
deleted file mode 100644
index f1861e8..0000000
--- a/PeliXNA/InputState.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-#region File Description
-
-//-----------------------------------------------------------------------------
-// InputState.cs
-//
-// Microsoft XNA Community Game Platform
-// Copyright (C) Microsoft Corporation. All rights reserved.
-//-----------------------------------------------------------------------------
-
-#endregion
-
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Input;
-
-namespace Net.Brotherus
-{
- ///
- /// Helper for reading input from keyboard and gamepad. This class tracks both
- /// the current and previous state of both input devices, and implements query
- /// properties for high level input actions such as "move up through the menu"
- /// or "pause the game".
- ///
- public class InputState
- {
- public GamePadState CurrentGamePadState;
- public KeyboardState CurrentKeyboardState;
- public MouseState CurrentMouseState;
-
- public GamePadState LastGamePadState;
- public KeyboardState LastKeyboardState;
- public MouseState LastMouseState;
-
- ///
- /// Reads the latest state of the keyboard and gamepad.
- ///
- public void Update()
- {
- LastKeyboardState = CurrentKeyboardState;
- LastGamePadState = CurrentGamePadState;
- LastMouseState = CurrentMouseState;
- CurrentKeyboardState = Keyboard.GetState();
- CurrentGamePadState = GamePad.GetState(PlayerIndex.One);
- CurrentMouseState = Mouse.GetState();
- }
-
- ///
- /// Helper for checking if a key was newly pressed during this update.
- ///
- public bool IsNewKeyPress(Keys key)
- {
- return (CurrentKeyboardState.IsKeyDown(key) && LastKeyboardState.IsKeyUp(key));
- }
-
- public bool IsKeyLifted(Keys key)
- {
- return (CurrentKeyboardState.IsKeyUp(key) && LastKeyboardState.IsKeyDown(key));
- }
- }
-}
\ No newline at end of file
diff --git a/PeliXNA/MathExt.cs b/PeliXNA/MathExt.cs
deleted file mode 100644
index a2fcf4a..0000000
--- a/PeliXNA/MathExt.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Net.Brotherus
-{
- public static class MathExt
- {
- public static float ToRadians(double angle)
- {
- return Convert.ToSingle(angle / 360.0 * 2 * Math.PI);
- }
-
- internal static double ToDegrees(double angle)
- {
- return angle / 2 / Math.PI * 360;
- }
-
- public static double Sqr(double value)
- {
- return value * value;
- }
-
- }
-}
diff --git a/PeliXNA/Obstacle.cs b/PeliXNA/Obstacle.cs
deleted file mode 100644
index 760eb99..0000000
--- a/PeliXNA/Obstacle.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System;
-using System.Collections.Generic;
-using FarseerGames.FarseerPhysics;
-using FarseerGames.FarseerPhysics.Collisions;
-using FarseerGames.FarseerPhysics.Dynamics;
-using FarseerGames.FarseerPhysics.Factories;
-using FarseerGames.GettingStarted.DrawingSystem;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace Net.Brotherus.SeikkailuLaakso
-{
- public class PolygonObstacle
- {
- private string _textureFile;
- private Vector2 _position;
-
- private Geom _geom;
- private Body _body;
- private Texture2D _texture;
-
- ///
- /// Constructor
- ///
- /// top-left position
- ///
- public PolygonObstacle(Vector2 position, string textureFile)
- {
- _position = position;
- _textureFile = textureFile;
- }
-
- ///
- /// This cannot be done in constructor since graphicsdevice and physicssimulator don't exist yet then.
- /// Load is called later
- ///
- public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
- {
- _texture = Texture2D.FromFile(graphicsDevice, _textureFile);
- uint[] textureData = new uint[_texture.Width * _texture.Height];
- _texture.GetData(textureData);
- Vertices poly = Vertices.CreatePolygon(textureData, _texture.Width, _texture.Height);
- _body = BodyFactory.Instance.CreateBody(physicsSimulator, 1, 1); // dummy moment of inertia and mass since static
- _body.Position = _position;
- _body.IsStatic = true;
-
- // Don't use Geom factory: it shifts the vertices according to center-of-mass
- _geom = new Geom(_body, poly, Vector2.Zero, 0, GeomFactory.Instance.CalculateGridCellSizeFromAABB(poly));
- _geom.RestitutionCoefficient = 0.0f;
- physicsSimulator.Add(_geom);
- }
-
- public void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(_texture, _body.Position, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0f);
- }
- }
-}
\ No newline at end of file
diff --git a/PeliXNA/PeliXNA.csproj b/PeliXNA/PeliXNA.csproj
index 67a0ee1..de9d6b4 100644
--- a/PeliXNA/PeliXNA.csproj
+++ b/PeliXNA/PeliXNA.csproj
@@ -1,4 +1,5 @@
-
+
+
{F7E1D8C1-5AB0-42A9-9AFE-8F3EEEBF1307}
{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
@@ -8,7 +9,7 @@
Properties
Net.Brotherus
PeliXNA
- v3.0
+ v3.5
v3.0
Windows
d85ac275-347b-4cc4-9543-6f1a7d01772c
@@ -38,10 +39,10 @@
-
-
+ 0
+ 4.0
true
@@ -69,10 +70,6 @@
true
-
- False
- ..\..\PhysicsEngines\FarseerPhysics2.0.1SimpleSamplesForXNA\FarseerPhysics2.0.1OnlyForXNA\bin\x86\Debug\FarseerProject.dll
-
False
True
@@ -87,14 +84,18 @@
False
+
+ 3.5
+
-
+
+
-
-
+
+
@@ -102,10 +103,10 @@
-
+
-
-
+
+
@@ -153,6 +154,12 @@
true
+
+
+ {B8114FBF-96BC-48D7-8DF2-085D380CA2C1}
+ Farseer
+
+