• Advertisement
Sign in to follow this  

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

This topic is 1454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement