- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define width 65
#define height 25
char mas[height][width+1];
typedef struct {
int x, y, w;
} TRocket;
TRocket racket;
typedef struct { float x, y; int ix, iy; float alfa; float speed;} TBall;
TBall ball;
int hitCnt = 0;int maxHitCnt = 0;
void init(int level)
{ for(int w=0; w<width; w++) mas[0][w] = '#'; strncpy(mas[1], mas[0], width) for(int w=1; w < width-1; w++) mas[1][w] = ' '; for(int h=2; h < height; h++) strncpy(mas[h], mas[1], width);
if(level == 1)
{
for(int w=10; w < width-10; w++)
mas[5][w] = '#';
}
}
void show()
{
for(int x=0; x<height; x++)
{
printf("%s", mas[x]); if(x == 3)
printf(" hit: %d", hitCnt);
if(x == 4) printf(" max: %d", maxHitCnt);
printf("\n");
}
}
void initRocket()
{
racket.w = 7;
racket.x = (width - racket.w) / 2;
racket.y = height - 1;
}
void initBall()
{
moveBall(2.0, 2.0);
ball.alfa = -1;
ball.speed = 0.5;
}
void putBall()
{
mas[ball.iy][ball.ix] = '*';
}
void moveBall(float x, float y)
{
ball.x = x;
ball.y = y;
ball.ix = (int)ball.x;
ball.iy = (int)ball.y;
}
void autoMoveBall()
{
if(ball.alfa < 0) ball.alfa += M_PI*2;
if(ball.alfa > M_PI*2) ball.alfa -= M_PI*2;
TBall bl = ball;
moveBall(ball.x + cos(ball.alfa) * ball.speed,
ball.y + sin(ball.alfa) * ball.speed);
if(mas[ball.iy][ball.ix] == '#' || mas[ball.iy][ball.ix] == '@')
{
if(mas[ball.iy][ball.ix] == '@')