M
Midastouch
Guest
Hello everyone,
I am trying to make a water system with objects as i saw it here :
https://drive.google.com/open?id=0B5SmSXI3oLGpRzBlRXFBeERjOTQ
I already did some code :
Step event :
Draw event :
As you can see i am in the begining of my project.
My question is how can i code a good system to do this project, i know the best way is to use ds_grid but for now i want to do it with objects.
For now it seems to me that i am doing something too complicated and long and unoptimised.
I am trying to make a water system with objects as i saw it here :
https://drive.google.com/open?id=0B5SmSXI3oLGpRzBlRXFBeERjOTQ
I already did some code :
Step event :
GML:
var a1;//up
a1 = instance_place(x,y-1,obj_water)
var a2;//right
a2 = instance_place(x+1,y,obj_water)
var a3;//down
a3 = instance_place(x,y+1,obj_water)
var a4;//left
a4 = instance_place(x-1,y,obj_water)
//gravity
if !place_meeting (x,y+32,obj_wall) && !place_meeting (x,y+32,obj_water) {
y = ((y div 32)*32)+32}
#region if water on top
if place_meeting(x,y-1,a1){
var A
A = amount_of_water + a1.amount_of_water
if A > 100 {
amount_of_water = 100
a1.amount_of_water = A-100}
if A <= 100 {
amount_of_water = amount_of_water + a1.amount_of_water
instance_destroy(a1)
}}
#endregion
#region Divide a block if nothing left and right
if amount_of_water = 100 && (place_meeting(x,y+1,obj_water) || place_meeting(x,y+1,obj_wall)) &&
!place_meeting(x-1,y,obj_wall) && !place_meeting(x+1,y,obj_wall) &&
!place_meeting(x-1,y,obj_water) && !place_meeting(x-1,y,obj_water) {
var inst
inst = instance_create_depth(x-32,y,-1,obj_water)
with inst {amount_of_water =25 }
var inst2
inst2 = instance_create_depth(x+32,y,-1,obj_water)
with inst2 {amount_of_water = 25}
amount_of_water = 50}
#endregion
Code:
if amount_of_water = 100 {image_index = 0}
if amount_of_water = 75 {image_index = 1}
if amount_of_water = 50 {image_index = 2}
if amount_of_water = 25 {image_index = 3}
draw_self()
draw_set_color(c_black)
draw_set_font(fnt)
draw_text(x,y,string(amount_of_water))
As you can see i am in the begining of my project.
My question is how can i code a good system to do this project, i know the best way is to use ds_grid but for now i want to do it with objects.
For now it seems to me that i am doing something too complicated and long and unoptimised.