Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop Space War Mini Game based on MonoGame

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to develop space war Mini Game based on MonoGame. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Without saying much, follow the editor to have a look.

On a whim recently, I downloaded Microsoft Small Basic and wrote Mini Program with two graphics transformations, hoping to make my son interested in technology (of course, it wasn't my intention to become a programmer like me). Pick up the first language GW Basic I learned when I started computer programming. After downloading Small Basic, the first graphics program I wrote was a colorful ball bouncing around on the screen, which looked a bit like the phenomenon of a small ball virus outbreak under DOS (sorry to expose my age), while the second program showed a pattern of airplanes that could be controlled by a mouse in the window, and my son looked very carefully at that time. I thought, I might as well make a game of jerking off for my son to play, considering that Small Basic is still relatively weak in graphics processing, so based on my previous research experience on Microsoft XNA, I realized a simple space war Mini Game with the help of MonoGame in Visual Studio 2013.

MonoGame

Let's start with a brief introduction to MonoGame. It is an open source implementation for Microsoft XNA 4 and can support a variety of platforms such as Xbox360, Windows, Windows Phone, iOS, Android, Mac OS X, Linux, Windows 8 Metro, Windows 10, and so on. Support for PlayStation Mobile, raspberry pie and PlayStation 4 is being refined. In terms of graphics systems, MonoGame allows developers to choose between OpenGL and DirectX. You can go to the introduction page of MonoGame's website to learn more about the history of MonoGame.

I planned to simulate a game similar to Contra two years ago, using Microsoft XNA Game Studio 4, but I stopped digging into the game because of a problem with map processing. So, for some time after that, I also wanted to amuse myself on Mini Game in my spare time, but I was told that Microsoft XNA Game Studio had been abandoned by Microsoft, and the last VS version that supported it was Visual Studio 2010, so after a search, I started my journey to MonoGame.

At first, MonoGame drove me crazy because it lacked one of the most important features: Content Pipeline. If you want to use MonoGame, you must continue to use Microsoft XNA Game Studio, and use XNA's Content Pipeline to compile the required materials such as materials, sounds, animations, fonts, etc., into xnb files, and then call it in MonoGame. This was very unacceptable, so I basically gave up the idea of using MonoGame at that time.

However, thanks to the efforts of the open source community, the new version of MonoGame fully supports Content Pipeline, and you can find the game's Content file in the solution manager created by MonoGame, and double-click it to open the Content editor:

It should be said that using the latest version of MonoGame can already meet the needs of developing medium-sized games, although it still has some Bugs.

Starwar

This is the end of the introduction of MonoGame, and I will not explain it in depth because of the limited space. Please move to the following video to see if my Starwar space war game is decent:

[click here to watch the video]

How's it going? Is it all right? In any case, it is OK to attract children. ^ _ ^

Download and install games

Please [click here] to download the installation package of the game. Note that during the installation process, you will be prompted to install OpenAL (an open audio library), and click to confirm the installation. After the installation is complete, you can start the game configuration program and the Starwar Space Wars game from the start menu.

When you start the game configuration system, a user account Control (User Access Control) dialog box appears, click "Yes" (Yes), and then open the configuration interface:

After the configuration is completed, click the OK button, and then go to the start menu and select Starwar to open the game:

Use the mouse to move the aircraft, click the left button to launch a laser to attack the enemy aircraft, press the ESC key at any time to exit the game.

Source code of the game

The source code of this game is public, the address is: https://github.com/daxnet/Starwar. You can use the Git client to clone the source code locally, and note that to compile the source code correctly, your computer needs to meet the following conditions:

Install Visual Studio 2013

Install MonoGame 3.4

.net Framework: version 4.0

Description: game resources are all from the network.

Background music: the second level of the game "Salaman Snake" Remix BGM (from http://v.youku.com/v_show/id_XNTcyNDUxODAw.html?from=s1.8-1-1.2)

Star background: from XNA Resource Network (http://xnaresources.com/)

Sound effects of bullet firing and blasting: from XNA Resource Network (http://xnaresources.com/)

Other images (mainframe, enemy aircraft, bullets): from Bing search results

Design of the game

The game adopts object-oriented design based on Visual C#. In the game business, the objects participating in the game are collectively referred to as Sprite. The following are the various types of elf class dependence diagrams of the game:

Sprite: the base class for all sprite types

LaserSprite: the spirit of laser bullets

ParallaxStarSprite: represents the spirit of the moving star. The star spirit will fall continuously throughout the game to show the effect that our plane is flying forward.

BackgroundSprite: star background genie, motionless throughout the game

EnemySprite: enemy aircraft genie

SpaceshipSprite: my machine spirit

AnimatedSprite: an animation wizard that produces animated effects through a given Sprite Sheet that contains each picture

SpritePool: a spirit library that manages the specified types of sprites displayed on the screen. When the sprite appears on the screen, the IsActive property of the sprite is true, and the sprite can be added to the sprite library for overall management; when the managed sprite disappears from the screen (the coordinates exceed the screen boundary), the elf library will release the wizard's resources and remove it from the library. The spirit library ensures that the objects generated during the whole game are within a certain range.

SpriteGenerator: a sprite dynamic generator used to generate a wizard anywhere on the screen at regular intervals and move it in a certain direction at any speed. For example, enemy planes and stars are randomly generated by the dynamic genie generator, and the generated sprites are added to the SpritePool, and the life cycle is managed by SpritePool.

The implementation code will not be posted here.

The above is how to develop space war Mini Game based on MonoGame. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report