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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685
|
/* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008-2014 Jimmy Christensen ( dusted at dusted dot dk )
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_image.h>
#include <math.h>
#include <string.h>
#include <list>
#include <vector>
#include <sys/time.h>
#include <sys/stat.h>
#include <dirent.h>
#ifdef WIN32
#include <windows.h>
#include <GL/glext.h>
#endif
/* ******************************************** *
Here are the compile-time options !! ;)
* ******************************************** */
//WIN32
#ifndef DATADIR
#define DATADIR "themes/"
#endif
//To disable sound support:
//#define NOSOUND
#ifdef WITH_WIIUSE
#include <wiiuse.h>
#define MAX_WIIMOTES 1
#endif
#ifndef NOSOUND
#define MIX_CHANNELS 16
#include <SDL/SDL_mixer.h>
#endif
#define VERSION "1.02"
#define SAVEGAMEVERSION 2
#include "declerations.h"
#define PI 3.14159265
#define RAD 6.28318531
#define BALL_MAX_DEGREE 2.61799388 //150+15 = 165 degrees
#define BALL_MIN_DEGREE 0.261799388 //15 degrees
#define FALSE 0
#define TRUE 1
//#define debugBall 1
// #define DEBUG_DRAW_BALL_QUAD
#define PO_COIN 0
#define PO_BIGBALL 1
#define PO_NORMALBALL 2
#define PO_SMALLBALL 3
#define PO_EXPLOSIVE 4
#define PO_GLUE 5
#define PO_MULTIBALL 6
#define PO_GROWPADDLE 7
#define PO_SHRINKPADDLE 8
#define PO_AIM 9
#define PO_GUN 10
#define PO_THRU 11
#define PO_LASER 12
#define PO_LIFE 13
#define PO_DIE 14
#define PO_DROP 15
#define PO_DETONATE 16
#define PO_EXPLOSIVE_GROW 17
#define PO_EASYBRICK 18
#define PO_NEXTLEVEL 19
#define PO_AIMHELP 20
//"Max powerups"
#define MAXPOTEXTURES 21
#define EASY 0
#define NORMAL 1
#define HARD 2
//Sound effects
#define SND_START 0
#define SND_BALL_HIT_BORDER 1
#define SND_BALL_HIT_PADDLE 2
#define SND_NORM_BRICK_BREAK 3
#define SND_EXPL_BRICK_BREAK 4
#define SND_GLASS_BRICK_HIT 5
#define SND_GLASS_BRICK_BREAK 6
#define SND_CEMENT_BRICK_HIT 7
#define SND_PO_HIT_BORDER 8
#define SND_GOOD_PO_HIT_PADDLE 9
#define SND_EVIL_PO_HIT_PADDLE 10
#define SND_SHOT 11
#define SND_DIE 12
#define SND_NEXTLEVEL 13
#define SND_GAMEOVER 14
#define SND_MENUCLICK 15
#define SND_DOOM_BRICK_BREAK 16
#define SND_GLUE_BALL_HIT_PADDLE 17
#define SND_INVISIBLE_BRICK_APPEAR 18
#define SND_HIGHSCORE 19
#define SND_BUY_POWERUP 20
#define SND_NORM_BRICK_BREAKB 21
#define SND_NORM_BRICK_BREAKC 22
#define SND_NORM_BRICK_BREAKD 23
#define SND_NORM_BRICK_BREAKE 24
#define SNDSAMPLES 25
using namespace std;
void writeSettings();
bool initScreen();
void initNewGame();
void pauseGame();
void resumeGame();
float rndflt(float total, float negative);
class ball;
class paddle_class;
float bounceOffAngle(GLfloat width, GLfloat posx, GLfloat hitx);
int globalTicks;
float globalMilliTicks;
int nonpausingGlobalTicks;
float nonpausingGlobalMilliTicks;
int globalTicksSinceLastDraw;
float globalMilliTicksSinceLastDraw;
struct pos {
GLfloat x;
GLfloat y;
};
struct difficultyStruct {
GLfloat ballspeed[3];
GLfloat maxballspeed[3];
GLfloat hitbrickinc[3];
GLfloat hitpaddleinc[3];
GLfloat slowdown[3];
GLfloat speedup[3];
};
struct difficultyStruct static_difficulty, difficulty;
struct settings {
string sndTheme,gfxTheme,lvlTheme;
bool cfgRes[2];
int resx;
int resy;
int fps;
bool showClock;
bool fullscreen;
bool showBg;
bool sound;
bool stereo;
bool eyeCandy;
bool particleCollide;
//Add to menu:
SDLKey keyLeft, keyRight, keyShoot, keyNextPo, keyPrevPo, keyBuyPo;
float controlAccel;
float controlStartSpeed;
float controlMaxSpeed;
bool joyEnabled, joyIsDigital;
int JoyCalMin, JoyCalMax, JoyCalHighJitter, JoyCalLowJitter;
};
struct scrollInfoScruct {
bool drop; //0 right, 1 left, 2 up, 3 down
unsigned int dropspeed;
unsigned int lastTick; // what was the time last they moved
};
struct privFileStruct {
string programRoot;
string settingsFile;
string saveGameFile;
string highScoreFile;
string screenshotDir;
};
struct privFileStruct privFile;
struct vars {
bool titleScreenShow;
int frame;
int halfresx;
int halfresy;
GLfloat glunits_per_xpixel, glunits_per_ypixel;
bool paused;
int menu;
int menuItem;
bool menuPressed;
int menuNumItems;
int menuJoyCalStage;
bool quit;
bool wiiConnect;
int numlevels;
bool transition_half_done;
bool clearScreen;
bool idiotlock; //transition
bool bricksHit; //tells the mainloop if it should copy the updated array of brick status.
GLfloat averageBallSpeed;
int showHighScores;
bool enterSaveGameName;
bool startedPlaying;
int effectnum;
struct scrollInfoScruct scrollInfo;
};
//Ting der har med spillogik at gøre
struct gameVars {
bool shopNextItem, shopPrevItem, shopBuyItem; //When set to 1 shop goes next or prev
int deadTime; //I hvor mange millisekunder har bolden intet rørt
bool nextlevel;
bool gameOver;
bool newLife;
bool newLevel; //Start en ny level
int bricksleft; //hvor mange brikker er der tilbage
};
struct gameVars gVar;
struct player_struct {
int coins;
int multiply;
bool powerup[MAXPOTEXTURES];
bool explodePaddle; //This lock makes the paddle explode and it won't come back until newlife.
int level;
int lives;
int difficulty;
int score;
};
int listSaveGames(string slotName[]);
void loadGame(int slot);
void saveGame(int slot, string name);
struct settings setting;
struct player_struct player;
struct player_struct SOLPlayer;
struct vars var;
typedef GLfloat texPos[8];
#ifndef uint // WIN32
typedef unsigned int uint;
#endif
struct texProp {
GLuint texture; //Den GLtexture der er loaded
GLfloat xoffset;// Hvor stort er springet mellem hver subframe
GLfloat yoffset; //
int cols,rows; //hvor mange rækker og kolonner er der i denne textur
int ticks;
uint frames; //This many frames in each se
bool bidir; //Går Looper den fra 0 -> X - 0 eller fra 0 -> X -> 0
bool playing;
bool padding; //Bit of a nasty hack, but if a texture is padded with 1 pixel around each frame, this have to be set to 1
float pxw, pxh; //pixels width, and height
GLfloat glTexColorInfo[4];
GLfloat glParColorInfo[3]; //This and above replaced object::color and particle colors
string fileName; //Quite the fugly.. This will be set by readTexProps();
};
/* This function attempts to open path
It will first look for the file in ~/.config/sdl-ball/themes/theme/path
Then in DATADIR/themes/setting.theme/path
This way, each user can even override a part of a theme that exist both
in their own homedir and in the global themes dir.
If still no luck it will use the file from DATADIR/path
It will return the full qualified filename */
string useTheme(string path, string theme)
{
struct stat st;
string name;
if(theme.compare("default") != 0)
{
//Try in ~/.config/sdl-ball/themes/themename
name = privFile.programRoot+"/themes/"+ theme+"/"+path;
if( stat(name.data(), &st) == 0)
{
return(name);
}
//Try in DATADIR/themename/
name = DATADIR + theme+"/"+path;
if( stat(name.data(), &st) == 0)
{
return(name);
}
}
//Fall back on default file.
name = DATADIR"default/" + path;
if( stat(name.data(), &st) == 0)
{
return(name);
} else {
cout << "File Error: Could not find '" << path << "'" << endl;
return(name);
}
}
struct themeInfo {
string name;
bool snd,gfx,lvl,valid; //Valid means that there seems to be data of some kind (ie. not just an empty folder)
};
/* This function looks in ~/.config/sdl-ball/themes/
and in DATADIR/themes
for directories, it looks inside the dir
to decide if a theme contains:
gfx folder - this theme contains graphics
snd folder - this theme contains sound
level.txt - this theme contains levels.
It will return info even if the theme is not valid
It returns a vector of structs with info */
vector<struct themeInfo> getThemes() {
DIR *pdir;
struct dirent *pent;
struct stat st;
struct themeInfo ti;
string themeDir;
string temp;
vector<struct themeInfo> v;
for(int i=0; i < 2; i++)
{
if(i==0)
{
themeDir = privFile.programRoot + "/themes";
} else if(i==1)
{
themeDir = DATADIR;
}
pdir = opendir(themeDir.data());
if (pdir)
{
themeDir.append("/");
while ((pent=readdir(pdir))){
temp=pent->d_name;
//We're not going to read hidden files
if(temp[0] != '.')
{
temp= themeDir + pent->d_name;
//Check if file is a dir.
if(stat(temp.data(), &st) == 0)
{
ti.name = pent->d_name;
ti.valid = 0;
//Check if theme have graphics
temp=themeDir + pent->d_name +"/gfx";
if(stat(temp.data(), &st) == 0)
{
ti.gfx=1;
ti.valid=1;
} else {
ti.gfx=0;
}
//Check if theme have sound
temp=themeDir + pent->d_name +"/snd";
if(stat(temp.data(), &st) == 0)
{
ti.snd=1;
ti.valid=1;
} else {
ti.snd=0;
}
//Check if theme have levels
temp=themeDir + pent->d_name +"/levels.txt";
if(stat(temp.data(), &st) == 0)
{
ti.lvl=1;
ti.valid=1;
} else {
ti.lvl=0;
}
v.push_back(ti);
}
}
}
}
}
return(v);
}
#include "text.cpp"
glTextClass *glText; //Pointer to the object, since we can't init (load fonts) because the settings have not been read yet.
class textureClass {
private:
float age; //Hvor gammel er den frame vi er ved?
bool dir; //hvis dette er en animation der går frem og tilbage hvilken retning
uint lastframe; //check om det er den samme frame som sidst, så vi kan vide om vis skal opdatere cords
public:
uint frame; //hvilken frame er vi nået til i texturen (den er public så vi kan lave offset)
bool playing; //spiller vi?
bool firstFrame; //If this is the first frame
texPos pos; //Kordinater for den frame på texturen der er nu
texProp prop; //Properties for den textur som dette objekt har
textureClass() {
age=10000;
firstFrame=1;
lastframe=1000;
frame=1;
dir=0;
}
void play()
{
int col=0,row=0;
if(prop.playing)
{
//Skal vi skifte frame?
age += globalTicksSinceLastDraw;
if(age >= prop.ticks) //Denne frame har været vist længe nok
{
age=0.0;
if(!dir)
{
if(frame == prop.frames)
{
if(prop.bidir)
{
dir=1;
} else {
frame=1;
}
} else {
frame++;
}
}
if(dir) {
if(frame == 1)
{
dir=0;
frame=2;
} else {
frame--;
}
}
}
}
uint f=0;
if(frame != lastframe || firstFrame)
{
lastframe=frame;
firstFrame=0;
//hvor mange kolonner er der på en række
for(row=0; row < prop.rows; row++)
{
for(col=0; col < prop.cols; col ++)
{
f++;
if(f == frame)
{
//Øverst Venstre
pos[0] = (prop.xoffset*(float)col); //0.0;
pos[1] = (prop.yoffset*(float)row);//0.0;
//Øverst højre
pos[2] = (prop.xoffset*(float)col) + prop.xoffset;
pos[3] = (prop.yoffset*(float)row);//0.0;
//Nederst højre
pos[4] = (prop.xoffset*(float)col) + prop.xoffset; // 1
pos[5] = (prop.yoffset*(float)row) + prop.yoffset; // 1
//Nederst venstre
pos[6] = (prop.xoffset*(float)col);//0.0;
pos[7] = (prop.yoffset*(float)row) + prop.yoffset; //1
if(prop.padding)
{
pos[0] += 1.0 / prop.pxw;
pos[1] += 1.0 / prop.pxh;
pos[2] -= 1.0 / prop.pxw;
pos[3] += 1.0 / prop.pxh;
pos[4] -= 1.0 / prop.pxw;
pos[5] -= 1.0 / prop.pxh;
pos[6] += 1.0 / prop.pxw;
pos[7] -= 1.0 / prop.pxh;
}
}
}
}
}
}
};
/* This function reads textureProperties from fileName
and applies them to *tex */
class textureManager {
public:
bool load(string file, textureClass & tex)
{
SDL_Surface *temp = NULL;
GLint maxTexSize;
GLuint glFormat = GL_RGBA;
if(file.substr(file.length()-3,3).compare("jpg") == 0)
{
glFormat = GL_RGB;
}
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
temp = IMG_Load(file.data());
if(temp == NULL)
{
cout << "Texture manager: " << file << " : "<< SDL_GetError() << endl;
SDL_FreeSurface( temp );
return(FALSE);
}
//Hvis større end tilladt:
if(temp->w > maxTexSize)
{
cout << "Texture manager: '" << file << "' texturesize too large." << endl;
SDL_FreeSurface( temp );
return(FALSE);
}
glGenTextures(1, &tex.prop.texture);
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, temp->w, temp->h, 0, glFormat, GL_UNSIGNED_BYTE, temp->pixels);
tex.prop.pxw = temp->w;
tex.prop.pxh = temp->h;
SDL_FreeSurface( temp );
return(TRUE);
}
void readTexProps(string fileName, textureClass & tex)
{
char rgba[4][5];
ifstream f;
string line,set,val;
f.open( fileName.data() );
if(f.is_open())
{
while(!f.eof())
{
getline(f, line);
if(line.find('=') != string::npos)
{
set=line.substr(0,line.find('='));
val=line.substr(line.find('=')+1);
if(set=="xoffset")
{
tex.prop.xoffset=atof(val.data());
} else if(set=="yoffset")
{
tex.prop.yoffset=atof(val.data());
} else if(set=="cols")
{
tex.prop.cols=atoi(val.data());
} else if(set=="rows")
{
tex.prop.rows=atoi(val.data());
} else if(set=="ticks")
{
tex.prop.ticks=atoi(val.data());
} else if(set=="frames")
{
tex.prop.frames=atoi(val.data());
} else if(set=="bidir")
{
tex.prop.bidir=atoi(val.data());
} else if(set=="playing")
{
tex.prop.playing=atoi(val.data());
} else if(set=="padding")
{
tex.prop.padding=atoi(val.data());
} else if(set=="texcolor")
{
//Color in hex RGBA
//Example:color=FFFFFFFF
sprintf(rgba[0], "0x%c%c", val[0], val[1]);
sprintf(rgba[1], "0x%c%c", val[2], val[3]);
sprintf(rgba[2], "0x%c%c", val[4], val[5]);
sprintf(rgba[3], "0x%c%c", val[6], val[7]);
tex.prop.glTexColorInfo[0] = 0.003921569 * strtol(rgba[0], NULL,16);
tex.prop.glTexColorInfo[1] = 0.003921569 * strtol(rgba[1], NULL,16);
tex.prop.glTexColorInfo[2] = 0.003921569 * strtol(rgba[2], NULL,16);
tex.prop.glTexColorInfo[3] = 0.003921569 * strtol(rgba[3], NULL,16);
} else if(set=="parcolor")
{
//Color in hex RGBA
//Example:color=FFFFFFFF
sprintf(rgba[0], "0x%c%c", val[0], val[1]);
sprintf(rgba[1], "0x%c%c", val[2], val[3]);
sprintf(rgba[2], "0x%c%c", val[4], val[5]);
tex.prop.glParColorInfo[0] = 0.003921569 * strtol(rgba[0], NULL,16);
tex.prop.glParColorInfo[1] = 0.003921569 * strtol(rgba[1], NULL,16);
tex.prop.glParColorInfo[2] = 0.003921569 * strtol(rgba[2], NULL,16);
} else if(set=="file")
{
tex.prop.fileName = val;
} else {
cout << "Error: '"<<fileName<<"'invalid setting '"<< set <<"' with value '" << val <<"'"<<endl;
}
}
}
//Load the texture if we have a filename.
if(tex.prop.fileName.length() > 1)
{
string name = "gfx/"+tex.prop.fileName;
load(useTheme(name,setting.gfxTheme), tex);
}
} else {
cout << "readTexProps: Cannot open '" << fileName << "'"<<endl;
}
}
};
#include "sound.cpp"
soundClass soundMan; //Public object so all objects can use it
#include "menu.cpp"
#include "scoreboard.cpp"
class object {
public:
// GLfloat color[3];
GLfloat opacity; //This is still used, because it can then be reset, and it's used for fading out bricks (i think)
GLfloat posx, posy;
GLfloat width,height;
GLuint dl; //opengl display list
bool active;
bool collide;
bool reflect; //NOTE: use this for bricks that are not going to reflect the ball? (trap brick? :D)
textureClass tex;
};
class paddle_class : public object {
private:
GLfloat growspeed;
GLfloat destwidth;
GLfloat aspect; //så meget stiger højden i forhold til bredden
bool growing;
public:
bool dead;
textureClass *layerTex;
paddle_class ()
{
init();
growing=0;
growspeed=0.05f;
aspect = 0.2f;
}
void init()
{
posy = -1.15;
width=0.1;
height=0.02;
dead=0;
}
void grow(GLfloat width)
{
destwidth = width;
growing = 1;
}
void draw()
{
if(!dead)
{
if(player.powerup[PO_DIE])
{
player.powerup[PO_DIE]=0;
dead=1;
width=0.0;
height=0.0;
}
if(growing)
{
GLfloat ix = growspeed * globalTicksSinceLastDraw;
width += ix;
if(width >= destwidth)
{
width = destwidth;
height = aspect*destwidth;
growing=0;
}
}
glLoadIdentity();
glTranslatef( posx, posy, -3.0 );
tex.play();
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glColor4f( tex.prop.glTexColorInfo[0], tex.prop.glTexColorInfo[1], tex.prop.glTexColorInfo[2], tex.prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(tex.pos[0], tex.pos[1]); glVertex3f(-width,height, 0.0f );
glTexCoord2f(tex.pos[2], tex.pos[3]); glVertex3f( width,height, 0.0f );
glTexCoord2f(tex.pos[4], tex.pos[5]); glVertex3f( width,-height, 0.0f );
glTexCoord2f(tex.pos[6], tex.pos[7]); glVertex3f(-width,-height, 0.0f );
glEnd( );
//Hvis glue?
if(player.powerup[PO_GLUE])
{
glBindTexture(GL_TEXTURE_2D, layerTex[0].prop.texture);
glColor4f( layerTex[0].prop.glTexColorInfo[0], layerTex[0].prop.glTexColorInfo[1], layerTex[0].prop.glTexColorInfo[2], layerTex[0].prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(-width, height, 0.0f );
glTexCoord2f(1.0f, 0.0f); glVertex3f( width, height, 0.0f );
glTexCoord2f(1.0f, 0.99f); glVertex3f( width,-height, 0.0f );
glTexCoord2f(0.0f, 0.99f); glVertex3f(-width,-height, 0.0f );
glEnd( );
}
//Hvis gun
if(player.powerup[PO_GUN])
{
layerTex[1].play();
glBindTexture(GL_TEXTURE_2D, layerTex[1].prop.texture);
glColor4f( layerTex[1].prop.glTexColorInfo[0], layerTex[1].prop.glTexColorInfo[1], layerTex[1].prop.glTexColorInfo[2], layerTex[1].prop.glTexColorInfo[3] );
glBegin( GL_QUADS );
glTexCoord2f(layerTex[1].pos[0], layerTex[1].pos[1]); glVertex3f(-width, height*4, 0.0f );
glTexCoord2f(layerTex[1].pos[2], layerTex[1].pos[3]); glVertex3f( width, height*4, 0.0f );
glTexCoord2f(layerTex[1].pos[4], layerTex[1].pos[5]-0.01); glVertex3f( width,height, 0.0f );
glTexCoord2f(layerTex[1].pos[6], layerTex[1].pos[7]-0.01); glVertex3f(-width,height, 0.0f );
glEnd( );
}
}
}
};
//nasty fix to a problem
int nbrick[23][26];
int updated_nbrick[23][26];
class brick;
void makeExplosive(brick & b);
textureClass * texExplosiveBrick; //NOTE:Ugly
class brick : public object {
public:
int score; //Hvor meget gir den
bool destroytowin; // Skal den smadres for at man kan vinde?
char powerup;
char type;
GLfloat fade; //hvor meget brik
GLfloat fadespeed;
GLfloat zoomspeed;
GLfloat zoom;
bool isdyingnormally;
bool isexploding; //springer den i luften
int row; //what row is this brick in
int bricknum; //brick in this row
int hitsLeft; //Hvor mange gange skal denne brik rammes før den dør?
bool justBecomeExplosive; //If this brick just become a explosive one.
bool n(int dir)
{
switch(dir)
{
case 0: //Er der en brik til venstre for dig?
if(bricknum > 0)
{
if(nbrick[row][bricknum-1] != -1)
return(1);
}
break;
case 1: //Er der en brik til højre for dig?
if(bricknum < 25) //26
{
if(nbrick[row][bricknum+1] != -1)
return(1);
}
break;
case 2: //Er der en brik Ovenpå dig
if(row > 0)
{
if(nbrick[row-1][bricknum] != -1)
return(1);
}
break;
case 3: //Er der en brik nedenunder dig
if(row < 22) //23
{
if(nbrick[row+1][bricknum] != -1)
return(1);
}
break;
}
return(0);
}
void hit(effectManager & fxMan, pos poSpawnPos, pos poSpawnVel, bool ballHitMe);
void draw(brick bricks[], effectManager & fxMan)
{
if(isdyingnormally)
{
fade -= fadespeed * globalMilliTicksSinceLastDraw;
opacity = fade;
zoom -= zoomspeed * globalMilliTicksSinceLastDraw;
if(fade < 0.0)
active=0;
}
if(isexploding && !var.paused)
{
fade -= 7.0 * globalMilliTicksSinceLastDraw;
opacity = fade;
if(fade<0.0)
{
active=0;
pos spos,svel;
spos.x=posx;
spos.y=posy;
if(bricknum > 0)
{
if(nbrick[row][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(bricknum < 25)
{
if(nbrick[row][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
if(row > 0)
{
if(nbrick[row-1][bricknum] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum]].hit(fxMan,spos,svel,0);
}
}
if(row < 22)
{
if(nbrick[row+1][bricknum] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum]].hit(fxMan,spos,svel,0);
}
}
if(row > 0 && bricknum > 0)
{
if(nbrick[row-1][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(row > 0 && bricknum < 25)
{
if(nbrick[row-1][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row-1][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
if(row < 22 && bricknum > 0)
{
if(nbrick[row+1][bricknum-1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum-1]].hit(fxMan,spos,svel,0);
}
}
if(row < 22 && bricknum < 25)
{
if(nbrick[row+1][bricknum+1] != -1)
{
svel.x=rndflt(2,0)/3.0;
svel.y=rndflt(2,0)/3.0;
bricks[nbrick[row+1][bricknum+1]].hit(fxMan,spos,svel,0);
}
}
}
}
tex.play();
glColor4f( tex.prop.glTexColorInfo[0], tex.prop.glTexColorInfo[1], tex.prop.glTexColorInfo[2], opacity );
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(tex.pos[0],tex.pos[1]);glVertex3f( posx + (-0.0616*zoom), posy + (0.035*zoom), 0.00 ); // øverst venst
glTexCoord2f(tex.pos[2],tex.pos[3]);glVertex3f( posx + ( 0.0616*zoom), posy + (0.035*zoom), 0.00 ); // øverst højre
glTexCoord2f(tex.pos[4],tex.pos[5]);glVertex3f( posx + ( 0.0616*zoom), posy + (-0.035*zoom), 0.00 ); // nederst højre
glTexCoord2f(tex.pos[6],tex.pos[7]);glVertex3f( posx + (-0.0616*zoom), posy + (-0.035*zoom), 0.00 ); // nederst venstre
glEnd( );
}
void growExplosive(brick bricks[])
{
if(type!='B' || justBecomeExplosive)
{
return;
}
if(bricknum > 0)
{
if(nbrick[row][bricknum-1] != -1)
{
makeExplosive(bricks[nbrick[row][bricknum-1]]);
}
}
if(bricknum < 25)
{
if(nbrick[row][bricknum+1] != -1)
{
makeExplosive(bricks[nbrick[row][bricknum+1]]);
}
}
if(row > 0)
{
if(nbrick[row-1][bricknum] != -1)
{
makeExplosive(bricks[nbrick[row-1][bricknum]]);
}
}
if(row < 22)
{
if(nbrick[row+1][bricknum] != -1)
{
makeExplosive(bricks[nbrick[row+1][bricknum]]);
}
}
if(row > 0 && bricknum > 0)
{
if(nbrick[row-1][bricknum-1] != -1)
{
makeExplosive(bricks[nbrick[row-1][bricknum-1]]);
}
}
if(row > 0 && bricknum < 25)
{
if(nbrick[row-1][bricknum+1] != -1)
{
makeExplosive(bricks[nbrick[row-1][bricknum+1]]);
}
}
if(row < 22 && bricknum > 0)
{
if(nbrick[row+1][bricknum-1] != -1)
{
makeExplosive(bricks[nbrick[row+1][bricknum-1]]);
}
}
if(row < 22 && bricknum < 25)
{
if(nbrick[row+1][bricknum+1] != -1)
{
makeExplosive(bricks[nbrick[row+1][bricknum+1]]);
}
}
}
void breakable()
{
if(type == '3')
{
score=300;
hitsLeft=1;
type='1'; //hehe..
tex.frame=2;
tex.play();
} else if(type=='4')
{
hitsLeft=1;
tex.frame=2;
tex.play();
} else if(type=='9')
{
hitsLeft=1;
tex.frame=3;
tex.play();
}
}
};
void makeExplosive(brick & b)
{
if(b.type != 'B')
{
b.type='B';
b.tex=*texExplosiveBrick;
//NOTE: for some reason, the color of the object was changed, why??
b.justBecomeExplosive=1;
}
}
#include "loadlevel.cpp"
class moving_object : public object {
public:
GLfloat xvel,yvel,velocity;
moving_object () {
xvel=0.0;
yvel=0.0;
}
};
#include "effects.cpp"
#include "background.cpp"
void spawnpowerup(char powerup, pos a, pos b);
class bulletsClass {
private:
moving_object bullets[16];
public:
int active;
bulletsClass(textureClass & texBullet)
{
int i;
for(i=0; i < 16; i++)
{
bullets[i].active=0;
bullets[i].tex = texBullet;
bullets[i].width = 0.02;
bullets[i].height = 0.02;
}
}
void shoot(pos p)
{
int i;
//Find ledig bullet
for(i=0; i < 16; i++)
{
if(!bullets[i].active)
{
soundMan.add(SND_SHOT, p.x);
bullets[i].active=1;
bullets[i].posx = p.x;
bullets[i].posy = p.y;
bullets[i].xvel =0;
bullets[i].yvel =1.0;
break;
}
}
}
void move()
{
int i;
for(i=0; i < 16; i++)
{
if(bullets[i].active)
{
//Flyt
bullets[i].posy += bullets[i].yvel * globalMilliTicks;
}
}
}
void draw()
{
int i;
glColor4f(1,1,1,1);
for(i=0; i < 16; i++)
{
if(bullets[i].active)
{
//draw
bullets[i].tex.play();
glLoadIdentity();
glTranslatef( bullets[i].posx, bullets[i].posy, -3.0 );
glBindTexture(GL_TEXTURE_2D, bullets[i].tex.prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(bullets[i].tex.pos[0],bullets[i].tex.pos[1]); glVertex3f( -bullets[i].width, bullets[i].height, 0.0 );
glTexCoord2f(bullets[i].tex.pos[2],bullets[i].tex.pos[3]); glVertex3f( bullets[i].width, bullets[i].height, 0.0 );
glTexCoord2f(bullets[i].tex.pos[4],bullets[i].tex.pos[5]); glVertex3f( bullets[i].width,-bullets[i].height, 0.0 );
glTexCoord2f(bullets[i].tex.pos[6],bullets[i].tex.pos[7]); glVertex3f( -bullets[i].width,-bullets[i].height, 0.0 );
glEnd( );
}
}
}
void clear()
{
int i;
for(i=0; i < 16; i++)
{
bullets[i].active=0;
}
}
void coldet(brick & b, effectManager & fxMan)
{
int i;
bool hit;
pos v,p;
v.x=0;
v.y=bullets[0].xvel;
for(i=0; i < 16; i++)
{
if(bullets[i].active)
{
hit=0;
//y
if(bullets[i].posy+bullets[i].height/10.0 > b.posy-b.height && bullets[i].posy+bullets[i].height/10.0 < b.posy+b.height)
{
p.x = b.posx;
p.y = b.posy;
//Venstre side:
if(bullets[i].posx > b.posx-b.width && bullets[i].posx < b.posx+b.width)
{
hit=1;
}
if(hit)
{
b.hit(fxMan, p, v,1);
if(!player.powerup[PO_THRU])
{
bullets[i].active=0;
}
p.x = bullets[i].posx;
p.y = bullets[i].posy;
if(setting.eyeCandy)
{
fxMan.set(FX_VAR_TYPE, FX_SPARKS);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_LIFE, 1300);
fxMan.set(FX_VAR_NUM, 16);
fxMan.set(FX_VAR_SIZE, 0.015f);
fxMan.set(FX_VAR_SPEED, 0.4f);
fxMan.set(FX_VAR_GRAVITY, 1.0f);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
fxMan.spawn(p);
}
}
} else if(bullets[i].posy > 1.6)
{
bullets[i].active=0;
}
}
}
}
};
void brick::hit(effectManager & fxMan, pos poSpawnPos, pos poSpawnVel, bool ballHitMe)
{
pos p,s;
if(type!='3' || player.powerup[PO_THRU])
hitsLeft--;
//We don't want to play a sound if this brick is not an explosive, and was hit by an explosion
if(ballHitMe || type=='B')
{
if(type=='3') //cement
{
soundMan.add(SND_CEMENT_BRICK_HIT, posx);
} else if(type=='4' || type=='9') //glass or invisible
{
if(hitsLeft == 2)
{
soundMan.add(SND_INVISIBLE_BRICK_APPEAR, posx);
} else if(hitsLeft == 1)
{
soundMan.add(SND_GLASS_BRICK_HIT, posx);
} else {
soundMan.add(SND_GLASS_BRICK_BREAK, posx);
}
} else if(type=='B') //explosive
{
soundMan.add(SND_EXPL_BRICK_BREAK, posx);
} else if(type=='C') //Doom brick
{
soundMan.add(SND_DOOM_BRICK_BREAK, posx);
} else { //All the other bricks
soundMan.add(SND_NORM_BRICK_BREAK, posx);
}
}
if(type != '3' || player.powerup[PO_THRU])
{
//Brick was hit, dont do anything
if(isdyingnormally || isexploding)
{
return;
}
player.score += (brick::score*player.multiply)* var.averageBallSpeed; //Speed bonus
if(hitsLeft < 1 || type == 'B') //Hvis brikken er explosiv kan den ikke have nogle hits tilbage
{
collide=0;
updated_nbrick[row][bricknum]=-1;
var.bricksHit = 1;
gVar.deadTime=0;
spawnpowerup(powerup, poSpawnPos, poSpawnVel);
powerup='0';
if(setting.eyeCandy)
{
p.x=posx;
p.y=posy;
s.x=width*2;
s.y=height*2;
fxMan.set(FX_VAR_TYPE, FX_PARTICLEFIELD);
fxMan.set(FX_VAR_COLDET, 1);
fxMan.set(FX_VAR_LIFE, 1300);
fxMan.set(FX_VAR_NUM, 20);
fxMan.set(FX_VAR_SIZE, 0.03f);
fxMan.set(FX_VAR_SPEED, 0.6f);
fxMan.set(FX_VAR_GRAVITY, 0.7f);
fxMan.set(FX_VAR_RECTANGLE, s);
fxMan.set(FX_VAR_COLOR, tex.prop.glParColorInfo[0],tex.prop.glParColorInfo[1],tex.prop.glParColorInfo[2]);
fxMan.spawn(p);
}
if(type=='B')
{
isexploding=1;
if(setting.eyeCandy)
{
p.x = posx;
p.y = posy;
fxMan.set(FX_VAR_TYPE, FX_PARTICLEFIELD);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_LIFE, 1200);
fxMan.set(FX_VAR_NUM, 10);
fxMan.set(FX_VAR_SIZE, 0.08f);
fxMan.set(FX_VAR_SPEED, 0.4f);
fxMan.set(FX_VAR_GRAVITY, -1.3f);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
fxMan.spawn(p);
}
} else {
isdyingnormally=1;
}
} else { //No hits left
tex.frame++;
tex.play();
} //Hits left
}
}
glAnnounceTextClass announce;
//Slet mig måske
float abs2(float x)
{
if (x<0) {return -x;}
return x;
}
int LinesCross(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3, GLfloat *linx, GLfloat *liny)
{
float d=(x1-x0)*(y3-y2)-(y1-y0)*(x3-x2);
if (abs2(d)<0.001f) {return -1;}
float AB=((y0-y2)*(x3-x2)-(x0-x2)*(y3-y2))/d;
if (AB>0.0 && AB<1.0)
{
float CD=((y0-y2)*(x1-x0)-(x0-x2)*(y1-y0))/d;
if (CD>0.0 && CD<1.0)
{
*linx=x0+AB*(x1-x0);
*liny=y0+AB*(y1-y0);
return 1;
}
}
return 0;
}
//Leaves an trail of the ball
class tracer {
private:
GLfloat x[100], y[100], r[100], g[100], b[100], a[100],s[100], cr,cg,cb;
bool active[100];
int color;
GLfloat lastX, lastY; //Last position where we spawned one
public:
GLfloat height, width;
// GLuint texture;
textureClass *tex;
int len;
void draw()
{
int i;
for(i=0; i < len; i++)
{
if(active[i])
{
a[i] -= 4.0*globalMilliTicksSinceLastDraw;
s[i] += 4.0*globalMilliTicksSinceLastDraw;
if(a[i] < 0.0)
active[i]=0;
tex->play();
glBindTexture(GL_TEXTURE_2D, tex->prop.texture);
glLoadIdentity();
glTranslatef(x[i],y[i],-3.0);
glColor4f(r[i], g[i], b[i], a[i]);
glBegin( GL_QUADS );
glTexCoord2f(tex->pos[0],tex->pos[1]);glVertex3f( -width*s[i], height*s[i], 0.00 ); // øverst venst
glTexCoord2f(tex->pos[2],tex->pos[3]);glVertex3f( width*s[i], height*s[i], 0.00 ); // øverst højre
glTexCoord2f(tex->pos[4],tex->pos[5]);glVertex3f( width*s[i],-height*s[i], 0.00 ); // nederst højre
glTexCoord2f(tex->pos[6],tex->pos[7]);glVertex3f( -width*s[i],-height*s[i], 0.00 ); // nederst venstre
glEnd( );
}
}
}
void colorRotate(bool explosive, GLfloat c[])
{
color++;
if(color > 5)
color=0;
if(!explosive)
{
cr=c[0];
cg=c[1];
cb=c[2];
} else {
cr=1.0;
cg=0.6;
cb=0.0;
}
}
tracer()
{
len=100;
lastX=0;
lastY=0;
cr=1;
cg=0;
cb=0;
height = 0.01;
width = 0.01;
int i;
for(i=0; i < 100; i++)
{
active[i]=0;
}
}
void update(GLfloat nx, GLfloat ny)
{
//If long enough away
GLfloat dist = sqrt( pow(nx-lastX, 2) + pow(ny-lastY, 2) );
if(dist > 0.01)
{
lastX = nx;
lastY = ny;
//find a non-active trail-part
int i;
for(i=0; i < len; i++)
{
if(!active[i])
{
active[i]=1;
a[i]=1.0; //tweak me
x[i]=nx;
y[i]=ny;
s[i]=1.0;
r[i]=cr;
g[i]=cg;
b[i]=cb;
break;
}
}
}
}
};
class ball : public moving_object {
private:
GLfloat rad;
bool growing,shrinking;
GLfloat destwidth, growspeed;
public:
tracer tail;
bool explosive; //Makes brick explosive (to get a explosion effect) and explode it
bool glued; //Sidder vi fast på padden for øjeblikket?
GLfloat gluedX;
//Variabler med forududregnede værdier
GLfloat bsin[32], bcos[32];
bool aimdir;
textureClass fireTex;
GLfloat lastX,lastY;
ball() {
growing=0;
growspeed=0.1;
width=0.0;
height=0.0;
glued=0;
posx=0.0f;
posy=0.0f;
aimdir=0;
}
void hit(GLfloat c[])
{
if(setting.eyeCandy)
tail.colorRotate(explosive, c);
}
void move()
{
//vi laver lige den her coldet her...
if(posx+width > 1.6 && xvel > 0.0)
{
soundMan.add(SND_BALL_HIT_BORDER, posx);
xvel *= -1;
} else if(posx-width < -1.6 && xvel < 0.0)
{
soundMan.add(SND_BALL_HIT_BORDER, posx);
xvel *= -1;
} else if(posy+width > 1.25 && yvel > 0.0)
{
soundMan.add(SND_BALL_HIT_BORDER, posx);
yvel *= -1;
} else if(posy-width < -1.24)
{
active=0;
}
posx +=xvel*globalMilliTicks;
if(!glued)
{
posy +=yvel*globalMilliTicks;
} else {
gVar.deadTime = 0;
}
if(setting.eyeCandy)
tail.update(posx,posy);
}
void draw(paddle_class &paddle)
{
GLfloat newsize;
if(setting.eyeCandy)
tail.draw();
if(growing)
{
newsize = growspeed * globalMilliTicksSinceLastDraw;
width += newsize;
height += newsize;
if(width >= destwidth)
{
width=destwidth;
height=destwidth;
growing=0;
}
tail.width = width;
tail.height = height;
} else if(shrinking)
{
newsize = growspeed * globalMilliTicksSinceLastDraw;
width -= newsize;
height -= newsize;
if(width <= destwidth)
{
width=destwidth;
height=destwidth;
shrinking=0;
}
tail.width = width;
tail.height = height;
}
if(glued && player.powerup[PO_LASER])
{
if(player.powerup[PO_AIM])
{
if(aimdir==0)
{
rad -= 1.2*globalMilliTicksSinceLastDraw;
if(rad < BALL_MIN_DEGREE)
aimdir=1;
} else {
rad += 1.2*globalMilliTicksSinceLastDraw;
if(rad > BALL_MAX_DEGREE+BALL_MIN_DEGREE)
aimdir=0;
}
setangle(rad);
} else {
getRad();
}
GLfloat bxb = cos(rad)*0.5, byb = sin(rad)*0.5;
glLoadIdentity();
glTranslatef( posx, posy, -3.0);
glDisable(GL_TEXTURE_2D);
glLineWidth ( 1.0 );
glEnable( GL_LINE_SMOOTH );
glBegin( GL_LINES );
glColor4f(rndflt(2,0), rndflt(1,0), 0.0, 0.0);
glVertex3f( 0.0, 0.0, 0.0 );
glColor4f(rndflt(2,0), 0.0, 0.0, 1.0);
glVertex3f( bxb, byb, 0.0 );
glEnd();
glPointSize( 5.0f );
glColor4f(1.0, 0.0, 0.0, 1.0);
glEnable(GL_POINT_SMOOTH);
glBegin( GL_POINTS );
glVertex3f(bxb, byb, 0.0);
glEnd( );
}
if(!glued && player.powerup[PO_AIMHELP])
{
//Use line intersect to determine if this ball will collide with the paddle
getRad();
GLfloat p[4], b[4], o[2]; //Paddle line, ball line, bounceoff endpoint
p[0] = paddle.posx - paddle.width;
p[1] = paddle.posx + paddle.width;
p[2] = paddle.posy + paddle.height + height;
p[3] = paddle.posy + paddle.height + height;
b[0] = posx;
b[1] = posx + (cos(rad) * 3.0);
b[2] = posy;
b[3] = posy + (sin(rad) * 3.0);
GLfloat cx,cy, R;
if(LinesCross(p[0], p[2], p[1],p[3], b[0], b[2], b[1], b[3], &cx, &cy))
{
R = bounceOffAngle(paddle.width, paddle.posx, cx);
o[0] = cx+(cos(R)*2.0);
o[1] = cy+(sin(R)*2.0);
glLoadIdentity();
glTranslatef( 0.0, 0.0, -3.0);
glDisable(GL_TEXTURE_2D);
glLineWidth ( 2.0 );
glEnable( GL_LINE_SMOOTH );
glBegin( GL_LINE_STRIP );
//Line from ball to paddle
glColor4f(1.0, 0.0, 0.0, 0.0);
glVertex3f( b[0], b[2], 0.0 );
glColor4f(1.0, 1.0, 0.0, 1.0);
glVertex3f( cx, cy, 0.0 );
//Bounce off line.
glColor4f(1.0, 0.0, 0.0, 0.0);
glVertex3f( o[0], o[1], 0.0 );
glEnd( );
}
}
glLoadIdentity();
glTranslatef( posx, posy, -3.0);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0, 1.0, 1.0, 1.0);
if(explosive)
{
fireTex.play();
glBindTexture(GL_TEXTURE_2D, fireTex.prop.texture);
glColor4f( fireTex.prop.glTexColorInfo[0], fireTex.prop.glTexColorInfo[1], fireTex.prop.glTexColorInfo[2], fireTex.prop.glTexColorInfo[3] );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin( GL_QUADS );
glTexCoord2f(fireTex.pos[0],fireTex.pos[1]); glVertex3f( -width, height, 0.0 );
glTexCoord2f(fireTex.pos[2],fireTex.pos[3]); glVertex3f( width, height, 0.0 );
glTexCoord2f(fireTex.pos[4],fireTex.pos[5]); glVertex3f( width,-height, 0.0 );
glTexCoord2f(fireTex.pos[6],fireTex.pos[7]); glVertex3f( -width,-height, 0.0 );
glEnd( );
} else {
tex.play();
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glColor4f( tex.prop.glTexColorInfo[0], tex.prop.glTexColorInfo[1], tex.prop.glTexColorInfo[2], tex.prop.glTexColorInfo[3] );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin( GL_QUADS );
glTexCoord2f(tex.pos[0],tex.pos[1]); glVertex3f( -width, height, 0.0 );
glTexCoord2f(tex.pos[2],tex.pos[3]); glVertex3f( width, height, 0.0 );
glTexCoord2f(tex.pos[4],tex.pos[5]); glVertex3f( width,-height, 0.0 );
glTexCoord2f(tex.pos[6],tex.pos[7]); glVertex3f( -width,-height, 0.0 );
glEnd( );
}
#ifdef DEBUG_DRAW_BALL_QUAD
glLoadIdentity();
glTranslatef(posx, posy, -3.0);
glDisable( GL_TEXTURE_2D );
glColor4f(1.0,1.0,1.0,1.0);
glBegin( GL_LINES );
glVertex3f( -width, height, 0);
glVertex3f( width, height, 0);
glVertex3f( -width, -height, 0);
glVertex3f( width, -height,0);
glVertex3f( -width, height, 0);
glVertex3f( -width, -height, 0);
glVertex3f( width, height, 0);
glVertex3f( width, -height, 0 );
glEnd();
glEnable(GL_TEXTURE_2D);
#endif
}
GLfloat getRad()
{
rad = atan2(yvel,xvel);
return(rad);
}
void setangle(GLfloat o)
{
if(o < BALL_MIN_DEGREE)
{
o=BALL_MIN_DEGREE;
}
if( o > BALL_MAX_DEGREE + BALL_MIN_DEGREE)
{
o=BALL_MAX_DEGREE + BALL_MIN_DEGREE;
}
rad=o;
xvel = velocity * cos(rad);
yvel = velocity * sin(rad);
}
void setspeed(GLfloat v)
{
if(v > difficulty.maxballspeed[player.difficulty])
{
velocity = difficulty.maxballspeed[player.difficulty];
} else {
velocity = v;
}
getRad();
xvel = velocity * cos(rad);
yvel = velocity * sin(rad);
}
void setSize(GLfloat s)
{
float rad;
if(s > width)
growing=1;
else if(s < width)
shrinking=1;
destwidth=s;
int i=0;
//opdater points
for(rad=0.0; rad < 6.3; rad +=0.2)
{
if(i < 32)
{
bsin[i] = sin(rad)*s;
bcos[i] = cos(rad)*s;
}
i++;
}
}
};
void coldet(brick & br, ball & ba, pos & p, effectManager & fxMan);
void padcoldet(ball & b, paddle_class & p, pos & po);
#define MAXBALLS 16
class ballManager {
public:
int activeBalls;
ball b[MAXBALLS];
textureClass tex[3];
void initBalls()
{
activeBalls=0;
clear();
}
ballManager(textureClass btex[])
{
int i;
tex[0] = btex[0];
tex[1] = btex[1];
tex[2] = btex[2];
for(i=0; i < MAXBALLS; i++)
{
b[i].tex=tex[0];
b[i].fireTex=tex[1];
b[i].tail.tex = &tex[2];
}
initBalls();
}
void getSpeed()
{
int i;
var.averageBallSpeed = 0.0;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
var.averageBallSpeed += b[i].velocity;
}
}
var.averageBallSpeed /= activeBalls;
}
//klon alle aktive bolde
void multiply()
{
pos op;
int a=0,c=0;
int i;
//How many balls are active?
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
a++;
}
}
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active && c != a)
{
c++;
op.y = b[i].posy;
op.x = b[i].posx;
spawn(op,0,0.0f,b[i].velocity, rndflt( BALL_MAX_DEGREE+BALL_MIN_DEGREE,0));
}
}
}
void unglue()
{
int i;
for(i=0; i < MAXBALLS; i++)
{
b[i].glued=0;
}
}
void spawn(pos p, bool glued, GLfloat gx ,GLfloat speed, GLfloat angle)
{
int i;
for(i=0; i < MAXBALLS; i++)
{
if(!b[i].active)
{
activeBalls++;
b[i].tex = tex[0];
b[i].fireTex = tex[1];
b[i].glued=glued;
b[i].width=0.0;
b[i].height=0.0;
b[i].gluedX=gx;
b[i].active=1;
b[i].collide=1;
b[i].reflect=1;
b[i].lastX = p.x;
b[i].lastY = p.y;
b[i].posx = p.x;
b[i].posy = p.y;
b[i].explosive=0;
b[i].setspeed(speed);
b[i].setangle(angle);
b[i].setSize(0.025);
//New balls get already applied powerups if not hard
if(player.difficulty < HARD)
{
b[i].explosive = player.powerup[PO_EXPLOSIVE];
if(player.powerup[PO_SMALLBALL])
{
powerup(PO_SMALLBALL);
}
if(player.powerup[PO_BIGBALL])
{
powerup(PO_BIGBALL);
}
}
getSpeed();
break;
}
}
}
void clear()
{
int i;
activeBalls=0;
for(i=0; i < MAXBALLS; i++)
{
b[i].active=0;
}
getSpeed();
}
void move()
{
int a=0;
int i;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
b[i].move();
a++;
}
}
activeBalls=a;
}
void draw(paddle_class &paddle)
{
int i;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
b[i].draw(paddle);
}
}
}
void bcoldet(brick & bri,effectManager & fxMan)
{
int i;
pos p;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
p.x=100;
coldet(bri, b[i], p, fxMan);
if(p.x < 50) //we totally hit?? :P
{
getSpeed();
if(setting.eyeCandy)
{
//spawn partikler
fxMan.set(FX_VAR_TYPE, FX_SPARKS);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_SPEED, 1.0f);
fxMan.set(FX_VAR_LIFE, 1500);
fxMan.set(FX_VAR_NUM, 16);
fxMan.set(FX_VAR_SIZE, 0.015f);
fxMan.set(FX_VAR_COLOR, 1.0,1.0,0.8);
fxMan.spawn(p);
}
}
}
}
}
int pcoldet(paddle_class & paddle,effectManager & fxMan)
{
int i, hits=0;
pos p;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
if(b[i].glued)
b[i].posx=paddle.posx+paddle.width-b[i].gluedX;
p.x=100;
padcoldet(b[i], paddle, p);
if(p.x < 50)
{
hits++;
getSpeed();
if(player.powerup[PO_GLUE])
{
soundMan.add(SND_GLUE_BALL_HIT_PADDLE, p.x);
} else {
soundMan.add(SND_BALL_HIT_PADDLE, p.x);
}
if(setting.eyeCandy)
{
//spawn partikler
fxMan.set(FX_VAR_TYPE, FX_SPARKS);
fxMan.set(FX_VAR_LIFE, 2000);
fxMan.set(FX_VAR_GRAVITY, 0.6f);
fxMan.set(FX_VAR_NUM, 16);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_SIZE, 0.01f);
fxMan.set(FX_VAR_COLOR, 1.0,1.0,0.8);
p.y = paddle.posy+paddle.height;
fxMan.set(FX_VAR_SPEED, 0.5f);
fxMan.spawn(p);
} //eyecandy
} // if col
} //if active
} //for loop
return(hits);
} //pcoldet
void updatelast()
{
int i;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
b[i].lastX=b[i].posx;
b[i].lastY=b[i].posy;
}
}
}
void powerup(int powerup)
{
int i;
for(i=0; i < MAXBALLS; i++)
{
if(b[i].active)
{
switch(powerup)
{
case PO_BIGBALL: //big balls
b[i].setSize(0.04);
b[i].setspeed(difficulty.ballspeed[player.difficulty]);
break;
case PO_SMALLBALL: //small balls
b[i].setSize(0.015);
//speed bolden op
b[i].setspeed( b[i].velocity + ((b[i].velocity/100.f)*difficulty.speedup[player.difficulty]) );
break;
case PO_NORMALBALL: // normal balls
b[i].setSize(0.025);
b[i].setspeed(difficulty.ballspeed[player.difficulty]);
break;
case PO_EXPLOSIVE: //exploderer brikker
b[i].explosive=1;
b[i].tail.colorRotate(TRUE, 0 );
break;
}
}
}
}
};
float bounceOffAngle(GLfloat width, GLfloat posx, GLfloat hitx)
{
return ( (BALL_MAX_DEGREE/(width*2.0))*(posx+width-hitx) + BALL_MIN_DEGREE );
}
class powerupClass : public moving_object {
public:
int score;
int type;
int level, maxlevel;
GLfloat gravity;
powerupClass()
{
posx=0.0;
posy=0.0;
xvel=0.0;
yvel=0.0;
width=0.055;
height=0.055;
}
void move()
{
//grav
yvel -= gravity*globalMilliTicks;
//cout << yvel << endl;
posx +=xvel*globalMilliTicks;
posy +=yvel*globalMilliTicks;
}
bool coldet(paddle_class & p, effectManager & fxMan, ballManager & bMan)
{
bool col=0;
if(posx+width > 1.6 && xvel > 0.0)
{
col=1;
xvel *= -1;
} else if(posx-width < -1.6 && xvel < 0.0)
{
col=1;
xvel *= -1;
} else if(posy+width > 1.25 && yvel > 0.0)
{
col=1;
yvel *= -1;
} else if(posy-width < -1.24)
{
active=0;
}
if(col)
{
soundMan.add(SND_PO_HIT_BORDER, posx);
}
//idiotisk lavet...
bool ycol=0;
bool xcol=0;
pos fxpos, fxSize;
//En side
if(posx+width > p.posx-p.width && posx+width < p.posx+p.width)
{
xcol=1;
}
if(posx-width > p.posx-p.width && posx-width < p.posx+p.width)
{
xcol=1;
}
if(posy-height < p.posy+p.height && posy-height > p.posy-p.height)
{
ycol=1;
}
if(posy+height < p.posy+p.height && posy+height > p.posy-p.height)
{
ycol=1;
}
if(xcol && ycol)
{
if(setting.eyeCandy)
{
fxpos.x = posx;
fxpos.y = posy;
fxSize.x=width;
fxSize.y=height;
fxMan.set(FX_VAR_TYPE, FX_PARTICLEFIELD);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_SPEED, yvel/1.5f);
fxMan.set(FX_VAR_LIFE, 1500);
fxMan.set(FX_VAR_GRAVITY, 0.7f);
fxMan.set(FX_VAR_NUM, 20);
fxMan.set(FX_VAR_SIZE, 0.03f);
fxMan.set(FX_VAR_RECTANGLE, fxSize);
fxMan.set(FX_VAR_COLOR, tex.prop.glParColorInfo[0],tex.prop.glParColorInfo[1],tex.prop.glParColorInfo[2]);
fxMan.spawn(fxpos);
}
active=0;
//Score
player.score += score*player.multiply;
//Apply powerup:
switch(type)
{
case PO_COIN:
player.coins += 1000;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_GLUE:
player.coins += 150;
player.powerup[PO_GLUE] = 1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_BIGBALL:
player.coins += 30;
bMan.powerup(PO_BIGBALL);
player.powerup[PO_BIGBALL]=1;
player.powerup[PO_NORMALBALL]=0;
player.powerup[PO_SMALLBALL]=0;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_NORMALBALL:
player.coins += 50;
bMan.powerup(PO_NORMALBALL);
player.powerup[PO_NORMALBALL]=1;
player.powerup[PO_BIGBALL]=0;
player.powerup[PO_SMALLBALL]=0;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_SMALLBALL:
player.coins += 10;
bMan.powerup(PO_SMALLBALL);
player.powerup[PO_SMALLBALL]=1;
player.powerup[PO_BIGBALL]=0;
player.powerup[PO_NORMALBALL]=0;
soundMan.add(SND_EVIL_PO_HIT_PADDLE, posx);
break;
case PO_MULTIBALL:
player.coins += 100;
bMan.multiply();
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_AIM:
player.coins += 50;
if(player.difficulty==0)
{
player.powerup[PO_GLUE]=1;
}
if(!player.powerup[PO_AIM])
{
player.powerup[PO_AIM]=1;
player.powerup[PO_LASER]=1;
} else {
player.powerup[PO_GLUE]=1;
}
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_GROWPADDLE:
player.coins += 100;
if(p.width < 0.4)
p.grow(p.width+0.03);
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_SHRINKPADDLE:
player.coins += 10;
if(p.width > 0.02) p.grow(p.width-0.02);
soundMan.add(SND_EVIL_PO_HIT_PADDLE, posx);
break;
case PO_EXPLOSIVE:
player.coins += 150;
bMan.powerup(PO_EXPLOSIVE);
player.powerup[PO_EXPLOSIVE]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_GUN:
player.coins += 200;
player.powerup[PO_GUN]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_THRU:
player.coins += 300;
player.powerup[PO_THRU]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_LASER:
player.coins += 40;
player.powerup[PO_LASER]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_LIFE:
player.coins += 400;
player.lives++;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_DIE:
player.coins += 1;
player.explodePaddle=1;
player.powerup[PO_DIE]=1;
//NOTE: no sound here, SND_DIE is played when paddle dissapers
break;
case PO_DROP:
player.coins += 1;
player.powerup[PO_DROP]=1;
soundMan.add(SND_EVIL_PO_HIT_PADDLE, posx);
break;
case PO_DETONATE:
player.coins += 200;
player.powerup[PO_DETONATE]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_EXPLOSIVE_GROW:
player.coins += 100;
player.powerup[PO_EXPLOSIVE_GROW]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_EASYBRICK:
player.coins += 90;
player.powerup[PO_EASYBRICK]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
case PO_NEXTLEVEL:
player.coins += 100;
player.powerup[PO_NEXTLEVEL]=1;
//NOTE: no sound here, SND_NEXTLEVEL is played when changing level
break;
case PO_AIMHELP:
player.coins += 50;
player.powerup[PO_AIMHELP]=1;
soundMan.add(SND_GOOD_PO_HIT_PADDLE, posx);
break;
}
return(1);
}
return(0);
}
void die(effectManager & fxMan)
{
active=0;
if(setting.eyeCandy)
{
struct pos p;
p.x = posx;
p.y = posy;
fxMan.set(FX_VAR_TYPE, FX_SPARKS);
fxMan.set(FX_VAR_COLDET,1);
fxMan.set(FX_VAR_LIFE, 1250);
fxMan.set(FX_VAR_NUM, 16);
fxMan.set(FX_VAR_SPEED, 0.8f);
fxMan.set(FX_VAR_GRAVITY, 0.6f);
fxMan.set(FX_VAR_SIZE, 0.025f);
fxMan.set(FX_VAR_COLOR, tex.prop.glParColorInfo[0],tex.prop.glParColorInfo[1],tex.prop.glParColorInfo[2]);
fxMan.spawn(p);
fxMan.set(FX_VAR_SPEED, 0.4f);
fxMan.set(FX_VAR_SIZE, 0.05f);
fxMan.set(FX_VAR_GRAVITY, -1.0f);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
fxMan.spawn(p);
}
}
void draw()
{
tex.play();
glBindTexture( GL_TEXTURE_2D, tex.prop.texture);
glColor4f(tex.prop.glTexColorInfo[0],tex.prop.glTexColorInfo[1],tex.prop.glTexColorInfo[2],tex.prop.glTexColorInfo[3]);
glLoadIdentity();
glTranslatef( posx, posy, -3.0f);
glBegin( GL_QUADS );
glTexCoord2f(tex.pos[0],tex.pos[1]);glVertex3f( -width, height, 0.00 ); // øverst venst
glTexCoord2f(tex.pos[2],tex.pos[3]);glVertex3f( width, height, 0.00 ); // øverst højre
glTexCoord2f(tex.pos[4],tex.pos[5]);glVertex3f( width,-height, 0.00 ); // nederst højre
glTexCoord2f(tex.pos[6],tex.pos[7]);glVertex3f( -width,-height, 0.00 ); // nederst venstre
glEnd( );
}
};
#define MAXPOWERUPS 64
class powerupManager {
private:
int i;
powerupClass p[MAXPOWERUPS];
textureClass* tex;
public:
void init(textureClass texPowerup[])
{
tex = new textureClass[40];
tex = texPowerup;
}
powerupManager()
{
clear();
}
void clear()
{
for(i=0; i < MAXPOWERUPS; i++)
{
p[i].active=0;
}
}
void die(effectManager & fxMan)
{
for(i=0; i < MAXPOWERUPS; i++)
{
if(p[i].active)
{
p[i].die(fxMan);
}
}
}
void spawn(pos spawnpos, pos velocity, int type)
{
for(i=0; i < MAXPOWERUPS; i++)
{
if(!p[i].active)
{
p[i].gravity = 0.7;
p[i].type = type;
p[i].posx = spawnpos.x;
p[i].posy = spawnpos.y;
p[i].xvel = velocity.x*-1;
p[i].yvel = velocity.y*-1;
p[i].active=1;
//Give texture that this type has.
p[i].tex = tex[type];
//FIXME: rewrite as a switch
//Set colors and score
if(type==PO_GLUE)
{
p[i].score = 500;
}
if(type==PO_MULTIBALL)
{
p[i].score = 500;
}
if(type==PO_BIGBALL)
{
p[i].score = 300;
}
if(type==PO_NORMALBALL)
{
p[i].score = 400;
}
if(type==PO_SMALLBALL)
{
p[i].score = 100;
}
if(type==PO_AIM)
{
p[i].score = 1600;
}
if(type==PO_GROWPADDLE)
{
p[i].score = 500;
}
if(type==PO_SHRINKPADDLE)
{
p[i].score = -1000;
}
if(type==PO_EXPLOSIVE)
{
p[i].score = 1400;
}
if(type==PO_GUN)
{
p[i].score = 1800;
}
if(type==PO_THRU)
{
p[i].score = 1000;
}
if(type==PO_LASER)
{
p[i].score = 500;
}
if(type==PO_LIFE)
{
p[i].score = 1000;
}
if(type==PO_DIE)
{
p[i].score = -1000;
}
if(type==PO_DROP)
{
p[i].score = -1000;
}
if(type==PO_DETONATE)
{
p[i].score = 1000;
}
if(type==PO_EXPLOSIVE_GROW)
{
p[i].score = 1000;
}
if(type==PO_EASYBRICK)
{
p[i].score = 1000;
}
if(type==PO_NEXTLEVEL)
{
p[i].score = 1000;
}
if(type==PO_AIMHELP)
{
p[i].score = 1000;
}
break; //Whats this doing?
}
}
}
int coldet(paddle_class & paddle, effectManager & fxMan, ballManager & bMan)
{
int hits=0;
for(i=0; i < MAXPOWERUPS; i++)
{
if(p[i].active)
{
if(p[i].coldet(paddle, fxMan, bMan))
{
hits++;
}
}
}
return(hits);
}
void move()
{
for(i=0; i < MAXPOWERUPS; i++)
{
if(p[i].active)
{
p[i].move();
}
}
}
void draw()
{
for(i=0; i < MAXPOWERUPS; i++)
{
if(p[i].active)
{
p[i].draw();
}
}
}
};
powerupManager pMan;
void spawnpowerup(char powerup, pos a, pos b)
{
if(powerup == '1')
{
pMan.spawn(a,b,PO_GROWPADDLE);
}
if(powerup == '2')
{
pMan.spawn(a,b,PO_SHRINKPADDLE);
}
if(powerup == '3')
{
pMan.spawn(a,b,PO_DIE);
}
if(powerup == '4')
{
pMan.spawn(a,b,PO_GLUE);
}
if(powerup == 'A')
{
pMan.spawn(a,b,PO_EASYBRICK);
}
if(powerup == 'B')
{
pMan.spawn(a,b,PO_EXPLOSIVE);
}
if(powerup == 'C')
{
pMan.spawn(a,b,PO_NEXTLEVEL);
}
if(powerup == 'D')
{
pMan.spawn(a,b,PO_AIMHELP);
}
if(powerup == 'E')
{
pMan.spawn(a,b,PO_COIN);
}
if(powerup == '5')
{
pMan.spawn(a,b,PO_MULTIBALL);
}
if(powerup == '6')
{
pMan.spawn(a,b,PO_THRU);
}
if(powerup == '7')
{
pMan.spawn(a,b,PO_DROP);
}
if(powerup == '8')
{
pMan.spawn(a,b,PO_DETONATE);
}
if(powerup == '9')
{
pMan.spawn(a,b,PO_EXPLOSIVE_GROW);
}
if(powerup == 'F')
{
pMan.spawn(a,b,PO_BIGBALL);
}
if(powerup == 'G')
{
pMan.spawn(a,b,PO_NORMALBALL);
}
if(powerup == 'H')
{
pMan.spawn(a,b,PO_SMALLBALL);
}
if(powerup == 'I')
{
pMan.spawn(a,b,PO_AIM);
}
if(powerup == 'P')
{
pMan.spawn(a,b,PO_GUN);
}
if(powerup == 'R')
{
pMan.spawn(a,b,PO_LASER);
}
if(powerup == 'O')
{
pMan.spawn(a,b,PO_LIFE);
}
}
SDL_Surface *screen = NULL;
/* function to reset our viewport after a window resize */
void resizeWindow( int width, int height )
{
/* Height / width ration */
GLfloat ratio;
/* Protect against a divide by zero */
if ( height == 0 )
height = 1;
ratio = ( GLfloat )width / ( GLfloat )height;
var.glunits_per_xpixel = (2.485281374*ratio) / setting.resx;
var.glunits_per_ypixel = 2.485281374 / setting.resy;
/* Setup our viewport. */
glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );
/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
/* Set our perspective */
gluPerspective( 45.0f, ratio, 0.1f, 10.0f );
/* Make sure we're chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );
/* Reset The View */
glLoadIdentity();
}
void initGL() {
// printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
// printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
// printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
//printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
/* Enable smooth shading */
glShadeModel( GL_SMOOTH );
/* Set the background black */
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
/* Depth buffer setup */
glClearDepth( 1.0f );
/* Enables Depth Testing */
// glEnable( GL_DEPTH_TEST );
/* The Type Of Depth Test To Do */
glDepthFunc( GL_LEQUAL );
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
float rndflt(float total, float negative)
{
return (rand()/(float(RAND_MAX)+1)*total)-negative;
}
bool initScreen()
{
bool success=1;
int SDL_videomodeSettings = SDL_OPENGL|SDL_RESIZABLE;
if(setting.fullscreen)
SDL_videomodeSettings |= SDL_FULLSCREEN;
/* Free the previously allocated surface */
if(screen != NULL)
{
SDL_FreeSurface( screen );
}
screen = SDL_SetVideoMode(setting.resx,setting.resy,32, SDL_videomodeSettings);
resizeWindow(setting.resx,setting.resy);
if( screen == NULL )
{
cout << "Error:" << SDL_GetError() << endl;
success=0;
var.quit=1;
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
var.halfresx = setting.resx /2;
var.halfresy = setting.resy / 2;
return(success);
}
void resetPlayerPowerups()
{
for(int i=0; i < MAXPOTEXTURES; i++)
{
player.powerup[i] = 0;
}
}
void initNewGame()
{
player.level=0;
player.score=0;
gVar.deadTime=0;
gVar.newLevel=1;
gVar.newLife=1;
player.multiply = 1;
switch(player.difficulty)
{
case EASY:
player.coins = 600;
player.lives = 5;
break;
case NORMAL:
player.coins = 0;
player.lives = 3;
break;
case HARD:
player.coins = 0;
player.lives = 3;
break;
}
resetPlayerPowerups();
}
void pauseGame()
{
var.paused=1;
#ifndef WIN32
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
SDL_ShowCursor(SDL_ENABLE);
}
void resumeGame()
{
#ifndef WIN32
SDL_WM_GrabInput(SDL_GRAB_ON);
#endif
SDL_ShowCursor(SDL_DISABLE);
var.paused=0;
var.menu=0;
}
void mkDLscene(GLuint *dl,textureClass tex)
{
//Scenen
*dl = glGenLists(1);
glNewList(*dl,GL_COMPILE);
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -3.0 );
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glBegin( GL_POINTS );
glVertex3f( -1.60, 1.25, 0.0 );
glEnd( );
glBegin( GL_QUADS );
//venstre kant
glTexCoord2f(0.0f,0.0f);glVertex3f( -1.66, 1.25, 0.0 );
glTexCoord2f(1.0f,0.0f);glVertex3f( -1.60, 1.25, 0.0 );
glTexCoord2f(1.0f,-1.0f);glVertex3f( -1.60,-1.25, 0.0 );
glTexCoord2f(0.0f,-1.0f);glVertex3f( -1.66,-1.25, 0.0 );
//højre kant
glTexCoord2f(0.0f,0.0f);glVertex3f( 1.66, 1.25, 0.0 );
glTexCoord2f(1.0f,0.0f);glVertex3f( 1.60, 1.25, 0.0 );
glTexCoord2f(1.0f,-1.0f);glVertex3f( 1.60,-1.25, 0.0 );
glTexCoord2f(0.0f,-1.0f);glVertex3f( 1.66,-1.25, 0.0 );
glEnd( );
glEndList();
}
void coldet(brick & br, ball &ba, pos & p, effectManager & fxMan)
{
GLfloat x,y;
int i=0;
int points=0;
GLfloat px=0,py=0;
bool col=0;
bool dirfound=0;
GLfloat dist[4] = { 4.0, 4.0, 4.0, 4.0 }; //measure the distance from last pos to each possible impact, the shortest should be the right one
//vi tager y først da der er mindst brikker
if(ba.posy < br.posy+br.height+ba.height && ba.posy > br.posy-br.height-ba.height)
{
//cout << " y " << endl;
if(ba.posx > br.posx-br.width-ba.width && ba.posx < br.posx+br.width+ba.width)
{
//cout << " x " << endl;
for(i=0; i < 32; i++) // 32 punkter præcis
{
x = ba.bsin[i];
y = ba.bcos[i];
if(ba.posx+x >= br.posx-br.width && ba.posx+x <= br.posx+br.width)
{
if(ba.posy+y <= br.posy+br.height && ba.posy+y >= br.posy-br.height)
{
//Vi har helt sikkert ramt
points++;
px += x;
py += y;
col=1;
} //y
} //x
} //32 punkters for loop
if(col)
{
px /= points;
py /= points;
if(ba.lastX-px <= br.posx-br.width && !br.n(0)) //
{
dirfound=1;
// cout << "På venstre"<<endl;
dist[0] = sqrt( pow( br.posx-br.width - (ba.lastX+px), 2) + pow( (ba.posy+py) - (ba.lastY+py), 2) );
}
if(ba.lastX-px >= br.posx+br.width && !br.n(1))
{
dirfound=1;
// cout << "På højre"<<endl;
dist[1] = sqrt( pow( br.posx+br.width - (ba.lastX+px), 2) + pow( (ba.posy+py) - (ba.lastY+py), 2) );
}
if(ba.lastY-py <= br.posy-br.height && !br.n(3))
{
dirfound=1;
// cout << "På bunden" << endl;
dist[2] = sqrt( pow( (ba.posx+px) - (ba.lastX+px), 2) + pow( br.posy-br.height - (ba.lastY+py), 2) );
}
if(ba.lastY-py >= br.posy+br.height && !br.n(2)) // &&
{
dirfound=1;
// cout << "På toppen"<< endl;
dist[3] = sqrt( pow( (ba.posx+px) - (ba.lastX+px), 2) + pow( br.posy+br.height - (ba.lastY+py), 2) );
}
//Was hit on left
if(dist[0] < dist[1] && dist[0] < dist[2] && dist[0] < dist[3])
{
ba.posx = br.posx - br.width - ba.width;
if(ba.xvel > 0.0 && !player.powerup[PO_THRU])
ba.xvel *=-1;
}
//Was hit on right
if(dist[1] < dist[0] && dist[1] < dist[2] && dist[1] < dist[3])
{
ba.posx = br.posx + br.width + ba.width;
if(ba.xvel < 0 && !player.powerup[PO_THRU])
ba.xvel *=-1;
}
//Was hit on bottom
if(dist[2] < dist[0] && dist[2] < dist[1] && dist[2] < dist[3])
{
ba.posy = br.posy - br.height - ba.height;
if(ba.yvel > 0 && !player.powerup[PO_THRU])
ba.yvel *=-1;
}
//Was hit on top
if(dist[3] < dist[0] && dist[3] < dist[1] && dist[3] < dist[2])
{
ba.posy = br.posy + br.height + ba.height;
if(ba.yvel < 0 && !player.powerup[PO_THRU])
ba.yvel *=-1;
}
//Setup vars for spawning powerups
pos a,b;
a.x = br.posx;
a.y = br.posy;
//Hastigheden en powerup blier sendt afsted med
if(player.difficulty == EASY)
{
b.x = ba.xvel/2.0;
b.y = ba.yvel/2.0;
} else if(player.difficulty == NORMAL)
{
b.x = ba.xvel/1.5;
b.y = ba.yvel/1.5;
} else //if(player.difficulty == HARD)
{
b.x = ba.xvel/1.25;
b.y = ba.yvel/1.25;
}
if(dirfound)
{
if(ba.explosive)
{
br.type='B';
}
//Update p, used by caller to find out if we hit anything..
p.x = ba.posx+px;
p.y = ba.posy+py;
ba.hit(br.tex.prop.glParColorInfo);
if(!player.powerup[PO_THRU] || player.difficulty == HARD)
{
ba.setspeed(ba.velocity + difficulty.hitbrickinc[player.difficulty]);
}
} else {
cout << "Collision detection error: Don't know where the ball hit." <<endl;
}
br.hit(fxMan, a,b,1);
} //collision
} //x boxcol
} //y boxcol
}
void padcoldet(ball & b, paddle_class & p, pos & po)
{
int i,points=0;
GLfloat x,y,px=0,py=0;
bool col=0;
//Er bolden tæt nok på?
if(b.posy < (p.posy+p.height)+b.height && b.posy > p.posy-p.height)
{
if(b.posx > p.posx-(p.width*2.0)-b.width && b.posx < p.posx+(p.width*2.0)+b.width)
{
for(i=0; i < 32; i++)
{
x = b.bsin[i];
y = b.bcos[i];
//Find de punkter der er inden i padden
if(b.posx+x > p.posx-p.width && b.posx+x < p.posx+p.width)
{
if(b.posy+y < p.posy+p.height && b.posy+y > p.posy-p.height)
{
col=1;
px +=x;
py +=y;
points++;
}
}
} //For loop
if(col)
{
col=0;
gVar.deadTime=0;
px /= (float)points;
py /= (float)points;
px = b.posx+px;
//Ved at reagere herinde fungerer yvel som en switch, så det kun sker een gang ;)
if(b.yvel < 0)
{
b.posy=p.posy+p.height+b.height; //løft op over pad
//Only decrease speed if the player does not have the go-thru powerup
if(!player.powerup[PO_THRU])
{
b.setspeed(b.velocity + difficulty.hitpaddleinc[player.difficulty]);
}
b.setangle(bounceOffAngle(p.width, p.posx, b.posx));
if(player.powerup[PO_GLUE])
{
b.gluedX = p.posx+p.width - px;
b.glued=1;
}
po.x = px;
po.y = py;
}
}
}
}
}
#include "highscores.cpp"
struct shopItemStruct {
int price;
int type;
};
class hudClass {
private:
textureClass texBall;
//For the hud text
int ticksSinceLastClockCheck;
time_t nixTime; //Seconds since epoch
tm timeStruct; //Time struct
char clockString[13]; //Clock: 00:00\0
//For the powerup "shop"
textureClass *texPowerup; //Pointer to array of powerup textures
int shopItemSelected;
#define NUMITEMSFORSALE 13
struct shopItemStruct item[NUMITEMSFORSALE];
bool shopItemBlocked[NUMITEMSFORSALE]; //One can only buy each powerup one time each life/level
public:
hudClass(textureClass texB, textureClass texPo[])
{
texPowerup = texPo;
texBall=texB;
ticksSinceLastClockCheck=1001;
item[0].type = PO_LASER;
item[0].price = 600;
item[1].type = PO_NORMALBALL;
item[1].price = 750;
item[2].type = PO_BIGBALL;
item[2].price = 800;
item[3].type = PO_AIMHELP;
item[3].price = 900;
item[4].type = PO_GROWPADDLE;
item[4].price = 960;
item[5].type = PO_MULTIBALL;
item[5].price = 980;
item[6].type = PO_EXPLOSIVE_GROW;
item[6].price = 990;
item[7].type = PO_EXPLOSIVE;
item[7].price = 1000;
item[8].type = PO_GLUE;
item[8].price = 1000;
item[9].type = PO_EASYBRICK;
item[9].price = 2000;
item[10].type = PO_GUN;
item[10].price = 3000;
item[11].type = PO_THRU;
item[11].price = 4000;
item[12].type = PO_LIFE;
item[12].price = 6000;
shopItemSelected=0;
}
void draw()
{
int i;
//Draw lives left.
glLoadIdentity();
glTranslatef(0,0,-3.0);
glColor4f( texBall.prop.glTexColorInfo[0],texBall.prop.glTexColorInfo[1],texBall.prop.glTexColorInfo[2],texBall.prop.glTexColorInfo[3]);
glBindTexture(GL_TEXTURE_2D, texBall.prop.texture);
texBall.play();
glBegin( GL_QUADS );
for(i=0; i < player.lives-1; i++)
{
glTexCoord2f(texBall.pos[0],texBall.pos[1]); glVertex3f(1.55-(0.05*i), 1.2, 0.0);
glTexCoord2f(texBall.pos[2],texBall.pos[3]); glVertex3f(1.5 -(0.05*i), 1.2, 0.0);
glTexCoord2f(texBall.pos[4],texBall.pos[5]); glVertex3f(1.5 -(0.05*i),1.15, 0.0);
glTexCoord2f(texBall.pos[6],texBall.pos[7]); glVertex3f(1.55 -(0.05*i), 1.15, 0.0);
}
glEnd( );
if(setting.showClock)
{
ticksSinceLastClockCheck += globalTicksSinceLastDraw;
if(ticksSinceLastClockCheck > 1000)
{
ticksSinceLastClockCheck=0;
time(&nixTime);
timeStruct = *(localtime(&nixTime));
sprintf(clockString, "Clock: %02i:%02i", timeStruct.tm_hour, timeStruct.tm_min); //Array is exactly 13 chars wide
}
glColor4f(1.0,1.0,1.0,1.0);
glText->write(clockString, FONT_INTRODESCRIPTION, 0, 1.0, -1.58, -1.25 + glText->getHeight(FONT_INTRODESCRIPTION));
}
//Draw the "shop"
//First, find out how many items the player can afford, so we can center them
int canAfford=0;
for(i=0; i < NUMITEMSFORSALE; i++)
{
if(item[i].price <= player.coins)
{
canAfford++;
}
}
if(shopItemSelected > canAfford || shopItemSelected < 0)
{
shopItemSelected=canAfford-1;
}
GLfloat shopListStartX = -((0.11*canAfford)/2.0);
if(gVar.shopNextItem)
{
gVar.shopNextItem=0;
shopItemSelected++;
if(shopItemSelected > canAfford-1)
{
shopItemSelected=0;
}
} else if(gVar.shopPrevItem)
{
gVar.shopPrevItem=0;
shopItemSelected--;
if(shopItemSelected < 0)
{
shopItemSelected=canAfford-1;
if(shopItemSelected < 0)
{
shopItemSelected=0;
}
}
} else if(gVar.shopBuyItem)
{
gVar.shopBuyItem=0;
if(item[shopItemSelected].price <= player.coins && !shopItemBlocked[shopItemSelected])
{
struct pos a,b;
a.x = shopListStartX + (0.11*shopItemSelected);
a.y = 1.15;
b.x = 0.0;
b.y = 0.0;
pMan.spawn(a,b,item[shopItemSelected].type);
player.coins -= item[shopItemSelected].price;
shopItemBlocked[shopItemSelected]=1;
gVar.shopNextItem=1;
soundMan.add(SND_BUY_POWERUP, 0.0);
}
}
glTranslatef( shopListStartX, 1.15, 0.0f);
for(i=0; i < canAfford; i++)
{
if(i==shopItemSelected)
{
if(shopItemBlocked[i])
{
glColor4f(1.0, 0.0, 0.0, 1.0);
} else {
glColor4f(1.0, 1.0, 1.0, 1.0);
}
} else {
if(shopItemBlocked[i])
{
glColor4f(1.0, 0.0, 0.0, 0.4);
} else {
glColor4f(1.0, 1.0, 1.0, 0.4);
}
}
texPowerup[item[i].type].play();
glBindTexture( GL_TEXTURE_2D, texPowerup[item[i].type].prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(texPowerup[item[i].type].pos[0],texPowerup[item[i].type].pos[1]);glVertex3f( -0.055, 0.055, 0.00 );
glTexCoord2f(texPowerup[item[i].type].pos[2],texPowerup[item[i].type].pos[3]);glVertex3f( 0.055, 0.055, 0.00 );
glTexCoord2f(texPowerup[item[i].type].pos[4],texPowerup[item[i].type].pos[5]);glVertex3f( 0.055,-0.055, 0.00 );
glTexCoord2f(texPowerup[item[i].type].pos[6],texPowerup[item[i].type].pos[7]);glVertex3f( -0.055,-0.055, 0.00 );
glEnd( );
glTranslatef( 0.11, 0.0, 0.0f);
}
}
void clearShop()
{
for(int i=0; i < NUMITEMSFORSALE; i++)
{
shopItemBlocked[i]=0;
}
}
};
void writeSettings()
{
ofstream conf;
conf.open(privFile.settingsFile.data(),ios::out | ios::trunc); //homeDirFiles.settingsFile.data()
if(conf.is_open())
{
conf << "eyecandy="<<setting.eyeCandy<<endl;
conf << "resx="<<setting.resx<<endl;
conf << "resy="<<setting.resy<<endl;
conf << "showbg="<<setting.showBg<<endl;
conf << "fullscreen="<<setting.fullscreen<<endl;
conf << "particlecollide="<<setting.particleCollide<<endl;
conf << "sound="<<setting.sound<<endl;
conf << "stereo="<<setting.stereo<<endl;
conf << "controlmaxspeed="<<setting.controlMaxSpeed<<endl;
conf << "controlaccel="<<setting.controlAccel<<endl;
conf << "controlstartspeed="<<setting.controlStartSpeed<<endl;
conf << "rightkey="<<setting.keyRight<<endl;
conf << "leftkey="<<setting.keyLeft<<endl;
conf << "nextkey="<<setting.keyNextPo<<endl;
conf << "buykey="<<setting.keyBuyPo<<endl;
conf << "prevkey="<<setting.keyPrevPo<<endl;
conf << "shootkey="<<setting.keyShoot<<endl;
conf << "joyenabled="<<setting.joyEnabled<<endl;
conf << "joyisdigital="<<setting.joyIsDigital<<endl;
conf << "joycalhighjitter="<<setting.JoyCalHighJitter<<endl;
conf << "joycallowjitter="<<setting.JoyCalLowJitter<<endl;
conf << "joycalmax="<<setting.JoyCalMax<<endl;
conf << "joycalmin="<<setting.JoyCalMin<<endl;
conf << "sndtheme="<<setting.sndTheme<<endl;
conf << "gfxtheme="<<setting.gfxTheme<<endl;
conf << "lvltheme="<<setting.lvlTheme<<endl;
conf << "startingdifficulty="<<player.difficulty<<endl;
conf << "showclock="<<setting.showClock<<endl;
conf << "fps="<<setting.fps<<endl;
conf.close();
} else {
cout << "Could not open ' ' for writing." << endl;
}
}
class speedometerClass {
public:
void draw()
{
//GLfloat y = -1.24 + difficulty.maxballspeed[player.difficulty]/2.44*var.averageBallSpeed;
GLfloat y = 2.48/ (difficulty.maxballspeed[player.difficulty] - difficulty.ballspeed[player.difficulty]) * (var.averageBallSpeed - difficulty.ballspeed[player.difficulty] );
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
glTranslatef(1.61, -1.24,-3.0);
glBegin( GL_QUADS );
glColor4f(0,1,0,1);
glVertex3f( 0, y, 0);
glVertex3f( 0.03, y, 0);
glColor4f(1,1,1,1);
glVertex3f( 0.03,0,0 );
glVertex3f( 0, 0 ,0);
glEnd( );
glEnable(GL_TEXTURE_2D);
}
};
struct savedGame {
char name[32];
struct player_struct player;
};
//Savegame files now consist of a int long header with a version number.
void saveGame(int slot, string name) {
fstream file;
struct savedGame game;
strcpy(game.name, name.data() );
game.player = SOLPlayer; //StartOfLevelPlayer, player as it was in the start of the level
file.open(privFile.saveGameFile.data(), ios::out | ios::in | ios::binary);
if(!file.is_open())
{
cout << "Could not open '"<<privFile.saveGameFile<<"' for Read+Write." << endl;
}
//move to the slot, mind the header
file.seekp( (sizeof(int))+((sizeof(savedGame)*slot)) );
file.write((char *)(&game), sizeof(savedGame));
file.close();
}
void clearSaveGames()
{
fstream file;
file.open(privFile.saveGameFile.data(), ios::out | ios::in | ios::binary);
if(!file.is_open())
{
cout << "Could not open '"<<privFile.saveGameFile<<"' for Read+Write." << endl;
}
//Write the header
const int sgHead = SAVEGAMEVERSION; //Savegame file version
file.write( (char *)(&sgHead), sizeof(int));
file.close();
saveGame(0, "Empty Slot");
saveGame(1, "Empty Slot");
saveGame(2, "Empty Slot");
saveGame(3, "Empty Slot");
saveGame(4, "Empty Slot");
saveGame(5, "Empty Slot");
}
void loadGame(int slot)
{
fstream file;
struct savedGame game;
file.open(privFile.saveGameFile.data(), ios::in | ios::binary);
if(!file.is_open())
cout << "Could not open '" << privFile.saveGameFile << "' for Reading." << endl;
//first, move to the slot
file.seekg( sizeof(int)+(sizeof(savedGame)*slot) );
file.read((char *)(&game), sizeof(savedGame));
file.close();
if(game.player.level != 0) //Only change level if level is not 0 (level one cannot be saved, and is used for the empty slots)
{
game.player.level--; //subtract one, because when the savegame is loaded, nextlevel is used to apply changes. nextlevel will add one to the level.
player = game.player;
gVar.nextlevel=1;
var.paused=1;
}
}
int listSaveGames(string slotName[])
{
fstream file;
struct savedGame slot[6];
int i=0;
file.open(privFile.saveGameFile.data() , ios::in | ios::binary);
if(!file.is_open())
{
cout << "Creating savegame slots in '"<<privFile.saveGameFile<<"'."<<endl;
file.open(privFile.saveGameFile.data(), ios::out | ios::binary);
if(!file.is_open())
{
cout << "Do not have permissions to write '" << privFile.saveGameFile << "'" <<endl;
return(0);
}
file.close();
clearSaveGames();
file.open(privFile.saveGameFile.data() , ios::in | ios::binary);
if(!file.is_open())
{
cout << "Could not write template."<<endl;
return(0);
}
}
//First we check if this is the right version
int sgHead=0x00; //Invalid version
file.read((char *)(&sgHead), sizeof(int));
if(sgHead!=SAVEGAMEVERSION)
{
cout << "Savegame format error, is v" << sgHead << " should be v'" << SAVEGAMEVERSION << "'." << endl;
cout << "Overwriting old savegames..." << endl;
file.close();
clearSaveGames();
file.open(privFile.saveGameFile.data() , ios::in | ios::binary);
file.seekp(sizeof(int));
}
while(1)
{
if(i == 6)
{
break;
}
file.read((char *)(&slot[i]), sizeof(savedGame));
if( file.eof())
{
break;
}
slotName[i] = slot[i].name;
i++;
}
file.close();
return(i);
}
void detonateExplosives(brick bricks[], effectManager & fxMan)
{
struct pos p,v;
for(int i=0; i < 598; i++)
{
if(bricks[i].active && bricks[i].type=='B')
{
p.x = bricks[i].posx;
p.y = bricks[i].posy;
v.x = 0.0;
v.y = 0.0;
bricks[i].hit(fxMan, p, v,0);
}
}
}
void dropBoard(brick bricks[])
{
for(int i=0; i < 598; i++)
{
if(bricks[i].active)
{
bricks[i].posy -= bricks[i].height*2;
if(bricks[i].posy < -1.00-bricks[i].height)
{
//Destroy brick, and subtract score
bricks[i].active=0;
updated_nbrick[bricks[i].row][bricks[i].bricknum]=-1;
var.bricksHit=1;
player.score -= bricks[i].score;
gVar.deadTime=0;
}
}
}
}
void explosiveGrow(brick bricks[])
{
for(int i=0; i < 598; i++)
{
if(bricks[i].active)
{
bricks[i].growExplosive(bricks);
}
}
for(int i=0; i < 598; i++)
{
bricks[i].justBecomeExplosive=0;
}
}
void easyBrick(brick bricks[])
{
for(int i=0; i < 598; i++)
{
if(bricks[i].active)
{
bricks[i].breakable();
}
}
}
bool checkDir(string & dir)
{
struct stat st;
if( stat(dir.data(), &st) != 0)
{
cout << "Directory '" << dir << "' does not exist, ";
#ifdef WIN32
if(CreateDirectory(dir.data(), NULL) != 0)
#else
if(mkdir(dir.data(), S_IRWXU | S_IRWXG) !=0)
#endif
{
cout << "could not create it." << endl;
return(0);
}
cout << "created it." << endl;
}
return(1);
}
#include "input.cpp"
#include "title.cpp"
bool screenShot()
{
FILE *fscreen;
char cName[256];
int i = 0;
bool found=0;
while(!found)
{
sprintf(cName, "%s/sdl-ball_%i.tga",privFile.screenshotDir.data(),i);
fscreen = fopen(cName,"rb");
if(fscreen==NULL)
found=1;
else
fclose(fscreen);
i++;
}
int nS = setting.resx * setting.resy * 3;
GLubyte *px = new GLubyte[nS];
if(px == NULL)
{
cout << "Alloc err, screenshot failed." <<endl;
return 0;
}
fscreen = fopen(cName,"wb");
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(0, 0, setting.resx, setting.resy, GL_BGR, GL_UNSIGNED_BYTE, px);
unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
unsigned char header[6] = { (unsigned char)(setting.resx%256), (unsigned char)(setting.resx/256),(unsigned char)(setting.resy%256),(unsigned char)(setting.resy/256),24,0};
fwrite(TGAheader, sizeof(unsigned char), 12, fscreen);
fwrite(header, sizeof(unsigned char), 6, fscreen);
fwrite(px, sizeof(GLubyte), nS, fscreen);
fclose(fscreen);
delete [] px;
cout << "Wrote screenshot to '" << cName << "'" <<endl;
return 1;
}
int main (int argc, char *argv[]) {
var.quit=0;
var.clearScreen=1;
var.titleScreenShow=1;
setting.gfxTheme="default";
setting.sndTheme="default";
setting.lvlTheme="default";
setting.eyeCandy = 1;
setting.showBg = 1;
setting.particleCollide=1;
setting.fullscreen = 1;
setting.sound = 1;
setting.stereo=1;
//Defaults for keyboard/joystick control
setting.keyLeft = (SDLKey)276;
setting.keyRight= (SDLKey)275;
setting.keyShoot= (SDLKey)273;
setting.keyNextPo=(SDLKey)SDLK_v;
setting.keyBuyPo =(SDLKey)SDLK_b;
setting.keyPrevPo=(SDLKey)SDLK_n;
setting.controlAccel = 7;
setting.controlStartSpeed = 1.0;
setting.controlMaxSpeed = 5;
setting.joyEnabled = 1;
setting.joyIsDigital = 1;
setting.showClock = 0;
//Default calibaration.
setting.JoyCalMin=-32767;
setting.JoyCalMax=32767;
setting.JoyCalLowJitter=-20;
setting.JoyCalHighJitter=20;
//Default starting difficulty
player.difficulty = NORMAL;
setting.fps=120;
int maxFrameAge= (1000/setting.fps); //When frame has been displayed this long
GLfloat mousex,mousey;
static_difficulty.ballspeed[EASY] = 0.7f;
static_difficulty.ballspeed[NORMAL] = 1.3f;
static_difficulty.ballspeed[HARD] = 1.6f;
static_difficulty.maxballspeed[EASY] = 1.5f;
static_difficulty.maxballspeed[NORMAL] = 2.2f;
static_difficulty.maxballspeed[HARD] = 3.0f;
static_difficulty.hitbrickinc[EASY] = 0.0025;
static_difficulty.hitbrickinc[NORMAL] = 0.003;
static_difficulty.hitbrickinc[HARD] = 0.004;
static_difficulty.hitpaddleinc[EASY] = -0.001;
static_difficulty.hitpaddleinc[NORMAL] = -0.0005;
static_difficulty.hitpaddleinc[HARD] = -0.0007;
//Percentage
static_difficulty.speedup[EASY] = 10.0f;
static_difficulty.speedup[NORMAL] = 20.0f;
static_difficulty.speedup[HARD] = 30.0f;
difficulty = static_difficulty;
cout << "SDL-Ball v "VERSION << endl;
// default to "" (If this have a 0 len after trying to getenv, it defaults to ./)
privFile.programRoot = "";
#ifndef WIN32
if(getenv("XDG_CONFIG_HOME") != NULL)
{
privFile.programRoot = getenv("XDG_CONFIG_HOME");
} else if(getenv("HOME") != NULL) {
privFile.programRoot = getenv("HOME");
privFile.programRoot.append("/.config");
}
#endif
//Default places if it can't place files another place.
privFile.saveGameFile = "./savegames.sav";
privFile.settingsFile ="./settings.cfg";
privFile.highScoreFile = "./highscores.txt";
privFile.screenshotDir = "./";
if(privFile.programRoot.length()==0)
{
cout << "Could not locate home directory defaulting to ./" << endl;
} else {
if( checkDir(privFile.programRoot))
{
privFile.programRoot.append("/sdl-ball");
if( checkDir(privFile.programRoot) )
{
privFile.saveGameFile = privFile.programRoot;
privFile.settingsFile = privFile.programRoot;
privFile.highScoreFile = privFile.programRoot;
privFile.saveGameFile.append("/savegame.sav");
privFile.settingsFile.append("/settings.cfg");
privFile.highScoreFile.append("/highscores.txt");
privFile.screenshotDir = privFile.programRoot;
privFile.screenshotDir.append("/screenshots");
if( !checkDir(privFile.screenshotDir) )
{
cout << "Screenshots are saved in current directory." << endl;
privFile.screenshotDir = "./";
}
}
}
}
srand((unsigned)time(0));
//Load settings
ifstream conf;
string line,set,val;
conf.open( privFile.settingsFile.data() );
if(conf.is_open())
{
while(!conf.eof())
{
getline(conf, line);
if(line.find('=') != string::npos)
{
set=line.substr(0,line.find('='));
val=line.substr(line.find('=')+1);
if(set=="eyecandy")
{
setting.eyeCandy=atoi(val.data());
} else if(set=="resx")
{
setting.cfgRes[0]=1;
setting.resx=atoi(val.data());
} else if(set=="resy")
{
setting.cfgRes[1]=1;
setting.resy=atoi(val.data());
} else if(set=="showbg")
{
setting.showBg=atoi(val.data());
} else if(set=="fullscreen")
{
setting.fullscreen=atoi(val.data());
} else if(set=="particlecollide")
{
setting.particleCollide=atoi(val.data());
} else if(set=="sound")
{
setting.sound=atoi(val.data());
} else if(set=="stereo")
{
setting.stereo=atoi(val.data());
} else if(set=="controlmaxspeed")
{
setting.controlMaxSpeed = atof(val.data());
} else if(set=="controlaccel")
{
setting.controlAccel = atof(val.data());
} else if(set=="controlstartspeed")
{
setting.controlStartSpeed = atof(val.data());
} else if(set=="rightkey")
{
setting.keyRight = (SDLKey)atoi(val.data());
} else if(set=="leftkey")
{
setting.keyLeft = (SDLKey)atoi(val.data());
} else if(set=="shootkey")
{
setting.keyShoot = (SDLKey)atoi(val.data());
} else if(set=="nextkey")
{
setting.keyNextPo = (SDLKey)atoi(val.data());
} else if(set=="buykey")
{
setting.keyBuyPo = (SDLKey)atoi(val.data());
} else if(set=="prevkey")
{
setting.keyPrevPo = (SDLKey)atoi(val.data());
} else if(set=="joyenabled")
{
setting.joyEnabled = atoi(val.data());
} else if(set=="joyisdigital")
{
setting.joyIsDigital = atoi(val.data());
} else if(set=="joycalhighjitter")
{
setting.JoyCalHighJitter = atoi(val.data());
} else if(set=="joycallowjitter")
{
setting.JoyCalLowJitter = atoi(val.data());
} else if(set=="joycalmax")
{
setting.JoyCalMax = atoi(val.data());
} else if(set=="joycalmin")
{
setting.JoyCalMin = atoi(val.data());
} else if(set=="lvltheme")
{
setting.lvlTheme = val;
} else if(set=="sndtheme")
{
setting.sndTheme = val;
} else if(set=="gfxtheme")
{
setting.gfxTheme = val;
} else if(set=="startingdifficulty")
{
player.difficulty=atoi(val.data());
} else if(set=="showclock")
{
setting.showClock=atoi(val.data());
} else if(set=="fps")
{
setting.fps=atoi(val.data());
maxFrameAge= (1000/setting.fps); }
else
{
cout << "I did not understand '"<<set<<"' in settings.cfg" << endl;
}
}
}
conf.close();
} else {
cout << "No config file found, using default settings." << endl;
}
//Initialize SDL
#ifndef NOSOUND
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) <0 )
#else
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK) <0 )
#endif
{
printf("\nError: Unable to initialize SDL:%s\n", SDL_GetError());
}
//Save current resolution so it can be restored at exit
int oldResX = SDL_GetVideoInfo()->current_w;
int oldResY = SDL_GetVideoInfo()->current_h;
int oldColorDepth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
/* Handle those situations where sdl gets a void resolution */
if(oldResX < 128 || oldResY < 96)
{
cout << "SDL Reported a screen resolution below 128x96."<< endl;
cout << "Assuming this is a bug in SDL or driver." << endl;
cout << "Falling back on 128x96";
oldResX=128;
oldResY=96;
if(!setting.cfgRes[0] || !setting.cfgRes[1])
{
setting.fullscreen=0;
cout << ", windowed mode.";
}
cout << endl;
}
/* The above code is not tested and might not work */
if(!setting.cfgRes[0] || !setting.cfgRes[1])
{
setting.resx = oldResX;
setting.resy = oldResY;
}
SDL_Event sdlevent;
#ifndef WIN32
SDL_WM_GrabInput(SDL_GRAB_ON);
#endif
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableUNICODE (1);
initScreen();
initGL();
glText = new glTextClass; // instantiate the class now that settings have been read.
soundMan.init();
SDL_WM_SetCaption("SDL-Ball", "SDL-Ball" );
SDL_WM_SetIcon( IMG_Load( useTheme("icon32.png", setting.gfxTheme).data() ), 0 );
SDL_WarpMouse(var.halfresx, var.halfresy);
textureManager texMgr;
textureClass texPaddleBase;
textureClass texPaddleLayers[2];
textureClass texBall[3];
textureClass texLvl[13];
texExplosiveBrick = &texLvl[0]; //Pointer to explosive texture..
textureClass texBorder;
textureClass texPowerup[MAXPOTEXTURES];
textureClass texBullet;
textureClass texParticle;
texMgr.readTexProps(useTheme("gfx/paddle/base.txt",setting.gfxTheme), texPaddleBase);
texMgr.readTexProps(useTheme("gfx/paddle/glue.txt",setting.gfxTheme), texPaddleLayers[0]);
texMgr.readTexProps(useTheme("gfx/paddle/gun.txt",setting.gfxTheme), texPaddleLayers[1]);
texMgr.readTexProps(useTheme("gfx/ball/normal.txt",setting.gfxTheme), texBall[0]);
texMgr.readTexProps(useTheme("gfx/ball/fireball.txt",setting.gfxTheme), texBall[1]);
texMgr.readTexProps(useTheme("gfx/ball/tail.txt",setting.gfxTheme), texBall[2]);
texMgr.readTexProps(useTheme("gfx/brick/explosive.txt", setting.gfxTheme), texLvl[0]);
texMgr.readTexProps(useTheme("gfx/brick/base.txt", setting.gfxTheme), texLvl[1]);
texMgr.readTexProps(useTheme("gfx/brick/cement.txt", setting.gfxTheme), texLvl[2]);
texMgr.readTexProps(useTheme("gfx/brick/doom.txt", setting.gfxTheme), texLvl[3]);
texMgr.readTexProps(useTheme("gfx/brick/glass.txt", setting.gfxTheme), texLvl[4]);
texMgr.readTexProps(useTheme("gfx/brick/invisible.txt", setting.gfxTheme), texLvl[5]);
texMgr.readTexProps(useTheme("gfx/brick/blue.txt", setting.gfxTheme), texLvl[6]);
texMgr.readTexProps(useTheme("gfx/brick/yellow.txt", setting.gfxTheme), texLvl[7]);
texMgr.readTexProps(useTheme("gfx/brick/green.txt", setting.gfxTheme), texLvl[8]);
texMgr.readTexProps(useTheme("gfx/brick/grey.txt", setting.gfxTheme), texLvl[9]);
texMgr.readTexProps(useTheme("gfx/brick/purple.txt", setting.gfxTheme), texLvl[10]);
texMgr.readTexProps(useTheme("gfx/brick/white.txt", setting.gfxTheme), texLvl[11]);
texMgr.readTexProps(useTheme("gfx/brick/red.txt", setting.gfxTheme), texLvl[12]);
texMgr.load(useTheme("gfx/border.png",setting.gfxTheme), texBorder);
texMgr.readTexProps(useTheme("gfx/powerup/coin.txt",setting.gfxTheme),texPowerup[PO_COIN]);
texMgr.readTexProps(useTheme("gfx/powerup/glue.txt",setting.gfxTheme),texPowerup[PO_GLUE]);
texMgr.readTexProps(useTheme("gfx/powerup/multiball.txt",setting.gfxTheme),texPowerup[PO_MULTIBALL]);
texMgr.readTexProps(useTheme("gfx/powerup/bigball.txt",setting.gfxTheme),texPowerup[PO_BIGBALL]);
texMgr.readTexProps(useTheme("gfx/powerup/normalball.txt",setting.gfxTheme),texPowerup[PO_NORMALBALL]);
texMgr.readTexProps(useTheme("gfx/powerup/smallball.txt",setting.gfxTheme),texPowerup[PO_SMALLBALL]);
texMgr.readTexProps(useTheme("gfx/powerup/aim.txt",setting.gfxTheme),texPowerup[PO_AIM]);
texMgr.readTexProps(useTheme("gfx/powerup/explosive.txt",setting.gfxTheme),texPowerup[PO_EXPLOSIVE]);
texMgr.readTexProps(useTheme("gfx/powerup/gun.txt",setting.gfxTheme),texPowerup[PO_GUN]);
texMgr.readTexProps(useTheme("gfx/powerup/go-thru.txt",setting.gfxTheme),texPowerup[PO_THRU]);
texMgr.readTexProps(useTheme("gfx/powerup/laser.txt",setting.gfxTheme),texPowerup[PO_LASER]);
texMgr.readTexProps(useTheme("gfx/powerup/life.txt",setting.gfxTheme),texPowerup[PO_LIFE]);
texMgr.readTexProps(useTheme("gfx/powerup/die.txt",setting.gfxTheme),texPowerup[PO_DIE]);
texMgr.readTexProps(useTheme("gfx/powerup/drop.txt",setting.gfxTheme),texPowerup[PO_DROP]);
texMgr.readTexProps(useTheme("gfx/powerup/detonate.txt",setting.gfxTheme),texPowerup[PO_DETONATE]);
texMgr.readTexProps(useTheme("gfx/powerup/explosive-grow.txt",setting.gfxTheme),texPowerup[PO_EXPLOSIVE_GROW]);
texMgr.readTexProps(useTheme("gfx/powerup/easybrick.txt",setting.gfxTheme),texPowerup[PO_EASYBRICK]);
texMgr.readTexProps(useTheme("gfx/powerup/nextlevel.txt",setting.gfxTheme),texPowerup[PO_NEXTLEVEL]);
texMgr.readTexProps(useTheme("gfx/powerup/aimhelp.txt",setting.gfxTheme),texPowerup[PO_AIMHELP]);
texMgr.readTexProps(useTheme("gfx/powerup/growbat.txt",setting.gfxTheme), texPowerup[PO_GROWPADDLE]);
texMgr.readTexProps(useTheme("gfx/powerup/shrinkbat.txt",setting.gfxTheme), texPowerup[PO_SHRINKPADDLE]);
texMgr.readTexProps(useTheme("gfx/powerup/bullet.txt",setting.gfxTheme), texBullet);
pMan.init(texPowerup);
texMgr.load(useTheme("gfx/particle.png",setting.gfxTheme), texParticle);
GLuint sceneDL;
mkDLscene(&sceneDL, texBorder);
brick bricks[598];
string levelfile = useTheme("levels.txt",setting.lvlTheme);
int i=0; //bruges i for loop xD
glScoreBoard scoreboard;
menuClass menu;
paddle_class paddle;
paddle.tex = texPaddleBase;
paddle.layerTex = texPaddleLayers;
struct pos p; //kordinater for hvor den stødte sammen
effectManager fxMan;
fxMan.set(FX_VAR_TEXTURE, texParticle);
fxMan.set(FX_VAR_GRAVITY, 0.6f);
titleScreenClass titleScreen(&fxMan, texPowerup, &menu);
ballManager bMan(texBall);
initNewGame();
paddle.posy = -1.15;
highScoreClass hKeeper;
backgroundClass bg;
bulletsClass bullet(texBullet);
speedometerClass speedo;
hudClass hud(texBall[0], texPowerup); //This is GOING to be containing the "hud" (score, borders, lives left, level, speedometer)
var.effectnum=-1;
int lastTick = SDL_GetTicks();
int nonpausingLastTick = lastTick;
char txt[256];
int frameAge=0; //How long have the current frame been shown
// #define performanceTimer
#ifdef performanceTimer
struct timeval timeStart,timeStop;
int renderTime;
#endif
controllerClass control(&paddle, &bullet, &bMan);
soundMan.add(SND_START,0);
while(!var.quit)
{
#ifdef performanceTimer
gettimeofday(&timeStart, NULL);
#endif
nonpausingGlobalTicks = SDL_GetTicks() - nonpausingLastTick;
frameAge += nonpausingGlobalTicks;
nonpausingGlobalMilliTicks = nonpausingGlobalTicks/1000.0;
nonpausingLastTick = SDL_GetTicks();
if(!var.paused)
{
globalTicks = SDL_GetTicks() - lastTick;
globalMilliTicks = globalTicks/1000.0;
} else {
globalTicks = globalMilliTicks = 0;
}
lastTick = SDL_GetTicks();
globalTicksSinceLastDraw += nonpausingGlobalTicks;
globalMilliTicksSinceLastDraw += nonpausingGlobalMilliTicks;
gVar.deadTime += globalTicks;
//really ugly... but easy
if(!var.titleScreenShow)
{
if(gVar.deadTime > 20000)
{
gVar.deadTime=0;
bMan.powerup(PO_EXPLOSIVE); //give the balls explosive ability, in order to blow up cement block and get on with the game
}
if(bMan.activeBalls == 0 && !gVar.newLevel) //check kun om vi er døde hvis vi faktisk er kommet igang med at spille
{
player.lives--;
if(player.lives > 0)
{
resetPlayerPowerups();
gVar.newLife=1;
if(!paddle.dead)
player.explodePaddle=1;
pMan.die(fxMan);
} else if(!gVar.gameOver) {
gVar.gameOver=1;
pauseGame();
if( hKeeper.isHighScore() )
{
// announce.write(string text, int mslife, int fontnum);
announce.write("Highscore!", 3000,FONT_ANNOUNCE_GOOD);
var.showHighScores=1;
soundMan.add(SND_HIGHSCORE, 0);
}
} else if(gVar.gameOver && !var.showHighScores)
{
//Only ran if there is gameover and no highscore
if(var.effectnum == -1)
{
fxMan.set(FX_VAR_TYPE, FX_TRANSIT);
fxMan.set(FX_VAR_LIFE, 3000);
fxMan.set(FX_VAR_COLOR, 0.0,0.0,0.0);
p.x = 0.0;
p.y = 0.0;
//Kør en transition effekt
var.effectnum = fxMan.spawn(p);
announce.write("GameOver!", 1500,FONT_ANNOUNCE_BAD);
soundMan.add(SND_GAMEOVER, 0);
} else {
if(var.transition_half_done)
{
var.titleScreenShow=1;
fxMan.kill(var.effectnum);
var.effectnum = -1;
initNewGame();
resumeGame();
}
}
}
}
if(gVar.nextlevel)
{
if(var.effectnum == -1)
{
announce.write("Well Done!", 1000, FONT_ANNOUNCE_GOOD);
soundMan.add(SND_NEXTLEVEL, 0);
if(bMan.activeBalls > 1)
{
sprintf(txt, "Bonus: %i", bMan.activeBalls*150);
player.score += (bMan.activeBalls*150)*player.multiply;
announce.write(txt, 2000, FONT_ANNOUNCE_GOOD);
}
fxMan.set(FX_VAR_TYPE, FX_TRANSIT);
fxMan.set(FX_VAR_LIFE, 1600);
fxMan.set(FX_VAR_COLOR, 0.0,0.0,0.0);
p.x = 0.0;
p.y = 0.0;
//Kør en transition effekt
var.effectnum = fxMan.spawn(p);
var.idiotlock = 0;
} else {
if(var.transition_half_done)
{
if(!var.idiotlock)
{
var.idiotlock=1;
player.level++;
SOLPlayer = player; // Capture how player is at the start of this level
//If player completed all levels, restart the game with higher multiplier
if(player.level == var.numlevels)
{
player.multiply += player.multiply*3;
player.level=0;
announce.write("Finished!",3500,FONT_ANNOUNCE_GOOD);
}
sprintf(txt, "Level %i",player.level+1); //+1 fordi levels starter fra 0
announce.write(txt,1500,FONT_ANNOUNCE_GOOD);
//check om vi skal fjerne powerups
if(player.difficulty > EASY)
{
resetPlayerPowerups();
}
gVar.newLevel = 1;
var.paused=0;
}
}
if(!fxMan.isActive(var.effectnum))
{
var.effectnum = -1; //nulstil så den er klar igen
gVar.nextlevel = 0;
var.paused = 0;
var.idiotlock=0;
}
}
}
if(gVar.newLevel)
{
var.bricksHit = 1;
gVar.newLevel=0;
loadlevel(levelfile, bricks,player.level);
initlevels(bricks,texLvl);
gVar.gameOver=0;
gVar.newLife=1;
pMan.clear();
bullet.clear();
paddle.posx = 0.0;
var.startedPlaying=0;
bg.init(texMgr);
hud.clearShop();
}
if(gVar.newLife)
{
gVar.newLife=0;
paddle.init();
p.x=paddle.posx;
p.y=paddle.posy+paddle.height+0.025;
bMan.clear();
bMan.spawn(p,1,paddle.width,difficulty.ballspeed[player.difficulty],1.57100000f); //Not exactly 90 degree, so the ball will always fall a bit to the side
}
if(frameAge >= maxFrameAge)
{
if(var.clearScreen)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
//Update player score
scoreboard.update(player.score);
//background
if(setting.showBg)
bg.draw();
//borders
glCallList(sceneDL);
if(var.scrollInfo.drop)
{
if( (SDL_GetTicks() - var.scrollInfo.lastTick ) > var.scrollInfo.dropspeed )
{
var.scrollInfo.lastTick=SDL_GetTicks();
dropBoard(bricks);
}
}
if(gVar.bricksleft==1)
{
player.powerup[PO_AIMHELP]=1;
}
}
bullet.move();
gVar.bricksleft=0;
//Update nbrick here
if(var.bricksHit)
{
memcpy(nbrick, updated_nbrick, sizeof(updated_nbrick));
var.bricksHit = 0;
}
for(i=0; i <598; i++)
{
if(bricks[i].active)
{
if(bricks[i].destroytowin && bricks[i].hitsLeft)
{
gVar.bricksleft++;
}
if(bricks[i].collide)
{
bMan.bcoldet(bricks[i], fxMan);
//bullets
if(player.powerup[PO_GUN])
{
bullet.coldet(bricks[i], fxMan);
}
//check kollision på effekterne
if(setting.particleCollide && setting.eyeCandy && frameAge >= maxFrameAge)
fxMan.coldet(bricks[i]);
}
if(frameAge >= maxFrameAge)
bricks[i].draw(bricks,fxMan);
} //aktiv brik
} // for loop
//Collission between paddle and balls
if( bMan.pcoldet(paddle, fxMan) )
{
if(player.powerup[PO_DROP])
{
dropBoard(bricks);
}
}
bMan.move();
if(setting.particleCollide && setting.eyeCandy && frameAge >= maxFrameAge)
fxMan.pcoldet(paddle);
pMan.move();
if(pMan.coldet(paddle, fxMan, bMan))
{
if(player.powerup[PO_DETONATE])
{
player.powerup[PO_DETONATE]=0;
detonateExplosives(bricks, fxMan);
}
if(player.powerup[PO_EASYBRICK])
{
player.powerup[PO_EASYBRICK]=0;
easyBrick(bricks);
}
if(player.powerup[PO_NEXTLEVEL])
{
player.powerup[PO_NEXTLEVEL]=0;
gVar.nextlevel=1;
var.paused=1;
}
if(player.powerup[PO_EXPLOSIVE_GROW])
{
player.powerup[PO_EXPLOSIVE_GROW]=0;
explosiveGrow(bricks);
}
}
if(frameAge >= maxFrameAge)
{
soundMan.play();
if(player.explodePaddle)
{
player.explodePaddle=0;
soundMan.add(SND_DIE,0);
if(setting.eyeCandy)
{
fxMan.set(FX_VAR_TYPE, FX_PARTICLEFIELD);
p.x=paddle.width*2;
p.y=paddle.height*2;
fxMan.set(FX_VAR_RECTANGLE, p);
p.x=paddle.posx;
p.y=paddle.posy;
fxMan.set(FX_VAR_LIFE, 2000);
fxMan.set(FX_VAR_NUM, 20);
fxMan.set(FX_VAR_SIZE, 0.025f);
fxMan.set(FX_VAR_SPEED, 0.35f);
fxMan.set(FX_VAR_GRAVITY, -0.7f);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
fxMan.spawn(p);
fxMan.set(FX_VAR_NUM, 32);
fxMan.set(FX_VAR_SIZE, 0.05f);
fxMan.set(FX_VAR_LIFE, 1500);
fxMan.set(FX_VAR_SPEED, 0.7f);
fxMan.set(FX_VAR_GRAVITY, 0.0f);
fxMan.set(FX_VAR_COLOR, 0.5f, 0.5f, 0.5f);
fxMan.spawn(p);
fxMan.set(FX_VAR_COLOR, 1.0f, 1.0f, 1.0f);
fxMan.spawn(p);
}
}
bMan.updatelast();
glColor3d(255,255,255);
bullet.draw();
paddle.draw();
pMan.draw();
bMan.draw(paddle);
scoreboard.draw();
speedo.draw();
hud.draw();
fxMan.draw();
if(var.showHighScores)
hKeeper.draw();
if(var.menu>0)
{
if(var.menu==10 || var.menu==11)
{
control.calibrate();
}
menu.doMenu();
}
announce.draw();
SDL_GL_SwapBuffers( );
frameAge = 0;
globalTicksSinceLastDraw=0;
globalMilliTicksSinceLastDraw=0;
#ifdef performanceTimer
cout << "FrameAge:";
} else {
cout << "LoopAge:";
}
gettimeofday(&timeStop, NULL);
renderTime = timeStop.tv_usec - timeStart.tv_usec;
cout << renderTime << endl;
#else
}
#endif
if(!gVar.bricksleft)
{
gVar.nextlevel=1;
var.paused=1;
}
} else {
//Show the title screen
titleScreen.draw(&frameAge, &maxFrameAge);
}
control.get(); //Check for keypresses and joystick events
while (SDL_PollEvent(&sdlevent) )
{
if( sdlevent.type == SDL_KEYDOWN ) {
if(var.showHighScores)
{
hKeeper.type(sdlevent, menu);
} else if(var.enterSaveGameName)
{
menu.enterSaveGameName(sdlevent);
} else {
if( sdlevent.key.keysym.sym==SDLK_p || sdlevent.key.keysym.sym==SDLK_PAUSE)
{
var.paused ? resumeGame() : pauseGame();
}
if( sdlevent.key.keysym.sym == SDLK_q )
{
var.quit=1;
} else if( sdlevent.key.keysym.sym == SDLK_s )
{
screenShot();
} else if( sdlevent.key.keysym.sym == setting.keyNextPo)
{
gVar.shopPrevItem=1;
} else if( sdlevent.key.keysym.sym == setting.keyBuyPo)
{
gVar.shopBuyItem=1;
} else if( sdlevent.key.keysym.sym == setting.keyPrevPo)
{
gVar.shopNextItem=1;
} else if(sdlevent.key.keysym.sym == SDLK_u)
{
var.clearScreen ? var.clearScreen=0:var.clearScreen=1;
} else if(sdlevent.key.keysym.sym == SDLK_c)
{
setting.showClock ? setting.showClock=0 : setting.showClock=1;
writeSettings();
}
#ifdef WITH_WIIUSE
if( sdlevent.key.keysym.sym == SDLK_w )
{
var.titleScreenShow=0;
pauseGame();
var.menu=11;
var.menuJoyCalStage=-1;
}
#endif
}
//Toggle menu
if( sdlevent.key.keysym.sym == SDLK_ESCAPE)
{
if(var.titleScreenShow)
var.titleScreenShow=0;
switch(var.menu)
{
case 0:
var.menu=1;
pauseGame();
break;
case 1:
resumeGame();
break;
default:
var.menu=1;
break;
}
} else if( sdlevent.key.keysym.sym == SDLK_F1 )
{
if(!var.titleScreenShow)
{
var.titleScreenShow=1;
} else {
var.titleScreenShow=0;
}
}
#ifndef WIN32
else if( sdlevent.key.keysym.sym == SDLK_F11 )
{
if(setting.fullscreen)
setting.fullscreen=0;
else
setting.fullscreen=1;
initScreen();
}
#endif
}
if( sdlevent.type == SDL_MOUSEMOTION )
{
mousex = (sdlevent.motion.x - var.halfresx) * var.glunits_per_xpixel;
mousey = (sdlevent.motion.y - var.halfresy) * var.glunits_per_ypixel * -1;
if(var.menu)
{
if(mousex > -0.5 && mousex < 0.5 && mousey < (-0.78)+(0.07) && mousey > (-0.78)-(0.07) )
var.menuItem = 1;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (-0.56)+(0.07) && mousey > (-0.56)-(0.07) )
var.menuItem = 2;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (-0.34)+(0.07) && mousey > (-0.34)-(0.07) )
var.menuItem = 3;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (-0.12)+(0.07) && mousey > (-0.12)-(0.07) )
var.menuItem = 4;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (0.1)+(0.07) && mousey > (0.1)-(0.07) )
var.menuItem = 5;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (0.32)+(0.07) && mousey > (0.32)-(0.07) )
var.menuItem = 6;
else if(mousex > -0.5 && mousex < 0.5 && mousey < (0.54)+(0.07) && mousey > (0.54)-(0.07) )
var.menuItem = 7;
else
var.menuItem = 0;
} else {
control.movePaddle(mousex);
}
} else if( sdlevent.type == SDL_MOUSEBUTTONDOWN )
{
if(sdlevent.button.button == SDL_BUTTON_LEFT )
{
if(var.menu)
{
var.menuPressed=1;
if(var.menuItem > 0)
soundMan.add(SND_MENUCLICK, 0);
}
control.btnPress();
} else if(sdlevent.button.button == SDL_BUTTON_RIGHT )
{
gVar.shopBuyItem=1;
} else if(sdlevent.button.button == 4)
{
gVar.shopPrevItem=1;
} else if(sdlevent.button.button == 5)
{
gVar.shopNextItem=1;
}
}
if( sdlevent.type == SDL_QUIT ) {
var.quit = 1;
} else if( sdlevent.type == SDL_VIDEORESIZE )
{
setting.resx = sdlevent.resize.w;
setting.resy = sdlevent.resize.h;
initScreen();
}
}
#ifdef WIN32
Sleep( 1 );
#else
usleep( 1000 );
#endif
}
#ifndef WIN32
if(setting.fullscreen)
SDL_SetVideoMode(oldResX,oldResY,oldColorDepth, SDL_OPENGL);
#endif
#ifndef WIN32
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
SDL_ShowCursor(SDL_ENABLE);
SDL_FreeSurface(screen);
SDL_Quit();
cout << "Thank you for playing sdl-ball ;)" << endl;
return EXIT_SUCCESS;
}
|