12 Replies - 8012 Views - Last Post: 26 June 2012 - 07:03 AM Rate Topic: -----

#1 Hashim1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-June 12

Designing A Game In JavaScript

Posted 13 June 2012 - 03:25 PM

Firstly, hi there. :) I'm new to the site, as you can see. Joined this forum with the intention of finding a good, reliable, and friendly coding community to be a part of. I've been a part of other coding forums, and tbe entirely fair, I find most of the programmers tend to have an attitude which makes it seem as they're speaking down to you most of the time. Hopefully I'll find something different here. :)

Basically, I'm just throwing around the idea of creating a basic Javascript game - not to be actually played, just to increase my own Javascript knowledge.

I have two questions around this.

Firstly, I understand that Javascript is a client-side programming/scripting language for the web. Because of it being client-side, it has limitations. Therefore, is creating a game in Javascript for the real world (i.e. wih the intention of actually being distributed or shared for others to play) something that is recommended, and something that people/developers do?

Secondly - whilst creating my basic text-based role-playing game with HTML, CSS, and Javascript, I've come across something where I've stopped and began to think: "Is this how other developers do it?2 I'm very code-conscious like that, I don't tend to want to be write any old code which simply does the job, I like to write code as I believe programmers, and I often wonder whether I'm doing it like that.

The thing that caused me to stop and think this, was where I was creating a scenario in which the player would be encountered by a random enemy (out of five). To get the randomness, I created an Enemies array, and then just used Math.random to randomize that array. My question is whether I'm doing this in the right wat? If a programmer wanted to create a random encounter with an enemy, would they do the same thing - i.e., use an array and call a random element from that array? It just seems so simple to me that it wouldn't strike me as the correct way of doing it.

When playing a game, whether it's an online Flash game or an Xbox 360 console game, you never stop to think: "How did the programmer create this scenario? How did he get this enemy to appear here randomly, or this random event to occur here randomly?" When actually coding, though, these things pop up, and it leaves me wondering how profesisonal programmers go about doing things like that.

Thanks in advance to any help whatsoever. I know it's rather a long question, but I'm genuinely very interested in the subject, and being so new to game programming in general, there's so much I don't know and would like to ask, that I when end up asking questions like this, I end up asking or wondering more than I set out to.

Is This A Good Question/Topic? 0
  • +

Replies To: Designing A Game In JavaScript

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Designing A Game In JavaScript

Posted 13 June 2012 - 06:21 PM

Hi Hashim1

Welcome to DIC.

I must admit that I'm not at all sure what you're asking, is it a technical question or simply our thought processes in solving problems given various scenarios? :)
Was This Post Helpful? 0
  • +
  • -

#3 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1011
  • View blog
  • Posts: 4,215
  • Joined: 14-February 08

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 02:41 AM

You will find that a lot of professional developers write code that works and not the most elegant solution. This is not because they don't value elegant code as much as you but because time constraints dictate how much work can be dedicated to each task.

As far as your random enemies question, if it works as you want it to then leave it that way. There are usually tasks which are time consuming yet extremely important, they must come first.
Was This Post Helpful? 2
  • +
  • -

#4 Hashim1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-June 12

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 04:49 AM

View PostButchDean, on 13 June 2012 - 06:21 PM, said:

Hi Hashim1

Welcome to DIC.

I must admit that I'm not at all sure what you're asking, is it a technical question or simply our thought processes in solving problems given various scenarios? :)


Hi Butch, and thanks.

My first question is simply regarding Javascript and gaming - is it recommended to create games in Javascript, and do many programmers do it, due to its limitations?

The second question I would say is more of thought processes - I want to really know what other programmers would do in the current scenario that I'm facing (making random characters appear). How I'm doing it now is very basic: creating an array of enemies, then using Math.random to call a random element of that array, i.e. a random monster. What I'm wondering, is whether this is the kind of way programmers would do something? It just seems so simplistic to me that it doesn't feel right, if you get me. I feel like there's a proper way to do it which I don't know of.

View Poststayscrisp, on 14 June 2012 - 02:41 AM, said:

You will find that a lot of professional developers write code that works and not the most elegant solution. This is not because they don't value elegant code as much as you but because time constraints dictate how much work can be dedicated to each task.

As far as your random enemies question, if it works as you want it to then leave it that way. There are usually tasks which are time consuming yet extremely important, they must come first.


Hi there, stayscrisp, thanks for the advice.

I'm a bit confused as to what you are saying, though. A lot of coding communities I've come across have been very insistent on always producing elegant, clean, efficient code. Are you basically that the focus shouldn't be so much on elegant code, but on simply getting the job done? I suppose with regards time constraints and restrictions, that does make a lot more sense.
Was This Post Helpful? 0
  • +
  • -

#5 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 691
  • Joined: 16-February 09

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 12:43 PM

A big mistake that I think lots of people tend to do is overthink stuff. Overthinking results to not getting anything done.

That's a great way to approach the scenario. Of course, there are things that you can do to improve things... but it only matters if you have certain goals. For example... some people might require a more data-centric approach which would make it easier for designers to add new content.

Figure out what your goals are then work based on those goals.


At this point of your career, too much overthinking means getting less done, resulting to less finished things. You could argue about quality over quantity, but the more you do the more you learn.

Don't worry too much about your mistakes. Learn from your mistakes, don't try to avoid your mistakes. The more mistakes you make, the more things you'll know what not to do when you are working on someone else's dime.

edit:
P.S.
For designing 2d games with Javascript, I highly recommend http://cocos2d-x.org

This post has been edited by sparkart: 14 June 2012 - 12:44 PM

Was This Post Helpful? 4
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1011
  • View blog
  • Posts: 4,215
  • Joined: 14-February 08

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 01:49 PM

View PostHashim1, on 14 June 2012 - 12:49 PM, said:

Hi there, stayscrisp, thanks for the advice.

I'm a bit confused as to what you are saying, though. A lot of coding communities I've come across have been very insistent on always producing elegant, clean, efficient code. Are you basically that the focus shouldn't be so much on elegant code, but on simply getting the job done? I suppose with regards time constraints and restrictions, that does make a lot more sense.


Coding communities where people might see you as a hobbyist or just learning will most likely advise you to write elegant code but trust me, in a real world situation where you just need to get the job done you will need to cut corners in places to focus on getting the product finished. If you were to tell your boss that you can either get something done that is elegant and nice to look at or just get it working in half the time what do you think they would pick?

There can be downtime to improve the way code is written or it might eventually be a project at some point but with a deadline approaching you just need a solution that works. Of course I am in no way saying you should write bad code :) but like sparkart said, don't over think things; Finish them instead :)
Was This Post Helpful? 2
  • +
  • -

#7 Hashim1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-June 12

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 04:14 PM

View Postsparkart, on 14 June 2012 - 12:43 PM, said:

A big mistake that I think lots of people tend to do is overthink stuff. Overthinking results to not getting anything done.

That's a great way to approach the scenario. Of course, there are things that you can do to improve things... but it only matters if you have certain goals. For example... some people might require a more data-centric approach which would make it easier for designers to add new content.

Figure out what your goals are then work based on those goals.

At this point of your career, too much overthinking means getting less done, resulting to less finished things. You could argue about quality over quantity, but the more you do the more you learn.

Don't worry too much about your mistakes. Learn from your mistakes, don't try to avoid your mistakes. The more mistakes you make, the more things you'll know what not to do when you are working on someone else's dime.

edit:
P.S.
For designing 2d games with Javascript, I highly recommend http://cocos2d-x.org


Thanks for the advice, it's extremely meaningful, and pretty much typifies how I can be as a coder. I understand what you mean about overthinking and overcomplicating things to the extent that nothing ever gets done, and if I'm honest, I'm guilty of this a lot of the time, being a perfectionist - I'd always much prefer to plan and plan for so long and end up executing something to perfection, than executing something without doing it perfectly.

In short, don't worry so much about clean, elegant code in the early stages of learning, about quality over quantity - just get coding. Only once mistakes have been made can they can be learnt from. What I toom from it. Thanks again. :)

View Poststayscrisp, on 14 June 2012 - 01:49 PM, said:

View PostHashim1, on 14 June 2012 - 12:49 PM, said:

Hi there, stayscrisp, thanks for the advice.

I'm a bit confused as to what you are saying, though. A lot of coding communities I've come across have been very insistent on always producing elegant, clean, efficient code. Are you basically that the focus shouldn't be so much on elegant code, but on simply getting the job done? I suppose with regards time constraints and restrictions, that does make a lot more sense.


Coding communities where people might see you as a hobbyist or just learning will most likely advise you to write elegant code but trust me, in a real world situation where you just need to get the job done you will need to cut corners in places to focus on getting the product finished. If you were to tell your boss that you can either get something done that is elegant and nice to look at or just get it working in half the time what do you think they would pick?

There can be downtime to improve the way code is written or it might eventually be a project at some point but with a deadline approaching you just need a solution that works. Of course I am in no way saying you should write bad code :) but like sparkart said, don't over think things. Finish them instead :)


If I'm entirely honest, however, I am a hobbyist coder. A little bg information about myself: I'm 16, a student in college, and I'm wanting to learn Javascript and game programming generally for no other reason than as a fun and productive hobby, at least for now. With this in mind, would the advice you gave above stay the same, or would you recommend for me to concentrate more on quality of the code seeing as I have no deadlines to work to?

View Postsparkart, on 14 June 2012 - 12:43 PM, said:

A big mistake that I think lots of people tend to do is overthink stuff. Overthinking results to not getting anything done.

That's a great way to approach the scenario. Of course, there are things that you can do to improve things... but it only matters if you have certain goals. For example... some people might require a more data-centric approach which would make it easier for designers to add new content.

Figure out what your goals are then work based on those goals.


At this point of your career, too much overthinking means getting less done, resulting to less finished things. You could argue about quality over quantity, but the more you do the more you learn.

Don't worry too much about your mistakes. Learn from your mistakes, don't try to avoid your mistakes. The more mistakes you make, the more things you'll know what not to do when you are working on someone else's dime.

edit:
P.S.
For designing 2d games with Javascript, I highly recommend http://cocos2d-x.org


Regarding the link you linked me to, I'm assuming that is a game engine? I'm confused, why would I need a game engine when coding with Javascript? Surely all the JS code that I write will be my game? Sorry if this is a very newbish question, I am new to game programming generally: I'm just a little baffled by the fact that even in Javascript I'll need a game engine.
Was This Post Helpful? 0
  • +
  • -

#8 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 691
  • Joined: 16-February 09

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 07:27 PM

It's a really decent framework for developing 2d video games. It's for the C++ programming language but it has some Lua bindings allowing you to develop games via Lua. They are working on Javascript bindings allowing you to develop games via Javascript for iOS, Android, and HTML5.

You can already develop HTML5 games through cocos2d-html5: http://cocos2d-x.goo...0.5.0-alpha.zip

It doesn't allow you to reach iOS and Android through Javascript, but in the near future it will be possible.
Was This Post Helpful? 0
  • +
  • -

#9 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: Designing A Game In JavaScript

Posted 14 June 2012 - 07:53 PM

Hi there. The best way to approach it, as many have already said above, is finish it first, then improve on your work. You'll never finish anything if you always think if your code is good enough for the eyes of others. I'm not a game programmer, but I managed to create two simple games in Javascript which are posted in this site. I didn't search first on how game programming works on Javascript, rather, I envisioned the games and searched for all the pieces that I thought would make it work on my vision. If you have an idea and you think it would work, then do it. But when you see limitations on your idea or it fails, that would be the time to search for other solutions. Try it for yourself, make mistakes, and learn. ^^
Was This Post Helpful? 1
  • +
  • -

#10 Hashim1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-June 12

Re: Designing A Game In JavaScript

Posted 15 June 2012 - 03:14 PM

View PostfromTheSprawl, on 14 June 2012 - 07:53 PM, said:

Hi there. The best way to approach it, as many have already said above, is finish it first, then improve on your work. You'll never finish anything if you always think if your code is good enough for the eyes of others. I'm not a game programmer, but I managed to create two simple games in Javascript which are posted in this site. I didn't search first on how game programming works on Javascript, rather, I envisioned the games and searched for all the pieces that I thought would make it work on my vision. If you have an idea and you think it would work, then do it. But when you see limitations on your idea or it fails, that would be the time to search for other solutions. Try it for yourself, make mistakes, and learn. ^^


Thanks for the advice. :) I'd be interested in seeing the two Javascript games you wrote - I'd appreciate if you could link me to them?
Was This Post Helpful? 0
  • +
  • -

#11 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,063
  • Joined: 28-December 10

Re: Designing A Game In JavaScript

Posted 18 June 2012 - 10:06 PM

Sure.

Here's the simplest(Tic - Tac - Toe)
http://www.dreaminco...and-javascript/ and one where I had to make an object of things flying(not so fancy as it sounds)
http://www.dreaminco...topic249566.htm

Good luck. ^^
Was This Post Helpful? 0
  • +
  • -

#12 Game_Creator  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 18-June 12

Re: Designing A Game In JavaScript

Posted 24 June 2012 - 06:37 PM

This topic has been really helpful to me. As I write code I too ask myself if I am going about it the right way even if it works. This topic has helped me understand that if it gets the job done than keep it.
Was This Post Helpful? 1
  • +
  • -

#13 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1011
  • View blog
  • Posts: 4,215
  • Joined: 14-February 08

Re: Designing A Game In JavaScript

Posted 26 June 2012 - 07:03 AM

Glad we could help Game_Creator :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1