Ludum Dare 31
December 5th-8th, 2014

Posts Tagged ‘code’

Hexagonal Grids!

Posted by (twitter: @theupgradezone)
Wednesday, November 12th, 2014 5:10 am

So, I did the maths on how to draw a perfect hexagon. Now, using the same logic from that
tutorial, in this tutorial I will show you how to make a hexagonal grid!

Maths:
Let’s say we have a hexagon with width a and height b.
(If you used the last tutorial, then the value of a from the last tutorial becomes twice that
value in this tutorial)

HexGrid_001

Now we generate a bunch of hexagons to fill up the screen area.
For this example the point of reference is in the center of the hexagon.

Each hexagon will be 3/4*a to the side of the last one, and b above or below:

HexGrid_002

Remember to keep a and b as whole numbers!

So the screen should look like this: (grey = hexagon, dark grey = overlap)

HexGrid_003

But we need every 2nd column to go up a bit, so that the hexagons interconnect properly.
So we use this equation, where x and y are the coordinates of the center of each hexagon:

HexGrid_004

Now your screen will look like this:

HexGrid_005

Excellent!

Now we can code it!

Pseudo Code:

Initialize:
width = (width of hexagon)
height = (height of hexagon)

Creation Loop:
create hexagon
x = x + (3*width)/4
if edge of screen is reached {
go back to starting edge of screen
y = y + height
}

Creation code for each hexagon:
y = y + mod(sin((90*(x/width))*height/2)

 

 

And there you have a hexagonal grid!

And this is the last of my little group of tutorials :3
Thanks for the comments on how to refine the logic and code of previous tutorials :)

How to draw a perfect Hexagon!

Posted by (twitter: @theupgradezone)
Tuesday, November 11th, 2014 9:55 am

So I did that maths of drawing a perfect octagon. Now, for a perfect hexagon!

Maths:

First, we must imagine a rectangle with width a and height b.
You must now choose which side, a or b, you want to specify.

Hexagon_001

If you specified a, to find b you must use this equation:

Hexagon_002

 

 

If you specified b, to find a you must use this equation:

Hexagon_003

Which can also be written as:

Hexagon_004

Remember to round to the nearest number!

 

Drawing:

Once you have a and b, we need to specify the 6 coordinates.
For this example, the frame of reference is the center of the rectangle.

The top and bottom two are b/2 up or down and a/2 to each side.

Hexagon_005

The two sides are a to the side.

Hexagon_006

Then you draw lines between the coordinates.

Hexagon_007

And there you have a perfect hexagon!

 

Pseudo Code:

Initialize:
// Let’s say we specified the width, a
width = (width of imaginary square)
height = 2 * width * sin(60)

Loop:

coord_1x = x – width/2
coord_1y = y + height/2
coord_2x = x + width/2
coord_2y = y + height/2
coord_3x = x + width
coord_3y = y
coord_4x = x + width/2
coord_4y = y – height/2
coord_5x = x – width/2
coord_5y = y – height/2
coord_6x = x – width
coord_6y = y

Hexagon_008

//draw_line(from_x,from_y,to_x,to_y)
draw_line(coord_1x,coord_1y,coord_2x,coord_2y)
draw_line(coord_2x,coord_2y,coord_3x,coord_3y)
draw_line(coord_3x,coord_3y,coord_4x,coord_4y)
draw_line(coord_4x,coord_4y,coord_5x,coord_5y)
draw_line(coord_5x,coord_5y,coord_6x,coord_6y)
draw_line(coord_6x,coord_6y,coord_1x,coord_1y)

 

And that’s how to draw a perfect hexagon!

Coming soon: Hexagonal grids!

How to draw a Perfect Octagon!

Posted by (twitter: @theupgradezone)
Tuesday, November 11th, 2014 4:45 am

I did some maths while I was bored, and I calculated a way to draw a perfect octagon.
I thought this might come in useful for some of you :3

Warning! Maths ahead!

 

Maths:

Imagine a square, with side length a.

001

Our octagon will fit in this square.

We will call the length of a side of the octagon b.

002

 

Now you put a into this equation:

003

Which can also be written as:

004

And you get b.

Now, round b to the nearest number. We can’t be dealing with fractions of pixels now, can we?

Now you have b, we can draw the octagon.

 

Drawing:

For this example, our reference point will be in the center of the octagon, which is also the center of our imaginary square.

005

Our first 2 co-ordinates will be a/2 up and b/2 to either side.

006

007

For the sides, it will be a/2 to the side and b/2 up or down.

008

Then, draw lines between the co-ordinates to finish the octagon.

009

And there you have a regular octagon!

 

Pseudo code:

Initialize:

size = (length of side of square)
oct_side = round((size*sqrt(2))/(2+sqrt(2)))

Loop:

coord_1x = x – oct_side/2
coord_1y = y + size/2
coord_2x = x + oct_side/2
coord_2y = y + size/2
coord_3x = x + size/2
coord_3y = y + oct_side/2
coord_4x = x + size/2
coord_4y = y – oct_side/2
coord_5x = x + oct_side/2
coord_5y = y – size/2
coord_6x = x – oct_side/2
coord_6y = y – size/2
coord_7x = x – size/2
coord_7y = y – oct_side/2
coord_8x = x – size/2
coord_8y = y + oct_side/2

010

//draw_line(from_x,from_y,to_x,to_y)

draw_line(coord_1x,coord_1y,coord_2x,coord_2y)
draw_line(coord_2x,coord_2y,coord_3x,coord_3y)
draw_line(coord_3x,coord_3y,coord_4x,coord_4y)
draw_line(coord_4x,coord_4y,coord_5x,coord_5y)
draw_line(coord_5x,coord_5y,coord_6x,coord_6y)
draw_line(coord_6x,coord_6y,coord_7x,coord_7y)
draw_line(coord_7x,coord_7y,coord_8x,coord_8y)
draw_line(coord_8x,coord_8y,coord_1x,coord_1y)

 

And that’s how to draw a perfect octagon!

Coming soon: How to draw a perfect hexagon!

 

To those interested in the maths involved to get the equation:

Maths

 

I originally calculated this to be able to draw the Aperture Science logo by hand, but I also saw the use of it on the computer!

Base code update

Friday, December 13th, 2013 4:04 pm

I’ve written a little base code project I’m going to start with.

It’s fairly simple and is available here.

To recap, it uses libgdx. If I fancy some postprocessing shader stuff, I’ll use the PostProcessor class from here, and if I need to do some pathfinding, I have my own simple A* implementation I wrote which is available right here.

Adios!

Hi everyone

****I posted new questions about compilers and editors in the comments please read them :) ****

I am an experienced programmer and know a few languages.

I want to start making games with a windows 7 computer for any operating system (linux, Mac and Windows).

I do not know which is the best coding language to use for that that is free But has a good compiler and runs well. I also do not want to use software like gamemaker or construct. Something like c++ or java or love2D so please take that into consideration!

Also what libraries would I need for 2D games for now to make it with.

Thanks so much for your help in advance! I really want to become some kind of game devloper so this is key.

Hope you all are having fun in the ludum dare! Expect me to be ready for the next one!

Hope my questions make sense!

Please comment!

Thanks

Swipefaststudios

Yesterday my stream peaked at 126 people watching me program! In order to make it a true 53 hour marathon, I just left the stream going overnight and pointed the camera at my bed. When I woke up, there were still 44 people in the stream who greeted me as I got back on! Aha, ha ah!

More coding action today at twitch.tv/dvcolgan! I’m making a massively multiplayer online capture the flag turn based real time game using Django and Coffeescript.  I’m hoping to have a playable game today.  Stay tuned! #ld48

Capture

Huldo LD

Posted by
Thursday, April 25th, 2013 1:23 pm

Signing up for the competition seems to be in order. It’s my first one, so hopefully it goes swimmingly.

I’m going to use my old XNA framework engine, but I’ll utilize ANX to get rid of the framework dependency. I tested it a few times and it seems to work mostly fine, except for Rendertargets which leak memory bad and crash the whole thing! Apparently fullscreen support is missing as well which is a bit of a bummer.

I might just ship two versions then eh, when/if I get something done of course.

Here is the codebase for those interested.

Have a nice day.

Chevy Ray’s Codebase

Posted by (twitter: @xMrPhil)
Friday, August 24th, 2012 7:36 am

I took Chevy Ray‘s code that he released as part of his keynote for LD23 and put it up on github.  It is written for his FlashPunk engine.   I used it to make my LD23 entry Seeds of Destruction and it worked out really well for me.

PS Chevy if you happen to see this, I’ll happily transfer the repository to you.

Code on GitHub

Posted by (twitter: @attrition0)
Tuesday, April 24th, 2012 9:14 pm

While more for myself than anything else, I’ve placed my Unity project on GitHub. Maybe somone can make it.

Game: Earth Is Dying!

GitHub: TinyWorld

Till next time!

Lunch #1 and Serious Bug

Posted by (twitter: @xMrPhil)
Saturday, April 21st, 2012 12:04 pm

Lunch 1
It’s almost 3 pm here in Arlington, VA and I’m having my first lunch for LD23. Kind of late but I wait until I’m hungry.

Chicken and Vegetable stir-fry.
Lunch 1

Progress
Screenshot 3
It’s coming a long, but I’m feeling the pressure. My task list seems too long. Worst part is I’ve hit a bug! Maybe you can help? My FlashPunk Entity is not calling the Update method! I’ve triple checked and the World Update is being called and calling the supper.Update()!

package SeedsOfDestruction
{
import com.greensock.easing.Cubic;
import com.greensock.easing.Quad;
import com.greensock.TweenMax;
import flash.display.BitmapData;
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;

public class SeedBullet extends Entity
{
[Embed(source = “/assets/Seed Bullet.png”)] public static const SEED_BULLET:Class;

public static const SPEED:Number = 200;

public var image:Image;

public function SeedBullet(player:Player)
{
// Make the Pink transparent
var bitmapData:BitmapData = Global.MakeTransparent(SEED_BULLET);
image = new Image(bitmapData);

super(x, y, image);

FP.angleXY(this, player.stem.angle, 40, player.x, player.y);
image.angle = player.stem.angle;
image.centerOrigin();
image.smooth = true;
active = false;
layer = 2;

setHitbox(40, 40);
type = “seedbullet”;

trace(“created”);
}

override public function update():void
{
trace(“update”);
super.update();

trace(“update2″);
if (collide(“BadPlant”, x, y))
{
explode();
}
}

override public function added():void
{
super.added();

var time:Number = FP.distance(x, y, world.mouseX, world.mouseY) / SPEED;
TweenMax.to(this, time, { x:world.mouseX, y:world.mouseY, ease:Quad.easeOut, onComplete:explode } );
}

public function explode():void
{
world.add(new Explode(this));
world.remove(this);
}
}
}

Desk Shot + Code

Posted by (twitter: @xMrPhil)
Friday, April 20th, 2012 4:51 pm

Here’s the command center, that’s right I code in a storage closet and that’s my cat Jack.  His hobby is to keep me from using the keyboard or mouse.

Mr. Phil Games Earth Headquarters

Mr. Phil Games Earth Headquarters

I also wanted to share this snippet of AS3 code that lets you choose a color and then convert pixels of that color to transparent pixels:

public static function MakeTransparent(source:*, color:uint = 0x00FF00FF) : BitmapData
{
// Get the bitmap data so we can fix it
var bitmapData:BitmapData
if (source is Class)
bitmapData = FP.getBitmap(source);
else if (source is BitmapData)
bitmapData = source;

// We aren’t use the transparent feature, hence the color
var bitmapDataNew:BitmapData = new BitmapData(bitmapData.width,
bitmapData.height, true, 0x00000000);
var pt:Point = new Point(0, 0);
var rect:Rectangle = new Rectangle(0, 0, bitmapData.width,
bitmapData.height);
var transparent:uint = 0x00000000;
var maskColor:uint = 0x00FFFFFF;
bitmapDataNew.threshold(bitmapData, rect, pt, “==”, color, transparent, maskColor, true);

return bitmapDataNew;
}

 

Ancient Rover

Posted by
Monday, December 19th, 2011 7:28 pm

I finished my game in time for the jam. http://www.ludumdare.com/compo/ludum-dare-22/?action=preview&uid=1044
If you thought that my last compo typing game was bad, this is a morse code game.
I’m an evil game designer… and loving it.

The only button that works is the spacebar.

[cache: storing page]