limited real time action, is this possible?

Started by , Tue 18/11/2003 22:59:20

Previous topic - Next topic

Bonkey

I hope I don't get blasted for asking this.(strict forums!!) I am a newbie, and I'm merely wondering if limited real-time action is possible within the abilities of AGS.
 For example:  Is it possible to have a character shoot moving objects on the screen, and have death animations?  (Like in the Blade Runner adventure game)  
  I assume you would need to use advanced scripting, but I can be hopeful, can't I?
 and to answer the obvious question of, "why use AGS to make an action game?"
 Answer:  Well,.. I don't want to make an action game so much as I want to make an adventure game with SOME action in it.
 Because if this isn't possible, then I'll have to mark out any idea for a game that involves zombies or hostiles period.
   

squinks

Yep, you can. May take a littel bit of work though...

CB..

#2
he he !! am niggling away at this myself (as a newbie myself so only using pretty newbie style coding)

i have for a submarine warfare simulation concept managed to create a destroyer (character DD) which randomly (at the moment) moves around on one walkable area at the top of the screen
using a timer to slow it's progress which is set in as room loads (run script)

SetTimer(3,200);

then in repeatedly execute (run script)....(thanks colosuss!)

if (IsTimerExpired(3)==1)
{if (character[DD].walking!=1){
MoveCharacter(DD, Random(320),Random(200));
}
SetTimer(3,200);
}    



this means every 5 second or so it randomly moves around the top walkable area which is the surface of the sea etc

it drags another character around in the second walkable area (underwater etc)
by using this to tie its movements to the destroyer

repeatedly execute(runscript)

character[SONAR].x=character[DD].x;


this character as yu might have guessed acts as the  destoyers sonar detector beam

then for the sensor to work i used (again setting the timer in as room loads)

SetTimer(3,200);

this in repeatdly execute

if (IsTimerExpired(5)==1)
{if ((character.x-character[SONAR].x<80 && character.x-character[SONAR].x>-80 && character.y-character[SONAR].y<80 && character.y-character[SONAR].y>-80)){
character[DC].room=character[DD].room;
character[DC].x=character[DD].x + 10;
character[DC].y=character[DD].y + 50;
PlaySoundEx(10, 5) && SetTimer(7,150) && MoveCharacter(DC, character[DD].x-20,character[DD].y+300);
}
SetTimer(5,160);
}    

//

which breaks down into

if the submarine (character SUB) is within 80 pixels in any direction of the sonar beam (character SONAR)

if ((character.x-character[SONAR].x<80 && character.x-character[SONAR].x>-80 && character.y-character[SONAR].y<80 && character.y-character[SONAR].y>-80)){

then it moves a new character into the room.. in this case a depth charge (character DC)

character[DC].room=character[DD].room;

places it just underneath the destroyer

character[DC].x=character[DD].x + 10;
character[DC].y=character[DD].y + 50;

then plays a sound (a sonar ping..PlaySoundEx (10, 5) and shoots the depthcharge down the screen //MoveCharacter(DC, character[DD].x-20,character[DD].y+300)// allso seting a new timer to set when the depth charge will explode//SetTimer(7,150)

PlaySoundEx(10, 5) && SetTimer(7,150) && MoveCharacter(DC, character[DD].x-20,character[DD].y+300);
}
SetTimer(5,160);
}  

then in repeatedly execute again to get the damage caused to the sub (if any) by the depth charge..

if (IsTimerExpired(7)==1)
{if ((character.x-character[DC].x<40 && character.x-character[DC].x>-40 && character.y-character[DC].y<40 && character.y-character[DC].y>-40)){
GiveScore(-20) && PlaySoundEx(12, 4) && ShakeScreen(1);}
PlaySoundEx(12, 4);
}



when the timer 7 has counted down if the character SUB is within 40 pixels in any direction of the character DC  (depth charge) it reduces my score by 20 plays an explosion sound and shakes the screen and if character sub isn't that close to the DC, then it just plays a different sound PlaySoundEx(12, 4); which is a muffled explosion sound..



this is something like yu are working on only i suppose in reverse..ie something shoots a weapon at the player rather than the other way round...it passes as real time because first the destroyer must detect the player character, thru yu being within a certain distance of it's sonar character before it drops the depth charge, then only if the depth charge (which travels more or less straight down the screen from directly underneath the moving destroyer) is within a set distance of the player when the timer counts down does it do damage ..if not then it passes harmlessly by  

argh didnt explain that too well..but i reckon that counts as real time?
its a bit of fun anyway..

am going to have to do something similar to yur idea to allow the players submarine to shoot torpedoes at moving ships etc..im going to really just do the depth charge routine in reverse at least till i can write something better    


heres the entire room code just in case it helps


/////////

// room script file
function room_a() {
 // script for room: Player enters screen (before fadein)
SetTimer(1,200);
SetTimer(2,400);
SetTimer(3,200);
SetTimer(5,200);
SetTimer(6,300);
SetTimer(8,300);
SetBackgroundFrame(1);
}

function room_b() {
 // script for room: Repeatedly execute
if (IsKeyPressed(403) == 1)  
SetBackgroundFrame(0);
if (IsKeyPressed(404) == 1)  
SetBackgroundFrame(2);
if (IsKeyPressed(405) == 1)  
SetBackgroundFrame(3);
if (IsKeyPressed(406) == 1)  
SetBackgroundFrame(1);
if (IsTimerExpired(1)==1)
{PlaySoundEx(1, 3);
SetTimer(1,200);}
if (IsKeyPressed(380) == 1)
 MoveCharacter(SUB,character.x,character.y+53) && MoveCharacter(EGO, character.x-5,character.y-10) && DisplaySpeechBackground (EGO, "Coming to new depth, Sir");
else if (IsKeyPressed(372) == 1)
 MoveCharacter(SUB,character.x,character.y-53) && MoveCharacter(EGO, character.x-5,character.y-10) && DisplaySpeechBackground (EGO, "Coming to new depth, Sir");
else if (IsKeyPressed(377) == 1)
 MoveCharacter(SUB,character.x+53,character.y) && MoveCharacter(EGO, character.x-5,character.y-10) && DisplaySpeechBackground (EGO, "Coming to new heading, Sir");
else if(IsKeyPressed(375) == 1)
 MoveCharacter(SUB,character.x-53,character.y) && MoveCharacter(EGO, character.x-5,character.y-10) && DisplaySpeechBackground (EGO, "Coming to new heading, Sir");
if (IsTimerExpired(2)==1)
{int ran=Random(7);
if (ran==0) PlaySoundEx(2, 4);
else if (ran==1) PlaySoundEx(3, 4);
else if (ran==2) PlaySoundEx(4, 4);
else if (ran==3) PlaySoundEx(5, 4);
else if (ran==4) PlaySoundEx(6, 4);
else if (ran==5) PlaySoundEx(7, 4);
else PlaySoundEx(9, 4);
SetTimer(2,1200);
}
if (IsTimerExpired(3)==1)
{if (character[DD].walking!=1){
MoveCharacter(DD, Random(320),Random(200));
}
SetTimer(3,200);
}    
character[SONAR].x=character[DD].x;
if (IsTimerExpired(5)==1)
{if ((character.x-character[SONAR].x<80 && character.x-character[SONAR].x>-80 && character.y-character[SONAR].y<80 && character.y-character[SONAR].y>-80)){
character[DC].room=character[DD].room;
character[DC].x=character[DD].x + 10;
character[DC].y=character[DD].y + 50;
PlaySoundEx(10, 5) && SetTimer(7,150) && MoveCharacter(DC, character[DD].x-20,character[DD].y+300);
}
SetTimer(5,160);
}  
if (IsTimerExpired(7)==1)
{if ((character.x-character[DC].x<40 && character.x-character[DC].x>-40 && character.y-character[DC].y<40 && character.y-character[DC].y>-40)){
GiveScore(-20) && PlaySoundEx(12, 4) && ShakeScreen(1);}
PlaySoundEx(12, 4);
}


character[GG].x=character[GetPlayerCharacter()].x;

}





function region4_a() {
 // script for region4: While player stands on region
if (IsTimerExpired(6)==1)
{if ((character.y>60 && character.y<90))
{DisplaySpeechBackground (EGO, "Periscope Depth");}
else if ((character.y>90 && character.y<150))
{DisplaySpeechBackground (EGO, "Depth 50 Metres");}
else if ((character.y>150 && character.y<190))
{DisplaySpeechBackground (EGO, "Depth 100 Metres");}
else if ((character.y>190 && character.y<230))
{DisplaySpeechBackground (EGO, "Depth 150 Metres");}
else if ((character.y>230 && character.y<260))
{DisplaySpeechBackground (EGO, "Depth 175 Metres");}
else if ((character.y>260 && character.y<280))
{DisplaySpeechBackground (EGO, "Depth 200 Metres");}
else if ((character.y>280 && character.y<290))
{DisplaySpeechBackground (EGO, "Depth 225 Metres ..Now Below Test Depth");}
else if ((character.y>290 && character.y<295))
{DisplaySpeechBackground (EGO, "Depth 250 Metres Minor Flooding") && GiveScore(-1);}
else {DisplaySpeechBackground (EGO, "Depth 275 Metres Pressure Hull Damaged") && GiveScore(-2);}
SetTimer(6,1000);}
if (IsTimerExpired(8)==1)
{if ((character.x>190 && character.x<210))
{DisplaySpeechBackground (SUB, "Heading 00 Degrees");}
else if ((character.x>210 && character.x<250))
{DisplaySpeechBackground (SUB, "Heading 15 Degrees");}
else if ((character.x>250 && character.x<300))
{DisplaySpeechBackground (SUB, "Heading 30 Degrees");}
else if ((character.x>300 && character.x<350))
{DisplaySpeechBackground (SUB, "Heading 45 Degrees");}
else if ((character.x>350 && character.x<400))
{DisplaySpeechBackground (SUB, "Heading Due East");}
else if ((character.x>170 && character.x<190))
{DisplaySpeechBackground (SUB, "Heading 345 Degrees");}
else if ((character.x>150 && character.x<170))
{DisplaySpeechBackground (SUB, "Heading 330 Degrees");}
else if ((character.x>100 && character.x<150))
{DisplaySpeechBackground (SUB, "Heading 315 Degrees");}
else {DisplaySpeechBackground (SUB, "Heading Due West");}
SetTimer(8,1000);}
 
}


CB..

#3
heres the code for a very simple weapon fired by the player at another named character...

repeatedly execute   run script  edit script copy this in..use yu own chraracters ie EGO instead of SUB and ARROW instead of TP etc..


if (IsKeyPressed(407) == 1)
SetTimer(10,40); //set a timer for one second
character[TP].room=character.room; //moves weapon to current room
character[TP].x=character.x ;//places weapon at same left right position as player
character[TP].y=character.y-10;//places weapon slightly above player
if (IsTimerExpired(10)==1)//after one second has elapsed
{MoveCharacterDirect(TP, character.x-1,character.y-300);}
if (AreCharactersColliding(TP,DD)==1){
GiveScore(100);
}  

pressing the ALT key on yur keyboard sets a timer for one second  

after the timer has expired the weapon character (choose a view like an arrow or such like) is moved from the players position up the screen...if the weapon/arrow collides with the target character yu are given some points .but it could allso do other things like play an animation and stop that character moving etc.

this creates a animation type effect for the weapon as it travels up the screen as the game flashes the character from the start postion to it's current position evry game cycle..which is quite effective (tho it had me confused for a while..the key press only activated the first command in the group not them all)

this could allso be written like this to remove the flashing effect and avoid having the weapon on view all the time

if (IsKeyPressed(407) == 1)
SetTimer(10,40);
if (IsKeyPressed(407) == 1)
character[TP].room=character.room;
if (IsKeyPressed(407) == 1)
character[TP].x=character.x ;
if (IsKeyPressed(407) == 1)
character[TP].y=character.y-10;
if (IsTimerExpired(10)==1)
{MoveCharacterDirect(TP, character.x-1,character.y-300);}
if (AreCharactersColliding(TP,DD)==1){
GiveScore(100);
}  



then its a matter of naming the character yu want to shoot at

here

if (AreCharactersColliding(TP,DD)==1)

im shooting the weapon  character TP at the non player character DD

susbstitute yur own characters names  

ie

if (AreCharactersColliding(ARROW,ENEMY)==1)  and so on..


some minor details need tidying up but it works and  once yu have the hang of using the run script option in AGS  is something to mess around with (as i am doing) while yur learning (again im in the same boat)


this might make it a little clearer  yu might use this in yur game


if (IsKeyPressed(407) == 1)
SetTimer(10,40);
if (IsKeyPressed(407) == 1)
character[ARROW].room=character[EGO].room;
if (IsKeyPressed(407) == 1)
character[ARROW].x=character[EGO].x ;
if (IsKeyPressed(407) == 1)
character[ARROW].y=character[EGO].y-10;
if (IsTimerExpired(10)==1)
{MoveCharacterDirect(ARROW, character[EGO].x-1,character[EGO].y-300);}
if (AreCharactersColliding(ARROW,ENEMY)==1){
GiveScore(100);
}



im pretty sure this will work


i did try and set it up so one button would load the weapon and another different buton would fire it, as this was more interactive and fun..
like this

if (IsKeyPressed(407) == 1)//alt key for load
character[TP].room=character.room;
character[TP].x=character.x;
character[TP].y=character.y-10;
if (IsKeyPressed(371) == 1)//home key for fire
SetTimer(10,40);
if (IsTimerExpired(10)==1)
{MoveCharacterDirect(TP, character.x-1,character.y-300);}
if (AreCharactersColliding(TP,DD)==1){
GiveScore(100);
}  

with a longer delay on the timer for loading and firing etc it made it feel quite realistic and much more interesting/fun ...but it was posible to try and fire the weapon before loading it which didnt work and caused an error of course..but im sure with a litle more work that having the extra load and fire facility can be worked so if yu try to fire the weapon before loadng it the game just displays a message or does nothing ..which i think would be a nice addition..

SMF spam blocked by CleanTalk