M
Midastouch
Guest
Hello everyone,
I am on a little project where you can create differents elements (water, sand....)
I am inspired by the amazing "Powder Game" (a Physics simulation game)
https://dan-ball.jp/en/javagame/dust/
So for now i just start my projet and maybe you can have ideas to optimise my projet, advices...
You can see my project actually (i am on the very begining).
I just implemented water and sand.
This is my step event
In the draw event
PS : i also tried to do the same things with 2d arrays but i don't see any difference with the performances maybe i am wrong???
I am on a little project where you can create differents elements (water, sand....)
I am inspired by the amazing "Powder Game" (a Physics simulation game)
https://dan-ball.jp/en/javagame/dust/
So for now i just start my projet and maybe you can have ideas to optimise my projet, advices...
You can see my project actually (i am on the very begining).
I just implemented water and sand.
This is my step event
GML:
f mouse_check_button(mb_left) {ds_grid_set(grid,xxx,yyy,1)}
if mouse_check_button(mb_right) {ds_grid_set(grid,xxx,yyy,2)}
for(var xx = 0; xx < ds_grid_width(grid); xx++) {
for(var yy = 0; yy < ds_grid_height(grid); yy++) {
#region//--------------------------SAND--------------------------//
if ds_grid_get(grid, xx, yy) = 1 {
if ds_grid_get(grid, xx, yy + 1) = 0 {//Set gravity (nothing under)
ds_grid_set(grid, xx, yy + 1, 1)
ds_grid_set(grid, xx, yy,0)
}
if ds_grid_get(grid, xx, yy + 1) = 2 {//water under
ds_grid_set(grid, xx, yy + 1, 1)
ds_grid_set(grid, xx, yy, 2)
}
else if ds_grid_get(grid, xx - 1, yy + 1) = 0 {//nothing left + down
ds_grid_set(grid, xx - 1, yy + 1, 1)
ds_grid_set(grid, xx, yy,0)
}
else if ds_grid_get(grid, xx + 1, yy + 1) = 0 {//nothing right + down
ds_grid_set(grid, xx + 1, yy + 1, 1)
ds_grid_set(grid, xx, yy,0)
}
}
#endregion
#region//--------------------------WATER--------------------------//
if ds_grid_get(grid, xx, yy) = 2 {
if ds_grid_get(grid, xx, yy + 1) = 0 {//Set gravity (nothing under)
ds_grid_set(grid, xx, yy + 1, 2)
ds_grid_set(grid, xx, yy,0)
}
else if ds_grid_get(grid, xx - 1, yy + 1) = 0 {//nothing left + down
ds_grid_set(grid, xx - 1, yy + 1, 2)
ds_grid_set(grid, xx, yy,0)
}
else if ds_grid_get(grid, xx + 1, yy + 1) = 0 {//nothing right + down
ds_grid_set(grid, xx + 1, yy + 1, 2)
ds_grid_set(grid, xx, yy,0)
}
else if ds_grid_get(grid, xx + 1, yy) = 0 {//nothing left
ds_grid_set(grid, xx + 1, yy, 2)
ds_grid_set(grid, xx, yy,0)
}
else if ds_grid_get(grid, xx - 1, yy) = 0 {//nothing right
ds_grid_set(grid, xx - 1, yy, 2)
ds_grid_set(grid, xx, yy,0)
}
}
#endregion
}
}
Code:
for(var xx = 0; xx < ds_grid_width(grid); xx++){
for(var yy = 0; yy < ds_grid_height(grid); yy++){
if ds_grid_get(grid, xx, yy) = 1 {
//draw_rectangle_color(xx*cellsize, yy*cellsize, xx*cellsize+8, yy*cellsize+8, c_yellow, c_yellow, c_yellow, c_yellow, false);
draw_sprite(spr_ground,0,xx*cellsize,yy*cellsize)
}
if ds_grid_get(grid, xx, yy) = 2 {
//draw_rectangle_color(xx*cellsize, yy*cellsize, xx*cellsize+8, yy*cellsize+8, c_blue, c_blue, c_blue, c_blue, false);
draw_sprite(spr_water,0,xx*cellsize,yy*cellsize)
}
}
}
PS : i also tried to do the same things with 2d arrays but i don't see any difference with the performances maybe i am wrong???
Last edited by a moderator: