Computer Science Canada

[Source] Shaking Window

Author:  Delos [ Sat May 21, 2005 11:52 am ]
Post subject:  [Source] Shaking Window

Here's a nifty little procedure. Replicates those much loved window-shakes (or nudges as some call them) that are seen in various chatting proggies.

Syntax:
shakeWindow (dx, dy, dur)

dx - how far left and right the window can move. Suggested: 1-5
dy - how far up and down the window can move. Suggested: 1-5
dur - duration. How long the window will shake for (in thousanths of a second. Suggested: 200-800.


The file has an example hardcoded at the end of it. To use, copy the proc into your source and call when needed. No need to specify which run window is being shaken, it automatically selects the active one. If you need to move between various windows (i.e., shake a window that is inactive, perhaps in the background), alter the source or PM me to set it up.

Author:  MysticVegeta [ Sat May 21, 2005 11:55 am ]
Post subject: 

nice, Thats what i needed. thanks!

Author:  [Gandalf] [ Sat May 21, 2005 8:58 pm ]
Post subject: 

Very, very nice. Would you mind it if I also added this to my list of "potentally evil programs"? Very Happy. But it has many good purposes too - thanks for the idea and program!

Author:  Lazarus [ Sat May 21, 2005 9:03 pm ]
Post subject: 

omg! thanks for reminding me, there's this song on ebaums world that uses a Java Script to do this.. Great song
dub dub dub

Author:  Flikerator [ Thu May 26, 2005 1:23 pm ]
Post subject: 

Just a thought, change the "a" to ""

Looks a bit better Smile

Or print Shake! Shake! Diaganally? Just a thought : )

Author:  Delos [ Thu May 26, 2005 5:52 pm ]
Post subject: 

The "a" was just the first letter that I typed...it's just part of an example demonstrating how the syntax works.
Sure it would have been more descriptive...but meh, I wasn't feeling entirely creative at the time.

Author:  Aziz [ Wed Jun 08, 2005 1:25 pm ]
Post subject: 

That's pretty cool. Could be used for a cool game. Like so: Smile

code:
% Example.
setscreen ("graphics:400;300,offscreenonly,position:center;truemiddle")

var endGame := false
var x, y, b : int
const CX := maxx div 2
const CY := maxy div 2
const CR := 25

procedure shakeWindow (dx, dy : int)
    /* Parameters:
     dx - how far left and right the window can move.  Suggested:  1-5
     dy - how far up and down the window can move.  Suggested:  1-5
     dur - duration.  How long the window will shake for (in thousanths of a second.  Suggested:  200-800.
     */

    var tempX, tempY : int
    var xNot, yNot : int
    % Original positions, will be reassigned before termination.
    Window.GetPosition (Window.GetActive, tempX, tempY)
    Window.GetPosition (Window.GetActive, xNot, yNot)
    % Assign values.
    loop
        exit when endGame
        if tempX <= (xNot - dx) then
            for i : 1 .. dx
                tempX += 1
            end for
        elsif tempX >= (xNot + dx) then
            for i : 1 .. dx
                tempX -= 1
            end for
        else
            for i : 1 .. dx
                tempX += Rand.Int (-1, 1)
            end for
        end if

        if tempY <= (yNot - dy) then
            for i : 1 .. dy
                tempY += 1
            end for
        elsif tempY >= (yNot + dy) then
            for i : 1 .. dy
                tempY -= 1
            end for
        else
            for i : 1 .. dy
                tempY += Rand.Int (-1, 1)
            end for
        end if
        % Set bounds for x- and y-.  Stops shake from moving too far away.
        Window.SetPosition (Window.GetActive, tempX, tempY)
        %Delay
        delay (10)
        View.Update
    end loop
    Window.SetPosition (Window.GetActive, xNot, yNot)
end shakeWindow

process shakeProcess (dx, dy : int)
    shakeWindow (dx, dy)
end shakeProcess

process checkEnd
    var key : string (1)
    loop
        exit when endGame
        if hasch then
            getch (key)
            if ord (key) = 27 then
                endGame := true
                exit
            end if
        end if
    end loop
end checkEnd

process mouseCheck
    loop
        exit when endGame
        mousewhere (x, y, b)
    end loop
end mouseCheck

put "Ready? Press any key when ready!"
put "[Hint: position mouse right now]"
put "[ESC to quit]"

drawfilloval (CX, CY, CR, CR, 7)

View.Update

Input.Pause
cls

fork checkEnd
fork mouseCheck
fork shakeProcess (25, 25)

loop

    exit when endGame

    locate (maxrow - 1, 1)
    put "X: ", x ..
    locate (maxrow, 1)
    put "Y: ", y ..


    drawfilloval (CX, CY, CR, CR, 7)

    View.Update

    if sqrt (((x - CX) ** 2) + ((y - CY) ** 2)) > CR then
        endGame := true
        exit
    end if

end loop
if endGame then
    cls
    put "YOU LOSE"
end if


or i've attached it

Author:  [Gandalf] [ Wed Jun 08, 2005 3:14 pm ]
Post subject: 

Welcome!

Great idea for a simple game! Nice first post.

Keep in mind though that you should always be limiting your use of proccess' to almost nothing.

Author:  decon1985 [ Wed Jun 08, 2005 3:52 pm ]
Post subject:  WHOA!

I may just be a novice, and this might not mean much coming from me, but this is fantastic! I think this would work very well in a battle game when you take damage or you do damange, either way. Great program man!

Author:  fehrge [ Wed Jun 08, 2005 4:06 pm ]
Post subject: 

I also think that it is a really cool idea. Nice program.

Author:  Delos [ Wed Jun 08, 2005 6:52 pm ]
Post subject: 

Nice! Try to add a counter that displays how long the player lasted. You'll need to incorporate Time.Elapsed() for that.

Author:  Drake [ Wed Jun 08, 2005 9:49 pm ]
Post subject: 

Great idea to begin with. Making a game with it was awesome, too!

And the best part is that, at first, you wouldn't think it has much use. But if you sit down and think about it, it is very useful.

Bits to both of you!

Author:  ViRuAl_InFeCtiON_vErsIonX [ Sat Sep 03, 2005 12:45 am ]
Post subject: 

[mod:51fb78cadd="Cervantes"]
If you're going to ressurect an old topic, at least do it with something useful, not a "open a million windows" program.
[/mod:51fb78cadd]


: