Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
, bạn sẽ tìm hiểu làm thế nào để tạo ra năng động giải trí trực tuyến của riêng bạn bằng cách sử dụng ngôn ngữ lập trình Java. Java báo hiệu một sự thay đổi mang tính cách mạng chơi game, đi từ máy tính để bàn và vào mạng. Sử dụng Java, bạn sẽ tạo ra các trò chơi mà mọi người có thể tải về thông qua web và chơi. | Black Art of Java Game Programming Building a Video Game else gun.setPosition x-gun_width gun_y fire missile from given x coordinate public void fireMissile int x if missile.isActive if missile sprite isn t active if x min_x missile.init mis_min_x else if x max_x missile.init mis_max_x else missile.init x-2 initialize missile update all the parameters associated with the gun. In this case only the missile needs to move automatically. Also the gun manager checks if the missile hits anything public void update missile.update paint all sprites associated with gun public void paint Graphics g gun.paint g missile.paint g accessor function for gun public GunSprite getGun return gun public int getGunY return gun_y file D Downloads Books Computer Java Blac.20Java 20Game 20Programming ch05 171-177.html 5 von 6 13.03.2002 13 18 10 Black Art of Java Game Programming Building a Video Game Previous Table of Contents Next file D Downloads Books Computer Java Blac.20Java 20Game 20Programming ch05 171-177.html 6 von 6 13.03.2002 13 18 10 Black Art of Java Game Programming Building a Video Game Black Art of Java Game Programming by Joel Fan Sams Macmillan Computer Publishing ISBN 1571690433 Pub Date 11 01 96 Previous Table of Contents Next Notice that the missile is fired by calling its init method. This is much faster than creating a new MissileSprite object for each mouse click and it illustrates another general rule when writing games Avoid dynamic allocation of objects during game play. Try to allocate all the objects you will use at the very beginning if possible so the runtime system doesn t need to construct one when the game is running. Now let s create the aliens Defining the UFOManager The UFOManager is responsible for initializing the individual UFO sprites and telling them when to paint and update. Let s create the UFO class first before defining UFOManager. The UFO Class The UFO class will animate the sequence of bitmaps shown in Figure 5-2 so it becomes a subclass .