Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bookmark I want to use processing to create a creatureFizzy...which is a ball with a red face and black eyes.... when the user presses 'w',

Bookmark

I want to use processing to create a creature"Fizzy"...which is a ball with a red face and black eyes....

when the user presses 'w', The Fizzy should turn and move up, 'a' will make Fizzy turn and move left, 's' will turn fizzy to face down the screen and 'd' will make Fizzy move right. Thus Fizzy will now be able to move in four separate directions controlled by the 'w', 's', 'a', and 'd' keys. it will also bounce back (let's say window sideA) and turn around (head the sideB of the window)... (we only allow to use conditional(if), loops(for, while),

i dont know how to rotate the Fizzy when it bounce by the wall.. here is my codes

int x; //x coordinate of fizzy int y; //y coordinate of fizzy int rot; //The rotation of fizzy int xspeed = 2; //how fast fizzy moves left and right int yspeed = 2; //how fast Fizzy moves up and down

void setup() { size(810, 810); x=width/2; y=height/2; }

void keyPressed() { }

void fizzy() { fill(#FF0303); //gives fizzy a red body ellipse(x, y, 50, 50); //draws body fill(0); //givews fizzy black eyes if (rot==0) { //when Fizzy is moving up the screen ellipse(x+10, y-25, 10, 10); //draws the eyes ellipse(x-10, y-25, 10, 10); } if (rot==90) { //when Fizzy is right on the screen ellipse(x+25, y-10, 10, 10); //draws the eyes ellipse(x+25, y+10, 10, 10); } if (rot==180) { //when Fizzy is moving down the screen ellipse(x+10, y+25, 10, 10); //draws the eyes ellipse(x-10, y+25, 10, 10); } if (rot==270) { //when Fizzy is right on the screen ellipse(x-25, y-10, 10, 10); //draws the eyes ellipse(x-25, y+10, 10, 10); } }

void poles() { for (int x = 0; x <= 810; x = x +90) { //The poles are drawn in a 810x810 box being 90 pixels away from each other for (int y = 0; y <= 810; y = y +90) { fill(0); //Gives the poles a black colour ellipse(x, y, 1, 1); //The pixels are 1 pixel big } } }

void draw() { background(255); poles(); if (x>width||x<0) { //if fizzy hits the left or right wall, move the other direction xspeed = -xspeed; } if (y>height||y<0) { //if fizzy hits the top or bottom wall, move the other direction yspeed = -yspeed; } if (key=='w') { //moves the character up rot=0; y=y-yspeed; } if (key=='s') { //moves the character down rot=180; y=y+yspeed; } if (key=='a') { //moves the character left rot=270; x=x-xspeed; } if (key=='d') { //moves the character right rot=90; x=x+xspeed; } fizzy(); //Fizzy is drawn onto the screen }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

b. A workshop on stress management sponsored by the company

Answered: 1 week ago