Black Hole of Codes (U: Optimized, draw to scale, etc.)

Talk about making games.

Black Hole of Codes (U: Optimized, draw to scale, etc.)

Postby DarkParadox » Sun Sep 19, 2010 12:50 am

Image
You must have Game-Editor 1.4.1 to use these demos, download it from here:
http://game-editor.com/forum/viewtopic.php?f=4&t=13001


ltCanvas API is dying!
Don't worry, this is a good thing. I'm going back and re-writing all the code I can think of from scratch. Introducing new features like loading in images as images or fonts, writing them easy, manipulating size and pixels, and drawing GUI using images instead! I also plan to continue to support the no-image-needed method by generating the GUI images using code instead.

ltCanvas API Changelog:
Code: Select all
(Most Recent) 6.0 >
          This update is mostly just to make all the code run
          a bit smoother for the user.
      Added new STYLE functionality to the drawText system
          STYLE option is now a DOUBLE, 0 is still normal text,
          1 is still bold text. ANY number above one will now be
          the scale to draw the text at (typing "2" will draw the
          text at double size). As said above, values like "1.5"
          are supported, but the resulted text will be pretty weird
          looking.
     Added "putpixeltoscale()" function
          This is the function I made to support the above scale drawing.
          Functions just like putpixel() but with a third parameter to
          set the scale of the pixel to be drawn. Supports DOUBLE type
          scale (decimals)
      Added "drawTextS()"
          More or less, I've decided to ignore drawTextP. I've left the
          function for the sake of backwards compatibility, but I've made
          the new function drawTextS. Four parameters: text, X, Y, Style.
          I've removed the RGB functions because they can be simulated with
          \a000 color codes instead.
      Simplified font variable list
          In previous versions, every letter of the font alphabet was its
          own variable. This totally clogged up the variables/menu list,
          and was hard to navigate when looking at this code file. Instead,
          I've replaced it with a single struct type (FONTSTRUCT) and its
          resulting font data "DEFAULTFONT." These two variables should
          show up in the variables/functions menu, but none of the other
          letters.
      Added "\v" option to drawText functions.
          This new option is used to shift the text over in any direction
          you want within the rows and colums of the text. Scroll down
          further into the text options to see exactly how to use it. You
          can even use it to type text over other text in the same command,
          and make stuff like underlined text by doing something like:
            drawText("Text\v-4+0____");

5.0 >
  In this new version, using "CURTHEME" has been changed! It is now "THEME(CURTHEME)" to allow in-game theme switching with the function   "setCURTHEME(theme_name);", so you'll have to go and edit all of your buttons for this, if you need to.

4.0 >
  changed the names of some of the functions, like drawGradientPlus and drawGradientPlusPlus to drawGradientP and drawGradientF. The new textbox() functions now have   one less parameter. As such, if you update an older project with this script make sure to check your code for these functions that may need to be changed!


Image
(The image is completely on-canvas, no graphics or files!)
Image
CanvasEx.ged
Should probably download this.
(106.11 KiB) Downloaded 113 times

Now, this one's cool. Some things you can do with this code?:
  • Draw coloured text anywhere on the canvas with no text actors or font files needed!
  • Draw gradients between two colours anywhere on a canvas with transparency and even skew.
  • Draw solid or empty rectangles easily anywhere on the canvas.
  • Draw solid circles and empty ellipses / ovals anywhere on a canvas.
  • Read through 2200 lines of code mostly consisting of 1's and 0's!
  • Create buttons, toggle buttons, labels, counters, sliders, and even EDITABLE TEXT BOXES on canvas with only about 2 to 4 lines of code!
  • Make interactive windows and menus that do fancy things!
  • Be amazed!
Cool right?

Image
DOCUMENTATION <- You're going to want to click that and view the documentation, as there's a TON of functions for this, it's a bit hard to figure out at first. And here's the script you need to start using them:
ltCT_Optimize.zip
Version 6 Hotfix 2
(13.66 KiB) Downloaded 93 times

Load it into GameEditor by opening it up, going to Global Code (Main Menu ► Scripts ► Global Code), and doing File ► Load.
If it doesn't work the first time, try going back into global code, re-loading and re-adding it once or twice. Game-Editor is a bit tempermental with my code. Let me know if you find any glitches or errors in the code! I haven't had much time to test everything and don't know how many bugs there are. Not counting the whole skewed gradient lengthening after it gets below the skew length. That I don't feel like fixing right now.

Image
Image
Left-click to draw, right click to adjust size and clear the canvas.
GridDrawing.zip
The lockToGrid function is in my canvas stuff too
(193.79 KiB) Downloaded 86 times


Image
Code: Select all
int lockToGrid(int val, int delimiter)
{
    return round(val/delimiter)*delimiter;
} // This function will return the nearest multiple of the delimiter to your value.

Usage:
Code: Select all
Player.x = lockToGrid(Player.x, 10); //The players X value will now round to the nearest 10th pixel.


Image
Image
Most of the code is on the actor "Control."
MenuDemo.zip
Doesn't use my new canvas stuff
(9.88 KiB) Downloaded 90 times


Image
Image
rpgbar.ged
Old, but works just fine.
(5.64 KiB) Downloaded 103 times


Image
(This code is OUT-OF-DATE and no longer compatible with ltCanvasTools, but the Standalone version works fine!)

Standalone
Code: Select all
// --Drawing Functions:
// Requires setpen before use.
void drawEdges(void)
{
   moveto(0, 0);
   lineto(width-2, 0);
   lineto(width-2, height-2);
   lineto(0, height-2);
   lineto(0, 0);
}

void drawGradient(char vh, int x1, int y1, int x2, int y2, double r1, double g1, double b1, double t1, double r2, double g2, double b2, double t2, double skew)
{
    double xmax = max(x1, x2);
    double xmin = min(x1, x2);
    double ymax = max(y1, y2);
    double ymin = min(y1, y2);
    double i;
    switch(vh)
    {
    default:
    case 'v':
    for(i=0; i<ymax-ymin; i++)
    {
        setpen(((1-max(i/(ymax-ymin),0))*r1)+(max(i/(ymax-ymin),0)*r2),
               ((1-max(i/(ymax-ymin),0))*g1)+(max(i/(ymax-ymin),0)*g2),
               ((1-max(i/(ymax-ymin),0))*b1)+(max(i/(ymax-ymin),0)*b2),
               ((1-max(i/(ymax-ymin),0))*t1)+(max(i/(ymax-ymin),0)*t2),
               1);
        moveto(x1,y1+i);
        lineto(x2,y1+i+skew);
    }
    break;

    case 'h':
    for(i=0; i<xmax-xmin; i++)
    {
        setpen(((1-max(i/(xmax-xmin),0))*r1)+(max(i/(xmax-xmin),0)*r2),
               ((1-max(i/(xmax-xmin),0))*g1)+(max(i/(xmax-xmin),0)*g2),
               ((1-max(i/(xmax-xmin),0))*b1)+(max(i/(xmax-xmin),0)*b2),
               ((1-max(i/(xmax-xmin),0))*t1)+(max(i/(xmax-xmin),0)*t2),
               1);
        moveto(x1+i, y1);
        lineto(x1+i+skew, y2);
    }
    }
}

//-- RPG bar functions! --

// Valid values for colour: 'r' (red), 'b' (blue), 'y' (yellow).
// colour is the foreground colour for the bar, the bg colour will always be red.
// The colour defaults to Green if you put in a non-valid value.
void HPDraw(double value, double max_value, char colour)
{
    int ygb[3];
    // Get the proper position for the health bar to
    // end on the bar.
    double curval = round((value/max_value) * (width-2));
 
    switch(colour)
    {
        // Set the array containing our RGB value to
        // a different set of colours based on the
        // letter your typed in.
        case 'b':
        ygb[0] = 0;
        ygb[1] = 0;
        ygb[2] = 255;
        break;
 
        case 'g':
        ygb[0] = 0;
        ygb[1] = 255;
        ygb[2] = 0;
        break;
 
        case 'y':
        ygb[0] = 255;
        ygb[1] = 255;
        ygb[2] = 0;
 
        case 'r':
        ygb[0] = 255;
        ygb[1] = 0;
        ygb[2] = 0;
    }
 
    // Draw a background gradient from black to red.
    drawGradient('h', 0,0, width,height, 255,0,0,0, 100,0,0,0, 0);
 
    // Draw a gradient from a darker version of the selected color
    // to the selected color
    drawGradient('h', 1,1, curval-1, height-2, max(ygb[0]-150, 0), max(ygb[1]-150,0), max(ygb[2]-150,0), 0, ygb[0], ygb[1], ygb[2], 0, 0);
 
    // Draw the edges of the bar
    setpen(125,125,125,0,0);
    drawEdges();
}

void HPDrawPlus(double value, double max_value, int r1, int g1, int b1)
{
    double curval = round((value/max_value) * (width-2));
    drawGradient('h', 0,0, width,height, 255,0,0,0, 100,0,0,0, 0);
    // Makes sure the RGB value doesn't go below 0.
    drawGradient('h', 1,1, curval-1, height-2, max(r1-150,0), max(g1-150,0), max(b1-150,0), 0, r1, g1, b1, 0, 0);
    setpen(125,125,125,0,0);
    drawEdges();
}


To use this function:
Create a new actor, whatever name you want, as long as it's a canvas.
Put the following code in the Draw Actor event of the canvas.
Code: Select all
HPDraw(50, 100, 'g');
//HPDraw(current_value, max_value, colour_value);
//Valid colour values: 'g', 'b', 'y'.
//use HPDrawPlus to put in your own RGB values:
//HPDrawPlus(current_value, max_value, red, green, blue);


Image
(These graphics are not mine, and should not be used freely in your own games. Thanks!)
Image
AntiMoonWalking.zip
How old is this again?
(68.41 KiB) Downloaded 93 times


Image
Image
Phys.ged
Wee, pixel physics!
(115.74 KiB) Downloaded 105 times


Left-Click to draw selected material. Right-Click to erase.
Version 3! Added magma and cement. Magma interacts with water in interesting ways, and cement hardens when it hits certain other materials! This has also been updated with a totally new GUI showing off my GUI functionality. You can also still save and load maps. In fact, if you want to see that in action, download the example map, unzip it and place "pixmap1.map" in the same folder as "Phys.ged", and then when you run it click "Load" in the bottom right.
pixmap1.zip
Sunny island and everything
(1.71 KiB) Downloaded 103 times

You can increase/decrease the amount of pixels on the map by going into Global Code, opening the "Phys" script, and changing "#define SCALE 4" to a different number. For the most amount of pixels allowed, use "#define SCALE 2", the higher the number, the less pixels on-screen.

Image
Image
Image
To use this:
  • Right-click the image above, click "Save As..." and save the picture.
  • Go in Game-Editor and make a new actor.
  • Go in that actor's control panel, and click "Text" in the top right.
  • Click "New Font" and "From Image File"
  • It should auto-set the number of characters to 95, if not, do it yourself.
  • Click the "Initial Character" text box and type a space.
  • Click OK!

Need a function to do something? Help coding? Just send me a PM and I'll see if I can help you.
Last edited by DarkParadox on Fri Jan 17, 2014 3:50 am, edited 67 times in total.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

[Reserved Post]

Postby DarkParadox » Wed Sep 22, 2010 6:59 pm

This post has been reserved for future use.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby Wertyboy » Wed Sep 22, 2010 11:50 pm

Now i know how to make this mennu, thx Dark
User avatar
Wertyboy
 
Posts: 543
Joined: Tue Jun 15, 2010 12:38 pm
Location: HCM City, Vietnam
Score: 44 Give a positive score

Re: Darkparadox's black hole of codes.

Postby lcl » Mon Sep 27, 2010 6:33 pm

Cool! :D
Nice work. :D
SABRE (semi-3D engine) official development topic: viewtopic.php?f=6&t=12644
A game project that utilizes SABRE: viewtopic.php?f=4&t=13297
User avatar
lcl
 
Posts: 2238
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 265 Give a positive score

Re: Darkparadox's black hole of codes.

Postby DarkParadox » Thu Sep 30, 2010 7:51 pm

Latest updates:
  • Colourful Grid Draw now.
  • Menu demo now has code for when you press "enter".
  • Canvas Drawing Functions updated with drawGradientPlus / drawGradientPlusPlus
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby DarkParadox » Sat Oct 02, 2010 11:40 am

Latest updates:
  • New HPDraw(); function!
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby Hblade » Sun Oct 03, 2010 8:17 pm

Amazing dude :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 180 Give a positive score

Re: Darkparadox's black hole of codes.

Postby DarkParadox » Thu Oct 07, 2010 5:47 pm

Latest updates:
  • New anti-moonwalking demo.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby NightOfHorror » Tue Nov 02, 2010 4:33 pm

Dear DarkParadox,

I would like you to continue on this. You were on a role so don't give up. This is on tutorials page.(Sorry Codedummys) You need to keep working on this:D



_NightOfHorror_
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1825
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

Re: Darkparadox's black hole of codes.

Postby DarkParadox » Tue Nov 02, 2010 7:38 pm

( Thanks for the support night Image )
Latest updates:
  • New Utilities section.
  • New BMP24 to PutPixel(); Utility.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby 247wkman » Mon Sep 09, 2013 12:18 am

i dl Canvas Drawing Functions example. firstly i set the workspace color from black to blue so when i teaked CanvasC to create the elypse it would do it on a dark background with to drawn elypse tranparent- confirming i could indeed create spotlights in perfect circles (potentially over any actor target i want hopefully). i don't yet know enough how to do it.
i creted a new ged and pasted the script from CanvasC into a newly created one- it then gave error warnings of no identifiers. so i copied over the global code to see if the referencies were in there- it seemed they weren't.
so i look in the other actors and in the variable list and it seems like the identifiers aren't in there. so where do you put them? if not in global code or other actors where is the identier script located to make the canvas scripts work?
247wkman
 
Posts: 63
Joined: Mon Dec 13, 2010 3:55 pm
Score: 3 Give a positive score

Re: Darkparadox's black hole of codes.

Postby DarkParadox » Sat Sep 14, 2013 12:53 am

The variable "timer" which is used in CanvasCs code is an actor variable I created for that demo to do the animations. To just copy over the code, you're going to have to add the variable timer as an actor variable set to the type real. (I think this is what the problem is, anyways)

You're lucky! This is the first time I've been on the forums in well over a year!
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Darkparadox's black hole of codes.

Postby bat78 » Wed Oct 02, 2013 1:04 pm

DarkParadox why are you so nice.
Future of "Project Game-Editor Revival" here
User avatar
bat78
 
Posts: 790
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 83 Give a positive score

Re: DarkParadox's Black Hole of Codes(HUGE UPDATE, Canvas te

Postby DarkParadox » Tue Oct 29, 2013 5:55 pm

Thanks for the flattery bat78, but I'm not that nice.

On that note, Huge Amazing Topic Update Time.
Check the topic post for details!
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: DarkParadox's Black Hole of Codes(HUGE UPDATE, Canvas te

Postby lcl » Tue Oct 29, 2013 7:13 pm

Great to see you here, DarkParadox! :D
Great job, I'll have to take a closer look at all the demos now after you've updated them.
Are you planning to stay on the forums for a longer time? :)
SABRE (semi-3D engine) official development topic: viewtopic.php?f=6&t=12644
A game project that utilizes SABRE: viewtopic.php?f=4&t=13297
User avatar
lcl
 
Posts: 2238
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 265 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron