mircscripting.info Forum Index mircscripting.info
#mIRCscripting Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PicWins 2: Games

 
Post new topic   Reply to topic    mircscripting.info Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
BlueThen2
Quite Active


Joined: 11 Jun 2008
Posts: 22

PostPosted: Tue Oct 28, 2008 8:54 pm    Post subject: PicWins 2: Games Reply with quote

You're going to want to read part 1 at http://www.mircscripting.info/forum/viewtopic.php?t=1354 if you haven't already.

Base Code
Remember the example snippet I posted in the last tutorial? We're going to reuse that for this tutorial. It's a little unnecessary for me to explain all the procedures of the animation here, since I already covered that in the last tutorial.
Code:
alias ma {
  window -pd @myanimation -1 -1 400 400
  window -hpd @myanimation.buffer -1 -1 400 400
  set %MA.X 200
  set %MA.Y 0
  ma.frame
}
alias -l ma.frame {
  if ($window(@myanimation)) {
    clear @MyAnimation.buffer
    drawfill @MyAnimation.buffer 0 0 1 1
    drawdot @MyAnimation.Buffer 1 20 %ma.x %ma.y
    drawcopy @MyAnimation.Buffer 0 0 400 400 @MyAnimation 0 0 400 400
    .timer 1 0 ma.frame
  }
}
on *:Close:@myanimation: {
  window -c @myanimation.buffer 
  unset %ma.*
}
If you haven't noticed, I removed all the comments and the inc %ma.y 2 part. We won't be needed those in this tutorial.

Mouse Events
If you've read the Picture Windows section of the mIRC Help file, you'll find out that it supports menu events. Mouse and sclick are some of the events you'll be using often in making games.
The Help file should already tell you what all of them are:
Quote:
The mouse event is triggered when you move a mouse inside a picture window. You can use the $mouse identifier (see below) for the x and y position of the mouse.

The sclick event is triggered when you click once inside a picture window. It will also trigger if you double-click.

The dclick event is triggered when you double-click inside a picture window.

The uclick event is triggered when a mouse button is released inside a picture window.

The lbclick event is triggered when an item is selected in a listbox, either with the mouse or the cursor keys.

The leave event is triggered when the mouse is moved outside the borders of a custom window.

The drop event is triggered if you clicked in the window, held the button down, moved the mouse, and then let go of the button.
lbclick won't be used in picwins.

$Mouse
There's also $mouse. The mIRC help file states that it returns the x, y position of the current mouse event, and whether the left mouse button, shift key, and/or control key are pressed.
$mouse.win returns the window the cursor is in
$mouse.x returns the cursor window x position
$mouse.y returns the cursor window y position
$mouse.mx returns the cursor main x position
$mouse.my returns the cursor main y position
$mouse.dx returns the cursor desktop x position
$mouse.dy returns the cursor desktop y position
$mouse.key returns the key that was pressed.
$mouse.lb tells whether or not the mouse is over a listbox

Menu Events
So lets construct our menu events.
Code:
menu @myanimation {
  mouse: {

  }
  sclick: {

  }
}

Mouse, sclick, and leave are all the events we'll need for this tutorial. You can experiment with others if you wish.

Mouse Position
Lets say we want the animation to draw a dot at the mouse's position every frame. In the mouse event, we'll want to have it reset the position of the dot to the cursor's X and Y.
Code:
set %ma.x $mouse.x
set %ma.y $mouse.y


Mouse Detection
There's an issue here though. Everytime the mouse leaves the window, the dot will freeze where it is. This makes the script very unrealistic and unprofessional. We're going to need to have the animation check for the mouse every frame. Let's add an if then else statement on the line before the drawdot part:
Code:
if ($mouse.win == @myanimation) {
Also, we need to add a } after the drawdot, just to avoid bracket mismatch errors.

DrawText
How 'bout we add some text to the window for everytime the cursor leaves the window.
Code:
else drawtext @myanimation.buffer 1 Tahoma 30 122 100 Come back!

Drawtext is sort of weird. The syntax is drawtext window color font size x y text.
You also may be wondering why I have 122 as the X position. Simply saying, that's where the text would be placed at if I were want it to be on the exact center of the x axis for that window. This probably seems hard to figure out at first, but using a simple equation can help you find it out: $calc(200 - ($width(Come Back!,Tahoma,30) /2))
200 being the half the window size. You should write this down somewhere, for it'll probably come in handy if you get any further into PicWins, or even Dialogs.

SClick
Now for sclick. How about we have the size of the dot increase whenever the mouse clicks. We don't have a variable for the size of the dot, so we're going to need to plug one in, and create one in the initial alias.
Code:
set %MA.S 20
should go into the initial alias anywhere before it starts the animation. It's a good idea to group variables together, just to be organized. Now we need to replace the old drawdot with one with the variable plugged in.
Code:
drawdot @MyAnimation.Buffer 1 %ma.s %ma.x %ma.y

Congratulations! The size is now dynamic. Lets not forget the sclick.
Code:
inc %ma.s 5

The dot should now increase by five pixels every click or so now.

Keys
That's not all there is to controls. mIRC supports most keys. on KEYDOWN and on KEYUP detects every key used within any Custom Window. They both have the same syntax of on <level>:KEYDOWN/UP:<@>:<key,...,keyN>:<commands>
The level can simply be *, the @ being your window of course. The key, however, you're going to have to find the value of manually. For most values, you can find by using $ASC. You're going to have to use $ASC(uppercase value) if it were to be a value, I have no clue to why it doesn't work with lowercase letters. Simply create a window: window -d @temp -1 -1 100 100, then create a small script to find any key pressed into it. on *:keydown:@temp:*: echo -s $keyval. This will echo the value of any key pressed into that window and echo it in the status window.
When I press the space bar, it echoes 32. So lets say I want the space bar to shrink the size of the dot.
Code:
on *:keydown:@MyAnimation:32: dec %ma.s 2


Example
How about that code? Here's the example.
Code:
alias ma {
  window -pd @myanimation -1 -1 400 400
  window -hpd @myanimation.buffer -1 -1 400 400
  set %MA.X 200
  set %MA.Y 0
  set %MA.S 20
  ;The size variable is set
  ma.frame
}
alias -l ma.frame {
  if ($window(@myanimation)) {
    clear @MyAnimation.buffer
    drawfill @MyAnimation.buffer 0 0 1 1
    if ($mouse.win == @myanimation) {
      ;Checks if the mouse is inside @MyAnimation
      drawdot @MyAnimation.Buffer 1 %ma.s %ma.x %ma.y
      ;Draws the dot using %ma.s for the size.
    }
    else drawtext @myanimation.buffer 1 Tahoma 30 122 100 Come back!
    ;Says "Come back!" if the mouse isn't inside @MyAnimation.
    drawcopy @MyAnimation.Buffer 0 0 400 400 @MyAnimation 0 0 400 400
    .timer 1 0 ma.frame
  }
}
on *:Close:@myanimation: {
  window -c @myanimation.buffer 
  unset %ma.*
}
menu @myanimation {
  mouse: {
    ;The Mouse event.
    set %ma.x $mouse.x
    set %ma.y $mouse.y
    ;Sets the dot's position to the mouse's position.
  }
  sclick: {
    inc %ma.s 5
    ;The Sclick event.
    ;Increases the dot's size
  }
}
on *:keydown:@MyAnimation:32: dec %ma.s 2
;Shrinks the dot when the space bar is pressed.


Experiment
This should be enough information to construct simple games. As I said in the last tutorial, feel free to experiment!


Written by BlueThen on October 28, 2008.
www.BlueThen.com
At this moment, BlueThen.com is down due to some issues with my host and his website. However, BlueThen.com should be back up in good time.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    mircscripting.info Forum Index -> Tutorials All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group