Simple Shooting Example - Monogame Typing CST Test
Loading…
Simple Shooting Example — Monogame Code
Player shoots bullets when pressing space.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
public class ShootingExample : Game
{
private GraphicsDeviceManager _graphics;
private List<Vector2> bullets = new List<Vector2>();
private Vector2 playerPos = new Vector2(100,100);
public ShootingExample() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; }
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Space)) { bullets.Add(playerPos); }
for(int i=0;i<bullets.Count;i++) { bullets[i] += new Vector2(5,0); }
base.Update(gameTime);
}
}Monogame Language Guide
MonoGame is an open-source, cross-platform game development framework written in C# and based on Microsoft’s XNA framework. It enables developers to build 2D and 3D games for multiple platforms using a single codebase.
Primary Use Cases
- ▸2D and 3D games
- ▸Cross-platform indie games
- ▸PC, mobile, and console games
- ▸Educational game development
- ▸Prototyping and experimental game projects
Notable Features
- ▸C# and .NET development
- ▸2D and 3D rendering support
- ▸Cross-platform deployment
- ▸Low-level graphics API access (DirectX, OpenGL, Metal)
- ▸Audio, input, networking, and shader support
Origin & Creator
MonoGame was created as an open-source implementation of Microsoft XNA in 2009 by Xamarin contributors, continuing XNA’s legacy for cross-platform development.
Industrial Note
MonoGame is popular for developers who want XNA-style development in C# with multi-platform deployment, including Windows, Mac, Linux, iOS, Android, consoles, and web via WebAssembly.