Déc 272013
 

For a while, I was (very) upset with ads on my tablets (android and ipad).
And unlike browsers on my windows (firefox or chrome) I could not find something like adblock for ipad.

Therefore I decided to setup a squid on my synology ds210j and to setup an adblock like in squid.
And success, no more nasty popups, quicker web sites, etc 🙂

the steps:

-install ipkg (see here for an how to, in french sorry).
-install squid : ipkg install squid
-customize squid.conf
-use a list of domain you wish to block (i used a list from this site)

my list of blocked domains : denied_domains

my squid.conf

negative_dns_ttl 10 second
connect_timeout 60 second
read_timeout 60 second
request_timeout 60 second
cache_dir ufs /opt/var/squid/cache 512 16 256
cache_access_log /opt/var/squid/logs/access.log
cache_log /opt/var/squid/logs/debug
cache_store_log /opt/var/squid/logs/storage
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32

acl localnet src 192.168.1.0/24

#on which ports do we allow connections using the proxy
acl SSL_ports port 443 # https
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl purge method PURGE
acl CONNECT method CONNECT
#acl url_ads url_regex "/opt/etc/squid/denied_ads.txt"
acl denied_domains dstdomain "/opt/etc/squid/denied_domains.txt"

#http_access deny url_ads
http_access deny denied_domains
http_access allow localnet
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
miss_access allow all

http_port 8080

via off
forwarded_for off
header_access From deny all
header_access Server deny all
header_access WWW-Authenticate deny all
header_access Link deny all
header_access Cache-Control deny all
header_access Proxy-Connection deny all
header_access X-Cache deny all
header_access X-Cache-Lookup deny all
header_access Via deny all
header_access Forwarded-For deny all
header_access X-Forwarded-For deny all
header_access Pragma deny all
header_access Keep-Alive deny all

note : you can use the dns_nameservers directive in squid.conf to use specific dns servers (i use opendns).
note : you can set a vpn client on your synology and your proxy will then use a different network (i use vyrvpn from giganews)
note : you can tweak your dhcp server to set the proxy for your clients automatically (see here)

 Posted by at 23 h 10 min
Déc 082013
 

As seen in article 19 (a platform game), I had came up with a text file format which I used to create levels.

I was about to start coding a level editor when I came on this editor : http://www.mapeditor.org/ .
This is freeware and it seems active enough.
Note : a nice thread here around possible tile editors.

I decided to use it with my current game project (a platform).
I choose the xml format (tmx format). See an example here : level .

I then had to code a method to parse the xml file.
In the process I also completed the multi-tiles to one block trick to avoid the edge-catching bug.
I also managed the texture tiling.

A class to create level in a farseer world will come in a next article.

Here below a screenshot of a level made with Tiled.

tiled

Here below a video playing this level.

 Posted by at 1 h 18 min
Déc 052013
 

Farseer has one specific not always easy to deal with : your world is meant in KMS (kilo meter second) whereas your rendering is in pixel.
Added to that, your world and rendering are two complete different things which does not make it easy to debug.

This where the DebugViewXNA class kicks in : it will render your world 🙂
This and a few other things like stats, datas, etc.

The how to use the DebugViewXNA class is rather easy :

add the project reference to debugview.xna.dll
add an imports to FarseerPhysics.DebugView
declare a _debugView As DebugViewXNA
set it up in loadcontent (for instance) :

_debugView = New DebugViewXNA(world)
_debugView.AppendFlags(DebugViewFlags.DebugPanel)
_debugView.DebugPanelPosition = New Vector2(15, 15)
_debugView.DefaultShapeColor = Color.White
_debugView.SleepingShapeColor = Color.LightGray
_debugView.LoadContent(GraphicsDevice, Content)

-use it in your draw method (after your spritebatch.end) :

Dim projection As Matrix = Matrix.CreateOrthographicOffCenter(0.0F, graphics.GraphicsDevice.Viewport.Width * DrawablePhysicsObject.pixelToUnit, graphics.GraphicsDevice.Viewport.Height * DrawablePhysicsObject.pixelToUnit, 0.0F, 0.0F, 1.0F)
_debugView.RenderDebugDataVB(projection)

A video to illustrate switching between rendering and debugging.

 Posted by at 22 h 35 min
Déc 032013
 

Recap #3 of recent articles around VB.Net and XNA :

VB.Net and Article 22 : 2 classes to handle character move
VB.Net and Article 21 : A simple 2D camera Version 2
VB.Net and XNA : Article 20 – A simple 2D camera
VB.Net and XNA : Article 19 – A platform game with FPE 3.5
XNA to Monogame part2
XNA to Monogame part1
VB.Net and XNA : Article 18 – Get text input from user
VB.Net and XNA : Article 17 – Farseer mouse joint & body from texture
VB.Net and XNA : Article 16 – Animating a sprite

Recap #2 of recent articles around VB.Net and XNA :

VB.Net and XNA : Vrooom V3 (car racing game)
VB.Net and XNA : PixDead by my 12 years old son 🙂
VB.Net and XNA : Article 15 – Screen Manager (i.e multi screens in XNA)
VB.Net and XNA : Article 14 – simple buttons
VB.Net and XNA : Article 13 – First steps with Farseer Physics Engine
VB.Net and XNA : Article 12 – Pixel collision on rotated shapes
VB.Net and XNA : Article 11 – Use a gamepad
VB.Net and XNA : Article 10 – A simple progressbar
XNA Games : how to distribute with Inno Setup

previous recap of recent articles around VB.Net and XNA :

VB.Net and XNA : Article 9 – A Pong Game
VB.Net and XNA : Vroom V1
VB.Net and XNA : Article 8 (pixel collision)
VB.Net and XNA : Article 7 (Scrolling)
VB.Net and XNA : Article 6 (move a texture, add a background, play some sound)
VB.Net and XNA : Article 5 (mouse input)
VB.NET and XNA : Article 4 (keyboard input)
VB.NET and XNA : Article 3 (draw text)
VB.Net and XNA : Article 2 (moving texture)
VB.Net and XNA : Article 1 (skeleton class)
VB.Net and XNA : Article 0 (introduction)

 Posted by at 19 h 45 min
Déc 032013
 

In previous article, I have regularly used either a rotating sprite (a car, a rocket, a tank, etc) OR an animated sprite (a walking character).

Here below these 2 classes.
You can use them in as a quick start for a game so that you dont have to bother with this part.

To use it the animated class :
declare it Dim animated As Animated
load it animated = New Animated(mTexture, 1, position, 0, 28, 32)
update it animated.Update(position, direction_)
draw it animated.Draw(spriteBatch)

Same goes with the rotating class :
declare it Dim rotated As rotated
load it rotated = New rotated(texture, _scale, New Vector2(50, 50), New Vector2(0, 0), _rotation, _speed)
update it rotated.Update(_rotation, _speed)
draw it rotated.Draw(SpriteBatch)

The animated class here : clsRotated .
The rotating class here : clsAnimated .

 Posted by at 19 h 38 min
Déc 022013
 

This time, lets add a zoom and rotating effect on our camera.

And lets re use the rotated sprite class you may have seen in Article 12 – Pixel collision on rotated shapes.

The only major change in the camera is the following where we will now use the position + rotation + zoom.

viewmatrix = Matrix.CreateTranslation(New Vector3(-position, 0)) * Matrix.CreateRotationZ(_rotation) * Matrix.CreateScale(New Vector3(_zoom, _zoom, 1))

The video.

The source code.
XNA_DEMO_20.2

 Posted by at 22 h 56 min
Déc 022013
 

In Article 16, we had animated a sprite.
Now lets enhance the demo with a 2d camera following our character creating a simple scrolling effect.
Note : a next article will cover parallax scrolling.

We will simply had a camera class.
Lets declare our camera,
then instantiate it in loadcontent passing the width and height,

cam = New camera(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height)

update it,

cam.setfocalpoint(New Vector2(dest_box.X, dest_box.Y), New Vector2(graphics.PreferredBackBufferWidth * 1.5 + 32, graphics.PreferredBackBufferHeight * 1.5 + 32))
cam.update()

and finally use it in our draw method thru a parameter in the spritebatch.begin method

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Nothing, Nothing, Nothing, Nothing, cam.viewmatrix)

The camera class is itself extremely simple (note that we will manage zoom and rotation also later)

Imports Microsoft.Xna.Framework
Public Class camera
Public position As Vector2
Public viewmatrix As Matrix
Dim _screenx As Integer
Dim _screeny As Integer
Public Sub New(SizeX As Integer, sizeY As Integer)
_screenx = SizeX
_screeny = sizeY
End Sub

Public Sub setfocalpoint(focalposition As Vector2)
position = New Vector2(focalposition.X - _screenx / 2, focalposition.Y - _screeny / 2)
If position.X < 0 Then position.X = 0 If position.Y < 0 Then position.Y = 0 End Sub Public Sub setfocalpoint(ByVal focalposition As Vector2, ByVal lock As Vector2) If focalposition.X > lock.X Then focalposition.X = lock.X
If focalposition.Y > lock.Y Then focalposition.Y = lock.Y

position = New Vector2(focalposition.X - _screenx / 2, focalposition.Y - _screeny / 2)

If position.X < 0 Then position.X = 0 If position.Y < 0 Then position.Y = 0 End Sub Public Sub update() viewmatrix = Matrix.CreateTranslation(New Vector3(-position, 0)) End Sub End Class

The video illustrating this.

The source code.
xna_demo_23.2

 Posted by at 21 h 10 min
Déc 012013
 

XNA and FPE is nice to play with.

This time lets start a platform game : an animated character jumping from one platform to another, collecting gems, in a wold of physics.

Some interesting point to note :

1-when my character is walking on tiles, the engine detects a collision at each edge, blocking my character 🙁
mad googling around, it seems i should :
-use joints : does not work
-use shapes : did not test it yet
-use multiple fixture for one bigger body : did not test it yet

For now, i create a circle for each tile instead of rectangles, it does mitigate (a lot) that bug : it is mostly invisible to the human eye (we see only the texture remember, not a body).

2-We want the character to jump only when touching the top of the tile, not the sides (or bottom).
Also, we dont want the character to jump while in the air.
There I have applied what seems the most common trick : a feet sensor, an extra body (not drawn) joined to my character (below) thru JointFactory.CreateWeldJoint.
When « feet » will collide with « floor » then isjumping=false else isjumping=true

3-The scenery is automatically generated from a text file (= a level) : level .
A level editor could come later.

As a whole, this is far from being perfect yet : the user/gamer experience is not optimal yet but still, I believe it is a good start 🙂

The video.

The source code.

XNA_DEMO_22

 Posted by at 18 h 41 min
Déc 012013
 

Here how far I got so far with monogame and ubuntu 13.04.
Remember I am not a linux boy. See previous article about monogame and windows.

1-install mono complete 2.1 (from ubuntu.org)
2-install mono develop 3.04 (from ubuntu store)
3-donwload and compile opentk (not sure this part is needed)
4-install monogame mpack (templates) for mono develop
5-sudo apt-get install libopenal1
6-sudo apt-get install libsdl1.2debian
7-sudo apt-get install libsdl-mixer1.2
8-test a monogame c# project

At this point you can build a c# project with monogame in ubuntu 🙂

Now for vb.net projects, I managed to create a new project but could not compile it (missing vb compiler?)
I guess I might have to look for more recent monodevelop/mono source (maybe from opensuse?)
Tip : for vb.net projects, change the file format to use when creating new projects to MSBuild (Visual Studio 2008) instead of the default MSBuild (Visual Studio 2010) From Preferences > Load/Save

 Posted by at 14 h 17 min