-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.c
More file actions
98 lines (85 loc) · 2.13 KB
/
ai.c
File metadata and controls
98 lines (85 loc) · 2.13 KB
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
#include <pic32mx.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "header.h"
#include <math.h>
int targetY;
int delayCounter = 0;
int delayTarget = 0;
void aiHandler()
{
if (delayCounter >= delayTarget)
{
if ((getPlayerPosition(2)) + (playerHeight / 2) < targetY)
{
updatePlayerPos(0.2, 2);
}
else if (getPlayerPosition(2) + (playerHeight / 2) > targetY)
{
updatePlayerPos(-0.2, 2);
}
} else {
delayCounter++;
}
}
void calculateBallImpact()
{
delayTarget = delayByDifficulty();
delayCounter = 0;
int gameHeight = 32;
double cloneBallX = getBallPositionX();
double cloneBallY = getBallPositionY();
double cloneBallSpeedX = ballSpeedX;
double cloneBallSpeedY = ballSpeedY;
double cloneBallSize = getBallSize();
while (cloneBallX + cloneBallSize < 123)
{
cloneBallY += cloneBallSpeedY;
cloneBallX += cloneBallSpeedX;
if ((cloneBallY + cloneBallSize) > gameHeight - 1)
{
cloneBallSpeedY = -1 * fabs(cloneBallSpeedY);
}
if (cloneBallY < 0)
{
cloneBallSpeedY = fabs(cloneBallSpeedY);
}
}
targetY = cloneBallY + (getBallSize() / 2);
}
/*
void calculateBallImpact()
{
double t = (123 - getBallPositionX() - getBallSize()) / ballSpeedX;
double dist = ballSpeedY > 0 ? (28 - getBallPositionY()) : getBallPositionY();
double dBY = fabs(ballSpeedY) * t;
double O = ((int)(dBY - dist) % (int)(32 - getBallSize())); // HAve to cast to ints... fmod are not avail.
double bouncesAmount = ((dBY - dist) / (32 - (getBallSize()))) + 1; // Amount of times the ball bounces
PORTE = (int)dist;
if (ballSpeedY > 0)
{
if (((int)floor(bouncesAmount) % 2) == 0)
{
targetY = O;
}
else
{
targetY = 28 - O;
}
PORTE |= 128;
}
else
{
if (((int)floor(bouncesAmount) % 2) != 0)
{
targetY = O;
}
else
{
targetY = 28 - O;
}
PORTE |= 64;
}
}
*/