Game Development Community

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.




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.

Page «Previous 1 2 3 4 Last »
#1
07/22/2009 (7:58 am)
ok, so my timer must I have determined be made up of three behaviours. All which will be added to said object. A timer, which has a 2 states (1 and 2), a swap image behaviour which will have two states aas well. the states are linked to the states of the timer. And, fianlly it must have a deals damage,or shield on off behaviour, this is linked to the swap image behaviour.


My only question is how to put it together. Is creating 3 seaparte behaviours which act like gears on each other cool? or should I be doing a one scripted game folders file, ie enemyBlock 01. I think behaviours. Ok so now to script, this is where I suck. Any help would be appreciated.



Ren
#2
07/22/2009 (8:30 am)
this has helped my thought process, please don't feel obliged to write, am learning will post.


Ren
#3
07/22/2009 (8:52 am)
Hi, I am wondering, regarding a timer.



All behaviours have fields. For instance a Projectile beahaviour will have a field for what image to shoot (object), rate (float) etc. What I am wondering is, what is the field for a timer? a Float too?



#4
07/22/2009 (11:18 am)
Hi,ok so I have this code, it is obviously rough as it crashes my game but.. this is what i have so far, I will be cracking on this for a while, but if anyone can PLEASE give me some tips as to what I am doing wrong, right, what I should do? thanks
Ren




if (!isObject(frameSwitcherBehavior))
{
%template = new BehaviorTemplate(frameSwitcherBehavior);

%template.friendlyName = "FrameSwitcher";
%template.behaviorType = "AI";
%template.description = "Timer Switches Frame Number of ImageMap";
}



%template.addBehaviorField(timer, "the length of time one framme lasts", float, 3);
%template.addBehaviorField(imageMap, "image map used", object, t2dSceneObject);
%template.addBehaviorField(frame, "The frame to swap to", int, 0);




function frameSwitcher::getFrame(%this.image, %this.frame, %this.time)
{
//here I must make this frame show or 3 seconds. While the followibng line must implement that while this frame is on, it inflicts damage.
if (isObject(%this.image))
%this.owner.setImageMap(%this.image, %this.frame, %this.time);
return;
else (isObject(%this.image))
%this.owner.setImageMap(%this.image, %this.frame, %this.time);
return;
}



#5
07/22/2009 (11:21 am)
ps. as an example of where i am a little confused....

this is a timerSHoots Behaviour which works. Where I am confused in the use of onAddToScene and fire.



function TimerShootsBehavior::onAddToScene(%this, %scenegraph)
{
%this.schedule(%this.fireRate, "fire");
}

function TimerShootsBehavior::fire(%this)
{
if (!isObject(%this.projectile))
return;

%projectile = %this.projectile.cloneWithBehaviors();

%projectile.setPosition(%this.owner.position);
%projectile.setRotation(%this.owner.rotation);
%projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);

%min = (%this.fireRate - %this.fireRateVariance) * 1000;
%max = (%this.fireRate + %this.fireRateVariance) * 1000;
%random = getRandom(%min, %max);
%this.schedule(%random, "fire");
}



a basic explanation of this would help me greatly... or just ref above post to really see closer to what I mean.
thanks
ren
#6
07/22/2009 (11:39 am)
well the first thing thats happening is as soon as the object is added to the scene its going to call the fire command onces the firerate is expired(timed).

is inside of the fire command its saying

is this a projectile? yes keep going, no then exit the function

then its creating the projectile based on the owner which i believe is the scene object
position = owner.position
rotation = ownder.rotation
then shoot the projectile at a certain rotation and speed.

then get a min and max based on the variance for the next time it will fire

get a random number between the min and max for the timer

then fire again at that random number.
#7
07/22/2009 (11:39 am)
I don't use behaviors in my project but you might be a bit confused on the schedule function. There is no default "timer" field (unless you add one) for behaviors. Instead you use the schedule function to schedule events to occur in some future time. You can see this in the shooter function which calls the fire function when the object is first added to the scene. But since we don't want everything to fire right when it appears, we need to delay the firing. The behavior does this by using the %this.schedule command. The two arguments that are needed are the amount of time to wait in millseconds (1000 = 1 second) and then the name of the function in quotes. If you're using the schedule function by itself, schedule() instead of %this.schedule(), then you need to include the object ID to associate the pending event with or 0 if you don't care. After the fire function activates, it schedules itself again with some additional code to give some random variation in the time.

For your frame switching example, you probly want something like:
//Start showing frame 1
SomeImage.setFrame(1);
//Switch the frame back to 0 after 3 seconds
SomeImage.schedule(3000, "setFrame", 0);

#8
07/22/2009 (11:43 am)
I'm still a little confused as to why you need 3 behaviors for this.

i would make one behavior that handles everything you need to do. but what i would do is create your scene object with collisions. then on a timer move the object up/down or left/right whichever what you want it to move to be out of the players way.

so it mario they have those huge blocks that come down and crush you on a certain timer.

set the blocks to use collision, in the onCollsion callback check to see if you collide with the player, if you do then cause damage. have a timer set up that moves the blocks up and down. it should be that simple.

if you use a behavior for this then you can specify what the timer variable should be for each object.

Let me know if that makes sense or not.
#9
07/22/2009 (1:51 pm)
well obviously.. now that i think of it, keeping all in one would be better. I am just figuring how. Wither way tho, one or three, i think i will need some help. Been on a bit of a break but will be back at this shortly.



7 hours of staring at a screen you need a break every once and a while.
will post further stuff later.
#10
07/22/2009 (2:00 pm)
this is rough and prolly won't work but should get you started

if (!isObject(SmasherBehavior))
{
%template = new BehaviorTemplate(SmasherBehavior);

%template.friendlyName = "Smasher";
%template.behaviorType = "AI";
%template.description = "Object that smashes the player";
}



%template.addBehaviorField(Uptimer, "the length of time one framme lasts", float, 3);
%template.addBehaviorField(Downtimer, "the length of time one framme lasts", float, 3);

function Smasher::onAddToScene(%this, %scenegraph)
{
%this.schedule(%this.Uptimer, "UPfunction");

}
function Smasher::UPfunction(%this)
{
Smaher.moveUp();
%this.schedule(%this.Downtimer, "Downfunction");

}
function Smasher::Downfunction(%this)
{
Smasher.moveDown();
%this.schedule(%this.Downtimer, "Downfunction");
}
function Smasher::onCollision(##add collsion params here##)
{
if(collidedObject == $playerObject)
{
$playerObject.dealDamage();
}
}
#11
07/22/2009 (2:12 pm)
see,this is what gets me and hopefully your near an can answer this quick but...



UpFunction,
for this you are thinking state1,
smasher, is the imageMap? just classed/named as Smasher

%schedule (%DownTimer, "DownFunction:)

Now this was for the schedule, DownTimer, this is previously undeclared. Ideally, would it simply appear in the
console as an adjustable variable of time? (Titled DownFunction)






#12
07/22/2009 (2:15 pm)
function Smasher::onCollision(##add collsion params here##)<-------this will need to have the variables that represent what the Smasher can do harm to, in this case, our hero. So would I be looking at %src, %ref, %strength



see, these are the bits that are going to get me, need a lot of work around here.



#13
07/22/2009 (2:25 pm)
smasher is the name of the class, when you assign a behavior to a scene object it should pick up to use the smasher class functions.

DownTimer is declared in the behavior template so you can assign it any value you want when you assign the behavior to the object. This is the same for the UpTimer.

as for the on collision you will have to find which params it takes in as i don't know off the top of my head. but you can either hardcode a damage amount or assign one dynamically according to the position in which the collision happened (i.e. if the player was in the center of the smasher then it would do some base damage plus some modifer)
#14
07/22/2009 (2:32 pm)
Yes that is great, thank you.

I just found this page
http://tdn.garagegames.com/wiki/TorqueScript_Console_Functions_10#objID.schedule.28_t_.2C_methodName.2C_arg0.2C_..._.2C_argN_.29

I believe it to be very relavent. I can call objID.Schedule(methodName) my thing is how to write this code.





objID.schedule( t , methodName, arg0, ... , argN )

Purpose
Use the objID.schedule method to schedule methodName to be executed with optional arguments at time t (specified in milliseconds) in the future on the object objID. This event is automatically associated with the object objID, and if that object is deleted prior to this event occuring, the event is automatically cancelled.

#15
07/22/2009 (2:36 pm)
found a couple things to help you out....

collision params.
onCollision(%srcObj, %dstObj, %srcRef,
%dstRef, %time, %normal, %contactCount, %contacts)

and to move the object up and down use

up
setLinearVelocityY(-10);

down
setLinearVelocityY(10);
#16
07/22/2009 (2:40 pm)
ok so add in the template setup

%template.addBehaviorField(DamageAmount, "the length of time one framme lasts", float, 3);


then do

Smasher.schedule( %Downtimer , "Downfunction", %DamageAmount, 1 )


argN is the number of params you are passing in.
#17
07/22/2009 (3:41 pm)
sorry, i should have been more clear as to what exactly it is that I need. I was saying ref the smasher as a rough example. but for this game it is more of a square panel which will flip. So, it needs to be on a timer still, but with no linear velocity. I am looking at making it flip from A to B (with an animation in between, tho that may be a little way off yet), where A is damaging to our hero, B is not. (A=frame0, B=frame1)



I figure I can switch Down and Up to A and B and remove the linear function.


Smasher.schedule I would swtich to...
BigSquare.schedule(... and this is where I will vary from you...
...
BigSquare.schedule(%timer...//this timer needs to either represent one state(therefore I would need two timers or contain the full 6 seconds, and I create a if-else situation where imageMap is frame 0 when t<3, and it is frame 1 when t>3.




#18
07/22/2009 (4:23 pm)
sounds like you are on the right track now. Let me know if you need any other help.
#19
07/22/2009 (6:49 pm)
thanks I will.
#20
07/23/2009 (12:32 pm)
Ok I am having a bit of trouble with it, I am programming right now, but any guidance would be mad cool.

In my note taking i decided that I need a behaviour with 2 functions, one to control frame exposure, ie, frame 0 lasts 3 seconds, then switches to frame 1 for 3 seconds and the loop starts over.

Also, a function which tuns collisionDamage on when on frame 0 of imageMap (or<3seconds) (not sure about this.. do I relate damage to time, or frame, does it even matter, probably not).

So what I have thus far is...

{code}if (!isObject(BigSquareBehavior))
{
%template = new BehaviorTemplate(BigSquareBehavior);

%template.friendlyName = "BigSquare";
%template.behaviorType = "AI";
%template.description = "Square changes modes from on to off, killing on on.";
}


%template.addBehaviorField(FrameSwitcher, "the mechanism controlling frame and time of exposure", float, 3);
%template.addBehaviorField(Sheild, "turns shields (damage) on and off", int, 3);{/code}


I have not gotten into the functions as that is where I am getting really confused but if anyone can reassure me I am moving forward properly, that this code, thus far would make sense, would be greatly appreciated.





Page «Previous 1 2 3 4 Last »