when i shoot a space invader and when i get shot it has a slight delay so you can actually see the damagedimage and also i think it gives it gives a retro vibe, one problem is that when my ufo goes atop of the screen it has a 12 second sound clip playing but the delay doesnt pause it so if i hit a bunch of space invaders within the 12 seconds the sound clip will finish way before the ufo gets to the other end of the screen.
i am using Greenfoot.delay(); for the delay
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Space here. * * @author (your name) * @version (a version number or a date) */ public class Space extends World { /** * Constructor for objects of class Space. * */ GreenfootSound ufo = new GreenfootSound( "ufo.wav" ); public Space() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 800 , 600 , 1 ); addObject (gameover, 400 , 300 ); addObject (lifeboard, 500 , 20 ); addObject (scoreboard, 100 , 20 ); addObject ( new Player(), 400 , 550 ); addObject ( new Invaders(), 0 , 0 ); addObject ( new Barrier1(), 200 , 475 ); addObject ( new Barrier2(), 400 , 475 ); addObject ( new Barrier3(), 600 , 475 ); setPaintOrder(GameOver. class ,Player. class ); } public void act() { if (getObjects(UFO. class ).size() == 0 ) { ufo.stop(); if (Greenfoot.getRandomNumber( 3000 ) == 1500 ) { addObject( new UFO(), 0 , 50 ); ufo.play(); return ; } } } public Scoreboard scoreboard = new Scoreboard(); public Lifeboard lifeboard = new Lifeboard(); public GameOver gameover = new GameOver(); } |