This site requires JavaScript, please enable it in your browser!
Greenfoot back
saw444

saw444

Welcome to my page

saw444's scenarios

This user has not made any scenarios.

saw444's collections

This user has no collections

Recent Comments

Why is he not jumping? import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Dante here. * * @author (your name) * @version (a version number or a date) */ public class Dante extends Actor { /** * Act - do whatever the Dante wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ static final int gravity = 2; static final int jumpForce = 30; int xSpeed = 4; int ySpeed = 0; public void act() { // Add your action code here. moveHorizontal(); } public void moveHorizontal() { int worldWidth = getWorld().getWidth(); int myWidth = getImage().getWidth(); int dx = 0; if(Greenfoot.isKeyDown("a")) dx--; if(Greenfoot.isKeyDown("d")) dx++; setLocation(getX()+dx*xSpeed, getY()); } private void moveVertically() { int worldHeight = getWorld().getHeight(); int myHeight = getImage().getHeight(); boolean onGround = false; ySpeed += gravity; setLocation(getX(), getY()+ySpeed); if(getY() > worldHeight-myHeight/2) { ySpeed = 0; onGround = true; } if(onGround && Greenfoot.isKeyDown("w")) { ySpeed =-jumpForce; } } }