game.dd 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  1. (include "game.ddh")
  2. (include "menu.ddh")
  3. (def extern int numberOfPlayers)
  4. (def extern int startingPlayer)
  5. (def extern int guide)
  6. # game phases
  7. (def int PHASE_INIT 0)
  8. (def int PHASE_PLAN 1)
  9. (def int PHASE_EXECUTION 2)
  10. (def int PHASE_END 3)
  11. # cards
  12. (def int CARD_SINGLE_STEP 0)
  13. (def int CARD_THREE_STEPS 1)
  14. (def int CARD_TRADE 2)
  15. (def int CARD_CONDITIONAL 3)
  16. (def int CARD_REPLACE 4)
  17. (def int CARD_GRAB 5)
  18. (def int CARD_GRAB_GENERIC 6)
  19. (def int CARD_APPROACH 7)
  20. (def int CARD_WIN 8)
  21. (def int CARD_ROSE 9)
  22. (def int CARD_TUT_1 10)
  23. # actions
  24. (def int ACTION_DELAY 0)
  25. (def int ACTION_ADVANCE_ROSE 2)
  26. (def int ACTION_DRAW_CARD 3)
  27. (def int ACTION_SELECT_CARD 4)
  28. (def int ACTION_PLAN_CARD 5)
  29. (def int ACTION_SET_ACTIVE_PLAYER 6)
  30. (def int ACTION_REVEAL_PLANNED_CARD 7)
  31. (def int ACTION_EXECUTE_PLANNED_CARD 8)
  32. (def int ACTION_DISCARD_PLANNED_CARD 9)
  33. (def int ACTION_CHANGE_PHASE 10)
  34. (def int ACTION_GIVE_CARD 11)
  35. (def int ACTION_HIDE_CARD 12)
  36. (def int ACTION_GRAB_ROSE 13)
  37. (def int ACTION_DISCARD_CARD 14)
  38. (def int ACTION_DISCARD_TO_DECK 15)
  39. (def int ACTION_WIN_CONDITION 16)
  40. (def extern ref dd_meshColour newCardMesh)
  41. (def extern ref Card newCard)
  42. (class_function world_game void create (group)
  43. (group
  44. (= this.victoriousPlayer -1)
  45. # game phases text
  46. (= this.phaseText "setting up the table")
  47. # game actions init
  48. (= this.actionsTotal 0)
  49. (= this.injectActionsTotal 0)
  50. # font
  51. (this.font.setAlign DD_STRING3D_ALIGN_CENTER)
  52. (this.font.setColorFront 0.9 0.9 0.9)
  53. (this.font.setColorBack 0.3 0.3 0.3)
  54. # card font
  55. (this.cardFont.setAlign DD_STRING3D_ALIGN_CENTER)
  56. (this.cardFont.setColorFront 0.0 0.0 0.0)
  57. (this.cardFont.setColorBack 0.0 0.0 0.0)
  58. # camera control
  59. (= this.rotX 0)
  60. (= this.rotY -15)
  61. (= this.targetRotX 0)
  62. (= this.targetRotY -15)
  63. (= this.holdRotX -1)
  64. (= this.holdRotY -1)
  65. # looking at mesh
  66. (this.lookat.load (asset "assets/looking_at.asset" DD_PLY))
  67. # center of world
  68. (dd_matrix_identity this.matCenter)
  69. (dd_matrix_translate this.matCenter 0 -4 -5)
  70. # stage
  71. (this.stage.load (asset "assets/stage_2.asset" DD_PLY))
  72. (this.table.load (asset "assets/table_1.asset" DD_PLY))
  73. (this.tableArrow.load (asset "assets/table_arrow.asset" DD_PLY))
  74. (this.tableArrowDecoration.load (asset "assets/table_arrow_decoration.asset" DD_PLY))
  75. # card back
  76. (this.cardBack.load (asset "assets/card_border.asset" DD_PLY))
  77. (this.cardBack.loadTexture (asset "assets/card_border_texture.asset" DD_PLY))
  78. # card cardFront
  79. (this.cardFront[0].load (asset "assets/card.asset" DD_PLY))
  80. (this.cardFront[0].loadTexture (asset "assets/card_single_step.asset" DD_PLY))
  81. (this.cardFront[1].load (asset "assets/card.asset" DD_PLY))
  82. (this.cardFront[1].loadTexture (asset "assets/card_triple_step.asset" DD_PLY))
  83. (this.cardFront[2].load (asset "assets/card.asset" DD_PLY))
  84. (this.cardFront[2].loadTexture (asset "assets/card_trade.asset" DD_PLY))
  85. (this.cardFront[3].load (asset "assets/card.asset" DD_PLY))
  86. (this.cardFront[3].loadTexture (asset "assets/card_one_step_cond.asset" DD_PLY))
  87. (this.cardFront[4].load (asset "assets/card.asset" DD_PLY))
  88. (this.cardFront[4].loadTexture (asset "assets/card_replace.asset" DD_PLY))
  89. (this.cardFront[5].load (asset "assets/card.asset" DD_PLY))
  90. (this.cardFront[5].loadTexture (asset "assets/card_grab.asset" DD_PLY))
  91. (this.cardFront[6].load (asset "assets/card.asset" DD_PLY))
  92. (this.cardFront[6].loadTexture (asset "assets/card_grab_gen.asset" DD_PLY))
  93. (this.cardFront[7].load (asset "assets/card.asset" DD_PLY))
  94. (this.cardFront[7].loadTexture (asset "assets/card_approach.asset" DD_PLY))
  95. (this.cardFront[8].load (asset "assets/card.asset" DD_PLY))
  96. (this.cardFront[8].loadTexture (asset "assets/card_win.asset" DD_PLY))
  97. (this.cardFront[9].load (asset "assets/card.asset" DD_PLY))
  98. (this.cardFront[9].loadTexture (asset "assets/card_tutorial.asset" DD_PLY))
  99. # cards
  100. #(= this.cardsTotal 48)
  101. (= this.cardsTotal 36)
  102. (for (def int i 0) (< i this.cardsTotal) (= i (+ i 1))
  103. (group
  104. #(def int index (dd_math_rand 5))
  105. #(= this.cards[i].mesh this.cardFront[index])
  106. #(= this.cards[i].font this.font)
  107. (= this.cards[i].hidden 1)
  108. (= this.cards[i].font this.cardFont)
  109. (= this.cards[i].meshBack this.cardBack)
  110. (dd_matrix_identity this.cards[i])
  111. )
  112. )
  113. # single steps
  114. (for (def int i 0) (< i 5) (= i (+ i 1))
  115. (group
  116. (this.cards[i].setId CARD_SINGLE_STEP)
  117. (= this.cards[i].mesh this.cardFront[CARD_SINGLE_STEP])
  118. )
  119. )
  120. # triple steps
  121. (for (def int i 5) (< i (+ 5 4)) (= i (+ i 1))
  122. (group
  123. (this.cards[i].setId CARD_THREE_STEPS)
  124. (= this.cards[i].mesh this.cardFront[CARD_THREE_STEPS])
  125. )
  126. )
  127. # trade
  128. (for (def int i 9) (< i (+ 9 3)) (= i (+ i 1))
  129. (group
  130. (this.cards[i].setId CARD_TRADE)
  131. (= this.cards[i].mesh this.cardFront[CARD_TRADE])
  132. )
  133. )
  134. # conditional
  135. (for (def int i 12) (< i (+ 12 5)) (= i (+ i 1))
  136. (group
  137. (this.cards[i].setId CARD_CONDITIONAL)
  138. (= this.cards[i].mesh this.cardFront[CARD_CONDITIONAL])
  139. )
  140. )
  141. # replace
  142. (for (def int i 17) (< i (+ 17 3)) (= i (+ i 1))
  143. (group
  144. (this.cards[i].setId CARD_REPLACE)
  145. (= this.cards[i].mesh this.cardFront[CARD_REPLACE])
  146. )
  147. )
  148. # grab
  149. (for (def int i 20) (< i (+ 20 4)) (= i (+ i 1))
  150. (group
  151. (this.cards[i].setId CARD_GRAB)
  152. (= this.cards[i].mesh this.cardFront[CARD_GRAB])
  153. )
  154. )
  155. # grab gen
  156. (for (def int i 24) (< i (+ 24 5)) (= i (+ i 1))
  157. (group
  158. (this.cards[i].setId CARD_GRAB_GENERIC)
  159. (= this.cards[i].mesh this.cardFront[CARD_GRAB_GENERIC])
  160. )
  161. )
  162. # approach
  163. (for (def int i 29) (< i (+ 29 3)) (= i (+ i 1))
  164. (group
  165. (this.cards[i].setId CARD_APPROACH)
  166. (= this.cards[i].mesh this.cardFront[CARD_APPROACH])
  167. )
  168. )
  169. # win
  170. (for (def int i 32) (< i (+ 32 4)) (= i (+ i 1))
  171. (group
  172. (this.cards[i].setId CARD_WIN)
  173. (= this.cards[i].mesh this.cardFront[CARD_WIN])
  174. )
  175. )
  176. # # all set debug
  177. # (for (def int i 0) (< i 36) (= i (+ i 1))
  178. # (group
  179. # (= this.cards[i].id CARD_TRADE)
  180. # (= this.cards[i].mesh this.cardFront[CARD_TRADE])
  181. # )
  182. # )
  183. # tut cards
  184. (= this.guide guide)
  185. (= this.tutCardsTotal 10)
  186. (for (def int i 0) (< i this.tutCardsTotal) (= i (+ i 1))
  187. (group
  188. (= this.tutCards[i].hidden 0)
  189. (this.tutCards[i].setId (+ CARD_TUT_1 i))
  190. (= this.tutCards[i].mesh this.cardFront[9])
  191. (= this.tutCards[i].font this.cardFont)
  192. (= this.tutCards[i].meshBack this.cardBack)
  193. (dd_matrix_identity this.tutCards[i].target)
  194. (dd_matrix_translate this.tutCards[i].target -1.75 2.01 2.7)
  195. (dd_matrix_rotate this.tutCards[i].target -90 1 0 0)
  196. (dd_matrix_rotate this.tutCards[i].target 55 0 0 1)
  197. (dd_matrix_copy this.tutCards[i] this.tutCards[i].target)
  198. )
  199. )
  200. # deck
  201. (dd_matrix_identity this.deckMatrix)
  202. (dd_matrix_translate this.deckMatrix -0.40 2 0)
  203. (dd_matrix_rotate this.deckMatrix 90 1 0 0)
  204. (= this.deckTotal 0)
  205. (for (def int i 0) (< i this.cardsTotal) (= i (+ i 1))
  206. (group
  207. (this.addToDeck this.cards[i])
  208. (dd_matrix_copy this.cards[i] this.cards[i].target)
  209. )
  210. )
  211. (this.shuffleDeck)
  212. # discard
  213. (dd_matrix_identity this.discardMatrix)
  214. (dd_matrix_translate this.discardMatrix 0.40 2 0)
  215. (dd_matrix_rotate this.discardMatrix -90 1 0 0)
  216. (= this.discardTotal 0)
  217. # players 3-8
  218. #(= this.playersTotal 4)
  219. (= this.playersTotal numberOfPlayers)
  220. (= this.player[0].isUser 1)
  221. # init player positions
  222. (for (def int i 1) (< i this.playersTotal) (= i (+ i 1))
  223. (group
  224. # rotate players kinda towards user
  225. (def float angle)
  226. (= angle (+ 0 (* (/ 360.0 this.playersTotal) i)))
  227. (= angle (/ (- angle 180) 180.0))
  228. (= angle (* angle 0.9))
  229. (= angle (+ (* angle 180) 180))
  230. (dd_matrix_identity this.player[i])
  231. (dd_matrix_rotate this.player[i] angle 0 -1 0)
  232. (dd_matrix_translate this.player[i] 0 0 4)
  233. (def float offset (* -20 (/ (- 180 angle) 180.0)))
  234. (dd_matrix_rotate this.player[i] offset 0 1 0)
  235. (dd_matrix_rotate this.player[i] 180 0 1 0)
  236. # players actual location
  237. (dd_matrix_identity this.player[i].actual)
  238. (dd_matrix_rotate this.player[i].actual (- 0 (* (/ 360.0 this.playersTotal) i)) 0 1 0)
  239. (dd_matrix_translate this.player[i].actual 0 0 4)
  240. (dd_matrix_rotate this.player[i].actual 180 0 1 0)
  241. )
  242. )
  243. # user's custom matrices
  244. (dd_matrix_identity this.player[0])
  245. (dd_matrix_translate this.player[0] 0 0 5)
  246. (dd_matrix_identity this.player[0].actual)
  247. (dd_matrix_translate this.player[0].actual 0 0 5)
  248. (dd_matrix_identity this.player[0].selectedMatrix)
  249. (dd_matrix_translate this.player[0].selectedMatrix 0 2.01 -3.6)
  250. (dd_matrix_rotate this.player[0].selectedMatrix 90 1 0 0)
  251. (dd_matrix_rotate this.player[0].selectedMatrix 180 0 0 1)
  252. # temp rotating card
  253. (= this.rotating 0)
  254. # rose player
  255. (= this.isRoseFlat 1)
  256. (this.roseCardMesh.load (asset "assets/card.asset" DD_PLY))
  257. (this.roseCardMesh.loadTexture (asset "assets/rose.asset" DD_PLY))
  258. (this.roseCard.setId CARD_ROSE)
  259. (= this.roseCard.mesh this.roseCardMesh)
  260. (= this.roseCard.meshBack this.cardBack)
  261. # begin the game
  262. (this.addAction ACTION_CHANGE_PHASE 0 PHASE_INIT 50)
  263. (this.arrowProgramAvdl.setVertexShader
  264. (multistring
  265. "AVDL_IN vec4 position;\n"
  266. "AVDL_IN vec3 colour;\n"
  267. "uniform mat4 matrix;\n"
  268. "uniform vec3 tint;\n"
  269. "AVDL_OUT vec4 outColour;\n"
  270. "void main() {\n"
  271. " vec4 pos = matrix *position;\n"
  272. " gl_Position = pos;\n"
  273. " outColour = vec4(colour.rgb *tint.rgb, 1.0);\n"
  274. "}\n"
  275. )
  276. )
  277. (this.arrowProgramAvdl.setFragmentShader
  278. (multistring
  279. "AVDL_IN vec4 outColour;\n"
  280. "void main() {\n"
  281. " avdl_frag_color = outColour;\n"
  282. "}\n"
  283. )
  284. )
  285. (= this.arrowActiveCol[0] 0.403)
  286. (= this.arrowActiveCol[1] 0.698)
  287. (= this.arrowActiveCol[2] 0.349)
  288. (= this.arrowInactiveCol[0] 0.694)
  289. (= this.arrowInactiveCol[1] 0.137)
  290. (= this.arrowInactiveCol[2] 0.137)
  291. (= this.arrowCurrentCol[0] 0.0)
  292. (= this.arrowCurrentCol[1] 0.0)
  293. (= this.arrowCurrentCol[2] 0.0)
  294. )
  295. )
  296. (class_function world_game void onload (group)
  297. (group
  298. )
  299. )
  300. #(class_function world_game void resize (group)
  301. # (group
  302. # )
  303. #)
  304. (class_function world_game void update (group)
  305. (group
  306. # currently displaying a card, handle that instead of game state
  307. (if this.ovButtons.cardToShow
  308. (this.ovButtons.lookAt this.rotX this.rotY)
  309. )
  310. # execute remaining actions
  311. (if (&& (> this.actionsTotal 0) (== this.ovButtons.cardToShow 0))
  312. (group
  313. # delay after executing an action
  314. (if (== this.actions[0].actionType ACTION_DELAY)
  315. (group
  316. (if (> this.actions[0].delay 0)
  317. (= this.actions[0].delay (- this.actions[0].delay 1))
  318. (this.removeAction)
  319. )
  320. )
  321. # change phases
  322. (== this.actions[0].actionType ACTION_CHANGE_PHASE)
  323. (group
  324. # initialise phase
  325. (if (== this.actions[0].value PHASE_INIT)
  326. (group
  327. (= this.phaseText "initialising game")
  328. # decide starting player
  329. (if (== startingPlayer -1)
  330. (= startingPlayer (dd_math_rand this.playersTotal))
  331. )
  332. (this.setRosePlayer startingPlayer)
  333. (dd_matrix_copy this.roseCard this.roseCard.target)
  334. # all players draw starting cards
  335. (for (def int j 0) (< j 5) (= j (+ j 1))
  336. (for (def int i 0) (< i this.playersTotal) (= i (+ i 1))
  337. (this.addAction ACTION_DRAW_CARD i 0 5)
  338. )
  339. )
  340. # start with planning phase
  341. (this.addAction ACTION_CHANGE_PHASE 0 PHASE_PLAN 50)
  342. # guide
  343. (if (== this.guide 0)
  344. (group
  345. (this.ovButtons.setCard this.tutCards[0])
  346. (= this.guide (+ this.guide 1))
  347. )
  348. )
  349. #(this.ovButtons.setCard this.deck[0])
  350. )
  351. # planning phase
  352. (== this.actions[0].value PHASE_PLAN)
  353. (group
  354. (= this.phaseText "planning phase")
  355. # ask all players to plan a card
  356. (for (def int i this.rosePlayer) (< i (+ this.playersTotal this.rosePlayer)) (= i (+ i 1))
  357. (group
  358. (def int index (% i this.playersTotal))
  359. (this.addAction ACTION_SET_ACTIVE_PLAYER index 0 20)
  360. (this.addAction ACTION_SELECT_CARD index 0 0)
  361. (this.addAction ACTION_PLAN_CARD -1 0 50)
  362. )
  363. )
  364. # when done, move to execution phase
  365. (this.addAction ACTION_CHANGE_PHASE 0 PHASE_EXECUTION 50)
  366. (if (== this.guide 1)
  367. (group
  368. (this.ovButtons.setCard this.tutCards[1])
  369. (= this.guide (+ this.guide 1))
  370. )
  371. )
  372. )
  373. # execution phase
  374. (== this.actions[0].value PHASE_EXECUTION)
  375. (group
  376. (= this.phaseText "execution phase")
  377. # reveal all planned cards, and execute their actions
  378. (for (def int i this.rosePlayer) (< i (+ this.playersTotal this.rosePlayer)) (= i (+ i 1))
  379. (group
  380. (def int index (% i this.playersTotal))
  381. (this.addAction ACTION_SET_ACTIVE_PLAYER index 0 20)
  382. (this.addAction ACTION_REVEAL_PLANNED_CARD index 0 50)
  383. (this.addAction ACTION_EXECUTE_PLANNED_CARD index 0 50)
  384. (this.addAction ACTION_DISCARD_PLANNED_CARD index 0 50)
  385. )
  386. )
  387. # when done, move to end phase
  388. (this.addAction ACTION_CHANGE_PHASE 0 PHASE_END 50)
  389. (if (== this.guide 3)
  390. (group
  391. (this.ovButtons.setCard this.tutCards[3])
  392. (= this.guide (+ this.guide 1))
  393. )
  394. )
  395. )
  396. # end phase
  397. (== this.actions[0].value PHASE_END)
  398. (group
  399. (= this.phaseText "end phase")
  400. # all players, apart from the rose player, draw a card
  401. (for (def int i (+ this.rosePlayer 1)) (< i (+ this.playersTotal this.rosePlayer)) (= i (+ i 1))
  402. (group
  403. (def int index (% i this.playersTotal))
  404. (this.addAction ACTION_DRAW_CARD index 0 5)
  405. )
  406. )
  407. # if held, flat rose
  408. (if (== this.isRoseFlat 0)
  409. (this.addAction ACTION_ADVANCE_ROSE 0 1 5)
  410. )
  411. # check for victory condition
  412. (this.addAction ACTION_WIN_CONDITION 0 0 0)
  413. # when done, restart planning phase
  414. (this.addAction ACTION_CHANGE_PHASE 0 PHASE_PLAN 50)
  415. (if (== this.guide 4)
  416. (group
  417. (this.ovButtons.setCard this.tutCards[4])
  418. (= this.guide (+ this.guide 1))
  419. )
  420. )
  421. )
  422. # error phase (should never trigger)
  423. (group
  424. (= this.phaseText "error phase")
  425. )
  426. )
  427. (= this.actions[0].actionType ACTION_DELAY)
  428. )
  429. # advance rose to next player
  430. (== this.actions[0].actionType ACTION_ADVANCE_ROSE)
  431. (group
  432. # rose is held by someone, flat it and lose one movement
  433. (if (== this.isRoseFlat 0)
  434. (group
  435. (= this.isRoseFlat 1)
  436. (= this.actions[0].value (- this.actions[0].value 1))
  437. # find the rose
  438. (def int roseIndex -1)
  439. (for (def int i 0) (< i this.player[this.rosePlayer].cardsTotal) (= i (+ i 1))
  440. (group
  441. (if (== this.player[this.rosePlayer].cards[i].id CARD_ROSE)
  442. (group
  443. (= roseIndex i)
  444. (= i 100)
  445. )
  446. )
  447. )
  448. )
  449. # should never happen
  450. (if (== roseIndex -1)
  451. (echo "rose is not held by rose player ?")
  452. # flat the rose
  453. (group
  454. (this.player[this.rosePlayer].removeCard roseIndex)
  455. (this.setRosePlayer this.rosePlayer)
  456. )
  457. )
  458. )
  459. )
  460. # there is movement left, move the rose
  461. (if (> this.actions[0].value 0)
  462. (group
  463. (this.setRosePlayer (% (+ this.rosePlayer this.actions[0].value) this.playersTotal))
  464. )
  465. )
  466. (= this.actions[0].actionType ACTION_DELAY)
  467. )
  468. # draw card
  469. (== this.actions[0].actionType ACTION_DRAW_CARD)
  470. (group
  471. (this.drawCard this.actions[0].playerIndex)
  472. (= this.actions[0].actionType ACTION_DELAY)
  473. )
  474. # select a card
  475. (== this.actions[0].actionType ACTION_SELECT_CARD)
  476. (group
  477. # invalid player has to select a card? (shouldn't happen)
  478. (if (|| (< this.actions[0].playerIndex 0) (>= this.actions[0].playerIndex this.playersTotal))
  479. (echo "invalid player cannot select a card")
  480. # user has to select a card
  481. (&& (== this.actions[0].playerIndex 0) (== this.actions[0].value 0))
  482. (group
  483. (if (== this.guide 2)
  484. (group
  485. (this.ovButtons.setCard this.tutCards[2])
  486. (= this.guide (+ this.guide 1))
  487. )
  488. )
  489. )
  490. # AI has to select a card or user selects randomly
  491. (group
  492. (= this.lastSelectedCardPlayerIndex this.actions[0].playerIndex)
  493. (= this.lastSelectedCardIndex (dd_math_rand this.player[this.lastSelectedCardPlayerIndex].cardsTotal))
  494. (= this.actions[0].actionType ACTION_DELAY)
  495. #(this.player[this.actions[0].playerIndex].selectCard)
  496. )
  497. )
  498. )
  499. # plan card
  500. (== this.actions[0].actionType ACTION_PLAN_CARD)
  501. (group
  502. # player index is given as -1, use last selected card/player combo
  503. (if (== this.actions[0].playerIndex -1)
  504. (group
  505. # player tried to plan the rose! blasphemy! select another card
  506. (if (== this.player[this.lastSelectedCardPlayerIndex].cards[this.lastSelectedCardIndex].id CARD_ROSE)
  507. (group
  508. (this.addInjectAction ACTION_SELECT_CARD this.lastSelectedCardPlayerIndex 0 0)
  509. (this.addInjectAction ACTION_PLAN_CARD -1 0 50)
  510. (this.injectActionsToActions)
  511. )
  512. # player tried to plan the "replace" card, while being last, select another card
  513. (&&
  514. (== this.player[this.lastSelectedCardPlayerIndex].cards[this.lastSelectedCardIndex].id CARD_REPLACE)
  515. (== (% (+ this.rosePlayer this.playersTotal -1) this.playersTotal) this.lastSelectedCardPlayerIndex)
  516. )
  517. (group
  518. (this.addInjectAction ACTION_SELECT_CARD this.lastSelectedCardPlayerIndex 0 0)
  519. (this.addInjectAction ACTION_PLAN_CARD -1 0 50)
  520. (this.injectActionsToActions)
  521. )
  522. # selected card can be planned, so plan it
  523. (this.player[this.lastSelectedCardPlayerIndex].planCard this.lastSelectedCardIndex)
  524. )
  525. )
  526. # player and card index are given, use those instead
  527. (group
  528. (this.player[this.actions[0].playerIndex].planCard this.actions[0].value)
  529. )
  530. )
  531. (= this.actions[0].actionType ACTION_DELAY)
  532. )
  533. # set active player
  534. (== this.actions[0].actionType ACTION_SET_ACTIVE_PLAYER)
  535. (group
  536. (this.applyArrowRotation this.actions[0].playerIndex)
  537. (= this.actions[0].actionType ACTION_DELAY)
  538. )
  539. # reveal planned card
  540. (== this.actions[0].actionType ACTION_REVEAL_PLANNED_CARD)
  541. (group
  542. (def int playerIndex this.actions[0].playerIndex)
  543. (= this.player[playerIndex].selectedCard2.hidden 0)
  544. (dd_matrix_rotate this.player[playerIndex].selectedCard2.target 180 0 1 0)
  545. (= this.actions[0].actionType ACTION_DELAY)
  546. (this.ovButtons.setCard this.player[playerIndex].selectedCard2)
  547. )
  548. # execute planned card
  549. (== this.actions[0].actionType ACTION_EXECUTE_PLANNED_CARD)
  550. (group
  551. (def int cardId this.player[this.actions[0].playerIndex].selectedCard2.id)
  552. # based on the card being executed, inject it's actions in the stack
  553. # move rose one step
  554. (if (== cardId CARD_SINGLE_STEP)
  555. (group
  556. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  557. (this.injectActionsToActions)
  558. )
  559. # move rose three steps
  560. (== cardId CARD_THREE_STEPS)
  561. (group
  562. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  563. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  564. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  565. (this.injectActionsToActions)
  566. )
  567. # trade - give 1 card to rose player, take 1 card back
  568. (== cardId CARD_TRADE)
  569. (group
  570. (if (== this.rosePlayer this.actions[0].playerIndex)
  571. (group
  572. )
  573. (group
  574. # rose player picks up rose
  575. (if this.isRoseFlat
  576. (this.addInjectAction ACTION_GRAB_ROSE 0 0 50)
  577. )
  578. # active player selects and gives a card to rose player
  579. (this.addInjectAction ACTION_SELECT_CARD this.actions[0].playerIndex 0 0)
  580. (this.addInjectAction ACTION_GIVE_CARD this.rosePlayer 0 50)
  581. # rose player selects and gives a card to active player
  582. # TODO: should be given a card at random, rose player doesn't select
  583. (this.addInjectAction ACTION_SELECT_CARD this.rosePlayer -1 0)
  584. (this.addInjectAction ACTION_GIVE_CARD this.actions[0].playerIndex 0 50)
  585. # move rose one step
  586. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  587. (this.injectActionsToActions)
  588. )
  589. )
  590. )
  591. # If rose is one step before active user, move it one step, otherwise move it three steps
  592. (== cardId CARD_CONDITIONAL)
  593. (group
  594. (def int onePreviousIndex (% (- (+ this.actions[0].playerIndex this.playersTotal) 1) 5))
  595. (if (== onePreviousIndex this.rosePlayer)
  596. (group
  597. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  598. (this.injectActionsToActions)
  599. )
  600. # else
  601. (group
  602. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  603. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  604. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  605. (this.injectActionsToActions)
  606. )
  607. )
  608. )
  609. # discard your planned card, draw one card, plan another card and execute it
  610. (== cardId CARD_REPLACE)
  611. (group
  612. (this.addInjectAction ACTION_DISCARD_PLANNED_CARD this.actions[0].playerIndex 0 50)
  613. (this.addInjectAction ACTION_DRAW_CARD this.actions[0].playerIndex 0 50)
  614. (this.addInjectAction ACTION_SELECT_CARD this.actions[0].playerIndex 0 0)
  615. (this.addInjectAction ACTION_PLAN_CARD -1 0 50)
  616. (this.addInjectAction ACTION_REVEAL_PLANNED_CARD this.actions[0].playerIndex 0 50)
  617. (this.addInjectAction ACTION_EXECUTE_PLANNED_CARD this.actions[0].playerIndex 0 50)
  618. (this.injectActionsToActions)
  619. )
  620. # grab
  621. # If rose is in front of you, grab it, otherwise move rose 1 step.
  622. # The new rose player grabs the rose.
  623. (== cardId CARD_GRAB)
  624. (group
  625. # rose is in front of user, grab it
  626. (if (== this.actions[0].playerIndex this.rosePlayer)
  627. (group
  628. (this.addInjectAction ACTION_GRAB_ROSE 0 0 50)
  629. (this.injectActionsToActions)
  630. )
  631. # otherwise, move one step, rose player grabs rose
  632. (group
  633. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  634. (this.addInjectAction ACTION_GRAB_ROSE 0 0 50)
  635. (this.injectActionsToActions)
  636. )
  637. )
  638. )
  639. # grab generic
  640. # If rose is flat, the player in front of it grabs it.
  641. (== cardId CARD_GRAB_GENERIC)
  642. (group
  643. (this.addInjectAction ACTION_GRAB_ROSE 0 0 50)
  644. (this.injectActionsToActions)
  645. )
  646. # aproach
  647. # If you are not the rose player, move rose 1 step, otherwise move it 3 steps.
  648. (== cardId CARD_APPROACH)
  649. (group
  650. # active user is rose player, move rose 3 steps
  651. (if (== this.actions[0].playerIndex this.rosePlayer)
  652. (group
  653. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  654. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  655. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 20)
  656. (this.injectActionsToActions)
  657. )
  658. # active user is not rose player, move rose 1 step
  659. (group
  660. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  661. (this.injectActionsToActions)
  662. )
  663. )
  664. )
  665. # win
  666. # If you are holding the rose, discard 1 card. Move rose 1 step.
  667. (== cardId CARD_WIN)
  668. (group
  669. # holding the rose, discard 1 card
  670. (if (&& (== this.actions[0].playerIndex this.rosePlayer) (== this.isRoseFlat 0))
  671. (group
  672. (this.addInjectAction ACTION_SELECT_CARD this.actions[0].playerIndex 0 50)
  673. )
  674. )
  675. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  676. (this.injectActionsToActions)
  677. )
  678. )
  679. (= this.actions[0].actionType ACTION_DELAY)
  680. )
  681. # discard planned card
  682. (== this.actions[0].actionType ACTION_DISCARD_PLANNED_CARD)
  683. (group
  684. (def int playerIndex this.actions[0].playerIndex)
  685. (this.addToDiscard this.player[playerIndex].selectedCard2)
  686. (this.player[playerIndex].deselectCard)
  687. (= this.actions[0].actionType ACTION_DELAY)
  688. )
  689. # give card to another player
  690. (== this.actions[0].actionType ACTION_GIVE_CARD)
  691. (group
  692. (def int receiverIndex this.actions[0].playerIndex)
  693. # user is receiving a card, reveal it straight away
  694. (if (== receiverIndex 0)
  695. (= this.player[this.lastSelectedCardPlayerIndex].cards[this.lastSelectedCardIndex].hidden 0)
  696. )
  697. # rose is being given
  698. (if (== this.player[this.lastSelectedCardPlayerIndex].cards[this.lastSelectedCardIndex].id CARD_ROSE)
  699. (= this.rosePlayer receiverIndex)
  700. # user is giving a non-rose card, mark it to become hidden when arriving at opponent
  701. (== this.lastSelectedCardPlayerIndex 0)
  702. (group
  703. (this.addInjectAction ACTION_HIDE_CARD receiverIndex this.player[receiverIndex].cardsTotal 0)
  704. (this.injectActionsToActions)
  705. )
  706. )
  707. (this.player[receiverIndex].addCard this.player[this.lastSelectedCardPlayerIndex].cards[this.lastSelectedCardIndex])
  708. (this.player[this.lastSelectedCardPlayerIndex].removeCard this.lastSelectedCardIndex)
  709. (= this.actions[0].actionType ACTION_DELAY)
  710. )
  711. # hide given card
  712. (== this.actions[0].actionType ACTION_HIDE_CARD)
  713. (group
  714. (= this.player[this.actions[0].playerIndex].cards[this.actions[0].value].hidden 1)
  715. (= this.actions[0].actionType ACTION_DELAY)
  716. )
  717. # the rose player, grabs the rose
  718. (== this.actions[0].actionType ACTION_GRAB_ROSE)
  719. (group
  720. (if this.isRoseFlat
  721. (this.grabRose)
  722. )
  723. (= this.actions[0].actionType ACTION_DELAY)
  724. )
  725. # discard card from player's hand
  726. (== this.actions[0].actionType ACTION_DISCARD_CARD)
  727. (group
  728. (def int playerIndex)
  729. (def int cardIndex)
  730. # discard previously selected card
  731. (if (== this.actions[0].playerIndex -1)
  732. (group
  733. (= playerIndex this.lastSelectedCardPlayerIndex)
  734. (= cardIndex this.lastSelectedCardIndex)
  735. )
  736. # discard given card
  737. (group
  738. (= playerIndex this.actions[0].playerIndex)
  739. (= cardIndex this.actions[0].value)
  740. )
  741. )
  742. # attempting to discard rose, flat it instead
  743. (if (== this.player[playerIndex].cards[cardIndex].id CARD_ROSE)
  744. (group
  745. (this.addInjectAction ACTION_ADVANCE_ROSE 0 1 50)
  746. (this.injectActionsToActions)
  747. )
  748. # discard selected card
  749. (group
  750. (= this.player[playerIndex].cards[cardIndex].hidden 0)
  751. (this.addToDiscard this.player[playerIndex].cards[cardIndex])
  752. (this.player[playerIndex].removeCard cardIndex)
  753. )
  754. )
  755. (= this.actions[0].actionType ACTION_DELAY)
  756. )
  757. # put discard pile to deck
  758. (== this.actions[0].actionType ACTION_DISCARD_TO_DECK)
  759. (group
  760. # there are still discarded cards
  761. (if (> this.discardTotal 0)
  762. (group
  763. # delay between each card
  764. (= this.actions[0].value (- this.actions[0].value 1))
  765. # put next discarded card to deck
  766. (if (<= this.actions[0].value 0)
  767. (group
  768. (def int disIndex (- this.discardTotal 1))
  769. (this.addToDeck this.discard[disIndex])
  770. (= this.discard[disIndex] 0)
  771. (= this.discardTotal (- this.discardTotal 1))
  772. (= this.actions[0].value this.actions[0].delay)
  773. )
  774. )
  775. )
  776. # no cards left in discard pile - move to next part
  777. (group
  778. (this.shuffleDeck)
  779. (= this.actions[0].actionType ACTION_DELAY)
  780. )
  781. )
  782. ) # discard pile to deck
  783. # win condition
  784. (== this.actions[0].actionType ACTION_WIN_CONDITION)
  785. (group
  786. (if (< this.victoriousPlayer 0)
  787. (group
  788. (def int winningPlayer -1)
  789. # a player with 2 cards or less is the winner
  790. # tie-breaker is whoever is closest to the rose player
  791. (for (def int i this.rosePlayer) (< i (+ this.rosePlayer this.playersTotal)) (= i (+ i 1))
  792. (group
  793. (def int index (% i this.playersTotal))
  794. # player won
  795. (if (<= this.player[index].cardsTotal 2)
  796. (group
  797. (= winningPlayer index)
  798. (= i 100)
  799. )
  800. )
  801. )
  802. )
  803. # someone won
  804. (if (>= winningPlayer 0)
  805. (group
  806. (= this.victoriousPlayer winningPlayer)
  807. #(dd_world_prepare world_menu 1.0)
  808. #(dd_world_ready)
  809. )
  810. # nobody won
  811. (group
  812. (= this.actions[0].actionType ACTION_DELAY)
  813. )
  814. )
  815. )
  816. )
  817. )
  818. ) # different behavior for each action
  819. )
  820. )
  821. (= this.rotating (+ this.rotating 0.05))
  822. # calculate new camera look at point
  823. (if (>= this.holdRotX 0)
  824. (group
  825. # not rotating yet, check threshold
  826. (if (== this.isRotating 0)
  827. (group
  828. (if (|| (> (dd_math_abs (- (dd_mouse_x) this.holdRotX)) 15)
  829. (> (dd_math_abs (- (dd_mouse_y) this.holdRotY)) 15))
  830. (group
  831. (= this.isRotating 1)
  832. (= this.holdRotX (dd_mouse_x))
  833. (= this.holdRotY (dd_mouse_y))
  834. )
  835. )
  836. )
  837. # is rotating, keep rotating
  838. (group
  839. (= this.targetRotX
  840. (dd_math_max
  841. (dd_math_min
  842. (+ this.targetRotX (* (- (dd_mouse_x) this.holdRotX) 0.25))
  843. 100
  844. )
  845. -100
  846. )
  847. )
  848. (= this.targetRotY
  849. (dd_math_max
  850. (dd_math_min
  851. (- this.targetRotY (* (- (dd_mouse_y) this.holdRotY) 0.25))
  852. 70
  853. )
  854. -65
  855. )
  856. )
  857. (= this.holdRotX (dd_mouse_x))
  858. (= this.holdRotY (dd_mouse_y))
  859. )
  860. )
  861. )
  862. )
  863. # slowly approach camera look at point
  864. (= this.rotX (dd_math_ease_linear 0.1 this.rotX this.targetRotX))
  865. (= this.rotY (dd_math_ease_linear 0.1 this.rotY this.targetRotY))
  866. #(if this.waitingPlayerCard
  867. (this.player[0].lookAtCard this.rotX this.rotY)
  868. #)
  869. #(def float tempRotX this.rotX)
  870. #(def float tempRotY this.rotY)
  871. #(echo "rot: " tempRotX " | " tempRotY)
  872. # update all cards to approach target
  873. (for (def int i 0) (< i this.cardsTotal) (= i (+ i 1))
  874. (group
  875. (dd_matrix_approach this.cards[i] this.cards[i].target 0.1)
  876. )
  877. )
  878. (dd_matrix_approach this.roseCard this.roseCard.target 0.1)
  879. (for (def int i 0) (< i this.tutCardsTotal) (= i (+ i 1))
  880. (dd_matrix_approach this.tutCards[i] this.tutCards[i].target 0.1)
  881. )
  882. # update table arrow
  883. (= this.arrowRotation (dd_math_ease_linear 0.1 this.arrowRotation this.arrowRotationTarget))
  884. # user is about to play a card
  885. (if (&& (> this.actionsTotal 0) (== this.actions[0].actionType ACTION_SELECT_CARD) (== this.actions[0].playerIndex 0))
  886. (group
  887. (= this.arrowCurrentCol[0] (dd_math_ease_linear 0.1 this.arrowCurrentCol[0] this.arrowActiveCol[0] ))
  888. (= this.arrowCurrentCol[1] (dd_math_ease_linear 0.1 this.arrowCurrentCol[1] this.arrowActiveCol[1] ))
  889. (= this.arrowCurrentCol[2] (dd_math_ease_linear 0.1 this.arrowCurrentCol[2] this.arrowActiveCol[2] ))
  890. )
  891. (group
  892. (= this.arrowCurrentCol[0] (dd_math_ease_linear 0.1 this.arrowCurrentCol[0] this.arrowInactiveCol[0] ))
  893. (= this.arrowCurrentCol[1] (dd_math_ease_linear 0.1 this.arrowCurrentCol[1] this.arrowInactiveCol[1] ))
  894. (= this.arrowCurrentCol[2] (dd_math_ease_linear 0.1 this.arrowCurrentCol[2] this.arrowInactiveCol[2] ))
  895. )
  896. )
  897. (this.ovButtons.update)
  898. )
  899. ) # update
  900. (class_function world_game void draw (group)
  901. (group
  902. (dd_matrix_push)
  903. # camera
  904. (dd_rotatef this.rotY -1 0 0)
  905. (dd_rotatef this.rotX 0 1 0)
  906. # center of world
  907. (dd_multMatrixf this.matCenter)
  908. # stage
  909. (this.stage.draw)
  910. (this.table.draw)
  911. (dd_matrix_push)
  912. (dd_rotatef this.arrowRotation 0 1 0)
  913. (this.arrowProgramAvdl.useProgram)
  914. (def int colLoc)
  915. (= colLoc (avdl_getUniformLocation this.arrowProgramAvdl "tint"))
  916. (avdl_setUniform3f colLoc this.arrowCurrentCol[0] this.arrowCurrentCol[1] this.arrowCurrentCol[2])
  917. (this.tableArrow.draw)
  918. (avdl_useProgram 0)
  919. (this.tableArrowDecoration.draw)
  920. (dd_matrix_pop)
  921. # draw deck
  922. (dd_matrix_push)
  923. (for (def int i 0) (< i this.deckTotal) (= i (+ i 1))
  924. (group
  925. (if this.deck[i]
  926. (this.deck[i].draw)
  927. )
  928. )
  929. )
  930. # draw tut cards
  931. (for (def int i 0) (< i this.tutCardsTotal) (= i (+ i 1))
  932. (group
  933. (this.tutCards[i].draw)
  934. )
  935. )
  936. # rose is flat, draw it
  937. # if rose is held, player will draw it
  938. (if this.isRoseFlat
  939. (this.roseCard.draw)
  940. )
  941. (dd_multMatrixf this.deckMatrix)
  942. # draw deck number
  943. (dd_rotatef 180 1 0 0)
  944. (dd_translatef 0 0 (+ (* 0.003 this.deckTotal) 0.12))
  945. (dd_rotatef 90 1 0 0)
  946. (dd_scalef 0.15 0.15 0.15)
  947. (this.font.drawInt this.deckTotal)
  948. (dd_matrix_pop)
  949. # draw discard
  950. (dd_matrix_push)
  951. (for (def int i 0) (< i this.discardTotal) (= i (+ i 1))
  952. (group
  953. (if this.discard[i]
  954. (this.discard[i].draw)
  955. )
  956. )
  957. )
  958. (dd_multMatrixf this.discardMatrix)
  959. # draw discard number
  960. (dd_translatef 0 0 (+ (* 0.003 this.discardTotal) 0.12))
  961. (dd_rotatef 90 1 0 0)
  962. (dd_scalef 0.15 0.15 0.15)
  963. (this.font.drawInt this.discardTotal)
  964. (dd_matrix_pop)
  965. # draw every player apart from self
  966. (for (def int i 1) (< i this.playersTotal) (= i (+ i 1))
  967. (group
  968. (dd_matrix_push)
  969. (this.player[i].draw)
  970. (dd_matrix_pop)
  971. )
  972. )
  973. # draw player
  974. (dd_matrix_push)
  975. (this.player[0].draw)
  976. (dd_matrix_pop)
  977. (if this.ovButtons.cardToShow
  978. (this.ovButtons.draw)
  979. )
  980. # rotating card
  981. #(dd_translatef 0 3.5 0)
  982. #(dd_rotatef this.rotating 0 1 0)
  983. #(dd_scalef 5.0 5.0 5.0)
  984. #(this.deck[32].drawRaw)
  985. #(this.tutCards[0].drawRaw)
  986. #(this.cardBack.draw)
  987. #(this.cardFront[1].draw)
  988. (dd_matrix_pop)
  989. (glClear GL_DEPTH_BUFFER_BIT)
  990. # states
  991. (dd_matrix_push)
  992. (dd_translatef 0 8 -25)
  993. # draw end game
  994. (if (>= this.victoriousPlayer 0)
  995. (if (== this.victoriousPlayer 0)
  996. (this.font.drawLimit "You won click anywhere to continue"
  997. (* (dd_screen_width_get 25) 1.8)
  998. )
  999. (this.font.drawLimit "You lost click anywhere to continue"
  1000. (* (dd_screen_width_get 25) 1.8)
  1001. )
  1002. )
  1003. # draw text of overlay card
  1004. this.ovButtons.isLookingAtCard
  1005. (this.font.drawLimit this.ovButtons.cardToShow.cardDescription
  1006. (* (dd_screen_width_get 25) 1.8)
  1007. )
  1008. # player looking card
  1009. (>= this.player[0].userLookingAtCard 0)
  1010. (this.font.drawLimit this.player[0].cards[this.player[0].userLookingAtCard].cardDescription
  1011. (* (dd_screen_width_get 25) 1.8)
  1012. )
  1013. # draw phase
  1014. (this.font.drawLimit this.phaseText
  1015. (* (dd_screen_width_get 25) 1.8)
  1016. )
  1017. )
  1018. (dd_matrix_pop)
  1019. # clear depth
  1020. (glClear GL_DEPTH_BUFFER_BIT)
  1021. # lookat mesh
  1022. (dd_matrix_push)
  1023. (dd_translatef 0 0 -25)
  1024. (this.lookat.draw)
  1025. (dd_matrix_pop)
  1026. (this.player[0].drawLookingAtText)
  1027. )
  1028. )
  1029. (class_function world_game void key_input (group char key)
  1030. (group
  1031. (if (== key 27)
  1032. (= dd_flag_exit 1) # exit game
  1033. ) # key input
  1034. )
  1035. )
  1036. (class_function world_game void clean (group)
  1037. (group
  1038. )
  1039. )
  1040. (class_function world_game void mouse_input (group int button int type)
  1041. (group
  1042. # control the camera look at point when click and dragging
  1043. (if (== type DD_INPUT_MOUSE_TYPE_PRESSED)
  1044. (group
  1045. (= this.holdRotX (dd_mouse_x))
  1046. (= this.holdRotY (dd_mouse_y))
  1047. (= this.isRotating 0)
  1048. )
  1049. (== type DD_INPUT_MOUSE_TYPE_RELEASED)
  1050. (group
  1051. (= this.holdRotX -1)
  1052. (= this.holdRotY -1)
  1053. # was not rotating - click
  1054. (if (== this.isRotating 0)
  1055. (group
  1056. # someone has won, move to next menu
  1057. (if (>= this.victoriousPlayer 0)
  1058. (group
  1059. (dd_world_prepare world_menu 1.0)
  1060. (dd_world_ready)
  1061. )
  1062. # showing overlay card
  1063. this.ovButtons.cardToShow
  1064. (group
  1065. (this.ovButtons.click)
  1066. )
  1067. # waiting user to select a card
  1068. (&& (> this.actionsTotal 0) (== this.actions[0].actionType ACTION_SELECT_CARD) (== this.actions[0].playerIndex 0))
  1069. (group
  1070. # just selected a card
  1071. (if (&& (== this.player[0].userLookingAtCard this.player[0].highlightCard)
  1072. (>= this.player[0].highlightCard 0))
  1073. (group
  1074. (= this.lastSelectedCardPlayerIndex 0)
  1075. (= this.lastSelectedCardIndex this.player[0].highlightCard)
  1076. (= this.actions[0].actionType ACTION_DELAY)
  1077. (= this.player[0].userLookingAtCard -1)
  1078. (= this.player[0].highlightCard -1)
  1079. )
  1080. # just highlighted card
  1081. (this.player[0].highlightLookingCard)
  1082. )
  1083. )
  1084. ) # was waiting for user input
  1085. )
  1086. )
  1087. )
  1088. ) # mouse button released
  1089. )
  1090. ) # mouse input
  1091. #
  1092. # call it to make a player draw a card from the deck
  1093. # `playerIndex` should be the index of that player
  1094. #
  1095. (class_function world_game void drawCard (group int playerIndex)
  1096. (group
  1097. # if deck is empty, refill it from discard pile
  1098. # this should happen infinitely, and they should
  1099. # never run out
  1100. (if (&& (<= this.deckTotal 0) (> this.discardTotal 0))
  1101. (group
  1102. # add discard to deck
  1103. # draw 1 card, same player
  1104. (this.addInjectAction ACTION_DISCARD_TO_DECK 0 0 10)
  1105. (this.addInjectAction ACTION_DRAW_CARD playerIndex 0 5)
  1106. (this.injectActionsToActions)
  1107. )
  1108. # check player index validity (shouldn't happen)
  1109. (|| (< playerIndex 0) (>= playerIndex this.playersTotal))
  1110. (echo "INVALID PLAYER ID")
  1111. # not any cards left in deck
  1112. (<= this.deckTotal 0)
  1113. (group
  1114. # deck is empty, and wasn't replenished by discard pile
  1115. (echo "CANNOT DRAW MORE CARDS FROM THE DECK, DISCARD ALSO EMPTY")
  1116. )
  1117. # deck has cards to draw from
  1118. (group
  1119. # get top card
  1120. (def int cardIndex (- this.deckTotal 1))
  1121. # player has too many cards already (should never happen)
  1122. (if (== this.player[playerIndex].cardsTotal 10)
  1123. (echo "CANNOT GIVE MORE CARDS, SKIP")
  1124. # player can handle one more card
  1125. (group
  1126. (this.player[playerIndex].addCard this.deck[cardIndex])
  1127. # if card goes to an opponent, hide it
  1128. (if (> playerIndex 0)
  1129. (= this.deck[cardIndex].hidden 1)
  1130. (= this.deck[cardIndex].hidden 0)
  1131. )
  1132. # remove card from deck
  1133. (= this.deck[cardIndex] 0)
  1134. (= this.deckTotal (- this.deckTotal 1))
  1135. )
  1136. ) # player has too many cards
  1137. )
  1138. ) #deck has cards to draw from
  1139. )
  1140. ) # draw card
  1141. (class_function world_game void addToDiscard (group Card card)
  1142. (group
  1143. # check limits, should never happen
  1144. (if (>= this.discardTotal 48)
  1145. (echo "Can't add card to discard")
  1146. # add card to discard pile
  1147. (group
  1148. (= this.discard[this.discardTotal] card)
  1149. (= this.discardTotal (+ this.discardTotal 1))
  1150. (dd_matrix_copy card.target this.discardMatrix)
  1151. (dd_matrix_translate card.target 0 0 (+ (* 0.003 (+ this.discardTotal 1)) 0.01))
  1152. )
  1153. )
  1154. )
  1155. )
  1156. (class_function world_game void addToDeck (group Card card)
  1157. (group
  1158. # check limits, should never happen
  1159. (if (>= this.deckTotal 48)
  1160. (echo "Can't add card to deck")
  1161. # add card to deck
  1162. (group
  1163. (= this.deck[this.deckTotal] card)
  1164. (= this.deckTotal (+ this.deckTotal 1))
  1165. (dd_matrix_copy card.target this.deckMatrix)
  1166. (dd_matrix_translate card.target 0 0 (+ (* -0.003 (+ this.deckTotal 1)) -0.01))
  1167. )
  1168. )
  1169. )
  1170. )
  1171. (class_function world_game void setRosePlayer (group int playerId)
  1172. (group
  1173. # check playerId sanity
  1174. (if (|| (< playerId 0) (>= playerId this.playersTotal))
  1175. (echo "invalid player id")
  1176. # special functionality for user
  1177. (== playerId 0)
  1178. (group
  1179. (= this.rosePlayer playerId)
  1180. (dd_matrix_identity this.roseCard.target)
  1181. (dd_matrix_translate this.roseCard.target 0 2.01 2.1)
  1182. (dd_matrix_rotate this.roseCard.target -90 1 0 0)
  1183. )
  1184. # position rose in front of another player
  1185. (group
  1186. (= this.rosePlayer playerId)
  1187. (dd_matrix_identity this.roseCard.target)
  1188. (dd_matrix_mult this.roseCard.target this.player[playerId].actual)
  1189. (dd_matrix_translate this.roseCard.target 0 2.01 1.9)
  1190. (dd_matrix_rotate this.roseCard.target -90 1 0 0)
  1191. (dd_matrix_rotate this.roseCard.target 180 0 0 1)
  1192. )
  1193. )
  1194. )
  1195. )
  1196. # shuffle all cards in the deck
  1197. (class_function world_game void shuffleDeck (group)
  1198. (group
  1199. (for (def int i 0) (< i this.deckTotal) (= i (+ i 1))
  1200. (group
  1201. (def int target (dd_math_rand this.deckTotal))
  1202. (def ref Card temp)
  1203. (= temp this.deck[i])
  1204. (= this.deck[i] this.deck[target])
  1205. (= this.deck[target] temp)
  1206. (dd_matrix_copy this.deck[i].target this.deckMatrix)
  1207. (dd_matrix_translate this.deck[i].target 0 0 (+ (* -0.003 (+ i 1)) -0.01))
  1208. (dd_matrix_copy this.deck[target].target this.deckMatrix)
  1209. (dd_matrix_translate this.deck[target].target 0 0 (+ (* -0.003 (+ target 1)) -0.01))
  1210. )
  1211. )
  1212. )
  1213. )
  1214. (class_function world_game void applyArrowRotation (group int playerIndex)
  1215. (group
  1216. (= this.arrowRotationTarget (- 0 (* (/ 360.0 this.playersTotal) playerIndex)))
  1217. (if (< this.arrowRotation this.arrowRotationTarget)
  1218. (group
  1219. (= this.arrowRotation (+ this.arrowRotation 360))
  1220. )
  1221. )
  1222. )
  1223. )
  1224. (class_function world_game void applyChooseCard (group int optionIndex)
  1225. (group
  1226. (if (== optionIndex 0)
  1227. (this.setRosePlayer (% (+ this.rosePlayer 1) this.playersTotal))
  1228. (this.setRosePlayer (% (+ this.rosePlayer 3) this.playersTotal))
  1229. )
  1230. )
  1231. )
  1232. (class_function world_game void addAction (group int actionType int playerIndex int valueAmount int delay)
  1233. (group
  1234. (if (>= this.actionsTotal 100)
  1235. (group
  1236. (echo "Max actions reached, cannot add more")
  1237. )
  1238. # else
  1239. (group
  1240. (this.actions[this.actionsTotal].set actionType playerIndex valueAmount delay)
  1241. (= this.actionsTotal (+ this.actionsTotal 1))
  1242. )
  1243. )
  1244. )
  1245. )
  1246. (class_function world_game void removeAction (group)
  1247. (group
  1248. (if (<= this.actionsTotal 0)
  1249. (group
  1250. (echo "No actions to remove")
  1251. )
  1252. (group
  1253. (for (def int i 1) (< i this.actionsTotal) (= i (+ i 1))
  1254. (group
  1255. (def int prevIndex (- i 1))
  1256. (this.actions[prevIndex].set this.actions[i].actionType this.actions[i].playerIndex this.actions[i].value this.actions[i].delay)
  1257. )
  1258. )
  1259. )
  1260. )
  1261. (= this.actionsTotal (- this.actionsTotal 1))
  1262. )
  1263. )
  1264. (class_function world_game void addInjectAction (group int actionType int playerIndex int valueAmount int delay)
  1265. (group
  1266. (if (>= this.injectActionsTotal 100)
  1267. (group
  1268. (echo "Max inject actions reached, cannot add more")
  1269. )
  1270. # else
  1271. (group
  1272. (this.injectActions[this.injectActionsTotal].set actionType playerIndex valueAmount delay)
  1273. (= this.injectActionsTotal (+ this.injectActionsTotal 1))
  1274. )
  1275. )
  1276. )
  1277. )
  1278. (class_function world_game void injectActionsToActions (group)
  1279. (group
  1280. (if (>= (+ this.injectActionsTotal this.actionsTotal) 100)
  1281. (group
  1282. (echo "Can't inject actions, too many")
  1283. )
  1284. # else
  1285. (group
  1286. # move all current actions towards the end of the array, to make room for injected ones
  1287. # current action remains intact
  1288. (for (def int i (- this.actionsTotal 1)) (> i 0) (= i (- i 1))
  1289. (group
  1290. (def int destIndex (+ i this.injectActionsTotal))
  1291. (this.actions[destIndex].set
  1292. this.actions[i].actionType
  1293. this.actions[i].playerIndex
  1294. this.actions[i].value
  1295. this.actions[i].delay
  1296. )
  1297. )
  1298. )
  1299. # add injected actions in that space
  1300. (for (def int i 0) (< i this.injectActionsTotal) (= i (+ i 1))
  1301. (group
  1302. (def int actIndex (+ i 1))
  1303. (this.actions[actIndex].set
  1304. this.injectActions[i].actionType
  1305. this.injectActions[i].playerIndex
  1306. this.injectActions[i].value
  1307. this.injectActions[i].delay
  1308. )
  1309. )
  1310. )
  1311. # reset injected actions array
  1312. (= this.actionsTotal (+ this.actionsTotal this.injectActionsTotal))
  1313. (= this.injectActionsTotal 0)
  1314. )
  1315. )
  1316. )
  1317. )
  1318. (class_function world_game void grabRose (group)
  1319. (group
  1320. # rose is flat, grab it!
  1321. (if this.isRoseFlat
  1322. (group
  1323. (= this.isRoseFlat 0)
  1324. (this.player[this.rosePlayer].addCard this.roseCard)
  1325. )
  1326. )
  1327. )
  1328. )
  1329. # game actions
  1330. (class_function GameAction void create (group)
  1331. (group
  1332. (= this.actionType -1)
  1333. (= this.playerIndex -1)
  1334. (= this.value 0)
  1335. )
  1336. )
  1337. (class_function GameAction void clean (group)
  1338. (group
  1339. )
  1340. )
  1341. (class_function GameAction void set (group int actionType int playerIndex int valueAmount int delay)
  1342. (group
  1343. (= this.actionType actionType)
  1344. (= this.playerIndex playerIndex)
  1345. (= this.value valueAmount)
  1346. (= this.delay delay)
  1347. )
  1348. )