⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.java

📁 一款模拟飞行类游戏的Java源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        m_bound_left = left;        m_bound_right = right;        m_bound_top = top;    }        void handleScroll(int x, int y, int delta)    {            if (m_is_lookahead)            {                int max = Common.mul(Common.toFP(m_full_width), 200);                if (m_scroll_offset_x > max) m_scroll_offset_x = max;                else if (m_scroll_offset_x < -max) m_scroll_offset_x = -max;                            }            else m_scroll_offset_x = 0;                        m_scroll_x = Common.toInt(x) - m_full_width / 2 + Common.toInt(m_scroll_offset_x);            m_scroll_y = Common.toInt(y) - m_view_height / 2 + 20 - m_view_start_height;                        limitScroll();    }        void limitScroll()    {            int h = m_view_height + m_view_start_height;                        //if (m_game_handler.isScoreBoard()) h -=  m_resource_manager.getScoreBoard().getHeight(0) ;            if (m_scroll_y > m_terrain.getBottomBound() - h) m_scroll_y = m_terrain.getBottomBound() - h;            else if (m_scroll_y < m_bound_top + m_view_start_height) m_scroll_y = m_bound_top + m_view_start_height;            if (m_scroll_x < m_bound_left) m_scroll_x = m_bound_left;            else if (m_scroll_x > m_bound_right - m_full_width) m_scroll_x = m_bound_right - m_full_width;    }            public void handle(int delta) throws Exception    {        if (m_handling)        {            if (m_handle_speed_factor != Common.FIXED)            {                int new_delta = Common.mul(delta, m_handle_speed_factor);                if (delta > 0 && new_delta == 0) new_delta = 1;                delta = new_delta;            }                        collision(delta);            for (int i = 0; i < m_objects.size(); i++)             {                GameObject go = (GameObject)m_objects.elementAt(i);                if (go.handle(delta) == GameObject.DELETE)                {                    if (go.getObjectType() == GameObject.PLANE) m_game_handler.planeDestroyed((Plane)go);                    if (go.getObjectType() == GameObject.TANK) m_game_handler.tankDestroyed((Tank)go);                    if (go.getObjectType() == GameObject.ZEPPELIN) m_game_handler.zeppelinDestroyed((Zeppelin)go);                    else if (go.getObjectType() == GameObject.BUILDING) m_game_handler.buildingDestroyed((Building)go);                    else m_game_handler.objectDestroyed(go);                    m_objects.removeElementAt(i);                    i--;                    go.destruct();                }            }            // sort X           insertionSort();        }                        // handle visual objects        for (int i = 0; i < m_visual.size(); i++)         {            if (((Visual)m_visual.elementAt(i)).handle(delta) == Visual.DELETE)            {                m_visual.removeElementAt(i);                i--;            }        }              // update targets        if (m_targets != null)        {            for (int i = 0; i < m_targets.length; i++)            {                if (m_targets[i] != null && m_targets[i].isAlive() == false) m_targets[i] = null;            }        }                      m_game_handler.handle(delta);        if (m_game_state_type == PLAYING && m_game_handler.isFinished() == GameHandler.FAILED)        {            gameOver();        }        else if (m_game_state_type == PLAYING && m_game_handler.isFinished() == GameHandler.SUCCESS)        {            levelComplete();        }        else if (m_game_state_type == GAME_OVER && m_game_handler.isFinished() != GameHandler.NOT_FINISHED)        {            m_quit = true;        }        else if (m_game_state_type == BRIEFING && m_game_handler.isFinished() != GameHandler.NOT_FINISHED)        {            gamePlay();        }        else if (m_game_state_type == LEVEL_COMPLETE && m_game_handler.isFinished() != GameHandler.NOT_FINISHED)        {            reset();        }        else if (m_game_state_type == CUSTOM && m_game_handler.isFinished() != GameHandler.NOT_FINISHED)        {            m_quit = true;        }        switch(m_game_handler.getScrollType())        {            case GameHandler.POINT:            {                m_scroll_offset_x = 0;                Point p = (Point)m_game_handler.getScroll();                m_scroll_x = Common.toInt(p.x);                m_scroll_y = Common.toInt(p.y);                limitScroll();                break;            }            case GameHandler.CENTER_POINT:            {                m_scroll_offset_x = 0;                Point p = (Point)m_game_handler.getScroll();                handleScroll(p.x, p.y, delta);                 break;            }                           case GameHandler.OBJECT:             {                GameObject go = (GameObject)m_game_handler.getScroll();                 if (go == null || go.isAlive() == false) break;                                 Point p =  go.getPos();                if (go instanceof Rotatable)                {                    int angle = ((Rotatable)go).getAngle();                    m_scroll_offset_x += Common.mul(Common.mul(Common.toFP(m_full_width)/2, Common.cos(angle)), delta) ;                    m_scroll_offset_x =  Common.mul(m_scroll_offset_x, 950);                }                handleScroll(p.x, p.y, delta);                 break;                }        }    }     public void draw(Graphics g)     {        resetClip(g);        int x = Common.toFP(m_scroll_x);        int y = Common.toFP(m_scroll_y);                        m_terrain.drawTerrain(g, m_scroll_x, m_scroll_y, m_full_width, m_view_height);                int clip_width = MAX_OBJECT_RADIUS + Common.toFP(g.getClipWidth());        for (int i = 0; i < m_objects.size(); i++) // WARN ME: optimize this        {                        GameObject go = (GameObject)m_objects.elementAt(i);            if (go.isAlive() == false) continue;            if (Math.abs(go.getPos().x - x) > clip_width) continue;            go.draw(g, x, y);        }        for (int i = 0; i < m_visual.size(); i++)         {            Visual vis = (Visual)m_visual.elementAt(i);            vis.draw(g, x, y);        }                Helper.resetFullScreenClip(g);        m_game_handler.draw(g, x, y);    }           public void collision(int delta)     {         int max_h = Common.toFP(m_terrain.getMaxHeight());         for (int i = 0; i < m_objects.size(); i++)          {             GameObject go = (GameObject)m_objects.elementAt(i);             if (go.isAlive() == false) continue;                          // --- handler over the bounds handling ---             int top = Common.toFP(m_bound_top);             int left = Common.toFP(m_bound_left);             int right = Common.toFP(m_bound_right);                          if ((go.getType() & GameObject.BOUNDS_DETECT) != 0)              {                int radius = go.getRadius();                                if (go.getPos().y + radius < top) m_game_handler.objectOutsideBounds(GameHandler.TOP, go);                else if (go.getPos().y - radius > 0) m_game_handler.objectOutsideBounds(GameHandler.BOTTOM, go);                if (go.getPos().x + radius < left) m_game_handler.objectOutsideBounds(GameHandler.LEFT, go);                else if (go.getPos().x - radius > right) m_game_handler.objectOutsideBounds(GameHandler.RIGHT, go);                if (go.isAlive() == false) continue;                              }             boolean immobile = (go.getType() & GameObject.IMMOBILE) != 0;             if ((go.getType() & GameObject.COLLIDABLE_INTER_OBJ) != 0)              {                 // --- object object collision ---                 int check_start = Math.max(binaryFindObject(go.getPos().x - MAX_OBJECT_RADIUS), i + 1);                 int check_end = Math.min(binaryFindObject(go.getPos().x + MAX_OBJECT_RADIUS) + 1, m_objects.size() - 1);                 for (int j = check_start; j <= check_end; j++)                  {                     GameObject go2 =  (GameObject)m_objects.elementAt(j);                     if (go2.isAlive() == false) continue;                     if (Math.abs(go.getPos().y  - go2.getPos().y) > MAX_OBJECT_RADIUS) continue;   // only y needs to be checked                                                                                                     // array is x sorted                              if (immobile && ((go2.getType() & GameObject.IMMOBILE) != 0)) continue;       // immobile-immobile check                                          if (go.checkCollision(go2))                     {                         go2.collided(go, delta);                         go.collided(go2, delta);                     }                 }             }             if ((go.getType() & GameObject.COLLIDABLE_TERRAIN) != 0)              {                // --- object ground collision ---                              if (go.getPos().y + go.getRadius() < max_h) continue;                 byte collide_type;                 BoundingBox bb = go.getBoundingBox();                 if (bb != null)                 {                     collide_type = m_terrain.collide(bb);                 }                 else if (go.getRadius() > 0)                 {                    collide_type = m_terrain.collide(go.getPos(), go.getRadius());                 }                 else                  {                    collide_type = m_terrain.collide(go.getPos());                 }                 if (collide_type != Terrain.NO_COLLIDE)                 {                    if ((go.getType() & GameObject.TERRAIN_DAMAGE) != 0 && (collide_type != Terrain.WATER))                        m_terrain.crater(Common.toInt(go.getPos().x), Common.toInt(go.getRadius()), 5);                    go.collidedTerrain(m_terrain, (collide_type == Terrain.WATER), delta);                    }             }         }     }// =========================================================================;//	protected void gameOver()//	Desc:	handles end of the game// ==========================================================================;          protected void gameOver() throws Exception     {         resetScreenOptions();         enableHandling();         m_game_handler = new GameOverHandler(this, Common.toFP(m_scroll_x), Common.toFP(m_scroll_y));         //m_game_handler = new StaticGameHandler(this, Str.game_over, m_control);         m_game_state_type = GAME_OVER;     }      protected void levelComplete()     {         resetScreenOptions();         enableHandling();         checkSpecialStateEnd();        // awards special handling flags (ie, awards tank buster, if available)         m_level++;         m_game_handler = new LevelCompleteHandler(this, Integer.toString(m_level), Common.toFP(m_scroll_x), Common.toFP(m_scroll_y));         //m_game_handler = new StaticGameHandler(this, Str.game_over, m_control);         m_game_state_type = LEVEL_COMPLETE;     }               protected void briefing(String[] message)     {         resetScreenOptions();         enableHandling();         m_game_state_type = BRIEFING;         m_game_handler = new BriefingGameHandler(this, message, m_targets);     }          protected void gamePlay()     {         resetScreenOptions();         enableHandling();         checkSpecialStateStart();  // sets special handling flags (ie, check, for example, if tank buster bonus is available)         m_game_handler = new MissionGameHandler(this, m_targets);         m_game_state_type = PLAYING;     }               public int getObjectSize()     {         return m_objects.size();     }          public GameObject getGameObject(int index)     {         return (GameObject)m_objects.elementAt(index);     }         public void addVisual(Visual visual)     {         m_visual.addElement(visual);     }          public void createBomb(int x, int y, int vx, int vy)      {         addObject(new Bomb(this, m_resource_manager.getBomb(0), m_resource_manager.getBomb(1), vx, vy, 20000, x, y));     }          public void createDebris(int x, int y, int vx, int vy, int radius)     {         addObject(new FallingDebris(this, x, y, vx, vy, radius, 20000));     }               public void createBlast(int x, int y, int radius, int smoke)      {          addObject(new Blast(this, x, y, radius, smoke));     }          public void addScore(int score)      {         if (score > 0)         {             switch (m_difficulty_setting)             {                 case 1: score = (score * 3) / 2; break;                 case 2: score *= 2; break;             }         }         m_score += score;         if (m_score < 0) m_score = 0;         if (m_score > 99999) m_score = 99999;     }          public Terrain getTerrain()      {        return m_terrain;     }          public void createExplosion(int x, int y)      {         addVisual(new Explosion(c_explosion_color_table, x, y, (byte)20, 6000, 6000));     }          public void createFireworks(int x, int y)     {         switch(Math.abs(random.nextInt() % 3))         {             case 0: addVisual(new Explosion(c_fireworks_green_color_table, x, y, (byte)20, 6000, 6000));break;             case 1: addVisual(new Explosion(c_fireworks_red_color_table, x, y, (byte)20, 6000, 6000));break;             case 2: addVisual(new Explosion(c_fireworks_blue_color_table, x, y, (byte)20, 6000, 6000));break;         }     }          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -