Skip to content
Snippets Groups Projects
Commit ae8ffde1 authored by CatoNator's avatar CatoNator
Browse files

bugit on korjattu ja monogame paskottu

parent 4982b125
No related branches found
No related tags found
No related merge requests found
Showing
with 341 additions and 70 deletions
......@@ -25,3 +25,16 @@
<xorig>128</xorig>
<yorig>128</yorig>
</sprite>
<sprite>
<index>2</index>
<name>sprBall</name>
<texture>Player</texture>
<left>64</left>
<top>0</top>
<width>32</width>
<height>32</height>
<images>0</images>
<xorig>16</xorig>
<yorig>16</yorig>
</sprite>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CatEngine
{
public sealed class CGameManager
{
//this shouldn't be here but it is now because I can't be bothered to make a new gamestate manager
public int iScore = 0;
public int iLives = 3;
private CGameManager()
{
}
//singletoning the singleton
public static CGameManager Instance { get { return Nested.instance; } }
private class Nested
{
static Nested()
{
}
internal static readonly CGameManager instance = new CGameManager();
}
public void UpdateGame()
{
//if no bricks exist then make some
if (!BallExists())
{
CObjectManager.Instance.CreateInstance(typeof(CBall), 208, 180);
}
if (!WallExists())
{
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 26; i++)
{
CObjectManager.Instance.CreateInstance(typeof(CWall), 16 * i, 2 + 10 * j);
}
}
}
}
private bool WallExists()
{
bool doesItReallyExistIWonder = false;
for (int i = 0; i < CObjectManager.MAX_INSTANCES; i++)
{
if (CObjectManager.Instance.pGameObjectList[i] != null
&& Object.ReferenceEquals(typeof(CWall), CObjectManager.Instance.pGameObjectList[i].GetType()))
doesItReallyExistIWonder = true;
}
return doesItReallyExistIWonder;
}
private bool BallExists()
{
bool doesItReallyExistIWonder = false;
for (int i = 0; i < CObjectManager.MAX_INSTANCES; i++)
{
if (CObjectManager.Instance.pGameObjectList[i] != null
&& Object.ReferenceEquals(typeof(CBall), CObjectManager.Instance.pGameObjectList[i].GetType()))
doesItReallyExistIWonder = true;
}
return doesItReallyExistIWonder;
}
}
}
......@@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace CatEngine
{
......@@ -28,8 +30,13 @@ public void Update()
{
}
public void Render()
public void Render(SpriteBatch spriteBatch, SpriteFont font)
{
spriteBatch.DrawString(font, CGameManager.Instance.iScore.ToString(), new Vector2(10, 220), Color.White);
spriteBatch.DrawString(font, CGameManager.Instance.iLives.ToString(), new Vector2(400, 220), Color.White);
if (CGameManager.Instance.iLives <= 0)
spriteBatch.DrawString(font, "Olet kuolio!!!", new Vector2(208, 110), Color.White);
}
}
}
......@@ -22,12 +22,8 @@ public sealed class CSettings
public float fMusicVolume = 1.0f;
public float fSoundVolume = 1.0f;
public Keys kPTurnLeft = Keys.A;
public Keys kPTurnRight = Keys.D;
public Keys kPMoveForward = Keys.W;
public Keys kPMoveBackward = Keys.S;
public Keys kPStrafeLeft = Keys.Q;
public Keys kPStrafeRight = Keys.E;
public Keys kPMoveLeft = Keys.A;
public Keys kPMoveRight = Keys.D;
public Keys kPFire = Keys.Space;
......
......@@ -5,7 +5,6 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Newtonsoft.Json;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
......
......@@ -39,6 +39,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="CAudioManager.cs" />
<Compile Include="CGameManager.cs" />
<Compile Include="CGameObject.cs" />
<Compile Include="CHud.cs" />
<Compile Include="CLight.cs" />
......@@ -47,6 +48,7 @@
<Compile Include="fmod.cs" />
<Compile Include="fmod_dsp.cs" />
<Compile Include="fmod_errors.cs" />
<Compile Include="GameObjects\CBall.cs" />
<Compile Include="GameObjects\CPlayer.cs" />
<Compile Include="CSprite.cs" />
<Compile Include="GameObjects\CWall.cs" />
......
......@@ -13,7 +13,7 @@
#---------------------------------- Content ---------------------------------#
#begin PlayerShip.png
#begin Lights.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
......@@ -23,9 +23,9 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:PlayerShip.png
/build:Lights.png
#begin Lights.png
#begin PlayerShip.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
......@@ -35,7 +35,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Lights.png
/build:PlayerShip.png
#begin PlayerTest.png
/importer:TextureImporter
......@@ -49,3 +49,10 @@
/processorParam:TextureFormat=Color
/build:PlayerTest.png
#begin ScoreFont.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:ScoreFont.spritefont
CatEngine/Content/PlayerTest.png

406 B | W: | H:

CatEngine/Content/PlayerTest.png

913 B | W: | H:

CatEngine/Content/PlayerTest.png
CatEngine/Content/PlayerTest.png
CatEngine/Content/PlayerTest.png
CatEngine/Content/PlayerTest.png
  • 2-up
  • Swipe
  • Onion skin
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>Arial</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>8</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
File added
File added
File added
No preview for this file type
File added
......@@ -16,13 +16,16 @@ public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteBatch lightBatch;
//the light system is not used as subtractive rendering is still broken...
//SpriteBatch lightBatch;
SpriteBatch screenBatch;
RenderTarget2D renderTarget;
private Random myRandom = new Random();
public SpriteFont scoreFont;
public readonly static BlendState
bsSubtract = new BlendState
{
......@@ -76,19 +79,15 @@ protected override void LoadContent()
CSprite.Instance.dTextureDict.Add("Player", Content.Load<Texture2D>("PlayerTest"));
CSprite.Instance.dTextureDict.Add("Lights", Content.Load<Texture2D>("Lights"));
scoreFont = Content.Load<SpriteFont>("ScoreFont");
//CSprite.Instance.txTexture = Content.Load<Texture2D>("PlayerTest");
CSprite.Instance.sbSpriteBatch = spriteBatch;
CSprite.Instance.graphics = graphics;
//DEBUG: creating a player and some platforms
CObjectManager.Instance.CreateInstance(typeof(CPlayer), 64, 64);
CObjectManager.Instance.CreateInstance(typeof(CWall), 64, 128);
CObjectManager.Instance.CreateInstance(typeof(CWall), 192, 160);
CObjectManager.Instance.CreateInstance(typeof(CWall), 320, 128);
//creating a player and some platforms
CObjectManager.Instance.CreateLight(78, 78);
CObjectManager.Instance.CreateInstance(typeof(CPlayer), 208, 200);
// TODO: use this.Content to load your game content here
}
......@@ -109,6 +108,8 @@ protected override void UnloadContent()
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
CGameManager.Instance.UpdateGame();
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
......@@ -135,7 +136,7 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.SetRenderTarget(renderTarget);
//the actual game engine draw calls
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.Clear(Color.Black);
//CSprite.Instance.sbSpriteBatch = spriteBatch;
......@@ -160,15 +161,14 @@ protected override void Draw(GameTime gameTime)
lightBatch.End();*/
/*GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.SetRenderTarget(renderTarget);
spriteBatch.Begin(SpriteSortMode.FrontToBack, null, SamplerState.PointClamp, null, null, null, null);
//rendering the HUD
CHud.Instance.Render();
spriteBatch.End();*/
CHud.Instance.Render(spriteBatch, scoreFont);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
namespace CatEngine
{
class CBall : CGameObject
{
private bool bStopped = true;
private int iStopTimer = 60;
public override void InstanceSpawn()
{
vCollisionOrigin = new Vector2(4, 4);
rCollisionRectangle = new Rectangle(0, 0, 8, 8);
UpdateCollision();
fHorSpeed = 2.0f - (float)(myRandom.NextDouble()*4.0);
fVerSpeed = -2.0f;
}
public override void Update()
{
UpdateCollision();
//floor collision
CGameObject collision = CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y + rCollisionRectangle.Height, rCollisionRectangle.Width, 1), typeof(CWall), true);
//collisions to the left and right
if (testHorCollision())
fHorSpeed = -fHorSpeed;
//collisions above and below
if (testVerCollision())
fVerSpeed = -fVerSpeed;
if (!bStopped)
{
x += fHorSpeed;
y += fVerSpeed;
}
else
{
iStopTimer--;
if (iStopTimer <= 0)
bStopped = false;
}
if (y > 210)
{
CObjectManager.Instance.DestroyInstance(iIndex);
CGameManager.Instance.iLives--;
}
}
private bool testHorCollision()
{
int collisionSafeZone = 2;
CGameObject horBrickCol = CollisionRectangle(new Rectangle(rCollisionRectangle.X - collisionSafeZone, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CWall), true);
CGameObject verBrickCol = CollisionRectangle(new Rectangle(rCollisionRectangle.X + rCollisionRectangle.Width, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CWall), true);
if (horBrickCol != null)
{
CObjectManager.Instance.DestroyInstance(horBrickCol.iIndex);
}
if (verBrickCol != null)
{
CObjectManager.Instance.DestroyInstance(verBrickCol.iIndex);
}
bool brickCollision = ((horBrickCol != null && fHorSpeed < 0) || (verBrickCol != null && fHorSpeed > 0));
bool playerCollision = ((CollisionRectangle(new Rectangle(rCollisionRectangle.X - collisionSafeZone, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CPlayer), true) != null && fHorSpeed < 0) ||
(CollisionRectangle(new Rectangle(rCollisionRectangle.X + rCollisionRectangle.Width, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CPlayer), true) != null && fHorSpeed > 0));
bool outOfScreen = (x <= 0 || x >= 416);
return brickCollision || playerCollision || outOfScreen;
}
private bool testVerCollision()
{
int collisionSafeZone = 2;
CGameObject horBrickCol = CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y - collisionSafeZone, rCollisionRectangle.Width, collisionSafeZone), typeof(CWall), true);
CGameObject verBrickCol = CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y + rCollisionRectangle.Height, rCollisionRectangle.Width, collisionSafeZone), typeof(CWall), true);
if (horBrickCol != null)
{
CObjectManager.Instance.DestroyInstance(horBrickCol.iIndex);
}
if (verBrickCol != null)
{
CObjectManager.Instance.DestroyInstance(horBrickCol.iIndex);
}
bool brickCollision = ((horBrickCol != null && fVerSpeed < 0) || (verBrickCol != null && fVerSpeed > 0));
bool playerCollision = (CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y - collisionSafeZone, rCollisionRectangle.Width, collisionSafeZone), typeof(CPlayer), true) != null && fVerSpeed < 0) ||
(CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y + rCollisionRectangle.Height, rCollisionRectangle.Width, collisionSafeZone), typeof(CPlayer), true) != null && fVerSpeed > 0);
bool outOfScreen = (y <= 0 || y >= 240);
return brickCollision || playerCollision || outOfScreen;
}
public override void Render()
{
CSprite.Instance.DrawRect(rCollisionRectangle, Color.Green);
//CSprite.Instance.Render("sprPlayer", x, y, 0, false, 0, 1.0f, Color.White);
}
}
}
......@@ -13,13 +13,12 @@ public class CPlayer : CGameObject
{
public float fAimDirection = 0.0f;
private int iFSpeed = 0;
private int iSSpeed = 0;
private int iSpeed = 0;
public override void InstanceSpawn()
{
vCollisionOrigin = new Vector2(16, 16);
rCollisionRectangle = new Rectangle(0, 0, 32, 32);
vCollisionOrigin = new Vector2(16, 4);
rCollisionRectangle = new Rectangle(0, 0, 48, 8);
}
public override void Update()
......@@ -34,39 +33,31 @@ public override void Update()
MovementKeyboard(keyboardState);
//capping the player rotation to [0.0f, 360.0f]
if (fAimDirection >= 360)
fAimDirection -= 360;
else if (fAimDirection <= 0)
fAimDirection += 360;
fHorSpeed = (float)distDirX((float)iFSpeed, degToRad(fAimDirection)) + (float)distDirX((float)iSSpeed, degToRad(fAimDirection+90.0f));
fVerSpeed = (float)distDirY((float)iFSpeed, degToRad(fAimDirection)) + (float)distDirY((float)iSSpeed, degToRad(fAimDirection+90.0f));
fHorSpeed = (float)iSpeed;
//note! current collision model only supports recantular collisions, no pixel perfect shapes
//collision always gets stuck, needs adjusting
int collisionSafeZone = 4;
//collisions to the left and right
if ((CollisionRectangle(new Rectangle(rCollisionRectangle.X - collisionSafeZone, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CWall), true) != null && fHorSpeed < 0) ||
(CollisionRectangle(new Rectangle(rCollisionRectangle.X + rCollisionRectangle.Width, rCollisionRectangle.Y, collisionSafeZone, rCollisionRectangle.Height), typeof(CWall), true) != null && fHorSpeed > 0))
if (x < 0)
{
x = 1;
fHorSpeed = 0;
}
//collisions above and below
if ((CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y - collisionSafeZone, rCollisionRectangle.Width, collisionSafeZone), typeof(CWall), true) != null && fVerSpeed < 0)||
(CollisionRectangle(new Rectangle(rCollisionRectangle.X, rCollisionRectangle.Y + rCollisionRectangle.Height, rCollisionRectangle.Width, collisionSafeZone), typeof(CWall), true) != null && fVerSpeed > 0))
fVerSpeed = 0;
else if (x > 416)
{
x = 415;
fHorSpeed = 0;
}
x += fHorSpeed;
y += fVerSpeed;
}
public override void Render()
{
//CSprite.Instance.DrawRect(rCollisionRectangle, Color.Green);
CSprite.Instance.DrawRect(rCollisionRectangle, Color.Red);
CSprite.Instance.Render("sprTest", x, y, 0, false, -degToRad(fAimDirection), 1.0f, Color.White);
//CSprite.Instance.Render("sprTest", x, y, 0, false, 0, 1.0f, Color.White);
}
public void MovementKeyboard(KeyboardState keyboardState)
......@@ -74,27 +65,13 @@ public void MovementKeyboard(KeyboardState keyboardState)
//rename this var
int maxSpeed = 2;
//turning
if (keyboardState.IsKeyDown(CSettings.Instance.kPTurnLeft))
fAimDirection += 2.0f;
else if (keyboardState.IsKeyDown(CSettings.Instance.kPTurnRight))
fAimDirection -= 2.0f;
//moving forward/backward
if (keyboardState.IsKeyDown(CSettings.Instance.kPMoveForward))
iFSpeed = maxSpeed;
else if (keyboardState.IsKeyDown(CSettings.Instance.kPMoveBackward))
iFSpeed = -maxSpeed;
else
iFSpeed = 0;
//strafing??
if (keyboardState.IsKeyDown(CSettings.Instance.kPStrafeLeft))
iSSpeed = maxSpeed;
else if (keyboardState.IsKeyDown(CSettings.Instance.kPStrafeRight))
iSSpeed = -maxSpeed;
if (keyboardState.IsKeyDown(CSettings.Instance.kPMoveRight))
iSpeed = maxSpeed;
else if (keyboardState.IsKeyDown(CSettings.Instance.kPMoveLeft))
iSpeed = -maxSpeed;
else
iSSpeed = 0;
iSpeed = 0;
}
}
}
......@@ -11,7 +11,14 @@ public class CWall : CGameObject
{
public override void InstanceSpawn()
{
rCollisionRectangle = new Rectangle(0, 0, 128, 16);
rCollisionRectangle = new Rectangle(0, 0, 16, 8);
UpdateCollision();
}
public override void OnDestruction()
{
CGameManager.Instance.iScore += 10;
}
public override void Render()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment