Skip to content

Commit 3e85833

Browse files
committed
uploaded everything because i know how to use git
1 parent e63cebb commit 3e85833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+50938
-0
lines changed

.idea/.gitignore

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jumpking.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace-LAPTOP-4GTCNHGO.xml

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Brain.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
class AIAction {
2+
constructor(isJump, holdTime, xDirection) {
3+
this.isJump = isJump;
4+
this.holdTime = holdTime;//number between 0 and 1
5+
this.xDirection = xDirection;
6+
7+
}
8+
9+
clone() {
10+
return new AIAction(this.isJump, this.holdTime, this.xDirection);
11+
}
12+
13+
mutate() {
14+
this.holdTime += random(-0.3,0.3);
15+
this.holdTime = constrain(this.holdTime,0.1,1);
16+
}
17+
}
18+
19+
20+
// let jumpChance = 0; //the chance that a random action is a jump
21+
let jumpChance = 0.5; //the chance that a random action is a jump
22+
let chanceOfFullJump = 0.2;
23+
// let chanceOfFullJump = 0.2;
24+
25+
class Brain {
26+
27+
constructor(size, randomiseInstructions = true) {
28+
this.instructions = [];
29+
this.currentInstructionNumber = 0;
30+
if (randomiseInstructions)
31+
this.randomize(size);
32+
this.parentReachedBestLevelAtActionNo = 0;
33+
}
34+
35+
randomize(size) {
36+
for (let i = 0; i < size; i++) {
37+
this.instructions[i] = this.getRandomAction();
38+
}
39+
}
40+
41+
getRandomAction() {
42+
let isJump = false;
43+
44+
if (random() > jumpChance) {
45+
isJump = true;
46+
}
47+
48+
let holdTime = random(0.1, 1);
49+
if(random()<chanceOfFullJump){
50+
holdTime = 1;
51+
}
52+
53+
54+
let directions = [-1, -1, -1, 0, 1, 1, 1]
55+
let xDirection = random(directions)
56+
57+
58+
return new AIAction(isJump, holdTime, xDirection)
59+
}
60+
61+
getNextAction() {
62+
if(this.currentInstructionNumber >= this.instructions.length){
63+
return null;
64+
}
65+
this.currentInstructionNumber += 1;
66+
return this.instructions[this.currentInstructionNumber - 1];
67+
}
68+
69+
70+
clone() {
71+
let clone = new Brain(this.size, false);
72+
clone.instructions = [];
73+
for (let i = 0; i < this.instructions.length; i++) {
74+
clone.instructions.push(this.instructions[i].clone())
75+
}
76+
return clone;
77+
}
78+
79+
mutate() {
80+
let mutationRate = 0.1;
81+
let chanceOfNewInstruction = 0.02;
82+
for (let i = this.parentReachedBestLevelAtActionNo; i < this.instructions.length; i++) {
83+
if (random() < chanceOfNewInstruction) {
84+
this.instructions[i] = this.getRandomAction()
85+
} else if (random() < mutationRate) {
86+
this.instructions[i].mutate();
87+
}
88+
}
89+
}
90+
91+
mutateActionNumber(actionNumber){
92+
// let mutationRate = 0.1;
93+
94+
actionNumber -=1; // this is done because im a bad programmer
95+
let chanceOfNewInstruction = 0.2;
96+
if (random() < chanceOfNewInstruction) {
97+
this.instructions[actionNumber] = this.getRandomAction()
98+
} else{
99+
this.instructions[actionNumber].mutate();
100+
}
101+
}
102+
103+
increaseMoves(increaseMovesBy){
104+
for(var i = 0 ; i< increaseMovesBy ;i++){
105+
this.instructions.push(this.getRandomAction());
106+
}
107+
108+
}
109+
110+
}

Coin.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Coin{
2+
constructor(x,y, type = "reward") {
3+
this.levelNo = 0;
4+
this.x = x;
5+
this.y= y;
6+
this.radius = 50;
7+
this.type = type;
8+
}
9+
10+
11+
collidesWithPlayer(playerToCheck){
12+
let playerMidPoint = playerToCheck.currentPos.copy();
13+
playerMidPoint.x += playerToCheck.width/2;
14+
playerMidPoint.y += playerToCheck.height/2;
15+
if(dist(playerMidPoint.x,playerMidPoint.y,this.x,this.y)<this.radius + playerToCheck.width/2){
16+
return true;
17+
}
18+
return false;
19+
}
20+
21+
show(){
22+
push();
23+
if(this.type == "reward"){
24+
25+
fill(255,150,0);
26+
}else{
27+
fill(0,200,0,100);
28+
}
29+
noStroke();
30+
ellipse(this.x,this.y,this.radius*2);
31+
pop();
32+
33+
34+
}
35+
36+
}

Level.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Level{
2+
constructor() {
3+
this.levelImage = null;
4+
this.lines = [];
5+
this.levelNo =0;
6+
this.isBlizzardLevel = false;
7+
this.isIceLevel = false;
8+
this.coins = [];
9+
this.hasProgressionCoins = false;
10+
}
11+
12+
show(){
13+
push();
14+
image(this.levelImage,0,0)
15+
if(showingLines){
16+
for(let l of lines){
17+
l.Show();
18+
}
19+
}
20+
if(showingCoins){
21+
for(let c of this.coins){
22+
c.show();
23+
}
24+
}
25+
26+
pop();
27+
}
28+
29+
30+
}

0 commit comments

Comments
 (0)