Well, once again, I am making a platformer and the character falls halfway through the blocks that he lands on, depending on the speed and height he lands from... any ideas? If the classes that I am using won't work, I am open to use another player class entirely... thanks code for the P1 subclass of player:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Code for the player class: /** * Write a description of class Player here. * * @author (your name) * @version (a version number or a date) */ public class Player extends Actor { public int JPower = 10; public int VSpeed = 0; public int Drag = VSpeed - 2; public int keyPressed = 0; public int bounce = 0; public int eighthWidth = getImage().getWidth()/8; public int quarterWidth = getImage().getWidth()/4; public int halfWidth = getImage().getWidth()/2; public int halfHeight = getImage().getHeight()/2; public double nextLevel; public int shootdelay=0; public int mindelay=5; //set JPower public void JPower(int Power) { JPower = Power; } //checks if chacracter is on the ground public boolean touchingWallL() { Actor actor = getOneObjectAtOffset(0-quarterWidth, 0, Wall.class); return actor != null; } public boolean touchingWallR() { Actor actor = getOneObjectAtOffset(quarterWidth, 0, Wall.class); return actor != null; } public boolean onWall() { Actor actor = getOneObjectAtOffset(0, halfHeight, Wall.class); return actor != null; } public boolean belowWall() { Actor actor = getOneObjectAtOffset(0, 0-halfWidth, Wall.class); return actor != null; } public boolean onGround() { Actor actor = getOneObjectAtOffset(0, halfWidth, Ground.class); return actor != null; } /**Listed actions so far are:jump/fall, moveL, moveR, boxPhysics */ public void Action(String Action, String Char, String Key, String Key2, int AnimationFrames, int Speed) { if(Action == "jump/fall") { if(Greenfoot.isKeyDown(Key)) { keyPressed = 1; } if( JPower > 0 && keyPressed == 1 && !belowWall()) { setLocation(getX(), getY()-JPower); JPower--; }else if (onGround() || onWall()){ JPower = 10; VSpeed = 0; keyPressed = 0; }else{ setLocation(getX(), getY()-VSpeed); VSpeed--; } if(belowWall()) { JPower = 0; } } if(Action == "moveL") { if(Greenfoot.isKeyDown(Key) && Greenfoot.isKeyDown(Key2) && !touchingWallL()) { setLocation(getX()-Speed*2, getY()); }else if(Greenfoot.isKeyDown(Key) && !touchingWallL()) { setLocation(getX()-Speed, getY()); } } if(Action == "moveR") { if(Greenfoot.isKeyDown(Key) && Greenfoot.isKeyDown(Key2) && !touchingWallR()) { setLocation(getX()+Speed*2, getY()); }else if(Greenfoot.isKeyDown(Key) && !touchingWallR()) { setLocation(getX()+Speed, getY()); } } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class P1 here. * * @author (your name) * @version (a version number or a date) */ public class P1 extends Player { private int level; public int shootdelay = 0; public int mindelay = 5; private Bullet bullet; /** * Act - do whatever the P1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { Action("jump/fall", " ", "up", " ", 10, 0); Action("moveL", " ", "left", "shift", 10, 3); Action("moveR", " ", "right", "shift", 10, 3); Gun gun = new Gun(); if (Greenfoot.mouseClicked(null)) shoot(); Actor P1 = getOneIntersectingObject(Enemy.class); if (P1 != null) { Level5 level5 = new Level5(); Greenfoot.setWorld(level5); } Actor actor = getOneIntersectingObject(Enemy6.class); if (P1 != null) { Level6p4 level6p4 = new Level6p4(); Greenfoot.setWorld(level6p4); } } public void shoot() { MouseInfo mouse = Greenfoot.getMouseInfo(); int rot = getRotation()-10; Bullet b = new Bullet(); getWorld().addObject(b, getX(), getY()); b.turnTowards(mouse.getX(),mouse.getY()); } }