-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·169 lines (148 loc) · 5.81 KB
/
main.py
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
# -*- coding: iso-8859-15 -*-
#from gwc_python.core import GestureWorksCore
#from gwc_python.GWCUtils import TOUCHREMOVED
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
#from kivy.properties import NumericProperty, ReferenceListProperty,\
# ObjectProperty
#from kivy.vector import Vector
from kivy.graphics import *
from kivy.clock import Clock
from peli.biljardipeli import Biljardipeli
from gui.piirtoalusta import PiirtoAlusta
from kivy.properties import ObjectProperty, NumericProperty, ListProperty, BooleanProperty
from peli.pelaajat import Pelaajat
from peli.lisaaKiihtyvyydet import LisaaKiihtyvyydet
from peli.velocityVerlet import VelocityVerlet
from pelilauta.seina import Seina
from pelilauta.reiat import Reiat
from pelilauta.pallot import Pallot
from pelilauta.lautadata import LautaData
from pelilauta.keppi import Keppi
from sys import exit
import time
lautadata = LautaData()
class Pelilauta(FloatLayout):
hole_d = NumericProperty(lautadata.reianHalkaisija)
max_y = NumericProperty(lautadata.maxLautaY)
def __init__(self, **kwargs):
super(Pelilauta,self).__init__(**kwargs)
class E8ballGame(FloatLayout):
lauta = ObjectProperty(None)
#pallo = ObjectProperty(None)
#pallo = ObjectProperty(None)
#keppi = ObjectProperty(None)
#kuuntelija = ObjectProperty(None)
x1 = NumericProperty()
y1 = NumericProperty()
x2 = NumericProperty()
y2 = NumericProperty()
def __init__(self, **kwargs):
super(E8ballGame,self).__init__(**kwargs)
self.pallot = Pallot()
self.pelilauta = Pelilauta()
for pallo in self.pallot.getPallotArray():
print "ADDING BALL-WIDGET"
self.add_widget(pallo)
self.keppi = Keppi()
self.pelaajat = Pelaajat();
self.lisaakiihtyvyydet = LisaaKiihtyvyydet();
self.nopeusVerlet= VelocityVerlet(LautaData.dt);
self.seina = Seina();
self.reiat = Reiat();
self.jatka = False
self.pallotliikkuu = True;
self.x1=0
self.y1=0
self.x2=0
self.y2=0
# def do_layout(self, *args):
# print "LAYOUT"
# for child in self.children:
# child.height = self.height
# child.width = self.width
# if (self.jatka):
# self.juokse()
def on_size(self, *args):
pass
def on_pos(self, *args):
pass
#self.do_lay()
def on_touch_up(self, touch):
""" Ammutaan pallo liikkeelle """
self.keppi.setPoikkeama(self.x1, self.y1, self.x2, self.y2)
self.keppi.setPoikkeama_x(self.x1, self.x2)
self.keppi.setPoikkeama_y(self.y1, self.y2)
self.x1=0
self.y1=0
self.x2=0
self.y2=0
self.keppi.iske(self.pallot.getLyontiPallo())
print "SHOT"
self.reiat.resetoiReiat()
self.jatka = True
self.do_layout()
#self.do_layout()
def on_touch_move(self, touch):
touch.ud['x1'] = self.pallot.getLyontiPallo().getPalloX()*self.width
touch.ud['y1'] = self.pallot.getLyontiPallo().getPalloY()*self.height
self.x1 = touch.ud['x1']
self.y1 = touch.ud['y1']
touch.ud['x2'] = touch.x
touch.ud['y2'] = touch.y
self.x2 = touch.ud['x2']
self.y2 = touch.ud['y2']
def do_layout(self, *args):
for child in self.children:
child.height = self.height
child.width = self.width
count = 0
if self.jatka:
self.pallot.nollaaKiihtyvyydet();
#self.lisaakiihtyvyydet.lisaaCoulombKiihtyvyydetBiljardiPallot(
# self.pallot);
#self.lisaakiihtyvyydet.lisaaHardCoreKiihtyvyydet(self.pallot);
self.lisaakiihtyvyydet.lisaaTormays(self.pallot);
self.lisaakiihtyvyydet.lisaaKitkaNopeuteen(self.pallot);
self.nopeusVerlet.PaivitaVelocityVerlet(self.pallot);
self.seina.VaihdaLiikemaara(self.pallot);
self.reiat.setEkanaReiassa(self.pallot);
self.reiat.lisaaReikiinMenneet(self.pallot);
self.pelaajat.alkaakoYrittaaMustaa(self.reiat);
self.reiat.tapaNormiPallot(self.pallot);
self.jatka = self.reiat.tarkastaPallo(self.pallot.getMustaPallo());
#self.do_layout()
if (not(self.reiat.tarkastaPallo(self.pallot.getLyontiPallo()
))):
self.pallot.arvoLyontiPallonPaikka(\
0, 0,
LautaData.maxLautaX,LautaData.maxLautaY,
0.20)
self.pallotliikkuu = False;
self.pallot.nollaaNopeudet();
# tutkitaan mitä tapahtui
self.jatka = self.pelaajat.tarkastaTilanne(
self.reiat, self.pallot);
elif ((self.nopeusVerlet.getMaxSiirtyma() < LautaData.maxSiirtyma)
and (self.pallot.suurinNopeus() < LautaData.maxNopeus)):
self.pallotliikkuu = False
self.pallot.nollaaNopeudet()
self.nopeusVerlet.setMaxSiirtyma(1.0)
# tutkitaan mitä tapahtui
self.jatka = self.pelaajat.tarkastaTilanne(
self.reiat, self.pallot)
#sys.exit()
# nollataan reikien tilanne uutta lyöntiä varten
self.jatka = self.pelaajat.tarkastaTilanne(self.reiat, self.pallot);
class E8ballApp(App):
def build(self):
game = E8ballGame()
#game.set_biljardipeli(biljardipeli)
#pelilauta.set_peli(biljardipeli)
#game.set_pelilauta(pelilauta)
#Clock.schedule_interval(game.do_layout, 0.1)
return game
#return parent
if __name__ == '__main__':
E8ballApp().run()