Game1:
Spoiler
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 swiatlo
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
sciana_ex a;
static public Texture2D tex;
static public int Xmax = 100;
static public int Ymax = 75;
static public int Size = 8;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
a = new sciana_ex();
IsMouseVisible = true;
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
tex = Content.Load<Texture2D>("empty");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (Mouse.GetState().LeftButton == ButtonState.Pressed) {
a.putwall(Mouse.GetState().X / Game1.Size, Mouse.GetState().Y / Game1.Size);
a.zerowanie();
a.update();
}
if (Mouse.GetState().MiddleButton == ButtonState.Pressed)
{
a.putnull(Mouse.GetState().X / Game1.Size, Mouse.GetState().Y / Game1.Size);
a.zerowanie();
a.update();
}
if (Mouse.GetState().RightButton == ButtonState.Pressed)
{
a.putlights(Mouse.GetState().X / Game1.Size, Mouse.GetState().Y / Game1.Size, 0.05f);
a.zerowanie();
a.update();
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
a.draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
sciana:
Spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace swiatlo
{
class sciana
{
Rectangle rec;
public int typ;
public float alpha;
public sciana(int x, int y)
{
rec = new Rectangle(x * Game1.Size, y * Game1.Size, Game1.Size, Game1.Size);
typ = 0;
alpha = 0;
}
public void draw(SpriteBatch SB)
{
if (typ == 0)
SB.Draw(Game1.tex, rec, Color.White * alpha);
else if (typ == 1)
{
SB.Draw(Game1.tex, rec, Color.Black);
SB.Draw(Game1.tex, rec, Color.Red * alpha);
}
else
{
SB.Draw(Game1.tex, rec, Color.GreenYellow);
}
}
}
}
sciany:
Spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace swiatlo
{
class sciana_ex
{
sciana[,] tab = new sciana[200,150];
int i, j;
public sciana_ex() {
for (i = 0; i < 200; i++)
for (j = 0; j < 150; j++)
tab[i, j] = new sciana(i, j);
}
public void draw(SpriteBatch SB)
{
for (i = 0; i < Game1.Xmax; i++)
for (j = 0; j < Game1.Ymax; j++)
tab[i, j].draw(SB);
}
public void zerowanie()
{
for (i = 0; i < Game1.Xmax; i++)
for (j = 0; j < Game1.Ymax; j++)
tab[i, j].alpha = 0;// = 0 ;
}
public void update()
{
for (i = 0; i < Game1.Xmax; i++)
for (j = 0; j < Game1.Ymax; j++)
if (tab[i, j].typ == 2) {
putlights(i, j, 0.4f);
}
}
public void putwall(int x, int y)
{
if (!((x < 0) || (x > Game1.Xmax) || (y < 0) || (y > Game1.Ymax)))
{
tab[x, y].typ = 1;
}
}
public void putnull(int x, int y)
{
if (!((x < 0) || (x > Game1.Xmax) || (y < 0) || (y > Game1.Ymax)))
{
tab[x, y].typ = 0;
}
}
public void putlights(int x,int y, float _alpha){
if (!((x < 0) || (x > Game1.Xmax) || (y < 0) || (y > Game1.Ymax)))
{
if ((_alpha > 0.01f) )
{
tab[x, y].alpha = tab[x, y].alpha + _alpha - 0.01f;
tab[x, y].typ = 2;
for (float i = -1; i <= 1; i = i + 0.15f)
for (float j = -1; j <= 1; j = j + 0.15f)
putlight_line(x, y, _alpha - 0.01f, (float)i, (float)j);
}
}
}
public void putlight_line(float x, float y, float _alpha, float x_kie, float y_kie)
{
if (!((x < 0) || (x > Game1.Xmax) || (y < 0) || (y > Game1.Ymax)))
{
if (_alpha > 0.01f)
{
if ((tab[(int)Math.Round(x), (int)Math.Round(y)].typ != 1))
{
putlight_line(x + x_kie, y + y_kie, _alpha - 0.01f, x_kie, y_kie);
tab[(int)x, (int)y].alpha = tab[(int)x, (int)y].alpha + _alpha - 0.01f;
}
else {
tab[(int)x, (int)y].alpha = tab[(int)x, (int)y].alpha + _alpha - 0.01f;
}
}
}
}
}
}