Resources > Coding

Game engine resources?

(1/4) > >>

Theforeshadower:
Been trying to code my own lightweight basic 2D game engine with SFML.net.  I've seen a few websites about 2d game engines but they usually go way beyond the scope of what I want early on.

I have only two source files thus far.  It's in C# in case you could not tell.

PROGRAM.cs

--- Code: ---/*
 * Created by SharpDevelop.
 * User: owner
 * Date: 7/8/2014
 * Time: 3:58 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace HyruleEngine
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("This is the Hyrule Engine Version 0.0.0.1");
Console.WriteLine("Features in this release: Basic engine functions.");

// TODO: Implement Functionality Here

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);


GameCore app = new GameCore();
app.Run();



}
}
}
--- End code ---

GameCore.cs

--- Code: ---/*
 * Created by Michael Jeffries
 * User: owner
 * Date: 7/8/2014
 * Time: 4:27 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using SFML;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;

namespace HyruleEngine
{
/// <summary>
/// Description of GameCore.
/// </summary>
public class GameCore
{
RenderWindow window;
bool gameRunning;
Music musicLoop;
Music musicStart;

public GameCore()
{


}
protected void Init()
{
//Game Initialization code goes here
window = new RenderWindow(new VideoMode(400, 224), "Hyrule Engine");//setting up our basic resolution for our game window
window.SetFramerateLimit(30);//Setting a base frame rate of 30
musicStart = new Music("Resources/Music/lttpOverworldStart.ogg");//test music
musicLoop = new Music("Resources/Music/lttpOverworldLoop.ogg");//blam
musicStart.Play();//playing the test muic
gameRunning = true;//bool for the game loop


}
public void Run()
{

Init();


//main loop
while (gameRunning == true)
{
if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
{
window.Close();
}
if ((musicStart.Status == 0) && (musicLoop.Status == 0))
{
musicLoop.Play();
musicLoop.Loop = true;
}



window.Clear(Color.Blue);

window.Display();
}
}



}
}


--- End code ---

I hope I am on the right track.  What I am aiming for is a simple engine that runs via states: Title, File Select, Game, End/Game Over.  I want drawable objects that draw themselves.  When I worked with XNA, that's how I handled objects that were drawn/active.

I do need to work more on SFML as well.  The damn documentation for .net is skimpy at best.  Been trying to correlate the normal C++ docs to the .net docs.

Anyway, if anyone has any resources , I'd appreciate it.  I should mention that the engine runs fine as is right now so I haven't broken anything yet.

Starforsaken101:
Very good start, and no you haven't broken anything yet but you can very easily with this code hehe.

Just looking at GameCore.cs you might want to learn about proper variable/method protection (public/private/protected). It's not a big deal at the moment but you have a lot of public variables and stuff. That makes it so any class outside can access it which I'm not sure you want for GameCore.cs.

Equally, seeing a game loop in a while loop is dangerous and I wouldn't honestly recommend it. If you have the chance, I would recommend you look at Update loops instead.

EDIT: Okay turns out I know jack !@#$% about .NET but regardless this loop is not efficient because of reasons.

I can go on but that's basic enough for now.

I haven't dabbled in .NET so I can't really...give you much help with that. I've been absorbed with Unity/C# as of late tight butthole.

LorentzChronon:

--- Quote from: Theforeshadower on July 10, 2014, 03:34:42 am ---Been trying to code my own lightweight basic 2D game engine with SFML.net.  I've seen a few websites about 2d game engines but they usually go way beyond the scope of what I want early on.

I have only two source files thus far.  It's in C# in case you could not tell.

PROGRAM.cs

--- Code: ---/*
 * Created by SharpDevelop.
 * User: owner
 * Date: 7/8/2014
 * Time: 3:58 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace HyruleEngine
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("This is the Hyrule Engine Version 0.0.0.1");
Console.WriteLine("Features in this release: Basic engine functions.");

// TODO: Implement Functionality Here

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);


GameCore app = new GameCore();
app.Run();



}
}
}
--- End code ---

GameCore.cs

--- Code: ---/*
 * Created by Michael Jeffries
 * User: owner
 * Date: 7/8/2014
 * Time: 4:27 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using SFML;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;

namespace HyruleEngine
{
/// <summary>
/// Description of GameCore.
/// </summary>
public class GameCore
{
RenderWindow window;
bool gameRunning;
Music musicLoop;
Music musicStart;

public GameCore()
{


}
protected void Init()
{
//Game Initialization code goes here
window = new RenderWindow(new VideoMode(400, 224), "Hyrule Engine");//setting up our basic resolution for our game window
window.SetFramerateLimit(30);//Setting a base frame rate of 30
musicStart = new Music("Resources/Music/lttpOverworldStart.ogg");//test music
musicLoop = new Music("Resources/Music/lttpOverworldLoop.ogg");//blam
musicStart.Play();//playing the test muic
gameRunning = true;//bool for the game loop


}
public void Run()
{

Init();


//main loop
while (gameRunning == true)
{
if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
{
window.Close();
}
if ((musicStart.Status == 0) && (musicLoop.Status == 0))
{
musicLoop.Play();
musicLoop.Loop = true;
}



window.Clear(Color.Blue);

window.Display();
}
}



}
}


--- End code ---

I hope I am on the right track.  What I am aiming for is a simple engine that runs via states: Title, File Select, Game, End/Game Over.  I want drawable objects that draw themselves.  When I worked with XNA, that's how I handled objects that were drawn/active.

I do need to work more on SFML as well.  The damn documentation for .net is skimpy at best.  Been trying to correlate the normal C++ docs to the .net docs.

Anyway, if anyone has any resources , I'd appreciate it.  I should mention that the engine runs fine as is right now so I haven't broken anything yet.

--- End quote ---

I miss XNA. Based on what you've started so far, it shows you have the understandings of the basic of the game loop which is great. I used to work on a project that accomplished some of these goals you have back when XNA was still officially supported by Microsoft. If you're interested in learning about states and state switching, consider using an interface for each state -- what does the game engine need to call or pass down into these states from the game loop? In XNA it was Update/Draw, and some initialization functions per-state.

You can also consider to add a frames-per-second handler that will monitor and can throttle the rate of these Update/Draw calls. XNA was 'smart enough' to know when to update more often than it did draw. I'm not honestly sure how it made that determination, however.

Anyways, cool stuff. I haven't posted here in a while, but reading about your start kind of inspired me.

Theforeshadower:
Not going to lie, I am trying to emulate XNA a little.  XNA was my favorite framework to mess with other than Game Maker.  Monogame isn't bad but afaik it still requires you build an XNA Content project for resources or something along that line.

I know a bit about states as my unfinished projects used states for changing levels and menu screens.  My issue now is making my own motor to run things instead of XNA.

I plan on working on the interface idea as SFML.net provides a Drawable interface which I need to learn more about.  Just juggling a job, construction project, 3 vehicle projects, and rehabilitating my dog which recently had a stroke..my plate is quite full. 

Star, I agree about the while loop.  My eventual plan though was to have the player be able to break out of the loop with either closingthe window or pressing escape.  The while loop will call updates to a single "level"(screen) which in turn handles its own drawing and events.

Would post some more but I am posting ona phone and my fingers hurt.  xD

Starforsaken101:
Haha yeah XD I posted about the fact that the while loop was super goofy but Steve noted that this is something sort of common in .NET? I don't know man. I'm so used to Unity now that I'm sort of giving all of the other languages the same treatment I guess.

Navigation

[0] Message Index

[#] Next page


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Go to full version