Learning C# - (Tile Based Game)

Hello

We are starting a project(me and @nissidis )
purpose of this project is to

  • get involved with c# codewriting
  • develop a tile based game logic integrated within vvvv

The first task was creating a node that produces an array(spread to be exact)
where, everytime we want(ex. if the right arrow is pressed)
all the lines move down (the last line is lost)
and a new line in the top is imported.

This is the code for a 8*8 array.

- region usings
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;

using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;

using VVVV.Core.Logging;
- endregion usings

namespace VVVV.Nodes
{
	#region PluginInfo
	[PluginInfo(Name = "Array_Edit", Category = "Value", Help = "Basic template with one value in/out", Tags = "")](PluginInfo(Name = "Array_Edit", Category = "Value", Help = "Basic template with one value in/out", Tags = ""))
	#endregion PluginInfo
	public class ValueArray_EditNode : IPluginEvaluate
	{
		#region fields & pins
		[Input("Input")](Input("Input"))
		ISpread<double> FInput;
		
		[Input("NewInput")](Input("NewInput"))
		ISpread<double> FNewInput;
	
		
		[Input("Add", IsBang = true)](Input("Add", IsBang = true))
		ISpread<bool> FAdd;
		
		[Input("GetArray", IsBang = true)](Input("GetArray", IsBang = true))
		ISpread<bool> FGet;

		[Output("Output")](Output("Output"))
		ISpread<double> FOutput;
		
		

		[Import()](Import())
		ILogger FLogger;
		
		
		
		#endregion fields & pins

				
		public void Evaluate(int SpreadMax)
		{
			var FHelper = new double[SpreadMax](SpreadMax);
			var Counter = new int();
			Counter = SpreadMax - 8;
			//8 is the number of columns in my spread
			
			FOutput.SliceCount = SpreadMax;
			if (FGet[0](0) == true)
			{
			      for (int i = 0; i < SpreadMax; i++)
				  {
				      FHelper[i](i) = FInput[i](i);
		
				      FOutput[i](i) = FHelper[i](i);
			      }	
				
            }
			if (FAdd[0](0) == true)
			{
				

			     
			     
				  for (int i = 0; i < SpreadMax-8; i++)
				      FOutput[i](i) = FOutput[i+8](i+8);
				
				  for (int i = 0;i < 8 ; i++)
				      FOutput[Counter +i](Counter +i) = FNewInput[i](i);
		    }
	     }
			  

			//FLogger.Log(LogType.Debug, "hi tty!");
		}
	}
  • How can we make the code more general(any way to find the number of columns in my spread, and not inserting it by hand)
  • Any other suggestions or comments are welcome.

Next task:
Create a node which replace each number of the array with a certain texture
and ouputs a single texture(simiral to cross transform).

Code+Help (15.7 kB)

We found it difficult (and maybe useless for now) to create
a c# code that produces a single texture by replacing array’s number with filepaths.

https://vvvv.org/sites/default/files/imagecache/large/images/file.jpg
(red quad is our hero!)

*if someone can help on this it will be great(just to see the logic behind textures on c#)

So we made a patch where
*replace the numbers of the array with some simple texture(naming will help also for the collision part)
*Moving the array to the left is done by pressing right button

with 2 simple features
*Hero can jump + “gravity”(Up button)
*Collisions by creating new “Walkable Array” and checking certain conditions

Tile_game_8bit_v2.rar (47.0 kB)

we have made big progress and now we are trying to make
a node containing all the properties of a simple tile based game.
(i will post the plugins and the patch as soon as we fix all the bugs)

https://vvvv.org/sites/default/files/imagecache/large/images/hero_walk_cycle_0.jpg

*i have a question on c# programming
i want to achieve the following:
if a button is pressed a variable starts to bang whit a certain (adjustable)
period.

thanks

you could start a Timer? or you sample the time from the IHDEHost:

code(lang=csharp):
Import()
IHDEHost FHDEHost;

FHDEHost.GetCurrentTime();

Here is our Bitmap Image Parser, created for the purpose of viewing and debugging Tile Maps, as soon as possible we will upload the BMPParser

https://vvvv.org/sites/default/files/imagecache/large/images/img_1_help_BMPparser.jpg

The project continued, focused on pure c# code. We managed to reach a good visual result. Many problems generated during the process (basically on collision manipulation, and non-discrete Hero Positions coming from double accuracy on variables).

Recently i try to rebuild ,clean up the code, and fix some bugs. This is the result:
https://vvvv.org/sites/default/files/imagecache/large/images/TileBasedGame.jpg
plugin can manipulate controlling hero with

  • 4 keys up/down/right/left
  • 3 keys jump(space)/right/left

https://vvvv.org/sites/default/files/imagecache/large/images/TileBasedGame_textured.jpg

The code still needs some cleaning.
If anyone interested, feel free to ask for it.

  • tsou