Git Product home page Git Product logo

win2dmazegame's Introduction

Win2D-MazeGame

The skeleton of a classic maze chase game for Windows 10, written in C# and using Win2D.

Introduction

If you’re looking for a project to keep the kids happy, or a way to re-create the 1980’s home computer boom, you might want to try writing your own classic video game.

A programming library for Windows 10 called Win2D is perfect for drawing and animating the kind of graphics that defined early video games.

This project uses Win2D to create the start of a maze chase game – one that you can use as the basis for your own game. It's written in C#, and comes complete with some basic graphics to start you off.

Requirements

This game was written on Windows 10 (Build 2004) using Visual Studio 2019.

Instructions

  1. Install the tools - you will need Visual Studio. The free Community edition will work perfectly.
  2. Download the project from this repo. The simplest way to do this is to select Download ZIP from the green CODE button, and extract all the files.
  3. Load it into Visual Studio. You can double-click on game.sln to do this.
  4. Build it and try it out! Make sure the target is set to x86 (in most cases) and press F5. The controls are W, A, S and D.
  5. Adapt, improve and learn!

Details

This is a simple maze chase / eat the dots game that demonstrates using Win2D to display and move images.

Maze.cs

This class defines the maze object. The game screen is a 1024 by 1024 canvas object, and while a single bitmap contains the maze image, behind the scenes the maze is a 16 by 16 array of integers with each element defining the possible directions the player or baddie can move in. When a player or baddie reaches a new tile in the maze (they move pixel by pixel, but only when line up with a tile perfectly can they change direction) they look at the maze data for that location. The data tells them which directions they can move in, and also if there is a "dot" present.

Player.cs

The player object contains the code that draws and moves the player's game character. The most involved code defines the action to take when the player's sprite reaches a tile junction, depending on what the keys (W, A, S or D) are being held down and what directions are available.

Baddie.cs

The baddie object chases the player around the maze. In fact, the baddie currently picks a direction at random (as long as it's not doubling back), so this is a great opportunity to add some intelligence to make the baddie pick a direction that will move them closer to the player. As with the player object, a new direction is only considered when the sprite is at the tile junction. Baddies can move at different speeds, as long as the speeds are a power of 2. There are three baddies currently defined, and more can be added by copying the code already present in the MainPage.cs class.

MainPage.cs

This is the "code behind" file for the MainPage.xaml file which defines the Win2D canvas object (where graphics can be drawn) and also sets up keyboard input events. The purpose of the code in MainPage.cs is to load the image files, and also create the player and baddie objects, and then move them around the screen based on a timer. The test for collisions is also performed in this class.

Suggestions for features

Game states need to be defined: for example, these could be "get ready", "game running", and "game over".

Lives need to be implemented. Traditionally you get three lives.

At the moment nothing happens when the baddies get too close to the player - other than the game stops moving. This is where you would "lose a life" and go to a game over screen. Likewise, nothing happens when the player has passed over all the dots. You might want the next level to have more baddies, or baddies which move faster or both.

As mentioned, the baddies are not smart and pick random directions. Adding some code that picks a direction closer to the player will make for a much more challenging game.

win2dmazegame's People

Contributors

aaronpinto avatar grantmestrength avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

win2dmazegame's Issues

Got error DEP6957 when trying to run the app for the first time

I just downloaded the .zip file, extracted it to a folder, then opened the .sln with VS 2019 Community Edition. I built it, which worked fine. But when I tried to run/debug it I got the following error:

DEP6957: Failed to connect to device '127.0.0.1' using Universal Authentication. Please verify the correct remote authentication
mode is specified in the project debug settings. COMException - No connection could be made because the target machine
actively refused it. (Exception from HRESULT: 0x8007274D) [0x8007274D] Game

I am running Windows 10 Professional, version 1909 (OS Build 18363.959), so perhaps that's the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.