physics gone wrong

ok in this code im not understanding where to place where the water should = false to stop the water from going and its just a disaster im trying to make it where you drop water and it spreads both directions when it hits the floor
i guess i got overwhelmed and lost track of things im really confused if anyone can help me fix this and make it work thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <conio.h>
#define KEY_UP 72
#define KEY_LEFT 75
#define KEY_DOWN 80
#define KEY_RIGHT 77
using namespace std;
int x = 1;
int y = 1;
  void gotoxy(int x,int y )
    {
    COORD p = { x, y };
    SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );
    }
    /************************************
    DRAW MAP
    *************************************/
void drawmap(){
     char block = 219;
      int top = 0;
     int left = 0;
     int bottom = 0;
     int right = 0;
     gotoxy(24,24);
     cout << block;
     while(top < 24){
     
     gotoxy(top,0);
     cout << block;
     top = top + 1;
     }
     while(left < 24){
     gotoxy(0,left);
     cout << block;
     left = left + 1;
    
     }
     while(bottom < 24){
     gotoxy(bottom,24);
     cout << block;
     bottom = bottom + 1;
     
     }
     while(right < 24){
     gotoxy(24,right);
     right = right + 1;
     cout << block;
     }
     }//end of draw map
     /*******************************
     DRAW PLAYER
     ********************************/
     void drawplayer(){
     char player = 1;
     gotoxy(x,y);
     cout << player;
     }
       /********************************************
  DROP WATER
  *********************************************/
  bool water = false;
  int waterx;
  int watery;
  void dropwater(){
       char block = 219;
       water = true;
       waterx = x + 1;
       watery = y;
       while(water){
       gotoxy(waterx,watery);
       cout << block;
       if(waterx > 0 && watery == 23){
       gotoxy(waterx,watery);
       cout << block;
       waterx --;
       }
       else if(waterx<23 && watery == 23){
       gotoxy(waterx,watery);
       cout << block;
       waterx++;
       }
       else if(watery<23){
            gotoxy(waterx,watery);
            cout << block;
            watery++;
            }
            
            }
            }
     /*******************************
     GETINPUT
     ********************************/
     void getinput(){
     char player = 1;
     char input;
     input = getch();
     switch(input){
     case KEY_UP:
     if(y == 1){
     }
     else{
     y = y - 1;
     gotoxy(x,y);
     cout << player;
     gotoxy(x,y+1);
     cout << " ";
     }
     break;
     case KEY_DOWN:
     if(y==23){
               }
     else{
     y = y + 1;
     gotoxy(x,y);
     cout << player;
     gotoxy(x,y-1);
     cout << " ";
     }
     break;
     
     case KEY_LEFT:
     if(x == 1){
          }
     else{
          x = x - 1;
     gotoxy(x,y);
     cout << player;
     gotoxy(x+1,y);
     cout << " ";
     }
     break;
     case KEY_RIGHT:
     if(x==23){
               }
     else{
     x = x + 1;
     gotoxy(x,y);
     cout << player;
     gotoxy(x-1,y);
     cout << " ";
     }
     case 'w':
          dropwater();
          break;
     }
   
     }

                     
       
  
       
  
     
int main(int argc, char *argv[])
{
    bool done = false;
    
    drawmap();
    drawplayer();
    while(!done){
    getinput();
                }
    
    return EXIT_SUCCESS;
}
Nice key defining idea, I'll use it in my game ;D
Last edited on
OK let me get this straight. U have a bounded region from (0, 0) to (24, 24) or so. U have a 'character' point which starts at the top left corner (1, 1). It's able to go down and up but when it goes left or right u want a 'water' drop to be simulated graphically true ?
while(water) clearly hangs because once it reaches the left boundary of x the loop doesn't resolve the collision. I'm guessing that it'd be ideal if the drop spreads left and right at (about) the same time right ?
Ok this is what u can do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
bool water = false;
int waterx;
int watery;
void dropwater()
{
       char block = 220;
       water = true;
       waterx = x + 1;
       watery = y;
      
	   int waterL = waterx; //the left side collision of x
	   int waterR = waterx; //the right side collision of x

while(water)
{
       gotoxy(waterx,watery);
       cout << block;

       if(waterL > 0 && watery == 23){
       gotoxy(waterL,watery);
       cout << block;
       waterL --;
       }
       if(waterR < 23 && watery == 23){
       gotoxy(waterR,watery);
       cout << block;
       waterR ++;
       }
      if(watery<23){
            gotoxy(waterx,watery);
            cout << block;
            watery++;
      }
	  if(waterL == 0 && waterR == 23) 
		  break;        
   }
}

Also, put those global vars in better places...
Last edited on
wait i realized i forgot to put a break after KEY_RIGHT thats why it ran the water when i pressed right..
if you look it was supposed to happen when you pressed w but i left out a break
Last edited on
ahhh yah i noticed that but focused on fixin that water function ;)
Topic archived. No new replies allowed.