2 procedures at once/registering a maching point in a shape
Author |
Message |
dawger
|
Posted: Thu Dec 21, 2006 9:45 pm Post subject: 2 procedures at once/registering a maching point in a shape |
|
|
im making a little game but ive come across 2 problems that are messing me up. firstly, the object of the game is to dodge the boxes that keep poping up randomly. if the boxes touch the circle on the mouse arrow, then you loose.
the problems i am having are, the refreshing of the boxes and the mouse are canceling each other out. im also finding it difficult (nigh impossible) figuring out how to record when the mouse comes in contact with any point in one of the red squares.
i needed help on finding a way to run 2 procedures at once (or 2 segments of code at once) so that the boxes aren't canceling out the circle and vise-versa
and a way to register the circle touching any given point in a box. if you can find any other ways around these problems than the ones ive come up with, by all means, let me know.
here is the script;
________________________________________________________
% x and y coordinates (square)
var xbox : int
var ybox : int
% size of the box
var size : int
% mouse values
var xaxis : int
var yaxis : int
var click : int
procedure boxes %this bity here spawns the red boxes randomly. these are suposed to be dodged.
randint (xbox, 0, maxx)
randint (ybox, 0, maxy)
randint (size, 10, 100)
drawfillbox (xbox, ybox, xbox + size, ybox + size, 40)
delay (200)
drawfillbox (xbox, ybox, xbox + size, ybox + size, 0)
end boxes
procedure mouse %and this bity here s you, a circle. keep this off the red boxes
mousewhere (xaxis, yaxis, click)
drawfilloval (xaxis, yaxis, 5, 5, 1)
delay (10)
drawfilloval (xaxis - 2, yaxis - 2, xaxis + 2, yaxis + 2, 0)
end mouse
loop %this is them running but not at the same time, i need them to run simutaniosly for this to work :S
boxes
mouse
end loop
_________________________________________________________
Thanks for the help (its very appreciated)
- Dawger |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Hackmaster
|
Posted: Fri Dec 22, 2006 9:59 pm Post subject: (No subject) |
|
|
lucky for you, both of these problems are EASY to fix!
For running 2 peices of code at once, instead of procedures, you want to use processes. they are the same thing, and do the same stuff(basically) but there is one key difference: you can run them in the background. here is an example of how to do that:
code: |
process drawbox
%%do stuff
end drawbox
%% some code, blah, whatever you are doing, and then:
[b]fork[/b] drawbox
%% more code
|
see? all you do is use the fork command. easy stuff. all this does is run whatever process you specify. you can also do things overtop of this, as well.
a great example is music in behind your game. if you couldn't fork processes... you would have to wait until the music is over before you could do anything, because the procdure you used to do it won't be over yet. if you use a process and fork it, you can have the music in the background.
as for collison detection... well, there are tutorials on it, but I'll give you a primer. there are lots of ways to do it, but two spring to mind:
1. WhatDotColor
2.not WhatDotColor
using whatdotcolor is easy stuff. there are tutorials, so I will explain the logic, not the syntax. all you have to do is color your player blue, and your boxes red. or whatever color scheme you like.
if the circle's radius + 1 = some color other than your background and your player then you die.
the non whatdotcolor way is to have lots of variables. in this case it is probably impractical. or use an array.
if the center of the circle + radius of circle = the boxes' xy, or something like that, then you die.
hope this helped! |
|
|
|
|
|
Clayton
|
Posted: Sat Dec 23, 2006 11:17 am Post subject: (No subject) |
|
|
Hackmaster wrote:
... you want to use processes ...
No, you don't. Processes are not needed here in any way whatsoever. Instead, break up each procedure and spread it out over the mainline to have it seem to run "parallel". Really, whenever you use processes, the code never runs parallel either. The processor randomly chooses from which process to run the code.
If you doubt what I say, here's Why you Should Avoid Processes. |
|
|
|
|
|
|
|