Hello everyone, im trying to create a game for class and im having a couple of problems.
for example i cannot seem to figure out how to animate directional idle animations and shooting animations.
Having a idle animation in one direction was simple enough since i only animated one direction.
However i dont know how to tell the programm in what direction i have previously used as in to give my game information what idle or standing shooting animation to use.
Next Problem is, if i want to create an improved jump i am facing two problems.
First, i do not know how to program a jump in which i can control the high of so to give it that megaman feel.
Second, nor do i know if i am able to create such a jump how to tell the game to play a different animation after the apex of the jump and when landing rather then after some unchangable time .
The following is the entire code of my Character. It would be really nice if somebody could help me.
I know there are probably already threats about these problems but despite my hardest effort i was not able to understand them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * This class is just an example. You can delete it or change the code. * It's not necessary for the scrolling system. */ public class Azure extends ScrollingActor { private int vSpeed = 0 ; private int acceleration = 1 ; private boolean jumping; private int jumpStrength = 20 ; private GreenfootImage Stand1 = new GreenfootImage( "Stand_01.png" ); private GreenfootImage Stand2 = new GreenfootImage( "Stand_02.png" ); private GreenfootImage Stand3 = new GreenfootImage( "Stand_03.png" ); private GreenfootImage Stand4 = new GreenfootImage( "Stand_04.png" ); private GreenfootImage Stand5 = new GreenfootImage( "Stand_05.png" ); private GreenfootImage Stand6 = new GreenfootImage( "Stand_06.png" ); private GreenfootImage Stand7 = new GreenfootImage( "Stand_07.png" ); private GreenfootImage Stand8 = new GreenfootImage( "Stand_08.png" ); private GreenfootImage Stand9 = new GreenfootImage( "Stand_09.png" ); private GreenfootImage WalkA1 = new GreenfootImage( "Walk-A_01.png" ); private GreenfootImage WalkA2 = new GreenfootImage( "Walk-A_02.png" ); private GreenfootImage WalkA3 = new GreenfootImage( "Walk-A_03.png" ); private GreenfootImage WalkA4 = new GreenfootImage( "Walk-A_04.png" ); private GreenfootImage WalkA5 = new GreenfootImage( "Walk-A_05.png" ); private GreenfootImage WalkA6 = new GreenfootImage( "Walk-A_06.png" ); private GreenfootImage WalkA7 = new GreenfootImage( "Walk-A_07.png" ); private GreenfootImage WalkA8 = new GreenfootImage( "Walk-A_08.png" ); private GreenfootImage WalkA9 = new GreenfootImage( "Walk-A_09.png" ); private GreenfootImage WalkA10 = new GreenfootImage( "Walk-A_10.png" ); private GreenfootImage WalkA11 = new GreenfootImage( "Walk-A_11.png" ); private int frame = 1 ; private int animationCounter = 0 ; /** * Here you can tell your actor what he has to do. */ public void act() { ceiling(); animationCounter ++; if (Greenfoot.isKeyDown( "space" )) { setLocation(getX(), getY() - 20 ); } if (Greenfoot.isKeyDown( "down" )) { setLocation(getX(), getY() + 10 ); } if (Greenfoot.isKeyDown( "left" ) && (Greenfoot.isKeyDown( "s" ))) { setLocation(getX() - 15 , getY()); } if (Greenfoot.isKeyDown( "right" ) && (Greenfoot.isKeyDown( "s" ))) { setLocation(getX() + 15 , getY()); } move(); canMoveRight(); canMoveLeft(); checkFall(); } public void move() { int y = getY(); int x = getX(); if (Greenfoot.isKeyDown( "right" ) && canMoveRight()) x+= 14 ; if (Greenfoot.isKeyDown( "left" ) && canMoveLeft()) x-= 14 ; if (Greenfoot.isKeyDown( "right" ) && canMoveRight()){ if (animationCounter % 2 == 0 ) animateWalkA(); } else { if (animationCounter % 6 == 0 ) animateStand(); } setLocation(x,y); } public void fall() { setLocation(getX(), getY() +vSpeed); { vSpeed = vSpeed + acceleration; } jumping = true ; } public boolean onGround() { int spriteHeight = getImage().getHeight(); int lookForGround = ( int ) (spriteHeight/ 2 + 30 ); Actor ground = getOneObjectAtOffset( 0 , lookForGround, Highway. class ); if (ground == null ) { jumping = true ; return false ; } else { moveToGround(ground); return true ; } } public boolean ceiling() { int spriteHeight = getImage().getHeight(); int yDistance = ( int ) (spriteHeight/- 2 - 30 ); Actor ceiling = getOneObjectAtOffset( 0 , yDistance, Highway. class ); if (ceiling != null ) { vSpeed = 1 ; hitHead(ceiling); return true ; } else { return false ; } } public void hitHead(Actor ceiling) { int ceilingHeight = ceiling.getImage().getHeight(); int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/ 2 ; setLocation(getX(), newY); } public boolean canMoveLeft() { boolean canMoveLeft = true ; int imageWidth = getImage().getWidth(); int imageHeight = getImage().getHeight(); if (getOneObjectAtOffset(imageWidth/- 2 - 3 , imageHeight/- 2 , Border. class ) != null || getOneObjectAtOffset(imageWidth/- 2 - 3 , imageHeight/ 2 , Border. class ) != null ) canMoveLeft = false ; return canMoveLeft; } public boolean canMoveRight() { boolean canMoveRight = true ; int imageWidth = getImage().getWidth(); int imageHeight = getImage().getHeight(); if (getOneObjectAtOffset(imageWidth/ 2 + 3 , imageHeight/- 2 , Border. class ) != null || getOneObjectAtOffset(imageWidth/ 2 + 3 , imageHeight/ 2 , Border. class ) != null ) canMoveRight = false ; return canMoveRight; } public void moveToGround(Actor ground) { int groundHeight = ground.getImage().getHeight(); int newY = ground.getY() - (groundHeight + getImage().getHeight())/ 2 + 30 ; setLocation(getX(), newY); jumping = false ; } public void checkFall() { if (onGround()) { vSpeed = 0 ; } else { fall(); } } public void jump() { vSpeed = vSpeed - jumpStrength; jumping = true ; fall(); } public void animateStand() { if (frame == 1 ) { setImage(Stand1); } else if (frame == 2 ) { setImage(Stand2); } else if (frame == 3 ) { setImage(Stand3); } else if (frame == 4 ) { setImage(Stand4); } else if (frame == 5 ) { setImage(Stand5); } else if (frame == 6 ) { setImage(Stand6); } else if (frame == 7 ) { setImage(Stand7); } else if (frame == 8 ) { setImage(Stand8); } else if (frame == 9 ) { setImage(Stand9); frame = 1 ; return ; } frame ++; } public void animateWalkA() { if (frame == 1 ) { setImage(WalkA1); } else if (frame == 2 ) { setImage(WalkA2); } else if (frame == 3 ) { setImage(WalkA3); } else if (frame == 4 ) { setImage(WalkA4); } else if (frame == 5 ) { setImage(WalkA5); } else if (frame == 6 ) { setImage(WalkA6); } else if (frame == 7 ) { setImage(WalkA7); } else if (frame == 8 ) { setImage(WalkA8); } else if (frame == 9 ) { setImage(WalkA9); } else if (frame == 10 ) { setImage(WalkA10); } else if (frame == 11 ) { setImage(WalkA11); frame = 3 ; return ; } frame ++; } } |