Mystic Software Forums

Mystic Software => General Discussion => Topic started by: AlienDude on May 30, 2005, 05:44:38 PM

Title: (no subject)
Post by: AlienDude on May 30, 2005, 05:44:38 PM
Hello all i need someone to show me how to use canvassing again, it's been a while since i coded, so any help would be appreciated. the current reason for it is for the menu, as there will hopefully be a menu demo later this week for teh expo.
Title: (no subject)
Post by: Xorlak on May 31, 2005, 08:43:52 PM
Checkout the online reference <a href='http://tk3.toolkitzone.com/help/?page=19&PHPSESSID=8489aa47dada6fe4e0cd66877946431d#createcanvas' target='_blank'>here</a>.

The basic idea is that you create a canvas, draw to it off screen (by appending the canvas' ID to most drawing commands), then draw the canvas itself to the screen.
Title: (no subject)
Post by: AlienDude on June 01, 2005, 09:21:24 AM
wow, after the literal millions of times i looked at that darn thing, it finally clicked on what i did wrong.  I have one question, does kill canvas delete the reference entirely, so you would have to reassign the pic everytime, or just once will do the trick, because i will only be working with one pic Smile .
Title: (no subject)
Post by: Colin on June 01, 2005, 04:29:23 PM
killCanvas() frees the memory allocated for the canvas (colour depth * width * height bits).
Title: (no subject)
Post by: AlienDude on June 01, 2005, 06:53:32 PM
so that would mean resetting the pic (ie drawimagetransparent() with the canvas index) every time the cursor is moved, right? or would it only kill that instance of it?

like you set up the canvas, set up each of the positions, and just kill the previous one and draw the desired one:

Code: [Select]
createcanvas(32,32)
drawimagetransparend(blah,,,,,,,0)
...
//cursor moves
killcanvas(//prev canvas pos)
drawcanvastransparent(0,,,,,,)
...


kinda like that.
Title: (no subject)
Post by: Colin on June 02, 2005, 05:12:03 PM
When you draw a line, can you erase that line? When you set a pixel, can you erase that pixel? Somehow people then think that they can magically peel up canvases. No.
Title: (no subject)
Post by: AlienDude on June 03, 2005, 07:03:53 AM
that did help...
Title: (no subject)
Post by: Colin on June 03, 2005, 08:55:55 AM
It was a real answer, not some out-of-nowhere attempt to insult you as your PM suggests.

Here's a longer response:

Clearing a canvas (i.e., clear(cnv!)) does work; it just doesn't do what you think it does. Canvases are off screen memory that--when you use drawCanvas()--can be copied (blitted) forward--that is, onto the screen. When you clear a canvas, you clear the memory, so that subsequent blits would blit only black forward, but you do not alter the screen. After a canvas has been blitted forward, it is exactly like any other drawing--be it lines, squares, etc.--and cannot be 'pulled up' because whatever might have been underneath it does not exist anymore.

When you're setting up your menu system, try to have a number of canvases and confine each one to holding a certain part of the screen: maybe one will hold an enemy, maybe one a cursor image. Don't think these need to be loose variables; they can be arrays or whatever the situation calls for and you feel is logical. The idea from here is to blit all these pieces onto another canvases in the correct order, then blit that canvas (i.e., the 'collage' canvas, the backbuffer) forward creating a whole scene with no flicker.

Of course, that's not too easy, so I'll elaborate here with an example less complicated than a menu system. Say we want to move an image--we'll use mwin.jpg for the simple reason that it's included with every game--across a background--which will be layout.gif for the same reason--and increment a number in the corner while producing no flicker at all.

First, think about the layers involved. The lowest is the background, then the image, and then the corner counter--of course, the counter might actually be equal to the image, but we'll draw it above in case the image passes under it. To render this scene, we'll want to build everything on a canvas that we cannot see--a backbuffer--then blit that backbuffer forward.

In other words, we're going to draw everything onto a canvas, draw that canvas, clear the canvas, draw again, blit the canvas forward again, and so forth until we've moved the image over the screen. I'm not sure how much you've read up on canvases, but we might accomplish our scene with the following code (assuming the resolution is 640 * 480):

Code: [Select]
// Create a canvas.
cnv! = createCanvas(640, 480)
// Iterate over the y axis.
for (i! = 1; i! < 480; i!++)
{
    // Clear the canvas.
    clear(cnv!)
    // Draw the background.
    bitmap("layout.gif", cnv!)
    // Draw the image.
    setImage("mwin.jpg", i!, i!, 30, 30, cnv!)

    // Write the current position.
    str$ = "Position: " + castLit(i!) + ", " + castLit(i!)
    colorRgb(0, 0, 0)
    // Make the part behind the text black.
    fillRect(1, 1, getTextWidth(str$), getTextHeight(str$), cnv!)
    colorRgb(255, 255, 255)
    text(1, 1, str$, cnv!)

    // Draw the canvas.
    drawCanvas(cnv!, 0, 0)
}
// Clean up.
killCanvas(cnv!)

If you study the code, you'll realize that it's really not that complex: we simply draw to a canvas, then draw that canvas. The main rendering portion of your menu system will look something like that, except instead of setting down images and text, you will set down whole other canvases. There's nothing harder about it: use drawCanvas()'s last parameter to draw it onto another canvas. So your rendering routine might lay down the menus, the HP values--possible by calling functions for each individual task--then blit that whole canvas forward. It's tricky to imagine, but as you code, it will all fall into place.
Title: (no subject)
Post by: AlienDude on June 03, 2005, 01:52:49 PM
THANK YOU, THAT IS MORE LIKE IT Smile
FOUR THUMBS UP!!!!!!
that goes also for designing the canvas concept, very nice!

So basically set up a canvas encompassing the whole menu, and then make another one for the cursor itself(and others for the other elements on there, of course), set up each possible position, and draw as needed.  SWEET!!!
Title: (no subject)
Post by: AlienDude on June 03, 2005, 06:26:09 PM
the problem with this program is that the background image disappears after the cursor loads up, wtf is going on here, i thought clear(cnv!) would only clear the canvas!!!  i tried drawcanvastransparent(),but it didnt clear properly, it gave me double pictures...

btw i WOULD have attached the file, but the board wouldn't let me >_>

<!--r1--><div class='codetop'>CODE</div><div class='codemain'><span style="position:relative;width:250px;background-color:#FFF;margin:3px;padding:3px;border:1px solid #F00;float:right;">Warnings
<a href="#IDacea801dfe455e8983d2a93f7f33740fLINE21"><span style="color:#A08;text-decoration:underline;">Unknown Variable Type</span></a>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE30"><span style="color:#A08;text-decoration:underline;">Unknown Variable Type</span></a></span>

<span style="position:relative;width:250px;background-color:#FFF;margin:3px;padding:3px;border:1px solid #F00;float:right;">Bookmarks
<a href="#IDacea801dfe455e8983d2a93f7f33740fLINE4"></a><span style="color:#A08;text-decoration:underline;">test prog</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE17"></a><span style="color:#A08;text-decoration:underline;">constructor-type dealie, slightly overloaded</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE18"></a><span style="color:#A08;text-decoration:underline;">sets up the array index</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE27"></a><span style="color:#A08;text-decoration:underline;">ovrloaded form used for possible mutiple skins,</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE34"></a><span style="color:#A08;text-decoration:underline;">stores all the positions into two arrays to be accessed later</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE35"></a><span style="color:#A08;text-decoration:underline;">this form sets up the index the order it is instanced</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE42"></a><span style="color:#A08;text-decoration:underline;">this form allows custom indexing</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE48"></a><span style="color:#A08;text-decoration:underline;">self explanatory, this is the problem method</span>, <a href="#IDacea801dfe455e8983d2a93f7f33740fLINE56"></a><span style="color:#A08;text-decoration:underline;">the actual cursor movements work, i just have a problem with the pic leaving!!</span></span>

<span style="font-family:courier;font-size:11px;white-space:pre;"><span style="color:#F80;">
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE1"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE2"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE3"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE4"></a><span style="color:#084;font-style:italic;">//test prog</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE5"></a><span style="color:#048;">cnv!</span> <span style="color:#94F;">=</span> <span style="color:#00F;font-weight:bold;">createcanvas</span><span style="color:#94F;">(200,<span style="color:#F80;">400</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE6"></a><span style="color:#00F;font-weight:bold;">bitmap</span><span style="color:#94F;">(<span style="color:#888;">"clockwerk.png"</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE7"></a><span style="color:#00F;font-weight:bold;">pcursor</span><span style="color:#94F;">(<span style="color:#888;">"aslogo.gif"</span>, <span style="color:#F80;">42</span>, <span style="color:#F80;">32</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE8"></a><span style="color:#00F;font-weight:bold;">setpos</span><span style="color:#94F;">(120, <span style="color:#F80;">60</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE9"></a><span style="color:#00F;font-weight:bold;">setpos</span><span style="color:#94F;">(120, <span style="color:#F80;">100</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE10"></a><span style="color:#00F;font-weight:bold;">setpos</span><span style="color:#94F;">(120, <span style="color:#F80;">140</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE11"></a><span style="color:#00F;font-weight:bold;">cursormove</span><span style="color:#94F;">(2)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE12"></a><span style="color:#00F;font-weight:bold;">wait</span><span style="color:#94F;">()</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE13"></a><span style="color:#00F;font-weight:bold;">cursormove</span><span style="color:#94F;">(0)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE14"></a><span style="color:#00F;font-weight:bold;">wait</span><span style="color:#94F;">()</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE15"></a><span style="color:#00F;font-weight:bold;">windows</span><span style="color:#94F;">()</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE16"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE17"></a><span style="color:#084;font-style:italic;">//constructor-type dealie, slightly overloaded</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE18"></a><span style="color:#00F;font-weight:bold;">method pcursor</span><span style="color:#94F;">()</span> <span style="color:#084;font-style:italic;">//sets up the array index<span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE19"></a><span style="color:#94F;">{</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE20"></a>   <span style="color:#048;">cnvindex!</span> <span style="color:#94F;">=</span> <span style="color:#94F;">-</span>1 <span style="color:#94F;">/</span><span style="color:#94F;">/</span>eventually used for debugging and such</a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE21"></a>   <span style="color:#F00;font-weight:bold;font-style:italic;">curs</span> <span style="color:#94F;">=</span> cfile <span style="color:#94F;">/</span><span style="color:#94F;">/</span>crystally cursor that is in all the old <span style="color:#048;">screenies!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE22"></a>   <span style="color:#048;">cx!</span> <span style="color:#94F;">=</span> 32</a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE23"></a>   <span style="color:#048;">cy!</span> <span style="color:#94F;">=</span> 32</a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE24"></a>   <span style="color:#00F;font-weight:bold;">setimagetransparent</span><span style="color:#94F;">(cfile, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#048;">cx!</span>, <span style="color:#048;">cy!</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#048;">cnv!</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE25"></a><span style="color:#94F;">}</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE26"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE27"></a><span style="color:#00F;font-weight:bold;">method pcursor</span><span style="color:#94F;">(file, <span style="color:#048;">x!</span>, <span style="color:#048;">y!</span>)</span> <span style="color:#084;font-style:italic;">//ovrloaded form used for possible mutiple skins,<span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE28"></a><span style="color:#94F;">{</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE29"></a>   <span style="color:#048;">cnvindex!</span> <span style="color:#94F;">=</span> <span style="color:#94F;">-</span>1</a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE30"></a>   <span style="color:#F00;font-weight:bold;font-style:italic;">curs</span> <span style="color:#94F;">=</span> file</a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE31"></a>   <span style="color:#048;">cx!</span> <span style="color:#94F;">=</span> <span style="color:#048;">x!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE32"></a>   <span style="color:#048;">cy!</span> <span style="color:#94F;">=</span> <span style="color:#048;">y!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE33"></a><span style="color:#94F;">}</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE34"></a><span style="color:#084;font-style:italic;">//stores all the positions into two arrays to be accessed later</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE35"></a><span style="color:#00F;font-weight:bold;">method setpos</span><span style="color:#94F;">(<span style="color:#048;">x!</span>, <span style="color:#048;">y!</span>)</span> <span style="color:#084;font-style:italic;">//this form sets up the index the order it is instanced<span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE36"></a><span style="color:#94F;">{</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE37"></a>   </a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE38"></a>   <span style="color:#048;">px[cnvindex!]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">x!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE39"></a>   <span style="color:#048;">py[cnvindex!]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">y!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE40"></a><span style="color:#94F;">}</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE41"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE42"></a><span style="color:#00F;font-weight:bold;">method setpos</span><span style="color:#94F;">(<span style="color:#048;">x!</span>, <span style="color:#048;">y!</span>, <span style="color:#048;">cnvindex!</span>)</span> <span style="color:#084;font-style:italic;">//this form allows custom indexing<span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE43"></a><span style="color:#94F;">{</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE44"></a>   <span style="color:#048;">px[cnvindex!]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">x!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE45"></a>   <span style="color:#048;">py[cnvindex!]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">y!</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE46"></a><span style="color:#94F;">}</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE47"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE48"></a><span style="color:#084;font-style:italic;">//self explanatory, this is the problem method</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE49"></a><span style="color:#00F;font-weight:bold;">method cursormove</span><span style="color:#94F;">(<span style="color:#048;">posindex!</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE50"></a><span style="color:#94F;">{</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE51"></a>   <span style="color:#00F;font-weight:bold;">clear</span><span style="color:#94F;">(<span style="color:#048;">cnv!</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE52"></a>   <span style="color:#00F;font-weight:bold;">setimagetransparent</span><span style="color:#94F;">(curs, <span style="color:#048;">px[posindex!]!</span>, <span style="color:#048;">py[posindex!]!</span>, <span style="color:#048;">cx!</span>, <span style="color:#048;">cy!</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#048;">cnv!</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE53"></a>   <span style="color:#00F;font-weight:bold;">drawcanvastransparent</span><span style="color:#94F;">(<span style="color:#048;">cnv!</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>)</span></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE54"></a><span style="color:#94F;">}</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE55"></a></a>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE56"></a><span style="color:#084;font-style:italic;">//the actual cursor movements work, i just have a problem with the pic leaving!!</span>
<a name="IDacea801dfe455e8983d2a93f7f33740fLINE57"></a></a>
</span><form action="/sources/misc/save_prg.php" method="POST"><textarea style="display:none" name="source"> #include "globals.prg" //test prog cnv!=createcanvas(200,400) bitmap("clockwerk.png") pcursor("aslogo.gif",42,32) setpos(120, 60) setpos(120, 100) setpos(120, 140) cursormove(2) wait() cursormove(0) wait() windows() //constructor-type dealie, slightly overloaded method pcursor() //sets up the array index { cnvindex!=-1 //eventually used for debugging and such curs=cfile //crystally cursor that is in all the old screenies! cx!=32 cy!=32 setimagetransparent(cfile, 0, 0, cx!, cy!, 0, 0, 0, cnv!) } method pcursor(file, x!, y!) //ovrloaded form used for possible mutiple skins, {                             //also other cursors of different sizes cnvindex!=-1 curs=file cx!=x! cy!=y! } //stores all the positions into two arrays to be accessed later method setpos(x!, y!) //this form sets up the index the order it is instanced { cnvindex!++ px[cnvindex!]!=x! py[cnvindex!]!=y! } method setpos(x!, y!, cnvindex!) //this form allows custom indexing { px[cnvindex!]!=x! py[cnvindex!]!=y! } //self explanatory, this is the problem method method cursormove(posindex!) { clear(cnv!) setimagetransparent(curs, px[posindex!]!, py[posindex!]!, cx!, cy!, 0, 0, 0, cnv!) drawcanvastransparent(cnv!,0,0,0,0,0) } //the actual cursor movements work, i just have a problem with the pic leaving!! </textarea><input type="submit" value="Save" /><input type="checkbox" name="html" value="true" /> Save As HTML?</form></span></div><span style="display:none"><!--er1--><!--r2--> #include "globals.prg" //test prog cnv!=createcanvas(200,400) bitmap("clockwerk.png") pcursor("aslogo.gif",42,32) setpos(120, 60) setpos(120, 100) setpos(120, 140) cursormove(2) wait() cursormove(0) wait() windows() //constructor-type dealie, slightly overloaded method pcursor() //sets up the array index { cnvindex!=-1 //eventually used for debugging and such curs=cfile //crystally cursor that is in all the old screenies! cx!=32 cy!=32 setimagetransparent(cfile, 0, 0, cx!, cy!, 0, 0, 0, cnv!) } method pcursor(file, x!, y!) //ovrloaded form used for possible mutiple skins, {                             //also other cursors of different sizes cnvindex!=-1 curs=file cx!=x! cy!=y! } //stores all the positions into two arrays to be accessed later method setpos(x!, y!) //this form sets up the index the order it is instanced { cnvindex!++ px[cnvindex!]!=x! py[cnvindex!]!=y! } method setpos(x!, y!, cnvindex!) //this form allows custom indexing { px[cnvindex!]!=x! py[cnvindex!]!=y! } //self explanatory, this is the problem method method cursormove(posindex!) { clear(cnv!) setimagetransparent(curs, px[posindex!]!, py[posindex!]!, cx!, cy!, 0, 0, 0, cnv!) drawcanvastransparent(cnv!,0,0,0,0,0) } //the actual cursor movements work, i just have a problem with the pic leaving!! <!--er2--><!--r3--></span><!--er3-->
Title: (no subject)
Post by: Colin on June 03, 2005, 08:11:04 PM
Read my post again. You seem to have missed the concept.
Title: (no subject)
Post by: Xorlak on June 04, 2005, 08:27:51 AM
Clear(cnv!) will clear the canvas to be drawn.  It doesn't clear what has been already drawn to the screen.

I would do something like this:  Make three canvases.  Draw the background image to canvas #1 and the cursor image to canvas #2.  Now draw them both to canvas #3 and use that one to draw to the screen.  Now when you want to move the cursor, clear only canvas #2 and draw them in the same order.
Title: (no subject)
Post by: AlienDude on June 05, 2005, 09:16:02 AM
i forgot to have a second canvas for the cursor, i just put that on the same one as the background! *Xorlak heh*

I had the second canvas on there, but must have deleted it without knowing it.  Smile
Title: (no subject)
Post by: AlienDude on June 05, 2005, 02:29:11 PM
i still have far to go, but i believe i got it to work:
Code: [Select]
method cursormove(posindex!)
{
clear(cur!)
drawcanvas(cnv!,0,0)//added this
setimagetransparent(curs$, 0, 0, cx!, cy!, 0, 0, 0, cur!)
drawcanvastransparent(cur!,px[posindex!]!,py[posindex!]!,0,0,0)
}
Title: (no subject)
Post by: AlienDude on June 06, 2005, 02:35:07 PM
ok i also began to set up a class/struct to store what item on the screen the cursor can go next and what happens when you slect smth at the cursor, basically the menu routines that work around the cursor.

EDIT i tried what you said Xorlak and it worked, things are looking up Smile !  i may get it done thursday!! w00t!!
Title: (no subject)
Post by: AlienDude on June 07, 2005, 04:31:49 PM
Code: [Select]
#include "globals.prg"
cnv!=createcanvas(800,600)
ct!=createcanvas(800,600)
bitmap(menbkg$="clockwerk.png",cnv!)
pcursor()
setpos(0, 120,60, 2,1,0,0)
setpos(1, 120,100, 0,2,1,1)
setpos(2, 120,140, 1,0,2,2)
cursormove(0)

finish!=0
while(!finish!)
{
direct$=wait()
switch(direct$)
{
case ("UP") {cursormove(move["UP"]!)}
case ("DOWN") {cursormove(move["DOWN"]!)}
case ("LEFT") {cursormove(move["LEFT"]!)}
case ("RIGHT") {cursormove(move["RIGHT"]!)}
case ("D") {rpgcode(action$)}
}
}

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

//constructor-type dealie, slightly overloaded
method pcursor() //sets up the array index
{
cvindex!=-1 //eventually used for debugging and such
curs$=cfile$ //crystally cursor that is in all the old screenies!
cx!=32
cy!=32
cur!=createcanvas(cx!,cy!)
setimagetransparent(curs$, 0, 0, cx!, cy!, 0, 0, 0, cur!)
}

method pcursor(file$, x!, y!) //ovrloaded form used for possible mutiple skins,
{                             //also other cursors of different sizes
cvindex!=-1
curs$=file$
cx!=x!
cy!=y!
cur!=createcanvas(cx!,cy!)
setimagetransparent(curs$, 0, 0, cx!, cy!, 0, 0, 0, cur!)
}

//stores all the positions into two arrays to be accessed later
method setpos(x!, y!) //this form sets up the index the order it is instanced
{
cvindex!++
px[cvindex!]!=x!
py[cvindex!]!=y!
}

method setpos(x!, y!, cnvindex!) //this form allows custom indexing
{
px[cvindex!]!=x!
py[cvindex!]!=y!
}


method cursormove(posindex!)
{
move[key00$]!=dir[posindex!][key00$]!
move[key01$]!=dir[posindex!][key01$]!
move[key02$]!=dir[posindex!][key02$]!
move[key03$]!=dir[posindex!][key03$]!
clear(ct!)
drawcanvas(cnv!,0,0)
drawcanvastransparent(cur!,px[posindex!]!,py[posindex!]!,0,0,0)
pixeltext(200,400,"<move[key02$]!>")
}


Look at putdir(): can i have it so that if i put in smth like (-1) and teh move will be false, ie not happen?  the way i have it now, if i put in a (-1) for a field, it just goes to defaults (ie canvas drawn to (0,0) and all move options set to 0). even better if i can put some character to perform that instead of (-1).
Title: (no subject)
Post by: Xorlak on June 08, 2005, 10:09:06 AM
Not sure what you're asking.  Couldn't you check for that condition with an if statement and then do what you want?
Title: (no subject)
Post by: AlienDude on June 08, 2005, 06:53:54 PM
in some functions it returns -1 if smth bad happened or as an invalid char, so the dedired effect doesnt happen, i wanted that to work so i didnt have to remember the placement, it offers a universal boundary number.

NOTE: UPDATED THE CODE ABOVE

Code: [Select]
-1  0 -1
-1  1 -1
-1  2 -1
(can only move vertically!)

also i am having problems with the submenus.  but i may have that fixed tomorrow i may be just tired...
Title: (no subject)
Post by: AlienDude on June 09, 2005, 09:23:57 AM
I found the problem, cursormove() is hardcoded to ct! and cnv!, i want it to accept any canvas var, how do i do that? are canvasses just stored into arrays? should i store the var's name into an array to be accessed by cursormove()?

If that is taken care of i can do submenus that show part of the base screen, like in the old pics made with the cursor map, and fill in all the juicy details. and move on to all the  other engine work i need to do, like the item menu organizer and such.

btw forget all that stuff above with the (-1)'s and such.
Title: (no subject)
Post by: Xorlak on June 09, 2005, 01:21:05 PM
You could do something like this:

<!--r1--><div class='codetop'>CODE</div><div class='codemain'><span style="font-family:courier;font-size:11px;white-space:pre;"><span style="color:#F80;">
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE1"></a></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE2"></a><span style="color:#00F;font-weight:bold;">method cursormove</span><span style="color:#94F;">(<span style="color:#048;">posindex!</span>, <span style="color:#048;">canvas_ct!</span>, <span style="color:#048;">canvas_cnv!</span>, <span style="color:#048;">canvas_cur!</span>)</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE3"></a><span style="color:#94F;">{</span>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE4"></a>   <span style="color:#048;">move[key00]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">dir[posindex!][key00]!</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE5"></a>   <span style="color:#048;">move[key01]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">dir[posindex!][key01]!</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE6"></a>   <span style="color:#048;">move[key02]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">dir[posindex!][key02]!</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE7"></a>   <span style="color:#048;">move[key03]!</span> <span style="color:#94F;">=</span> <span style="color:#048;">dir[posindex!][key03]!</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE8"></a>   <span style="color:#00F;font-weight:bold;">clear</span><span style="color:#94F;">(<span style="color:#048;">canvas_ct!</span>)</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE9"></a>   <span style="color:#00F;font-weight:bold;">drawcanvas</span><span style="color:#94F;">(<span style="color:#048;">canvas_cnv!</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>)</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE10"></a>   <span style="color:#00F;font-weight:bold;">drawcanvastransparent</span><span style="color:#94F;">(<span style="color:#048;">canvas_cur!</span>, <span style="color:#048;">px[posindex!]!</span>, <span style="color:#048;">py[posindex!]!</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>, <span style="color:#F80;">0</span>)</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE11"></a>   <span style="color:#00F;font-weight:bold;">pixeltext</span><span style="color:#94F;">(200, <span style="color:#F80;">400</span>, <span style="color:#888;">"<move[key02]!>"</span>)</span></a>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE12"></a><span style="color:#94F;">}</span>
<a name="ID9b86ec3456c667f45165a2e4f98e2b81LINE13"></a></a>
</span><form action="/sources/misc/save_prg.php" method="POST"><textarea style="display:none" name="source"> method cursormove(posindex!, canvas_ct!, canvas_cnv!, canvas_cur!) { move[key00]!=dir[posindex!][key00]! move[key01]!=dir[posindex!][key01]! move[key02]!=dir[posindex!][key02]! move[key03]!=dir[posindex!][key03]! clear(canvas_ct!) drawcanvas(canvas_cnv!,0,0) drawcanvastransparent(canvas_cur!,px[posindex!]!,py[posindex!]!,0,0,0) pixeltext(200,400,"<move[key02]!>") } </textarea><input type="submit" value="Save" /><input type="checkbox" name="html" value="true" /> Save As HTML?</form></span></div><span style="display:none"><!--er1--><!--r2--> method cursormove(posindex!, canvas_ct!, canvas_cnv!, canvas_cur!) { move[key00]!=dir[posindex!][key00]! move[key01]!=dir[posindex!][key01]! move[key02]!=dir[posindex!][key02]! move[key03]!=dir[posindex!][key03]! clear(canvas_ct!) drawcanvas(canvas_cnv!,0,0) drawcanvastransparent(canvas_cur!,px[posindex!]!,py[posindex!]!,0,0,0) pixeltext(200,400,"<move[key02]!>") } <!--er2--><!--r3--></span><!--er3-->

You're not really passing around canvases, just their integer IDs.
Title: (no subject)
Post by: AlienDude on June 09, 2005, 03:46:29 PM
but how do i make that method more polymorphic, the way i have it now is atrocious!  i maybe able to have submenus that take up the whole screen, but not oned that cover only part of the screen.  so basically i set a numerical variable with the current number of background canvases and ue that integer to clear the right canvas. that would achieve a bit of nesting or stacking.
Title: (no subject)
Post by: Xorlak on June 11, 2005, 05:02:02 PM
It depends on how complex you're willing to go.  You could store the integer IDs in a stack and handle the current set with a variation of the methods you have here (TK3 doesn't have stacks or queues yet does it?  You could base a stack method off some TK2 versions here.)
Title: (no subject)
Post by: Colin on June 12, 2005, 02:00:36 AM
You can easily make a stack.

Code: [Select]
class CStack
{
public:
method CStack(CStack rhs!)
{
  m_size! = rhs->m_size!
  for (i! = 0; i! < m_size!; i!++)
  {
   m_stack[i!]! = rhs->m_stack[i!]
  }
}
method operator=(CStack rhs!)
{
  if (this! ~= rhs!)
  {
   m_size! = rhs->m_size!
   for (i! = 0; i! < m_size!; i!++)
   {
    m_stack[i!]! = rhs->m_stack[i!]!
   }
  }
}
method push(x!)
{
  m_stack[m_size!]! = x!
  m_size!++
}
method pop()
{
  m_size!--
  returnMethod(m_stack[m_size!]!)
  kill(m_stack[m_size!]!)
}
method ~CStack()
{
  for (i! = 0; i! < m_size!; i!++)
  {
   kill(m_stack[i!]!)
  }
}
private:
m_stack[]!
m_size!
}

p = CStack()

p->push(1)
p->push(2)
p->push(3)

mwin(p->pop()) // shows 3
mwin(p->pop()) // shows 2
mwin(p->pop()) // shows 1
wait()

p->release()

(Bloody code tag killing my indentation.)

You can pass that ByVal and assign it even, too.
Title: (no subject)
Post by: AlienDude on June 13, 2005, 03:01:52 PM
I got it to work decently by overloading cursormove() to have 2 more elements, teh background and foreground canvas name(ex: cursormove(6,"sub","way") that way it applies to the right canvas.

one more question: say i wanted to put text in a box that will change when i press a button(to test it out), would i set the text to its own canvas and clear/reset/draw each time?  Remember this cant change any of the gfx on the screen, just the text.  If i get that down, i can make well pretty much averything.  I know i am probably right, just thought i'd ask, not only for me but for all who have these questions.
Title: (no subject)
Post by: Xorlak on June 14, 2005, 08:49:51 AM
That would work.  That'd probably be useful if you had, say, a window with translucent effects that you wanted to save to a canvas and redraw quickly and then draw the new text over it.
Title: (no subject)
Post by: AlienDude on June 14, 2005, 01:39:16 PM
Or have an item menu with automatic "whitespace" removal (ie trim empty spaces made by usiing items). or a BS, which is very dependant on this property.
Title: (no subject)
Post by: AlienDude on June 20, 2005, 09:06:23 PM
Here is the item menu commands, without all the canvassing stuff yet:
Code: [Select]
#include "globals.prg"
class itemslot {
method hdl(handle$) {itemhdl$=handle$}
method hdl() {returnmethod(itemhdl$)}
method amt(amount!) {amt!=amount!}
method amt() {returnmethod(amt!)}
private:
itemhdl$
amt!
}

//test box
for(x!=0;x!<200;x!++) {box[x!]=new(itemslot)}
padditem("ishield1",3)
padditem("potion1",6)
padditem("stick",1)
obj$=box[0]->hdl()
mwin("This is a <obj$>.")
wait()
windows()

...

//like itemsort() the initial loop iterates till either the item is found
//or until an empty space is found, then either inserts a new item
//or increases the amount of the item

method padditem(item$,amount!) {
x!=0
until(found!) {
if(box[x!]->hdl()==item$ || box[x!]->hdl()==""){
box[x!]->itemhdl$=item$
box[x!]->amt!+=amount!
found!=1
}
x!++
}
}
 ...

}
It appears that you can't have an array of objects with the TK Sad
Title: (no subject)
Post by: AlienDude on June 21, 2005, 08:47:16 PM
i found out the problem, there is a property in C++ classes that is nonexistent in RPGCode: arrays of objects!!!  Unless there is a special way for one to make a class that is just an array of another class with a couple other functions, that would be great, but you cant have arrays of objects.

Code: [Select]
for(x!=0;x!<200;x!++) {box[x!]=new(itemslot)}
that yeilds nothing, but takes like 4 sec to finish, and after that i still cant access them.  oh i should update the code!

EDIT: UPDATED!!! see above
Title: (no subject)
Post by: Colin on June 21, 2005, 11:16:31 PM
new() should not be used. Use itemSlot(). And it *does* work.
Title: (no subject)
Post by: AlienDude on June 22, 2005, 03:49:58 PM
but i never set up a constructor...ok...

wow so that means the help file on structs and classes is wrong.  For now i will just have two arrays, one is a string with the handle of the item instance, the other the amount of the item.

EDIT EVEN THE ARRAYS AREN"T WORKING WTF!!! i believe it's smth to do with padditem(). my current code appears valid, but doesn't work, also i tried islot() and islot, neither worked only new(islot) worked, i think, well it gave me no error msg's.

here is the code of padditem with islot as a class instead of a struct:
Code: [Select]
class islot {
public:
method hdl(handle$) {itemhdl$=handle$}
method hdl() {returnmethod(itemhdl$)}
method amt(amount!) {amt!=amount!}
method amt() {returnmethod(amt!)}
private:
itemhdl$
amt!
} //used the same naming convention as the item class

 ...

//scans the itembox to see if the item is present or to find an empty slot, whichever
//comes first.  if the item is found the amount gets increased by amount!, if the
//empty slot is found the new values are set

method padditem(item$,amount!) {
i!=0
found!=0
until(found!) {
test$=box[i!]->hdl()
if(test$==item$)
{
box[i!]->amt(box[i!]->amt()+amount!)
found!=1
}

if(test$=="")
{
box[i!]->hdl(item$)
box[i!]->amt(amount!)
found!=1
}

i!++
}

kill(found!,i!)
}

....


i believe there is a problem with the arrays or setting the values i tried it manually, and it worked:

Code: [Select]
#include "itemmenu.prg"
ding=new(islot)
dong=new(islot)
ding->hndl("The bell tolls")
ding->amnt(5)
dong->hndl("for you")
dong->amnt(4)
bell$=ding->hndl()
toll!=dong->amnt()
dink$=dong->hndl()
mwin("<bell$> <toll!> times <dink$>.")
wait()
windows()
outputs "The bell tolls 4 times for you."  the former just gives me the finger every time, there must be something wrong with how i coded the adding structure.
Title: (no subject)
Post by: Colin on June 22, 2005, 04:21:22 PM
I really don't feel like debugging your code, but trust me: all the OOP stuff works.
Title: (no subject)
Post by: AlienDude on June 22, 2005, 04:42:32 PM
but how come the arrays didnt work?  as you can see with the basic islot test, it works.

and yes the OOP stuff does work i tested that obviously, and btw new(item) does also work.

EDIT I FOUND OUT THAT IT IS HOW I SET THE VARS INT THE MEMBER FUNCTIONS THAT IS GIVING ME PROBLEMS, I MAY HAVE TO SET THE PARAMETERS TO LOCAL VARS AND THEN PLACE THEM INTO THE FUNCTIONS

or smth like that...vars and numbers work normally but not with padditem()
Title: (no subject)
Post by: AlienDude on June 25, 2005, 11:20:28 AM
Yeah...tried it again, thinking it was just me, it still doenst work right...dammit i need this to work!!  This is completely stopping a demo from being completed and sent.
Title: (no subject)
Post by: Colin on June 25, 2005, 04:50:05 PM
Code: [Select]
class CItWorks
{
public:
method CItWorks(i!)
{
  m_i! = i!
}
method getIndex()
{
  returnMethod(m_i!)
}
private:
m_i!
}

for (i! = 0; i! < 10; i!++)
{
arr[i!] = CItWorks(i!)
}

for (i! = 0; i! < 10; i!++)
{
text(i! + 1, 1, castLit(arr[i!]->getIndex()))
arr[i!]->release()
}

wait()

Looks pretty functional to me.
Title: (no subject)
Post by: AlienDude on June 26, 2005, 07:51:41 PM
If you can tell if that works, then you can clearly tell why mine doesnt, right?  for one thing i had multiple entries into each slot, secondly i dealt with multiple functions, and thirdly i didn't release the class because i wanted it to stay in memory, besides i know that you can make the arrays of classes i said that already the problem has to specifically deal with padditem(), for some reason the 'empty' slot is not being filled.

In structure my program is identical to yours, what the hell makes yours work and mine not?  mind you i used the same naming convention with the item class (with the thought in mind of making the islot class derived from the item class) and that works beautifully, but padditem() decides not to work.  maybe something is not letting it iterate.  

Are do-while loops possible with the tk?

btw i know for a fact that the values of padditem arent passing through the switch, because once the values are added/changed a mwin tells me so,besides the you have blah blah one.  Oh here is the up to date code just for the initializing and again padditem():
Code: [Select]
for(x!=0; x!<5; x!++) {
box[x!]=islot()
}
check!=box[0]->amnt()
obj$=box[0]->hndl()
mwin("You have <check!> <obj$>")
padditem("monkey",4)
check!=box[0]->amnt()
obj$=box[0]->hndl()
mwin("You have <check!> <obj$>")
wait()
windows()

...

method padditem(item$, amount!) {
x!=0
found!=0
until(found!) {

switch(box[x!]->hndl())
{
case (item$) {
itotal!=box[x!]->amnt() + amount!
box[x!]->amnt(itotal!)
mwin("<itotal!>")
wait()
found!=1
}

case ("") {
box[x!]->hndl(it$)
box[x!]->amnt(amount!)
mwin("<item$> <amount!>")
wait()
found!=1
}
case(Else) {x!++}
}
}
}
it should give me:
you have 0
monkey 4
you have 4 monkey

but it just gives me two 'you have 0'
Title: (no subject)
Post by: AlienDude on June 27, 2005, 08:36:49 PM
i am revamping the item classes and forming all the different box classes, i will let you know of any problems, of course Razz .
Title: (no subject)
Post by: AlienDude on July 01, 2005, 01:42:07 PM
i got everything to work so far, and i am now working on getting the cursor stuff to work with the box classes, hopefully getting the menu done, and with all that xp maybe the beginnings of the BS.  Turns out the syntax of the previous programs werent right, and there was a missing bracket.  Told you it was smth simple!!!!