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

Started by
3 comments, last by RLS0812 10 years, 2 months ago

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

Advertisement

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 ?

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.

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
}

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

This topic is closed to new replies.

Advertisement