Hallo.
Ich habe seit ein paar Tagen mit C# XNA angefangen.
Ich habe auch schon das eine oder andere 2d Game gemacht.
Nur jetzt Frage ich mich in welchem Programmierstil sollte man komplexere Spiele machen?
Ich meine z.B. lege ich bis jetzt für jeden Gegner / Gegenstand(Kiste, Items...) immer eine Klasse an.
Und dann erstelle ich ein Objekt dieser Klasse:
Ist das so Richtig, oder sollte ich in meinem Programmierstil etwas ändern?
Ich habe seit ein paar Tagen mit C# XNA angefangen.
Ich habe auch schon das eine oder andere 2d Game gemacht.
Nur jetzt Frage ich mich in welchem Programmierstil sollte man komplexere Spiele machen?
Ich meine z.B. lege ich bis jetzt für jeden Gegner / Gegenstand(Kiste, Items...) immer eine Klasse an.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Cartoon_Wars.Castle
{
class Castle
{
// Eigenschaften
private SpriteEffects sprite_effects;
private Texture2D texture;
private Vector2 position;
private Color color;
// Konstruktor
public Castle(bool site)
{
position = new Vector2(0, 0);
color = Color.White;
}
// Skelett
public void Initialize()
{
}
public void LoadContent(ContentManager content_manager)
{
texture = content_manager.Load<Texture2D>("Castle");
}
public void UnloadContent()
{
}
public void Update(GameTime game_time)
{
// Physik usw...
}
public void Draw(SpriteBatch sprite_batch)
{
sprite_batch.Draw(texture, position, color);
}
}
}
Und dann erstelle ich ein Objekt dieser Klasse:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Cartoon_Wars
{
public class Game1 : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private Castle.Castle castle_1;
public Game1()
{
castle_1 = new Castle.Castle(true);
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
IsMouseVisible = true;
graphics.PreferredBackBufferWidth = 1600;
graphics.PreferredBackBufferHeight = 900;
graphics.ApplyChanges();
base.Initialize();
// Klassen
castle_1.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
// Klassen
castle_1.LoadContent(Content);
}
protected override void UnloadContent()
{
// Klassen
castle_1.UnloadContent();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
// Klassen
castle_1.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
//Klassen
castle_1.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Ist das so Richtig, oder sollte ich in meinem Programmierstil etwas ändern?