need assistance accelerating goval vigilant (making dermatitis game)


hey peoples, i've study java integrate weeks, have solid furnish possess chronicle breakout. diversion operative fine, removed slight ostensible cgange round (goval) speed formed speed paddle (grect). anyway, method:



private double paddlevelocity(){
double paddletracker=(paddlextracker+paddlextrackertwo+paddlextrackerthree)/3; //get normal x-coordinate paddle
if(loopcounter>3){ //if diversion by loop some-more 3 times (to pledge 3 x-coordinates have stored)
paddlevelocity=(paddle.getx()-paddletracker)/50; //set paddlevelocity tide paddle x-coordinate discount normal before 3 paddle x-coordinates (which therefore finds quickness direction)
}else{
paddlevelocity=(paddle.getx()-paddlextracker)/50; //takes before paddle x-coordinate subtracts tide x-coordinate (which therefore finds quickness direction)
}

relapse (paddlevelocity);
}


and slight calls it:



            private vacant detectcollisionpaddle(){;
double bally = ball.gety()+(ball_radius*2);
if(paddle.gety()<=bally && ball.getx()+ball_radius>=paddle.getx() && ball.getx()+ball_radius/2<=(paddle.getx()+paddle_width)){ //a disaster formula ensures round within finish paddle
yvel=-yvel; //make round rebound off
bounceclip.play(); //play rebound clip
xvel=xvel+paddlevelocity(); //increase quickness round instruction speed paddle
} }


the instance variables include:



private int loopcounter; //how loops diversion formula have executed
private double paddlevelocity; //velocity paddle
private double paddlextracker = 1; //value x-coordinate paddle loop previous
private double paddlextrackertwo; //value x-coordinate paddle twin loops previous
private double paddlextrackerthree; //value x-coordinate paddle 3 loops previous
private double yvel = -1; //y quickness ball
private double xvel = 1; //x quickness ball


basically i wish paddlevelocity squeeze 3 unwavering x-coordinates paddle, review tide position (paddle.getx()). allows me establish speed instruction user changed paddle. i following relapse outcome (paddlevelocity) ostensible supplement tide quickness round (xvel). however, doesn't seem duty properly. paddlevelocity() removed, formula works ideally (albeit but acceleration). i know there's an emanate paddlevelocity method. seems inequitable right side. maybe guys help, afterall, initial critical try during programming. here's diversion atm:



yes, bricks don't smack yet. :p cheers!



edit: easier, here's formula the unfinished glory:



/*
* file: breakout.java
* -------------------
* name: vito cassisi
*/

import acm.graphics.*;
import acm.program.*;
import acm.util.*;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public category dermatitis extends graphicsprogram {

/** extent tallness concentration window pixels */
open stationary final int application_width = 400;
open stationary final int application_height = 600;

/** magnitude diversion house (usually same) */
private stationary final int extent = application_width;
private stationary final int tallness = application_height;

/** magnitude paddle */
private stationary final int paddle_width = 60;
private stationary final int paddle_height = 10;

/** homogeneous paddle adult bottom */
private stationary final int paddle_y_offset = 30;

/** array bricks per quarrel */
private stationary final int nbricks_per_row = 10;

/** array rows bricks */
private stationary final int nbrick_rows = 10;

/** fortitude between bricks */
private stationary final int brick_sep = 4;

/** extent section */
private stationary final int brick_width =
(width - (nbricks_per_row - 1) * brick_sep) / nbricks_per_row;

/** tallness section */
private stationary final int brick_height = 8;

/** radius round pixels */
private stationary final int ball_radius = 10;

/**ball speed milliseonds*/
private stationary final int check = 10;

/** homogeneous tip section quarrel tip */
private stationary final int brick_y_offset = 70;

/** array turns */
private stationary final int nturns = 3;

private stationary final int countdown = 200;

private goval ball;
private grect paddle;
private grect block;
private glabel life;
private glabel countdown;
private gobject getobject;
audioclip bounceclip = mediatools.loadaudioclip("bounce.au");

/* method: run() */
/** runs dermatitis program. */
open vacant run() {
drawblocks();
drawpaddle();
drawball();
drawlife();
addmouselisteners();

while(!lose) {
detectcollisionwall();
detectcollisionblock();
detectcollisionpaddle();
decelerate();
assignpaddletrackers();
pause(delay);
loopcounter++;
}
glabel youlose = new glabel("you lose!",application_width/2,application_height/2);
youlose.setlocation((getwidth()-youlose.getwidth())/2, (getheight()-youlose.getascent())/2);
add(youlose);
}
private vacant drawblocks(){
/**draw rows tangible consistent 'nbricks_per_row'*/
for(int i = 0;i<nbrick_rows;i++){
blockx=(application_width-((brick_width+brick_sep)*nbricks_per_row))/2; //center blocks horizontally
drawrow(); //draw row
blocky+=brick_height+brick_sep; //move quarrel down
}
}

private vacant drawrow(){
/**draw bricks tangible consistent 'nbricks_per_row'*/
for(int i = 0;i<nbricks_per_row;i++){
retard = new grect(blockx,blocky,brick_width,brick_height); //initialise blocks
add(block); //draw blocks
blockx+=brick_width+brick_sep; //move x prepare across
}
}

private vacant drawpaddle(){
paddle = new grect((application_width-paddle_width)/2,(application_height-paddle_y_offset-paddle_height),paddle_width, paddle_height);
add(paddle);
}

private vacant drawball(){
double hole = ball_radius*2;
round = new goval((application_width-diameter)/2,application_height-paddle_y_offset-paddle_height*2-diameter,diameter,diameter);
add(ball);
}

private vacant moveball(){

ball.move(xvel, yvel);
}

private vacant detectcollisionwall(){
if(ball.gety()+(ball_radius*2)<getheight() && ball.gety()>0 && ball.getx()+(ball_radius*2)<getwidth() && ball.getx()>0){
moveball();
}
if(ball.gety()+(ball_radius*2)>getheight()){
yvel=-yvel;
turnsleft--;
testforlose();
bounceclip.play();
}
if(ball.gety()<0){
yvel=-yvel;
bounceclip.play();
}
if(ball.getx()+(ball_radius*2)>=getwidth()){
xvel=-xvel;
bounceclip.play();
}
if(ball.getx()<=0){
xvel=-xvel;
bounceclip.play();
}
moveball();
}

private vacant testforlose(){
if(turnsleft==0){
lose=true;
life.setlabel("you have "+turnsleft+" lives!");
return;
}
life.setlabel("you have "+turnsleft+" lives!");
remove(ball);
drawball();
xvel=1;
yvel=-1;
drawcountdown();
}

private vacant drawcountdown(){
glabel countdown = new glabel("",application_width/2,application_height/2);
for(int i=3;i>0;i--){
countdown.setlabel("respawn in: "+i);
countdown.setlocation((getwidth()-countdown.getwidth())/2, (getheight()-countdown.getascent())/2);
add(countdown);
pause(countdown);
}
countdown.setlabel("go");
countdown.setlocation((getwidth()-countdown.getwidth())/2, (getheight()-countdown.getascent())/2);
pause(countdown);
remove(countdown);
}

private vacant drawlife(){
life = new glabel("you have "+turnsleft+" lives!", application_width/2,15);
life.setlocation((getwidth()-life.getwidth())/2, 20);
add(life);
}

private vacant detectcollisionblock(){
gobject collisionobject = detectobject(ball, ball_radius*2, ball_radius*2);
if(collisionobject==block){
remove(collisionobject);
yvel=-yvel;
}
}

private double paddlevelocity(){
double paddletracker=(paddlextracker+paddlextrackertwo+paddlextrackerthree)/3;
if(loopcounter>3){
paddlevelocity=(paddle.getx()-paddletracker)/50;
//paddlextracker=paddle.getx();
}else{
paddlevelocity=(paddle.getx()-paddlextracker)/50;
}

relapse (paddlevelocity);
}

private vacant detectcollisionpaddle(){;
double bally = ball.gety()+(ball_radius*2);
//double ballx = ball.getx()+(ball_radius*2);
/*if(ball.gety()+ball_radius*2>=paddle.gety() && ball.getx()+ball_radius*2>=paddle.getx() && ball.getx()<=paddle.getx()){
ball.setlocation(ball.getx(),paddle.gety()-ball_radius*2-1);
}*/
if(paddle.gety()<=bally && ball.getx()+ball_radius>=paddle.getx() && ball.getx()+ball_radius/2<=(paddle.getx()+paddle_width)){
yvel=-yvel;
bounceclip.play();
xvel=xvel+paddlevelocity();
/*
int x = 4;
int core = paddle_width/2;
double parts=center/x;
int location=0;
if(ball.getx()+ball_radius*2>paddle.getx()&& ball.getx()<paddle.getx()+paddle_width){
for(int i = 0;i<x;i++){
(ball.getx()<center+paddle.getx() && ball.getx()>(parts*i)+paddle.getx()){

}else{
plcae = i;
break;
}

}
xvel=x/location;
}
}
//

if(ball.getx()+ball_radius<paddle.getx()+paddle_width/4){
if(xvel!=1){
if(xvel<0)
{
xvel=xvel-1;
}else{
xvel=-xvel-1;
}
}
}
(ball.getx()>paddle.getx()+(paddle_width-paddle_width/4)){
if(xvel>0){
xvel=xvel+1;
}else{
xvel=-xvel+1;
}
}
(ball.getx()<paddle.getx()+(paddle_width-paddle_width/4) && ball.getx()+ball_radius>paddle.getx()+paddle_width/4){
if(xvel>1){
xvel=xvel-1;
}
if(xvel<-1){
xvel=xvel+1;
}
}
*/
}


}

open vacant mousemoved(mouseevent e){
paddle.move((e.getx()-paddle.getx()-paddle_width/2),0);
}

/*passes an vigilant checked, i.e. ball, asks it's tallness width. advantage vigilant present, differently retuns null.**/
private gobject detectobject(gobject object, int width, int height){
double right = object.getx()+width;
double bottom = object.gety()+height;
getobject = getelementat(object.getx(),object.gety());

if(getobject==null){
getobject = getelementat(right,object.gety());
}else{
relapse getobject;
}

if(getobject==null){
getobject = getelementat(object.getx(),bottom);
}else{
relapse getobject;
}

if(getobject==null){
getobject = getelementat(right,bottom);
}else{
relapse getobject;
}

if(getobject==null){
relapse null;
}else{
relapse getobject;
}

}

private vacant decelerate(){
if(xvel<-1){
xvel=xvel+0.01;
}
if(xvel>1){
xvel=xvel-0.01;
}
}

private vacant assignpaddletrackers(){
paddlextrackerthree=paddlextrackertwo;
paddlextrackertwo=paddlextrackerthree;
paddlextracker=paddle.getx();
}

private int loopcounter;
private double paddlevelocity;
private double paddlextracker = 1;
private double paddlextrackertwo;
private double paddlextrackerthree;
private double yvel = -1;
private double xvel = 1;
private int turnsleft = nturns;
private int blocky = brick_y_offset;
private int blockx = 0;
private stationary boolean remove = false;
private randomgenerator rgen = randomgenerator.getinstance();

}


Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?