-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathincorporado
177 lines (123 loc) · 3.47 KB
/
incorporado
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
169
170
171
172
173
174
175
176
177
#coordenadas da tela
x = 800
y = 800
def Menu():
global estado
background(0)
rectMode(CENTER)
textAlign(CENTER)
textSize(30)
text('MINIGOLF',width/2,100)
textSize(20)
noFill()
stroke(255)
text('New Game', width/2, 300)
if mouseX <= width/2 + 90 and mouseX >= width/2 - 90 and mouseY <= 300+45 and mouseY >= 300-45:
rect(width/2, 300,180,90)
if mousePressed == True:
estado = Minigolf
text('Credits', width/2, 500)
if mouseX <= width/2 + 90 and mouseX >= width/2 - 90 and mouseY <= 500+45 and mouseY >= 500-45:
rect(width/2, 500,180,90)
if mousePressed == True:
estado = Creditos
#definicao da bola
v = PVector(0,0)
p = PVector(400,400)
r = 10
#incrementos e verfificadores de movimento
inc = PVector(0,0)
ver = False
class Bola:
def __init__(self,p,v,r):
self.v = v
self.p = p
self.r = r
def move(self,dt):
self.p.add(self.v*dt)
def xlr8(self,dt):
v = self.v.copy()
if v.mag() < 0.005:
self.v.add(v.mult(-1))
elif v.mag() < 0.1:
mi = -0.3*v.mag()
v.mult(mi)
self.v.add(v)
else:
mi = -0.09*v.mag()**2
v.mult(mi)
self.v.add(v)
b = Bola(p,v,r)
def colide(b, s):
vy = s.mult(b.v.dot(s))
vx = b.v.sub(vy)
vy = vy.mult(-1)
b.v = vx.add(vy)
t = millis()
xmin = ymin = 200
xmax = ymax = 600
def Minigolf():
global estado, Menu, t, xmin, xmax, ymin, ymax
oldt = t
t = millis()
dt = t-oldt
background(0)
rectMode(CORNERS)
noFill()
stroke(255)
rect(xmin,ymin,xmax,ymax)
b.move(dt)
b.xlr8(dt)
if b.p.x <= xmin+b.r:
colide(b, PVector(1,0))
elif b.p.x >= xmax-b.r:
colide(b, PVector(-1,0))
elif b.p.y <= ymin+b.r:
colide(b, PVector(0,1))
elif b.p.y >= ymax-b.r:
colide(b, PVector(0,-1))
fill(255)
noStroke()
ellipse(b.p.x,b.p.y, 2*b.r, 2*b.r)
noFill()
stroke(255)
ellipse(b.p.x,b.p.y, 2*b.r+20, 2*b.r+20)
rectMode(CENTER)
text('Back', 0.2*width, 50)
if mouseX <= 0.2*width + 0.1*width and mouseX >= 0.2*width - 0.1*width and mouseY <= 50+30 and mouseY >= 50-30:
rect(0.2*width, 50, 0.2*width, 60)
if mousePressed == True:
estado = Menu
posy = y-50
def Creditos():
global posy, Menu, estado
background(0)
posx = width/2
v = -3
posy += v
text("Minigolf: \n Isaque Vieira Machado Pim \n Igor Patricio Michels \n \n Agradecimentos: \n Paulo Cesar \n Asla de Sa \n Coffee Machine do 14", posx, posy)
if posy < -400:
estado = Menu
posy = y-50
estado = Menu
def setup():
size(x, y)
def draw():
global estado
estado()
def mouseDragged():
global inc, ver
if v.mag() == 0: #condição para não aceitar tacadas se a bola estiver se movendo
if sqrt((mouseX - b.p.x)**2 + (mouseY-b.p.y)**2) <= r+10:
ver = True
if ver:
inc.x = b.p.x - mouseX
inc.y = b.p.y - mouseY
stroke(255,0,0)
line(b.p.x,b.p.y,mouseX,mouseY)
def mouseReleased():
global inc, ver
if ver:
b.v.add(inc.div(500))
inc = PVector(0,0)
ver = False