Timed Enemy Pattern
by rennie moffat · in Torque Game Builder · 07/22/2009 (7:32 am) · 69 replies
Hi guys, today I will be working on a pattern timer for a scene object which will act like an enemy to my hero. It will simply turn on and off, when on, my hero can not cross it, move over it. When it is off he can. So I must develop some type of shield. which must be turned on and off. I of course want to take that and make it so that I could have several on screen at once which can then have there own timers on so that an object. our hero, must maneuver safely between. Think Mario Bros, when he has to time his run underneath the giant monoliths.
As I say I will be working on this today, research, piecing together code, but if anyone has any clue, tips prior, please don't hesitate to chirp in.
As I say I will be working on this today, research, piecing together code, but if anyone has any clue, tips prior, please don't hesitate to chirp in.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#42
07/24/2009 (5:29 am)
please excuse that, i just added in the image variable in the template, just erased it.
#43
I have used your code as is, I know it took me a while but i got it. I just had to figure out the logoc of the code itself before I felt safe using it. Whats the point in building a house if you dont know how to hammer?
Anyhow, Ihave loade the behaviour as such. But when I do, my game crashes. I am not sure whats wrong. I am still unsure as to how to check the console log {I am on a Mac and I havent seen a reference for that, I searhed.. blah blah blah).
I am not sure if I need to ad an onLevel,... perhaps it is the checkForPlayer Function, it currently lacks any methods... Nope, I just checked. Hmmmmmmm.
07/24/2009 (6:05 am)
Hi Tom and whomever may be reading this,I have used your code as is, I know it took me a while but i got it. I just had to figure out the logoc of the code itself before I felt safe using it. Whats the point in building a house if you dont know how to hammer?
Anyhow, Ihave loade the behaviour as such. But when I do, my game crashes. I am not sure whats wrong. I am still unsure as to how to check the console log {I am on a Mac and I havent seen a reference for that, I searhed.. blah blah blah).
I am not sure if I need to ad an onLevel,... perhaps it is the checkForPlayer Function, it currently lacks any methods... Nope, I just checked. Hmmmmmmm.
if (!isObject(BigSquareBehavior))
{
%template = new BehaviorTemplate(BigSquareBehavior);
%template.friendlyName = "FrameSwitcher";
%template.behaviorType = "AI";
%template.description = "Square changes modes from dagerous to safe.";
}
%template.addBehaviorField(rate, "length of time a state lasts", float, 3);
%template.addBehaviorField(damage, "damage amount", int, 30);
function BigSquareBehavior::onBehaviorAdd(%this)
{
//initialize safe to be something, use switch to start the schedule
%this.safe = true;
%this.switch();
}
function BigSquareBehavior::switch(%this)
{
//switch the safe state, set the frame accordingly
%this.safe = !%this.safe;
if(%this.safe)
%this.owner.setFrame(0);
else {
%this.owner.setFrame(1);
%this.checkForPlayer();
}
{
if(isEventPending(%this.switchSchedule))
cancel(%this.switchSchedule);
//Start the switch schedule (convert to milliseconds)
%this.switchSchedule = %this.schedule(%this.stableTime * 1000, "switch");
}
}
function BigSquareBehavior::checkForPlayer(%this){
//Just turn on collisions, cast for a collision and do damage to the player or whatever here
}
#44
I don't fully grasp this bit of code.
why am I doing a "Remove Behaviour"?
This code comes from the Night and Day UFO tutorial.
EDIT:
I think I discovered the reason for.
Also, as we talked about I also do not get this very important bit.
07/24/2009 (8:32 am)
more Coding Questions...I don't fully grasp this bit of code.
why am I doing a "Remove Behaviour"?
This code comes from the Night and Day UFO tutorial.
EDIT:
I think I discovered the reason for.
function TimeBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
}Also, as we talked about I also do not get this very important bit.
if (!isObject(moveMap))
return;
#45
It's probably crashing because I foolishly called the function switch, which is more than likely reserved for the control flow keyword. Try renaming it switchState or something.
07/24/2009 (10:10 am)
I don't know what the moveMap is for - maybe that behavior added an actionmap for controls or something?It's probably crashing because I foolishly called the function switch, which is more than likely reserved for the control flow keyword. Try renaming it switchState or something.
#47
But whatever :)
Oh, and that checkPlayer function was just placeholder for where you'd want to check the square in some way to damage the player - it got called when the square changes from safe to not safe.
07/24/2009 (10:22 am)
It takes time to get comfortable with it - I think most people already have significant programming experience before learning Torquescript, which makes it easier. If you haven't done the tutorials or understood some of the demos, you might want to go over those and ask questions until you really know how they work.But whatever :)
Oh, and that checkPlayer function was just placeholder for where you'd want to check the square in some way to damage the player - it got called when the square changes from safe to not safe.
#48
well thats cool,
it is all learning for me.
I may check those tuts, again. but still I got something decent cooking here.
07/24/2009 (10:24 am)
ok,well thats cool,
it is all learning for me.
I may check those tuts, again. but still I got something decent cooking here.
#49
this code is troubling to me, please if you can, explain the very basics of it for me?
it is mainly the method that bothers me. I fully understand the %this's.
07/24/2009 (10:28 am)
can I ask you something quick?this code is troubling to me, please if you can, explain the very basics of it for me?
it is mainly the method that bothers me. I fully understand the %this's.
function SelectDestination::onMouseDown(%this, %worldPos, %mouseClicks)
{
$mouseObj.setPosition(%worldPos);
}
#50
07/24/2009 (10:34 am)
it is mainly the method that bothers me. I fully understand the %this's.function SelectDestination::onMouseDown(%this, %worldPos, %mouseClicks)
{
$mouseObj.setPosition(%worldPos);
}
#52
%worldPos is a string holding two floats, like "132 14.5" which are the coordinates of the mouse click in worldspace (same coordinate system that the objects hang out it).
Oh, also the $mouseObj is a global variable (that's what the $ means) reference to an object, so it's just setting it's position.
That answer it?
07/24/2009 (10:43 am)
onMouseDown is just a built-in object mouse callback. More examples can be see here and all over TDN.%worldPos is a string holding two floats, like "132 14.5" which are the coordinates of the mouse click in worldspace (same coordinate system that the objects hang out it).
Oh, also the $mouseObj is a global variable (that's what the $ means) reference to an object, so it's just setting it's position.
That answer it?
#53
$mouseObj.setPosition(%worldPos);
obviously this sets an object which is slave to the mouse, and sets a position. That I get. What I dont get is, is this it? If I put a mouseDown Command for instance as a function, then include this method, as is. Will this relocate said object where the click took place? The reason I ask is because it seems a little sparse, this is what I need to know or be reassured of...
07/24/2009 (10:49 am)
no not really. i am trying to get to the meat of the matter, mainly what it does in this sense...$mouseObj.setPosition(%worldPos);
obviously this sets an object which is slave to the mouse, and sets a position. That I get. What I dont get is, is this it? If I put a mouseDown Command for instance as a function, then include this method, as is. Will this relocate said object where the click took place? The reason I ask is because it seems a little sparse, this is what I need to know or be reassured of...
#54
07/24/2009 (10:51 am)
Yeah, so $mouseObj is an object created somewhere else. The $mouseObj variable itself is a global variable (that's why it seems kind of random just hanging out there), indicated by the $. That line will move the $mouseObj to the click.
#55
so where is the mouseBoj declared defined?
Obviously it could be in differnet places, a playerscript, enemy script, friend script.. whatever, just an imageMap in most cases? but if so, is that it? where do I type in MouseObj elsewhere in code? is he needed?
I realize mouseObj is not a very far ranging variable like say time. Not as essential if you will.
07/24/2009 (10:55 am)
I get that, so where is the mouseBoj declared defined?
Obviously it could be in differnet places, a playerscript, enemy script, friend script.. whatever, just an imageMap in most cases? but if so, is that it? where do I type in MouseObj elsewhere in code? is he needed?
I realize mouseObj is not a very far ranging variable like say time. Not as essential if you will.
#56
07/24/2009 (10:57 am)
but still important!!!
#57
Make an object in your level, just an imageMap or whatever, make it of class MousePointer. Then, make a new script file called that (doesn't matter, but makes it nice), exec it from game.cs or wherever you're doing your execs, and add a MousePointer::onLevelLoaded function that sets $mouseObj = %this. Then, you can use $mouseObj wherever you want.
07/24/2009 (10:58 am)
No idea where it's defined in that example, but an easy way would be like this:Make an object in your level, just an imageMap or whatever, make it of class MousePointer. Then, make a new script file called that (doesn't matter, but makes it nice), exec it from game.cs or wherever you're doing your execs, and add a MousePointer::onLevelLoaded function that sets $mouseObj = %this. Then, you can use $mouseObj wherever you want.
#58
what do you think of me buying the old torque x book, that batty for teens ain't packing how I like.
07/24/2009 (11:01 am)
hmm, dude, what do you think of me buying the old torque x book, that batty for teens ain't packing how I like.
#59
:P
07/24/2009 (11:04 am)
i think im gona have to buy torque x to the max. this service aint what i hoped for.. waiter!!!:P
#60
Good luck, it's fun :)
07/24/2009 (11:08 am)
If you want to learn TorqueScript, TorqueX won't help you - it doesn't use scripting, it's all C#. It is a lot of fun, though, but it's probably easier to stick with TGB. I guess you could go with one of the TGE books, because they use TorqueScript too. Maybe it would be easier, though, to rip apart some of the demos. Some of them are really well commented and you could try modifying them to get a feel for what's going on. I wrote the BehaviorShooter, which I think is pretty transparent. It uses only behaviors and the level editor. Or, check this out - there's a link that goes to my whole thought process on it, as well as really nice code. You could modify that to see how it all works.Good luck, it's fun :)
Torque Owner rennie moffat
Renman3000
ok.. another note.
I just put thru your code, as is essentially, I haven't been able to run it yet, as where the image variable appears in the console (which image should i select) my only option is "none".
Not good.
What do I do... I am quite sure I need to add code to the beginning of the behaviour which calls for an image?
As in get Image X onLevelLoaded.
:?slightly unsure.