技术开发 频道

Java中2.5D游戏八方走法实现原理及相关代码

  Main.java(初始配置及程序运行)

1 package org.loon.game.simple.alldirection.main;
2 import org.loon.game.simple.alldirection.GameCursor;
3 import org.loon.game.simple.alldirection.GameFrame;
4 import org.loon.game.simple.alldirection.rpg.Config;
5 import org.loon.game.simple.alldirection.rpg.Role;
6 import org.loon.game.simple.alldirection.rpg.RpgLayout;
7 import org.loon.game.simple.alldirection.rpg.RpgMap;
8 /**
9 * Copyright 2008 - 2009
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
12 * use this file except in compliance with the License. You may obtain a copy of
13 * the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20 * License for the specific language governing permissions and limitations under
21 * the License.
22 *
23 * @project loonframework
24 * @author chenpeng
25 * @email:ceponline@yahoo.com.cn
26 * @version 0.1
27 */
28 public class Main {
29     public static void main(String[] args) {
30         java.awt.EventQueue.invokeLater(new Runnable() {
31             public void run() {
32                 GameFrame frame = new GameFrame(
33                         "Java 2.5D游戏开发中的八方走法实现<LoonFramework-Game>", 640, 480);
34                 // 设定游标
35                 frame.setCursor(GameCursor.getCursor("image/cursor.png"));
36                 // 游戏地图
37                 RpgMap rpgMap = new RpgMap("image/map/maze.jpg",
38                         "./image/map/maze.map");
39                 // 显示网格
40                  rpgMap.showGrid(false);
41                 // 创建主角
42                 Role hero = new Role("image/role/gm.png", 7, 8, Config.DOWN, 0,
43                         rpgMap);
44                 hero.setName("妈妈说坏孩子长大以后就是GM");
45                 hero.setPartyName("曾经的北S商人");
46                 // 创建NPC1
47                 Role npc1 = new Role("image/role/assassin.png", 3, 14,
48                         Config.LEFT, 1, rpgMap);
49                 npc1.setName("炼妖狐(爆刺、爆刺、一拍即死)");
50                 npc1.setPartyName("此人已死,有事烧纸");
51                 // //创建NPC2
52                 Role npc2 = new Role("image/role/rogue.png", 15, 21, Config.LEFT,
53                         1, rpgMap);
54                 npc2.setName("猫猫(巴帽小偷)");
55                 npc2.setPartyName("病猫不发威你还拿我当老虎了");
56                 // 设定主角
57                 rpgMap.setupHero(hero);
58                 // 设定NPC
59                 rpgMap.addRole(npc1);
60                 rpgMap.addRole(npc2);
61                 frame.getGame().setControl(new RpgLayout(rpgMap));
62                 // 游戏全屏
63                 // frame.updateFullScreen();
64                 frame.setFPS(true);
65                 frame.mainLoop();
66                 frame.showFrame();
67             }
68         });
69     }
70 }
0
相关文章