diff options
author | Tomer Shalev <shalev.tomer@gmail.com> | 2010-02-21 17:16:07 +0000 |
---|---|---|
committer | Tomer Shalev <shalev.tomer@gmail.com> | 2010-02-21 17:16:07 +0000 |
commit | cd08122e4e6a8aef60b0580c8dfba55d73ea1790 (patch) | |
tree | 59b5a98b96906b94df7d2b92ed03aba6f6b5b1c6 | |
parent | 3dc9d111b39f24ace7f8afcb3958dcb218dff8de (diff) | |
download | rockbox-cd08122e4e6a8aef60b0580c8dfba55d73ea1790.tar.gz rockbox-cd08122e4e6a8aef60b0580c8dfba55d73ea1790.zip |
Brickmania: Hopefully prevent dissappearing of the ball
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24810 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/brickmania.c | 208 |
1 files changed, 104 insertions, 104 deletions
diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index e8adb76738..25eb7e9ef7 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c | |||
@@ -1851,127 +1851,127 @@ static int brickmania_game_loop(void) | |||
1851 | } | 1851 | } |
1852 | } | 1852 | } |
1853 | 1853 | ||
1854 | /* Check if the ball hit the left side */ | 1854 | if (game_state != ST_READY && !ball[k].glue) |
1855 | screen_edge.p1.x = 0; | ||
1856 | screen_edge.p1.y = 0; | ||
1857 | |||
1858 | screen_edge.p2.x = 0; | ||
1859 | screen_edge.p2.y = GAMESCREEN_HEIGHT; | ||
1860 | if ( !ball[k].glue && | ||
1861 | check_lines(&misc_line, &screen_edge, &pt_hit)) | ||
1862 | { | ||
1863 | /* Reverse direction */ | ||
1864 | ball[k].speedx = -ball[k].speedx; | ||
1865 | |||
1866 | /* Re-position ball in gameboard */ | ||
1867 | ball[k].tempy = pt_hit.y; | ||
1868 | ball[k].tempx = 0; | ||
1869 | } | ||
1870 | |||
1871 | /* Check if the ball hit the right side */ | ||
1872 | screen_edge.p1.x = GAMESCREEN_WIDTH; | ||
1873 | screen_edge.p1.y = 0; | ||
1874 | |||
1875 | screen_edge.p2.x = GAMESCREEN_WIDTH; | ||
1876 | screen_edge.p2.y = GAMESCREEN_HEIGHT; | ||
1877 | if ( !ball[k].glue && | ||
1878 | check_lines(&misc_line, &screen_edge, &pt_hit)) | ||
1879 | { | 1855 | { |
1880 | /* Reverse direction */ | 1856 | /* Check if the ball hit the left side */ |
1881 | ball[k].speedx = -ball[k].speedx; | 1857 | screen_edge.p1.x = 0; |
1858 | screen_edge.p1.y = 0; | ||
1882 | 1859 | ||
1883 | /* Re-position ball in gameboard */ | 1860 | screen_edge.p2.x = 0; |
1884 | ball[k].tempy = pt_hit.y; | 1861 | screen_edge.p2.y = GAMESCREEN_HEIGHT; |
1885 | ball[k].tempx = GAMESCREEN_WIDTH - FIXED3(1); | 1862 | if (check_lines(&misc_line, &screen_edge, &pt_hit)) |
1886 | } | 1863 | { |
1864 | /* Reverse direction */ | ||
1865 | ball[k].speedx = -ball[k].speedx; | ||
1887 | 1866 | ||
1888 | /* Did the ball hit the paddle? Depending on where the ball | 1867 | /* Re-position ball in gameboard */ |
1889 | * Hit set the x/y speed appropriately. | 1868 | ball[k].tempy = pt_hit.y; |
1890 | */ | 1869 | ball[k].tempx = 0; |
1891 | if( game_state!=ST_READY && !ball[k].glue && | 1870 | } |
1892 | check_lines(&misc_line, &pad_line, &pt_hit) ) | ||
1893 | { | ||
1894 | /* Re-position ball based on collision */ | ||
1895 | ball[k].tempy = ON_PAD_POS_Y; | ||
1896 | ball[k].tempx = pt_hit.x; | ||
1897 | 1871 | ||
1898 | /* Calculate the ball position relative to the paddle width */ | 1872 | /* Check if the ball hit the right side */ |
1899 | int ball_repos = pt_hit.x - pad_pos_x; | 1873 | screen_edge.p1.x = GAMESCREEN_WIDTH; |
1900 | /* If the ball hits the right half of paddle, x speed | 1874 | screen_edge.p1.y = 0; |
1901 | * should be positive, if it hits the left half it | ||
1902 | * should be negative. | ||
1903 | */ | ||
1904 | int x_direction = -1; | ||
1905 | 1875 | ||
1906 | /* Comparisons are done with respect to 1/2 pad_width */ | 1876 | screen_edge.p2.x = GAMESCREEN_WIDTH; |
1907 | if(ball_repos > pad_width/2) | 1877 | screen_edge.p2.y = GAMESCREEN_HEIGHT; |
1878 | if (check_lines(&misc_line, &screen_edge, &pt_hit)) | ||
1908 | { | 1879 | { |
1909 | /* flip the relative position */ | 1880 | /* Reverse direction */ |
1910 | ball_repos -= ((ball_repos - pad_width/2) << 1); | 1881 | ball[k].speedx = -ball[k].speedx; |
1911 | /* Ball hit the right half so X speed calculations | 1882 | |
1912 | * should be positive. | 1883 | /* Re-position ball in gameboard */ |
1913 | */ | 1884 | ball[k].tempy = pt_hit.y; |
1914 | x_direction = 1; | 1885 | ball[k].tempx = GAMESCREEN_WIDTH - FIXED3(1); |
1915 | } | 1886 | } |
1916 | 1887 | ||
1917 | /* Figure out where the ball hit relative to 1/2 pad | 1888 | /* Did the ball hit the paddle? Depending on where the ball |
1918 | * and in divisions of 4. | 1889 | * Hit set the x/y speed appropriately. |
1919 | */ | 1890 | */ |
1920 | ball_repos = ball_repos / (pad_width/2/4); | 1891 | if(check_lines(&misc_line, &pad_line, &pt_hit) ) |
1921 | |||
1922 | switch(ball_repos) | ||
1923 | { | 1892 | { |
1924 | /* Ball hit the outer edge of the paddle */ | 1893 | /* Re-position ball based on collision */ |
1925 | case 0: | 1894 | ball[k].tempy = ON_PAD_POS_Y; |
1926 | ball[k].speedy = SPEED_1Q_Y; | 1895 | ball[k].tempx = pt_hit.x; |
1927 | ball[k].speedx = SPEED_1Q_X * x_direction; | 1896 | |
1928 | break; | 1897 | /* Calculate the ball position relative to the paddle width */ |
1929 | /* Ball hit the next fourth of the paddle */ | 1898 | int ball_repos = pt_hit.x - pad_pos_x; |
1930 | case 1: | 1899 | /* If the ball hits the right half of paddle, x speed |
1931 | ball[k].speedy = SPEED_2Q_Y; | 1900 | * should be positive, if it hits the left half it |
1932 | ball[k].speedx = SPEED_2Q_X * x_direction; | 1901 | * should be negative. |
1933 | break; | ||
1934 | /* Ball hit the third fourth of the paddle */ | ||
1935 | case 2: | ||
1936 | ball[k].speedy = SPEED_3Q_Y; | ||
1937 | ball[k].speedx = SPEED_3Q_X * x_direction; | ||
1938 | break; | ||
1939 | /* Ball hit the fourth fourth of the paddle or dead | ||
1940 | * center. | ||
1941 | */ | ||
1942 | case 3: | ||
1943 | case 4: | ||
1944 | ball[k].speedy = SPEED_4Q_Y; | ||
1945 | /* Since this is the middle we don't want to | ||
1946 | * force the ball in a different direction. | ||
1947 | * Just keep it going in the same direction | ||
1948 | * with a specific speed. | ||
1949 | */ | 1902 | */ |
1950 | if(ball[k].speedx > 0) | 1903 | int x_direction = -1; |
1904 | |||
1905 | /* Comparisons are done with respect to 1/2 pad_width */ | ||
1906 | if(ball_repos > pad_width/2) | ||
1951 | { | 1907 | { |
1952 | ball[k].speedx = SPEED_4Q_X; | 1908 | /* flip the relative position */ |
1909 | ball_repos -= ((ball_repos - pad_width/2) << 1); | ||
1910 | /* Ball hit the right half so X speed calculations | ||
1911 | * should be positive. | ||
1912 | */ | ||
1913 | x_direction = 1; | ||
1953 | } | 1914 | } |
1954 | else | 1915 | |
1916 | /* Figure out where the ball hit relative to 1/2 pad | ||
1917 | * and in divisions of 4. | ||
1918 | */ | ||
1919 | ball_repos = ball_repos / (pad_width/2/4); | ||
1920 | |||
1921 | switch(ball_repos) | ||
1955 | { | 1922 | { |
1956 | ball[k].speedx = -SPEED_4Q_X; | 1923 | /* Ball hit the outer edge of the paddle */ |
1957 | } | 1924 | case 0: |
1958 | break; | 1925 | ball[k].speedy = SPEED_1Q_Y; |
1926 | ball[k].speedx = SPEED_1Q_X * x_direction; | ||
1927 | break; | ||
1928 | /* Ball hit the next fourth of the paddle */ | ||
1929 | case 1: | ||
1930 | ball[k].speedy = SPEED_2Q_Y; | ||
1931 | ball[k].speedx = SPEED_2Q_X * x_direction; | ||
1932 | break; | ||
1933 | /* Ball hit the third fourth of the paddle */ | ||
1934 | case 2: | ||
1935 | ball[k].speedy = SPEED_3Q_Y; | ||
1936 | ball[k].speedx = SPEED_3Q_X * x_direction; | ||
1937 | break; | ||
1938 | /* Ball hit the fourth fourth of the paddle or dead | ||
1939 | * center. | ||
1940 | */ | ||
1941 | case 3: | ||
1942 | case 4: | ||
1943 | ball[k].speedy = SPEED_4Q_Y; | ||
1944 | /* Since this is the middle we don't want to | ||
1945 | * force the ball in a different direction. | ||
1946 | * Just keep it going in the same direction | ||
1947 | * with a specific speed. | ||
1948 | */ | ||
1949 | if(ball[k].speedx > 0) | ||
1950 | { | ||
1951 | ball[k].speedx = SPEED_4Q_X; | ||
1952 | } | ||
1953 | else | ||
1954 | { | ||
1955 | ball[k].speedx = -SPEED_4Q_X; | ||
1956 | } | ||
1957 | break; | ||
1959 | 1958 | ||
1960 | default: | 1959 | default: |
1961 | ball[k].speedy = SPEED_4Q_Y; | 1960 | ball[k].speedy = SPEED_4Q_Y; |
1962 | break; | 1961 | break; |
1963 | } | 1962 | } |
1964 | 1963 | ||
1965 | if(pad_type == STICKY) | 1964 | if(pad_type == STICKY) |
1966 | { | 1965 | { |
1967 | ball[k].speedy = -ball[k].speedy; | 1966 | ball[k].speedy = -ball[k].speedy; |
1968 | ball[k].glue=true; | 1967 | ball[k].glue=true; |
1969 | 1968 | ||
1970 | /* X location should not be forced since that is moved with the paddle. The Y | 1969 | /* X location should not be forced since that is moved with the paddle. The Y |
1971 | * position should be forced to keep the ball at the paddle. | 1970 | * position should be forced to keep the ball at the paddle. |
1972 | */ | 1971 | */ |
1973 | ball[k].tempx = 0; | 1972 | ball[k].tempx = 0; |
1974 | ball[k].tempy = ON_PAD_POS_Y; | 1973 | ball[k].tempy = ON_PAD_POS_Y; |
1974 | } | ||
1975 | } | 1975 | } |
1976 | } | 1976 | } |
1977 | 1977 | ||