From 430ab994e0218c5e926343bd0e035d3bff3c87c3 Mon Sep 17 00:00:00 2001 From: notifrin <80722932+notifrin@users.noreply.github.com> Date: Fri, 22 Nov 2024 22:32:34 -0800 Subject: [PATCH] Update AsteroidsGame.pde --- AsteroidsGame.pde | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/AsteroidsGame.pde b/AsteroidsGame.pde index de9044b11..a78d822fb 100644 --- a/AsteroidsGame.pde +++ b/AsteroidsGame.pde @@ -1,10 +1,74 @@ //your variable declarations here +Star [] david; +Spaceship bob; public void setup() { + size(500,500); + bob = new Spaceship(); + david = new Star [500]; + + + for(int i =0; i < david.length; i++) { + david[i] = new Star(); + } + //your code here } public void draw() { + background(0); + noStroke(); + for(int i =0; i < david.length; i++) { + + david[i].show(); + } + + bob.show(); + bob.move(); //your code here } + +public void keyPressed() { + if (key == 'w') { + bob.accelerate(.1); + + } + + if(key == 's') { + bob.accelerate(-.1); + } + + if(key == 'd') { + bob.turn(10); + } + + if(key == 'a') { + bob.turn(-10); + } + +} + + +public void keyReleased() { + if (key == 'w') { + bob.setYSpeed(0); + bob.setXSpeed(0); + } + + if(key == 's') { + bob.setYSpeed(0); + bob.setXSpeed(0); + } + + if (key == 'h') { + int bomba = (int)(Math.random()500); + int bomb = (int)(Math.random()500); + int wilbur = (int)(Math.random()360); + bob.setX(bomba); + bob.setY(bomb); + bob.setYSpeed(0); + bob.setXSpeed(0); + bob.setDirect((double)wilbur); + } +}