Last active
August 29, 2015 14:23
-
-
Save jonaslsaa/5f1d506f840370441caa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void keyPressed() { //Controls | |
//println(keyCode); | |
if (key == CODED) { | |
if (keyCode == UP) { | |
direction = "up"; | |
accelerate = true; | |
} if (keyCode == DOWN) { | |
direction = "down"; | |
accelerate = true; | |
} if (keyCode == RIGHT) { | |
direction = "right"; | |
accelerate = true; | |
} if (keyCode == LEFT) { | |
direction = "left"; | |
accelerate = true; | |
} | |
} | |
} | |
void keyReleased() { | |
if (playerSpeed <= 0.1){ | |
direction = "none"; | |
} | |
accelerate = false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prog.io - Agar.io based game made in Processing by Jonas Silva 2015 | |
// A Week Project | |
void setup(){ | |
background(250,250,250); //Setting white bg | |
frameRate(FPS); //Limiting FPS to 60 | |
size(windowX,windowY); //Dynamic Window Size | |
smooth(); // I have no idea what this does | |
a=random(10,250); //Random colors | |
b=random(10,250); | |
c=random(10,250); | |
r=random(10,250); //Random colors | |
g=random(10,250); | |
b2=random(10,250); | |
playerPosX = startPosX; //Sets Start Position (X) | |
playerPosY = startPosY; //Sets Start Position (Y) | |
for (int i = 0; i < FoodCountMAX; i++){ | |
array[(int)random(30,windowX-30)][(int)random(30,windowY-30)] = 1; | |
} | |
} | |
// Food Spawning | |
void drawFood(){ | |
for(int i = 0; i < array.length; i++){ | |
for(int j = 0; j < array[i].length; j++){ | |
if(array[i][j] == 1){ | |
fill(r,g,b); | |
ellipse(i, j, 35, 35); | |
} | |
} | |
} | |
} | |
// Collision Detection | |
void FoodCollision(){ | |
for(int i = 0; i < array.length; i++){ | |
for(int j = 0; j < array[i].length; j++){ | |
if(array[i][j] == 1){ | |
if (playerPosX + offsetX + (playerSize / 2) > i && i > playerPosX + offsetX - (playerSize / 2)) { | |
if (playerPosY + offsetY + (playerSize / 2) > j && j > playerPosY + offsetY - (playerSize / 2)){ | |
score++; | |
array[i][j] = 0; | |
acceleration -= 0.002; | |
} | |
} | |
} | |
} | |
} | |
} | |
void FoodSpawn(){ | |
for (int i = 0; i < FoodCountMAX; i++){ | |
array[(int)random(30,windowX-30)][(int)random(30,windowY-30)] = 1; | |
} | |
} | |
void draw(){ | |
background(250,250,250); //Clears Drawn Pixels and sets bg | |
playerSize = score + 50; //Sets player size by multiplying score by 50 | |
drawFood(); // Calls DrawFood Method | |
FoodCollision(); // Calls the food collision method | |
fill(0,0,0); //Sets Color Black for Text | |
text("Score: "+score,20,30); //Score Text | |
text("FPS: " + frameRate,windowX - 100, 30); //FPS Text | |
text("Speed: " + playerSpeed,20, 45); //FPS Text | |
// Acceleration | |
if (playerSpeed < max_speed && accelerate == true){ | |
playerSpeed += acceleration; | |
} | |
// Deacceleration | |
if (playerSpeed > 0 && accelerate == false){ | |
playerSpeed -= acceleration*4; | |
} | |
//Count Fps for spawning food every 15 seconds | |
if (fps_count < spawn_cooldown * FPS){ | |
fps_count++; | |
} else { | |
fps_count = 0; | |
FoodSpawn(); // Calls the food spawning method | |
} | |
drawFood(); | |
fill(a,b,c); //Sets Random color on the player | |
if (direction == "up") { | |
ellipse(playerPosX + offsetX, playerPosY + offsetY, playerSize, playerSize); | |
offsetX = offsetX + 0; | |
offsetY = offsetY - playerSpeed; | |
} | |
else if(direction == "down"){ | |
ellipse(playerPosX + offsetX, playerPosY + offsetY, playerSize, playerSize); | |
offsetY = offsetY + playerSpeed; | |
} else if(direction == "right"){ | |
ellipse(playerPosX + offsetX,playerPosY + offsetY, playerSize, playerSize); | |
offsetX = offsetX + playerSpeed; | |
} else if(direction == "left"){ | |
ellipse(playerPosX + offsetX, playerPosY + offsetY, playerSize, playerSize); | |
offsetX = offsetX - playerSpeed; | |
//Multiple Button Movement | |
} else if(direction == "left" && direction == "down"){ | |
ellipse(playerPosX + offsetX, playerPosY + offsetY, playerSize, playerSize); | |
offsetX = offsetX - playerSpeed; | |
} | |
// Idle | |
else if (playerSpeed <= 0.1){ | |
ellipse(playerPosX + offsetX, playerPosY + offsetY, playerSize, playerSize); | |
} | |
//println(playerPosX+offsetX); // Debug | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mode.id=processing.mode.java.JavaMode | |
mode=Java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float playerSize; | |
int FPS = 60; | |
int score = 1; //Default Starting Score | |
int windowX = 1280; //Dynamic Width Window Size | |
int windowY = 720; //Dynamic Height Window Size | |
float a; //Random Colors | |
float b; | |
float c; | |
float r; | |
float g; | |
float b2; | |
float playerPosX; | |
float playerPosY; | |
float startPosX = windowX/2; //Finds Start Position based on window size | |
float startPosY = windowY/2; | |
String direction; //Direction | |
float offsetX = 0; //Offset for player | |
float offsetY = 0; | |
float textOffsetPoint = 20; | |
float playerSpeed = 0; | |
float max_speed = 10; | |
boolean accelerate = false; | |
float acceleration = 0.01; | |
int FoodCountMAX = (int)random(1,10); | |
int FoodCount = 0; | |
float foodPosX; | |
float foodPosY; | |
int[][] array = new int[windowX][windowY]; | |
int fps_count = 0; | |
int spawn_cooldown = 15; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment