Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


trying to make a js HTML game with or without canvas.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 netameta   Members   -  Reputation: 111

Like
0Likes
Like

Posted 24 January 2014 - 09:14 PM

hey everyone.

 

I am new to the forum and to games development in general.

 

I've been programming for about 2 years (web applications - js/php..mainly) have some experience with c# and c back from high school.

 

Recently i've decided to test and see if i could create a game with js and HTML elements(not canvas - for now) with no previous expereince so i basically made things up as i go.

 

so i have a main loop that refreshes as fast as it could. this loop controls everything. its checks for keyclicks, set objects position, set object graphics and test for colission and this is where i have issues with.

 

To handle colission i have a big 2d matrix array with the same size of the game area in pixes so if i have 500 width, 500 height, the array is 500x500.. the content of the cells are true/false.

 

To check for collision i take my current x/y add the radius add my walking distance and together with the angel i calculate my future x/y. i then check the array if there's anything there for every step between me to the future position. this seems to work fine for about 300-500 elementss. then things get slow and everything get bugy (things get out of the screen border etc.)

 

is my approuch completely wrong ? do i need to try and use quadtree ?  or another method ?

 

p.s

You can see an example of what i already have at: http://myfirstgame.e-ddl.com/ -  you can go up/down.... and by clicking on the NPC and clicking number 1 you fire at him


Edited by netameta, 24 January 2014 - 09:15 PM.


Sponsor:

#2 d4n1   Members   -  Reputation: 516

Like
0Likes
Like

Posted 24 January 2014 - 11:12 PM

What do you mean by wrong....its your game there's no such notion as doing something wrong; there is such a notion of doing something more efficiently.

 

If you mean to ask is my code efficient, I would have to say that no one here will read your code, you will need to step through your own code and do some bottleneck checking. 

 

Depending on the complexity of your game will require complex functionality such as quad/octrees, and only the person designing the game can answer a vague question like that.


Edited by d4n1, 24 January 2014 - 11:12 PM.


#3 netameta   Members   -  Reputation: 111

Like
0Likes
Like

Posted 25 January 2014 - 05:01 AM

I was refering to the colission checks i am making specificly, is this an acceptable way ? i mean so far from what i read alot of people do collision check against other objects - they reduce the amount of objects to check against with certain methods.

 

Also if i check against other objects, how will i check for paths or  walls . do i make them as objects also ?



#4 dejaime   Crossbones+   -  Reputation: 4139

Like
0Likes
Like

Posted 29 January 2014 - 09:01 PM

Also if i check against other objects, how will i check for paths or  walls . do i make them as objects also ?

Yes, making them objects is a good approach.

I guess this wasn't supposed to happen.
inputsystem.png
It happened when I cornered my enemy, leaving him little space to wander. He eventually gone through the wall.

#5 Code Fox   GDNet+   -  Reputation: 2756

Like
0Likes
Like

Posted 29 January 2014 - 09:54 PM

Figure out grid coordinates based on sprite size ...

{simplified code}

X / sprite size ... Y / sprite size = grid location

If ( enemy_grid_location == 0 OR max_grid ) {
cancel move
 }
if  (enemy_grid_location == object_location){
cancel move
}

The Only Winning Move Is Not To Play  ~WOPR

Code_Fox_Sig.png





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS