Jump to content


~Dannyboy~

Member Since 23 Mar 2007
Offline Last Active Nov 16 2012 10:09 AM

Topics I've Started

Drawing A Filled Simple Polygon

02 October 2009 - 02:40 AM

Hey there everyone,

I've been working on a soft-body physics engine in between other stuff for quite a while now. I've come to a rather interesting problem, how do I fill the polygon? This polygon (defined by two arrays of coordinates) is guaranteed to be simple but not necessarily convex. For now just knowing how to fill it a solid colour will do.

The obvious thing would be to just do a triangle-fan using all the points, this fails though because it may be concave.

Another thing I had to do was calculate the area of the polygon, to do this I used a formula I came across in my research:
Posted Image

While convincing myself how this formula worked I had an idea of how to draw the polygon. I could draw an inverted triangle-fan as areas which were included an even number of times would not be part of the polygon. Here's the code I came up with:
PRE
{
draw_set_color(c_white);
draw_set_blend_mode_ext(bm_inv_dest_color, bm_inv_src_color);
draw_primitive_begin(pr_trianglefan);
for (j = 0; j < number; j += 1)
{
draw_vertex(point_x[j], point_y[j]);
}
draw_primitive_end();
draw_set_blend_mode(bm_normal);
}

And here's proof that it works: (No my soft-body doesn't look quite like that, it's just a random concave polygon I made to test the script.)
Posted Image

So, problem solved ;) ... Well not quite yet. :)

This is fine if my background's a solid colour, but it won't always be. If the background is textured, the polygon will also be textured (not the desired outcome).

To ensure that the polygon is always a solid colour, I could each step:
  • Create a surface the right size.
  • Clear this surface black, alpha 0.
  • Draw the inverted polygon to the surface.
  • Draw that surface with the colour I want.
  • Destroy the surface.

I have not yet implemented this but it sounds awfully expensive to be creating and destroying a surface every step. Not to mention the inconvenience of having to do some of it in the end-step event as you cannot change render targets during the draw event.

So any ideas? Am I going about this the right way or am I missing something?

Thanks,
~Dannyboy~

Mapping All Scripts

02 June 2009 - 08:01 AM

Hey everyone,

I'm looking for a way to create a map of all script resources, this is for use in my proposed system for the GMCG. It would be very useful to be able to keep track of the scripts without having to manually add them to a list.

As I'm sure many of you know there are a number of resource mapping scripts on gmlscripts.com; unfortunately there is no script for mapping scripts, I'm assuming this is because the author hit the same hurdle...

The problem is that no scripts can be created in game and therefore the maximum number of scripts cannot be determined. The only logical workaround I can think of is to have the caller guess the maximum number of ids (of course if you enter a huge number you're fairly sure you'll get all the scripts).

So basically my question is, is this the best way of doing this?
PRE
// scr_map_scripts(map, max)
{
// We assume there are no more than 'max' script ids
// Is this really the best solution?
var i;
for (i = 0; i < argument1; i += 1)
{
if (script_exists(i))
{
ds_map_add(argument0, script_get_name(i), i);
}
}
}


Your expert opinion would be appreciated, thanks,
~Dannyboy~

Unexpected Outline *understood*

15 February 2009 - 05:55 AM

Hey everybody,

I recently stumbled across something that stumped me. I was using the subtractive blend mode to erase parts of a surface. It's a bit hard to explain in English so here's some code, a screen-shot and a minimal gmk file.

The erase code is simple... or so I thought.
surface_set_target(s);
	draw_set_blend_mode(bm_subtract);
		draw_background(b_mask, mouse_x - 33, mouse_y - 33);
	draw_set_blend_mode(bm_normal);
surface_reset_target();

This used with my background, b_mask causes the area I wanted to be erased. But also it caused a single pixel outline around the erased area. See this screen-shot...
Posted Image

And here's a gmk file showing the full implementation: Download weird.gmk

So my question is... why is this outline appearing? I know I can remove it by using bm_zero but I'd still like to know why it's there! Who knows, this effect could even be useful but I'd appreciate an explanation.

Thanks,
~Dannyboy~

Table Soccer

02 February 2009 - 09:56 AM

TABLE SOCCER

Hey everyone! This is my winning entry to the "Sport's and Sim's Contest" Results are here!

This game works just like normal 11 per side Table Soccer... (almost)
Use the mouse to control your team. Move up and down to select rows of players and move left and right to shift them.
The goal of the game is to be the first team to get 11 points.

Screenshots:

Posted Image Posted Image Posted Image

Download:

http://www.yoyogames...ames/show/69364. Please play and rate it  :D

Mirror:

Download Table Soccer.zip

My Website:

link


Gm Credits

08 January 2009 - 07:15 AM

  • Title: GM Credits
  • Description: Add credits to games created with your extension
  • GM Version: 7.0
  • Registered: Yes
  • File Type: zip (includes: txt, gmk, gex, gml and png)
  • File Size: 50kb
  • File Link: Download GM Credits from Host-A (V1.5)
Additional Info
If you plan to build (or already have built) an extension package for Game Maker 7.0, this tutorial is for you.


AND SO THE JOURNEY BEGINS

This tutorial explains a simple way I've discovered to add credits to games created with your extension. While making it there were several things I had to take into account.

  • The credits could not affect anything in the game.
  • They couldn't be annoying for the developer using the extension or the user of their game.
  • They had to be easy to read, so you get proper recognition for your hard work.
Enough of the waffle, let's get to the good stuff already!

CREATING THE FOLDER
  • Create a new folder somewhere in your documents to keep all the files we make along the way.
CREATING THE IMAGE
  • Open your favourite image editing program and create a new image
  • Choose a suitable size and make a suitable image like this

    Posted Image

  • Save it as credits.png (or whatever you prefer)
  • Close the image editor, we don't need it any more
CREATING THE SCRIPT
  • Open up Game Maker 7.0
  • Add a new script
  • Name it show_credits (or whatever you prefer)
  • Type (READ: copy & paste) the following

    PRE
    // Hide window
    window_set_visible(false);

    // Set up splash window
    splash_set_main(false);
    splash_set_scale(1);
    splash_set_border(false);

    // Show image
    splash_show_image(temp_directory + "\temp\credits.png", 2000);

  • Click the OK tick
  • Right click on the script in the resource tree on the left
  • Select "Export Selected Script"
  • Save the script as credits.gml (or whatever you prefer)
  • Minimise GM, we'll use it again later
CREATING THE EXTENSION
  • For this step you'll need Extension Maker which is available here
  • Open Extension Maker (for now we'll just use a blank extension but you can easily add this to your other ones as well)
  • Name your extension my_extension (or whatever you prefer)
  • In the folder field type temp (or whatever you prefer) NOTE: You'll also have to change the script.
  • Fill in version and author appropriately
  • Click the Add GML button down the bottom left and find the file (credits.gml) you created earlier
  • Add a function and give it the same name as before (show_credits)
  • Leave external name and help line blank
  • Set arguments to 0 and tick the Hidden box
  • Navigate to the misc tab and fill in the "Finalization" field with the name (show_credits)
  • Click the Add Other button down the bottom left and find the file (credits.png) you created earlier
  • Save the package description and build a package from it
TESTING
  • Pop GM back up
  • Make a new game (don't worry about saving)
  • Add a blank room and press the OK tick
  • Go to extension packages
  • Hit install and install the package you just made
  • Select the package in available packages and move it across to used packages
  • Start the game
  • Hit the close button
  • Your credits should appear as the game is ending
WRAPPING UP

If you have any questions, comments, suggestions or typos to report, post away! :D