My code

Off-topic discussion
Post Reply
User avatar
VortexGaming
Registered user
Posts: 219
Joined: 14 Mar 2018, 15:47
Location: Maryland
Byond: VortexGaming

My code

Post by VortexGaming » 31 Aug 2018, 09:29

This is one of my Coding projects that I wanted people to see Im working on my coding skills so Im probably going to be posting more of my code in this post. Feel free to leave comments and tips I really only know java, CSS, HTML, javascript, and bootstrap. But all this code really does is make 2 balls randomly bounce around the screen while one ball is player controlled Im still workin on the game over section but uh. yeah this took two hours to make

Code: Select all

void setup() {
  size(500, 500);
 
}

void draw() {
 background(255);
 player();
 baddie();
 baddie1();
 GameOver();
}

/**void mouseClicked() {
  background(255);
  
}
*/

Code: Select all

float speedX = 1;
float speedY = 1;
float spotX = 50;
float spotY = 50;

void baddie(){
   fill(255,0,0);
  ellipse(spotX,spotY,50, 50);
 
  
  // allows ellipse to move
  spotX = spotX + speedX;
  spotY = spotY + speedY;
  
  // allows Ellipse to change directions when hitting the borders of the draw 
  if(spotX > width - 25 || spotX < 25){
    speedX = speedX * -1;
  }
  if(spotY > height - 25 || spotY < 25){
    speedY = speedY * -1;
  }

  
  
}

Code: Select all

float speedX1 = 1;
float speedY1 = 1;
float spotX1 = 50;
float spotY1 = 100;

void baddie1(){
  fill(255,0,0);
  ellipse(spotX1,spotY1,50, 50);
  
  
  // allows ellipse to move
  spotX1 = spotX1 + speedX1;
  spotY1 = spotY1 + speedY1;
  
  // allows Ellipse to change directions when hitting the borders of the draw 
  if(spotX1 > width - 25 || spotX1 < 25){
    speedX1 = speedX1 * -1;
  }
  if(spotY1 > height - 25 || spotY1 < 25){
    speedY1 = speedY1 * -1;
  }

  
  
}

Code: Select all

void GameOver(){
  if(spotX2 - 50 < spotX && spotY2 - 50 < spotY && spotX2 + 50 > spotX && spotY2 + 50 > spotY) {
    background(0);
   
  }
  
  else if(spotX2 - 50 < spotX1 && spotY2 - 50 < spotY1 && spotX2 + 50 > spotX1 && spotY2 + 50 > spotY1) {
    background(0);
    println("hi");
    
    
  }

  
}

Code: Select all

float speedX2 = 4;
float speedY2 = 4;
float spotX2 = 400;
float spotY2 = 100;



void player() {
   fill(255,255,0);
   ellipse(spotX2,spotY2,50,50);
 
 // Allows player based movement.
   if (keyPressed) {
    if (key == 'w' || key == 'W') {
      spotY2 = spotY2 - speedY2;
    }
    if (key == 's' || key == 'S') {
      spotY2 = spotY2 + speedY2;
    }
    if (key == 'a' || key == 'A') {
      spotX2 = spotX2 - speedX2;
    }
    if (key == 'd' || key == 'D') {
      spotX2 = spotX2 + speedX2;
    }
   }
   
   // Prevents player from leaving the map
  if(spotX2 > width - 25){
    spotX2 = spotX2 - 4;
  }
  if(spotY2 > height - 25){
    spotY2 = spotY2 - 4;
  }
  if(spotX2 < width - 475){
   spotX2 = spotX2 + 4; 
  }
  if(spotY2 < height - 475){
   spotY2 = spotY2 + 4 ; 
  }

  
  
}
Kaitlynn Lawson The Commander. http://www.cm-ss13.com/viewtopic.php?f=142&t=18802
Alicia:viewtopic.php?f=149&t=17406
Staff history
► Show Spoiler

User avatar
VortexGaming
Registered user
Posts: 219
Joined: 14 Mar 2018, 15:47
Location: Maryland
Byond: VortexGaming

Re: My code

Post by VortexGaming » 31 Aug 2018, 09:33

PS I use processing to make this and each code thing a whole different tab
Kaitlynn Lawson The Commander. http://www.cm-ss13.com/viewtopic.php?f=142&t=18802
Alicia:viewtopic.php?f=149&t=17406
Staff history
► Show Spoiler

User avatar
David Stormwell
Registered user
Posts: 243
Joined: 01 Jul 2018, 00:23
Location: Midwest USA
Byond: David Stormwell

Re: My code

Post by David Stormwell » 31 Aug 2018, 20:43

I am not very good in coding but fron what I can tell it sends a baldie into a black hole of some short?
They Which Play with the Devils Rattles, Will Be Brought by Degrees to Wield His Sword
-Buckmister Fuller

User avatar
VortexGaming
Registered user
Posts: 219
Joined: 14 Mar 2018, 15:47
Location: Maryland
Byond: VortexGaming

Re: My code

Post by VortexGaming » 01 Sep 2018, 08:52

David Stormwell wrote:
31 Aug 2018, 20:43
I am not very good in coding but fron what I can tell it sends a baldie into a black hole of some short?
Oof this is just a half year of taking coding classes.
Kaitlynn Lawson The Commander. http://www.cm-ss13.com/viewtopic.php?f=142&t=18802
Alicia:viewtopic.php?f=149&t=17406
Staff history
► Show Spoiler

User avatar
GenericUsername
Registered user
Posts: 185
Joined: 27 Aug 2017, 20:55
Byond: Foolosopher

Re: My code

Post by GenericUsername » 03 Sep 2018, 12:34

Good code overall but very simplistic, mainly since you're using a simplified language, namely Processing. But don't worry about using a simple tool as a beginner, I myself started coding with Scratch and Gamemaker 1 and managed to move to C/C++.
Be aware, though, that If you eventually move to a OOP language, it's a bitch to learn at first (though it may be easier to learn Java than to learn C++)
As for improving the code, try making it so everytime you press a key a ball is created
The hero that we need, but not the one we deserveImage
ImageImage

User avatar
VortexGaming
Registered user
Posts: 219
Joined: 14 Mar 2018, 15:47
Location: Maryland
Byond: VortexGaming

Re: My code

Post by VortexGaming » 04 Sep 2018, 20:07

Something I just whipped up in an hour because I wanted to test some array's

Code: Select all

void setup() {
  size(900, 900);
 
}

void draw() {
 background(255);

 
    
 // creates a spread of rects throughout the size of the setup
  for (int x=0; x <= width; x+=20) {
    
    for (int y=0; y <= height; y+=20){
      if( mouseX - 21 < x && mouseY - 21 < y && mouseX > x && mouseY > y) {
        
        // changes the color of the rect the mouse is over
        int col1;
  
    color[] colarray1 = new color[5];
 
    colarray1[0] = color(0,0,51);
    colarray1[1] = color(0,0,102);
    colarray1[2] = color(0,0,153);
    colarray1[3] = color(0,0,204);
    colarray1[4] = color(0,0,255);
    
    col1 = color(colarray1[(int)random(0,4)]);

    fill(col1);
    
      }
      
      else{
        // creates another array for when the mouse isnt over the rectangle
       int col;
  
    color[] colarray = new color[5];
 
    colarray[0] = color(192,192,192);
    colarray[1] = color(160,160,160);
    colarray[2] = color(128,128,128);
    colarray[3] = color(96,96,96);
    colarray[4] = color(64,64,64);
    
    col = color(colarray[(int)random(0,4)]);

    fill(col);
      }
      rect(x,y,20,20);
      
    }
  }
}
Kaitlynn Lawson The Commander. http://www.cm-ss13.com/viewtopic.php?f=142&t=18802
Alicia:viewtopic.php?f=149&t=17406
Staff history
► Show Spoiler

User avatar
z a n e b o t
Registered user
Posts: 260
Joined: 08 Jun 2017, 22:46
Byond: z a n e b o t

Re: My code

Post by z a n e b o t » 04 Sep 2018, 23:09

trash

User avatar
VortexGaming
Registered user
Posts: 219
Joined: 14 Mar 2018, 15:47
Location: Maryland
Byond: VortexGaming

Re: My code

Post by VortexGaming » 05 Sep 2018, 18:28

Zane shush you literally eat beans
Kaitlynn Lawson The Commander. http://www.cm-ss13.com/viewtopic.php?f=142&t=18802
Alicia:viewtopic.php?f=149&t=17406
Staff history
► Show Spoiler

Post Reply