 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
satyrisci ~guo~

Joined: 28 Feb 2007 Posts: 73
|
Posted: Tue Apr 24, 2007 1:37 pm Post subject: Movement and shooting |
|
|
Hey,
I'm trying to create a script whereby the left and right directional keys would rotate the direction the player is facing, the up directional key would step the player forward and the down arrow would step them backward. I'm using (key is pressed), but I'm quite inept at plotscripting right now and I'm wondering if rather than invent the wheel someone could please help me?
I would also appreciate help implementing a shoot script whereby a key is pressed and an instanced NPC would fire from the direction player is facing until it strikes either an enemy or a wall, and deal damage to a variable representing the enemy's health.
Any help would be much appreciated.
Cheers. |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Tue Apr 24, 2007 2:38 pm Post subject: |
|
|
If you are attempting to make a first-person perspective, all I can say is that it is not impossible per se, but you are much better off using some other engine.
On the other hand, if you are trying to keep the overhead perspective, then the turning script is not very difficult, but the controls may seem awkward to most players (on screen, if the hero will be facing east, and then pressing up will make them move east, pressing down will make them move west, and left and right will make them face north and south respecitvely).
First off, all map-autorun scripts should have a suspend player command to prevent the arrows from moving the player normally. Then have the following as an on-keypress script:
Code: | variable (dir)
dir:=herodirection(me)
if(keyispressed(key:up)),then
begin
walk hero(me,dir,1)
wait for hero (me)
end
if(keyispressed(key:down)),then
begin
walk hero(me, (dir+2,mod,4),1)
set hero direction(me,dir)
wait for hero(me)
end
if(keyispressed(key:right)),then
begin
setherodirection(me,(dir+1,mod,4))
end
if(keyispressed(key:left)),then
begin
setherodirection(me,(dir--1,mod,4))
end
|
I have not tested this, so there may be a few small errors, but I believe that this is the central idea for a script that would do what you asked for in the OHR's terms.
I'm afraid I don't feel very confident with the 'shooting an NPC' part, so I will have to defer that to someone else. Please let us know though if this is what you are looking for. Again, if you are trying to make a first-person perspective game, you are almost certainly using the wrong game-creation engine. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Apr 24, 2007 5:35 pm Post subject: |
|
|
This is possible to pull off without extraordinary scripting if you stick to tile-based 4 directional movement with an overhead perspective.
msw188 wrote: | Code: | if(keyispressed(key:left)),then
begin
setherodirection(me,(dir--1,mod,4))
end
|
|
Using mod on negative numbers does not work the way you would expect. (-1, mod, 4) returns -1. Instead, use (dir+3, mod, 4).
Also, you don't need to put suspend player in all your map autorun scripts, you only need it once. Unless there are areas of the game which return to normal controls.
However, using suspend player creates 2 considerations:
* The player can't access the menu. You can fix this by adding some scripting to the on key press handler:
Code: | script, on key press handler, begin
if (key is pressed (key:esc) or, key is pressed (key:alt)) then (
# give the engine's default key handers control again for this tick
resume player
wait (1)
suspend player
) else (
variable (dir)
dir:=herodirection(me)
# ...
)
end |
* The player can't use the use key to use npcs. You'll have script this in the key handler script as well. The code to do that might look like this:
Code: | if (key is pressed (key:ctrl), or, key is pressed (key:enter), or, key is pressed (key:space)) then (
variable (x, y, dir, npc)
# we need to find the x,y coordinate of the spot in front of the hero
x := hero x
y := hero y
dir := hero direction
if (dir == north) then (y -= 1)
if (dir == south) then (y += 1)
if (dir == west) then (x -= 1)
if (dir == east) then (x += 1)
npc := npc at spot (x, y)
if (npc) then (use npc (npc))
) |
_________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Tue Apr 24, 2007 9:20 pm Post subject: |
|
|
Quote: | Using mod on negative numbers does not work the way you would expect. (-1, mod, 4) returns -1. |
Is there a reason for this? Does anyone use the mod function expecting the possibility of negative numbers? If the answer to both those questions is no, I believe that the mod function should be changed to return non-negative numbers. This is actually making me afraid that there are some possible errors hidden deep within my scripts that I never noticed as errors on playthroughs... _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Apr 24, 2007 11:38 pm Post subject: |
|
|
msw188 wrote: | Quote: | Using mod on negative numbers does not work the way you would expect. (-1, mod, 4) returns -1. |
Is there a reason for this? Does anyone use the mod function expecting the possibility of negative numbers? If the answer to both those questions is no, I believe that the mod function should be changed to return non-negative numbers. This is actually making me afraid that there are some possible errors hidden deep within my scripts that I never noticed as errors on playthroughs... |
Yeah, this really annoys me too. But it works like that for good reason: that's the way computers do division on signed integers. According to the Division algorithm remainders should never be negative, but computer manufacturers have taken their own route and decided that -1 / 100 is 0, not -1 (this is an artifact of the twos-complement working of modern computers, I'm betting).
However one defines division, you need to at least ensure that:
b * (a / b) + (a mod b) == a
is always true. Which results in negative remainders because of the difference in division.
I ran some tests:
Under FreeBASIC 0.16:
-13 \ 5 = -2
-13 MOD 5 = -3
Under QuickBasic 7.0:
-13 \ 5 = -2
-13 MOD 5 = -3
Under C++ (MinGW gcc port):
-13 / 5 = -2
-13 % 5 = -3
Under Python 2.5:
-13 / 5 = -3
-13 % 5 = 2
So interestingly Python is compensating and returning the mathematically correct result.
One expects algorithms to work the same regardless of language, so we shouldn't change anything. I myself probably rely on it somewhere.
Edit: Fixed and rewrote. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Apr 25, 2007 7:37 am Post subject: |
|
|
Hm, okay. That kind of sucks, but I can understand it. I don't know what the 'twos-complement' is, but whatever it is, I don't think I like it. Regardless, I guess we're stuck with it now. And it wouldn't be hard to make some autonumber functions to do this correctly, anyway. Maybe for my next game I will do that. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Apr 26, 2007 3:58 am Post subject: |
|
|
It's just the (modern) way that negative integers are represented as bit patterns. Much better than one's-complement, which results in negative zero.
Anyway, prehaps you should ignore that I said about emulating the use key, on second thoughts it's easier to suspend player only when they press a directional key, which won't interfere with use and menu controls. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
satyrisci ~guo~

Joined: 28 Feb 2007 Posts: 73
|
Posted: Thu Apr 26, 2007 4:23 am Post subject: |
|
|
Thanks kindly for your help, all of you. The script I have currently is thus:
Code: | Script, Movement, begin
variable (dir)
dir:=herodirection(me)
suspend player
if(keyispressed(72)),then
begin
walk hero(me,dir,1)
wait for hero (me)
end
if(keyispressed(80)),then
begin
walk hero(me, (dir+2,mod,4),1)
set hero direction(me,dir)
wait for hero(me)
end
if(keyispressed(77)),then
begin
setherodirection(me,(dir+1,mod,4))
end
if(keyispressed(75)),then
begin
setherodirection(me,(dir+3,mod,4))
resume player
end
end
|
This works... But if I press the left key the character moves to the left whilst spinning ala Tasmanian Devil. Also walking backwards doesn't work when facing right
I may have to add a delay to the turning aswell, as currently it's too fast to accurately pick a direction. |
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Apr 26, 2007 7:24 am Post subject: |
|
|
Your resume player command should be outside of the last if, so between the last two ends, rather than before them. On the other hand, having a delay is tricky. I think that this is similar to the problem H-Bomb is having, and I'm really not sure what is the best way to solve it. Maybe having a tag to force the on keypress script to bypass until the delay is over? Something like:
[pseudocode]
script,onkeypress,begin
if(checktag(1)==off),then
begin
suspendplayer
set tag(1,on)
#all the directional stuff, any other stuff
wait (4 ticks, maybe?)
set tag(1,off)
resumeplayer
end
end
[/pseudocode]
Could this also help with H-Bomb's problem? Here is another idea that might help both: what if in the keypress script we place a command to set the onkeypress script to nothing, until the keypress script was finished with its commands and waits, and at the end of the keypress script we set the onkeypress script back? That seems awfully confusing, here's some more pseudo:
[pseudocode]
script,keypress,begin
set on keypress script #no argument disables it, right?
suspend player
#do all the stuff, including any waits
resume player
set on keypress script (this very script, called keypress, but we need its ID, not name here)
end
[/pseudocode] _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
satyrisci ~guo~

Joined: 28 Feb 2007 Posts: 73
|
Posted: Thu Apr 26, 2007 3:17 pm Post subject: |
|
|
Cheers MSW, har I should have noticed that resume player was in the wrong position :S
I'll keep playing around and post an update. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sat Apr 28, 2007 8:21 am Post subject: |
|
|
satyrisci wrote: | Code: | Script, Movement, begin
variable (dir)
dir:=herodirection(me)
suspend player
if(keyispressed(72)),then
begin
walk hero(me,dir,1)
wait for hero (me)
end
if(keyispressed(80)),then
begin
walk hero(me, (dir+2,mod,4),1)
set hero direction(me,dir)
wait for hero(me)
end
if(keyispressed(77)),then
begin
setherodirection(me,(dir+1,mod,4))
end
if(keyispressed(75)),then
begin
setherodirection(me,(dir+3,mod,4))
resume player
end
end
|
|
mod has a higher precedence than +. You must write dir+1,mod,4 as (dir+1),mod,4 because otherwise it is translated to dir+(1,mod,4). The reason you didn't notice the problem is because setherodirection takes the direction mod 4 anyway. Walk hero doesn't.
Sorry, I just made this mistake further up the page. As you can see, it's really easy to forget. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|