Tileset into level

Tilebased levels are very common in 2D games. It makes it easier for the artist to create the looks, and it's easier to make levels in general. You can use multiple images as tiles, or you can use only 1 tileset. That last one is a more proper way, and I'm going to show you how to do it. Read more >>


public Level ()
			this.imgTileset = contentTileset;
			// We want to setup the rectangles here.
			for (int i = 0; i < this.map.Length; i++) {
				dataRectangle [i] = new Rectangle (this.tsMargin + (j % this.tsCols) * (this.tileWidth + this.tsMargin),
							  this.tsMargin + (int)Math.Floor((double)(j / this.tsRows)) * (this.tileHeight + this.tsMargin)

Slopes in a platformer

Instead of using a library, I decided to create my own platformer mechanics. This way I can understand what is actually going on, and I learn a lot from it. All of it was basic rectangle colliison, but I decided to include slopes as well. The slopes were the tricky part, but I managed pull it off. Read more >>


function checkSlope(i,x,y,w,h,tX,tY)
	local tW = Level.solid.tileWidth
	local tH = Level.solid.tileHeight

	if (x+w>=tX-tW/2 and x+w<=tX+tW/2) then
		if (i==2) then

			if (y+h >= (tY+tH/6) - ((x+w)-(tX-tW/2))/3) then
				overlap = y+h - ((tY+tH/6) - ((x+w)-(tX-tW/2))/3)
				hit = true
	return hit

Matrix numbers

If you don't have a lot to work with, try to be creative! Here I made matrix-style numbers in the console with basic C++ knowledge.


	//Place the cursor at the start of the console
	COORD cur = {0, 0};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cur);
	//Timer update
	timer += 1;
	//Reset string
	numberstring = "";

	for (int j = 0; j < 24; j++)
		for (int i = 0; i < 39; i++)
			//Check if the line can move.
			if (timer % delay[i]==0){
				//If it's the first line, create a new random character.
				if (j == 0){
					valueholder[j][i] = matrixChars[j][i];
					character = charlist[rand() % 62];
					matrixChars[j][i] = character;

Pendulum movement

Pendulum movement learned me a lot. It made me understand the concept of sine and cosine a lot better. It's the trick to understand sine and cosine, and to use them the right way. Here I explain the concept step for step. Read more >>


function weight:update(dt)

	self.velocity = self.velocity + dt * (self.grav * self.pendulum.cos)
   	self.xPos = self.xPos + dt*(self.velocity*-self.pendulum.sin)
   	self.yPos = self.yPos + dt*(self.velocity*self.pendulum.cos)

	local dx,dy = self.xPos-self.pendulum.xStart, self.yPos-self.pendulum.yStart
	local currentLength = math.sqrt(dx^2+dy^2)
	local correctionFactor = currentLength/self.pendulum.length
	self.xPos = self.pendulum.xStart + dx / correctionFactor
	self.yPos = self.pendulum.yStart + dy / correctionFactor


function pendulum:update(dt)

	self.xEnd, self.yEnd = self.parent.xPos, self.parent.yPos
	self.radian = math.atan2(self.xStart-self.xEnd,self.yStart-self.yEnd)
	self.sin = math.sin(self.radian)
	self.cos = math.cos(self.radian)
	self.length = math.sqrt((self.xStart-self.xEnd)^2 + (self.yStart-self.yEnd)^2)