473,811 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hrmmm...Suggest ions, Ideas, Pointless Remarks?

Well in theory it was a good idea:
http://www.backwater-productions.net...ame/index.html

Press "4" to move left, press "6" to move right.

The question remains though...is there some way of limiting
onkeypress? Cause if you hold the key down, boy that's just all
shades of unhappy right there.

: char_l_img = 1;
: char_r_img = 1;
: start_pos = 300;
: nav4 = window.Event ? true : false;
:
: function move_left()
: {
: start_pos = start_pos - 5;
: char_l_img++;
: if ( start_pos == 25 ) { start_pos = 30; }
: if ( char_l_img == 5 )
: {
: char_l_img = "1";
: window.clearInt erval(farfoos);
: }
: document.getEle mentById("char_ div").style.lef t = start_pos + "px";
: document.getEle mentById("char_ img").src = "l" + char_l_img + ".gif";
: }
:
: function move_right()
: {
: start_pos = start_pos + 5;
: char_r_img++;
: if ( start_pos == 500 ) { start_pos = 495; }
: if ( char_r_img == 5 )
: {
: char_r_img = "1";
: window.clearInt erval(farfoos);
: }
: document.getEle mentById("char_ div").style.lef t = start_pos + "px";
: document.getEle mentById("char_ img").src = "r" + char_r_img + ".gif";
: }
:
: function move(e)
: {
: if (nav4) { whichCode = e.which; }
: else { whichCode = event.keyCode; }
: if( String.fromChar Code(whichCode) == 4 && char_l_img == 1 ) { farfoos = window.setInter val('move_left( )', 35); }
: if( String.fromChar Code(whichCode) == 6 && char_r_img == 1 ) { farfoos = window.setInter val('move_right ()', 35);}
: }
:
: document.onkeyp ress = move;
:
: document.write( "<div id='char_div' style='position :absolute; z-index:0; left:" + start_pos + "px; top:150px; width:32px height:64px'><i mg id='char_img' src='r1.gif'></div>");

I tried that && char_l_img == 1 thing, but that didn't seem to cut it.
Is there some way to detect when a key is NOT being pushed?
Hrmmm...I'm at a loss on this one at the moment, I think maybe I need
to get some sleep. -_-

I might need to rethink the whole way it actually functions...may be do
it in PHP...hrmmm...w onder if PHP has an onkeypress equivalent...

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
Jul 23 '05 #1
14 1626
VK
I guess you never programmed for ZX Spectrum... It puts your brains
under the right angle once and for a while :-)

The onkeydown starts the process of movement regulated by your internal
timer.

The onkeyup stops the process of the movement and clears the timer.

As the PC/Mac keyboard approach sucks from the very beginning, it's
impossible to reach a "PC Game" functionality w/o your own keyboard
driver (so say you could hold a key to keep moving forward and press
other keys to shoot/kick the enemies).

But a primitive movement is fairly simple:
....
var obj = null;
function init() {
obj = document.getEle mentById('Monke y');
obj.onkeydown = moveIt;
obj.onkeyup = stopIt;
}

function moveIt() {
/* Check what key is pressed
and setTimeout for the appropriate movement
function (left/right/up/down) */
}

function stopIt() {
/* clearTimeout */
}

windows.onload = init;
....

Jul 23 '05 #2
VK wrote:
[...]
windows.onload = init;

--------^

This runs when the OS loads? :-)

--
Rob
Jul 23 '05 #3
VK
>> windows.onload = init;
This runs when the OS loads? :-)


That would be cool... :-)

Sorry, just a typo. Of course:

window.onload = init;

Jul 23 '05 #4
Lee
Onideus Mad Hatter said:
I might need to rethink the whole way it actually functions...may be do
it in PHP...hrmmm...w onder if PHP has an onkeypress equivalent...


PHP runs on the server to generate pages to be sent to the client
browser. It's finished its job long before the first key is pressed.

Jul 23 '05 #5
On 3 Jul 2005 05:00:55 -0700, "VK" <sc**********@y ahoo.com> wrote:
I guess you never programmed for ZX Spectrum... It puts your brains
under the right angle once and for a while :-)

The onkeydown starts the process of movement regulated by your internal
timer.

The onkeyup stops the process of the movement and clears the timer.

As the PC/Mac keyboard approach sucks from the very beginning, it's
impossible to reach a "PC Game" functionality w/o your own keyboard
driver (so say you could hold a key to keep moving forward and press
other keys to shoot/kick the enemies).

But a primitive movement is fairly simple:
...
var obj = null;
function init() {
obj = document.getEle mentById('Monke y');
obj.onkeydown = moveIt;
obj.onkeyup = stopIt;
}

function moveIt() {
/* Check what key is pressed
and setTimeout for the appropriate movement
function (left/right/up/down) */
}

function stopIt() {
/* clearTimeout */
}

windows.onlo ad = init;
...


Ahhh, thank yas! I shall copy your code, test it, rip it all apart,
test it some more, rebuild it from scratch, poke it with the testing
stick again and hopefully I should have a new working version by this
evening. My gawd I love this shit...*shudder *...I think I have an
obsession with technology, I can't seem to get enough...graphi cs,
networking, video, web design, gaming, programming it WANTS to be
learned...ALL of it! o_O

Once I've got the game thing finished I'm gonna integrate it into my
new true liquid website:
http://www.backwater-productions.net...600/index.html

I might change the subject though, I originally made it for alt.2600,
but I've been thinking about turning it into a kind of retro Nintendo
esque site.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
Jul 23 '05 #6
On 3 Jul 2005 05:00:55 -0700, "VK" <sc**********@y ahoo.com> wrote:
I guess you never programmed for ZX Spectrum... It puts your brains
under the right angle once and for a while :-)
I prefer Mt. Dew to put my brain into the right angle.

I decide to try it my own way first and fix what I had, this is the
result:
http://www.backwater-productions.net...ame/index.html

: char_l_img = 1;
: char_r_img = 1;
: char_ar_img = 0;
: char_al_img = 0;
: start_pos = 300;
: nav4 = window.Event ? true : false;
: left = null;
: right = null;
: attack = null;
: pos = "rightface" ;
:
: function move_left()
: {
: start_pos = start_pos - 5;
: char_l_img++;
: if ( start_pos == 25 ) { start_pos = 30; }
: if ( char_l_img == 5 )
: {
: char_l_img = 1;
: window.clearInt erval(left);
: left = null;
: pos = "leftface";
: }
: document.getEle mentById("char_ div").style.lef t = start_pos + "px";
: document.getEle mentById("char_ img").src = "l" + char_l_img + ".gif";
: }
:
: function move_right()
: {
: start_pos = start_pos + 5;
: char_r_img++;
: if ( start_pos == 540 ) { start_pos = 535; }
: if ( char_r_img == 5 )
: {
: char_r_img = 1;
: window.clearInt erval(right);
: right = null;
: pos = "rightface" ;
: }
: document.getEle mentById("char_ div").style.lef t = start_pos + "px";
: document.getEle mentById("char_ img").src = "r" + char_r_img + ".gif";
: }
:
: function attack_right()
: {
: char_ar_img++;
: document.getEle mentById("char_ img").src = "ar" + char_ar_img + ".gif";
:
: if ( char_ar_img == 3 )
: {
: char_ar_img = 0;
: window.clearInt erval(attack);
: attack = null;
: }
: }
:
: function attack_left()
: {
: char_al_img++;
: document.getEle mentById("char_ img").src = "al" + char_al_img + ".gif";
:
: if ( char_al_img == 3 )
: {
: char_al_img = 0;
: window.clearInt erval(attack);
: attack = null;
: }
: }
:
: function move(e)
: {
: if (nav4) { whichCode = e.which; }
: else { whichCode = event.keyCode; }
: if( whichCode == 100 ) { if ( !left ) { left = window.setInter val('move_left( )', 35); } }
: if( whichCode == 102 ) { if ( !right ) { right = window.setInter val('move_right ()', 35);} }
: if( whichCode == 32 )
: {
: if ( !attack && pos == "leftface" ) { attack = window.setInter val('attack_lef t()', 75);}
: else if ( !attack && pos == "rightface" ) { attack = window.setInter val('attack_rig ht()', 75);}
: }
: }
:
: document.onkeyp ress = move;

The trick I found was to set the interval variables to null and then
only allow it to engage the function if they were. And then at the
end of each function it would reset the interval back to null so it
could engage again. Essentially the earlier way I had it was just
running dozens of the same interval every time the key was pressed.
The onkeydown starts the process of movement regulated by your internal
timer.

The onkeyup stops the process of the movement and clears the timer.
Hrmmm...timers. ..I'll try that later, see if it works any better than
my current methodology.
As the PC/Mac keyboard approach sucks from the very beginning, it's
impossible to reach a "PC Game" functionality w/o your own keyboard
driver (so say you could hold a key to keep moving forward and press
other keys to shoot/kick the enemies).
I find it works better if I alter my keyboards repeat delay settings
to the shortest setting. The major problem with my current ver is
that if a key is held down and you push another key once, then
everything just stops, so like you said, only one button at a time
essentially.
But a primitive movement is fairly simple:

<snip>
Will using onkeydown eliminate the prior problem I mentioned, or does
it function just like onkeypress?

And if it works no differently what about combining the two? For
example what if I used onkeydown for the movement, but then in the
move function could I include an onkeypress function that would handle
the sword movement. Or do the functions onkeydown and onkeypress
cancel one another out (or rather, take the place of one another)?

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
Jul 23 '05 #7
VK
> Will using onkeydown eliminate the prior problem I mentioned,
or does it function just like onkeypress?
And if it works no differently what about combining the two? For
example what if I used onkeydown for the movement, but then in the
move function could I include an onkeypress function that would handle
the sword movement. Or do the functions onkeydown and onkeypress
cancel one another out (or rather, take the place of one another)?


Nothing will eliminate this problem because of the driver limitation I
just mentioned. It takes us rather far from JavaScript, but just to
make the picture clear:

ZX Spectrum and Atari (the great old) as well as Nintendo and Co (the
great new) have a keyboard driver based on so called "agressive
scanning". It means that from your program you may read the state of
*any key*. So user can hold 8 keys and hit the 9th one, and you can
still read it. So it doesn't have a keyboard IRQ (like PC). But you may
set up say "spacebar IRQ" (something very strange for PC terms).

PC's (back to IBM PC) decided to use much less convenient but more
resource effective scheme with passive listening of keyboard IRQ's. It
means that you cannot produce a new keyboard event until when the old
key is released. Well, no one thought about Doom or Halflife that time
:-)
To overpass the limitations of this approach, later they had to add
more and more modifiers on the keyboard (Ctrl, Alt, then divide them on
left and right control keys etc.)

Still this scheme is not usable for any more-or-less complex game. So
usually any game starts from installing its own keyboard driver. But
JavaScript doesn't let you this plesure. So I see two main options:

1) Use keys together with modifiers. Say RightArrow means go right,
Alt+RightArrow means go right and hit with the sword and so on.

2) Try to use Quake approach where the movement is regulated by keys,
and extra actions by mouse.

Jul 23 '05 #8
On 4 Jul 2005 01:15:16 -0700, "VK" <sc**********@y ahoo.com> wrote:
Will using onkeydown eliminate the prior problem I mentioned,
or does it function just like onkeypress?
And if it works no differently what about combining the two? For
example what if I used onkeydown for the movement, but then in the
move function could I include an onkeypress function that would handle
the sword movement. Or do the functions onkeydown and onkeypress
cancel one another out (or rather, take the place of one another)?
Nothing will eliminate this problem because of the driver limitation I
just mentioned. It takes us rather far from JavaScript, but just to
make the picture clear:<snip>


I gotcha, I found a way around the problem though, rather than rely on
the keyboard for movement I'm simply going to create graphical
controls on the screen, so you can move your mouse over them to
control the left, right and stop movement and then I'll just use the
keyboard for like the jumping and attack...essent ially that'll
simulate how old Nintendo controllers work (a and b buttons single
tap...unless you have turbo).

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
Jul 23 '05 #9
VK
> I'm simply going to create graphical
controls on the screen, so you can
move your mouse over them to
control the left, right and stop movement
and then I'll just use the
keyboard for like the jumping and attack


It's your game (in all meanings of it), but I'm finding this approach
rather odd from the common gaming practice. Usially a primitive
<left/right/top/down> movement in arcades is always regulated by some
"physical" input device (keyboard keys in our case). Gamer needs a
continuos tactil sensations for the movement, otherwise you're forcing
him/her to continuosly switch the attention from the game field to the
navigation panel and back. I can tell in advance that your game will be
*very* irritating for the most of the users. They can rather easy to
forgive you to be "killed" because they could not get out the sword on
time. They get bazurk of "being killed" because they couldn't go to the
left on time because your interface was to fancy for it.
If you decided to be a game writer, remember The Rule One:
"The movement is the King, all other is after that".

You may also think of the WRML approach, where the cursor point defines
the point where the hero is trying to come to. Despite it already
prooved its questionability , "something is better than nothing".

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1305
by: Aditi | last post by:
hi all...i m a software engg. student completed my 2nd yr...i have been asked to make a project during these summer vacations...and hereby i would like to invite some ideas bout the design and implementation of an APPLICATION MONITORING SYSTEM....i have to start from scrach so please tell me how to go bout it rite from the beggining this is the first time i m making a project of this complexity... i have to make a system used by the IT...
1
1460
by: jsnX | last post by:
hi, i would like to make some code that operates on sets of points - does convex hulls and other operations. but it looks like i will need a lot of pointless object copies: ====================================================================================== // point cloud class class pc : public std::vector<vec2d> {
18
1634
by: chellappa | last post by:
hi suppose like this function ,,, i want optimize to exceute more fast.... please give some optimization techiques for this routine and also give some ideas for c programming optimzation for 1.complier optimzation 2.programming optimzation int hextodecimal(char a,int no) {
62
2437
by: A.M. Kuchling | last post by:
Here are some thoughts on reorganizing Python's documentation, with one big suggestion. The tutorial seems to be in pretty good shape because Raymond Hettinger has been keeping it up to date. It doesn't cover everything, but it's a solid introduction, and if people don't find it works for them, they have lots of alternative books. No suggestions here. There are endless minor bugs in the library reference, but that seems
45
3470
by: Gregory Petrosyan | last post by:
1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance 2) In python: >>> raise NameError Traceback (most recent call last): File "<stdin>", line 1, in ? NameError
1
2088
by: danibecr | last post by:
Hello all, I have a form that contains a remarks field for user input and a checkbox for out of compliance orders. I need to make the remarks field mandatory after the checkbox is checked. Right now I'm using the expression = Is Not Null for the validation rule but all that does is make the remarks field mandatory BEFORE you can check the checkbox.
1
1479
by: danibecr | last post by:
Hello again all, I'v got a problem that I'm needing help on please. I have a form whos record source is a query. On this form I'v got a drop down error field, a remarks field, a check box and a user ID field, I also have 4 or 5 remarks fields in the table. I'm trying to make the remarks field save remarks for today and tomorrow put any remarks in the second remarks field. Any changes on the 3rd day go to the 3rd remarks field and so on. ...
3
3198
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with /W3 I get warnings that with /W4 are shown as remarks, e.g.: warning #177: variable "Foo" was declared but never referenced ....is displayed as a "remark #177" with /W4. That doesn't fit the
26
1863
by: Frank Samuelson | last post by:
I love Python, and it is one of my 2 favorite languages. I would suggest that Python steal some aspects of the S language. ------------------------------------------------------- 1. Currently in Python def foo(x,y): ... assigns the name foo to a function object. Is this pythonic? Why not use the = operator like most other assignments?
0
10389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10402
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.