Making a VERY simple shooter

Started by canavan, Fri 08/08/2003 22:26:37

Previous topic - Next topic

canavan

I am attempting to make an extremely simple shooter arcade sequence. Basically, All I am going to do is have a tall room, all walkable, with a little space ship as the main characer, have the arrow keys move it left right forward and back, and space bar to shoot. I would then need to do some sprite detection to notice whent he bullet hit a character entering the screen, and vice versa.


Is there a very simple solution to this. I guess Ill start with how does one map keys to character movment, and turn the mouse off?

canavan

How is it possible to script so that when a character enters a room the mouse is disabled and it switches so that arrow keys (up, down, left, right) control the character?

TerranRich

Look at the Demo Quest game. And stop posting so many common questions! ;)
Status: Trying to come up with some ideas...

Pumaman


Just handle the keypresses in  on_key_press  like this:


if (keycode == 372) {  // up arrow
 MoveCharacterStraight (EGO, character[EGO].x, character[EGO].y - 100);
}

and so on for each arrow key.

canavan

Ok I did this on the repeat excute of the room:

if (IsKeyPressed(380) == 1){
 MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y+400);}
if (IsKeyPressed(372) == 1){
 MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y-400);}  
if (IsKeyPressed(377) == 1){
 MoveCharacter(POKEY,character[POKEY].x+400,character[POKEY].y);}
if (IsKeyPressed(375) == 1){
 MoveCharacter(POKEY,character[POKEY].x-400,character[POKEY].y);}

and this works, but only if I tap the keys. I would like it to work even while holding down the keys. For instance, holding left moves the character left, and then going to holding right moves it right. With this, if I hold a key the character stops moving.

Any ideas?

Pumaman

You need to do it backwards.

In other words, in on_key_press you need:

if (keycode == 380){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y+400);}
if (keycode == 372){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y-400);}
if (keycode == 377){
MoveCharacter(POKEY,character[POKEY].x+400,character[POKEY].y);}
if (keycode == 375){
MoveCharacter(POKEY,character[POKEY].x-400,character[POKEY].y);}

SetGlobalInt(XX, keycode);


where XX is a spare globalint number. Then, in repeatedly_execute:

if (GetGlobalInt(XX) > 0) {
if (IsKeyPressed(GetGlobalInt(XX)) == 0) {
StopMoving(POKEY);
SetGlobalInt(XX, 0);
}
}


In other words, you start the move when the key is pressed down, and then check continually for the key release, at which point you stop them moving.

The reason your current code doesn't work is because you're calling MoveCharacter continually, which keeps resetting the movement.

canavan

Ok I gave this code a try, and it sort of works. The arrows seem to move my character for a short time, but it seems my character acts a little crazy... like its waiting for the keys to catch up, freeze, only moves a step before getting stuck... almost, but not quite there. I think I have a problem with my coding.

This is what I have in my global script:

function game_start() {
SetCharacterIdle(POKEY,2,5);
SetGlobalInt(14,0);
SetGlobalInt(10,0);}


function on_key_press(int keycode) {
if (IsGamePaused() == 1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17)  GUIOn(2); // Ctrl-Q
if (keycode==363){
SetGlobalInt(14,1);
load_thumbnails();
SetButtonPic(1,10,1,7);
InterfaceOn(1);}
if (keycode==365){
SetGlobalInt(14,2);
load_thumbnails();
SetButtonPic(1,10,1,8);
InterfaceOn(1);}
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode==9)   InventoryScreen(); // Tab, show inventory
if (keycode == 380){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y+3);}
if (keycode == 372){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y-3);}
if (keycode == 377){
MoveCharacter(POKEY,character[POKEY].x+400,character[POKEY].y);}
if (keycode == 375){
MoveCharacter(POKEY,character[POKEY].x-400,character[POKEY].y);}
SetGlobalInt(10, keycode);
}


function repeatedly_execute() {
if ( ((GetGUIAt(mouse.x,mouse.y)==3)||(GetGUIAt(mouse.x,mouse.y)==4)) && (UseGUI==0) ) {
PrevCursorMode=GetCursorMode();
SetCursorMode(6);
UseGUI=1;}
else if ( (GetGUIAt(mouse.x,mouse.y)==-1) && (UseGUI==1) ) {
UseGUI=0;
if (GetCursorMode()==6)
SetCursorMode(PrevCursorMode);}
if (GetGlobalInt(10) > 0) {
if (IsKeyPressed(GetGlobalInt(10)) == 0) {
StopMoving(POKEY);
SetGlobalInt(10, 0);}
PlaySoundOnGUI();
CheckOtherGUI();
}}


So, two issues really. First, this almost works but my character isnt quite excuting this correctly (although it does compile and run.) Second, I really only want the arrow keys available to move the character around in one room (not the entire game.) For an arcade sequence.

Thanks for hanging in, im kinda new. Still learning.

canavan

Hmmm also if it helps ... i also screwed up my script so my curser doesnt change to an arrow and make sounds over buttons anymore, so i think issues are with rep. excute.. hmmm.. not touching it for now to see if one of you experts have any advice on how to fix :)

Pumaman

You probably need to enclose this bit in an extra condition:

if (character[POKEY].walking == 0) {
if (keycode == 380){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y+3);}
if (keycode == 372){
MoveCharacter(POKEY,character[POKEY].x,character[POKEY].y-3);}
if (keycode == 377){
MoveCharacter(POKEY,character[POKEY].x+400,character[POKEY].y);}
if (keycode == 375){
MoveCharacter(POKEY,character[POKEY].x-400,character[POKEY].y);}
SetGlobalInt(10, keycode);
}

Because if you hold the key down, it will start calling on_key_press again after a while.

canavan

Ok... Ill have to try this.

Is there any way to make this kind of thing (using arrow keys to control one character) happen ONLY in one room? Can you put on key events in the room script somewhere? I seems all this this would only work int he global script?

I really only want the character controllable by arrow keys in one room.

Pumaman

Just replace the first line I gave you with this:

if ((character[POKEY].walking == 0) && (character[POKEY].room == XXXX)) {

where XXXX is the room number you want it to work in.

canavan

ok and what about the rep. excute code given in the earlier example?

Then, in repeatedly_execute:

if (GetGlobalInt(XX) > 0) {
if (IsKeyPressed(GetGlobalInt(XX)) == 0) {
StopMoving(POKEY);
SetGlobalInt(XX, 0);
}
}

Do I use another IF and ROOM= for this? Or include this int he room rep. excute?

Thank you very much. Almost have this :)

canavan

For those of you following this thread, I found the complete solution to my question here:

ftp://a-v-o.selfhost.de/ags/keyboardcontrol.txt

Its a full script for keyboard control in AGS from a way way back thread, but works perfectly.

Jodo Kast

I just want to say I have been trying to rely on the forums for help, but a lot of the threads can't be found, and links like this FTP site are offline.

Please host files somewhere where they won't get deleted.  Anyone have A-V-O's script or know what time of the day the FTP server is running (if at all)?

Thanks for your help.  I've been saving the good links because adding them to my favorites probably won't work for much longer.

canavan

That is an OLD thread.

As far as I can tell, that ftp sight isnt open. The text file I was pointing to contained the exact same information contained in earlier posts to this thread about controlling a character with the keyboard, so you arent missing much.

SMF spam blocked by CleanTalk