Object oriented Game Development -P5

Object oriented Game Development -P5: There’s a better than 50% chance that you have picked this title off the shelf in a bookshop and are wondering if it’s going to be another one of those ‘secrets of the inner circle’ type of titles. You know, the ones that promise to tell you unspoken truths on how to write really cool games but in reality offer up a rehash of a manual you may already have for free anyway. | 106 Object-oriented game development include package class MyClass public package_Type public Your operations here. If this is a bit too abstract let s look at a real-life example. One project had a package to handle game controllers. These game controllers could come in various flavours joypad keyboard mouse etc. The package defined a polymorphic handler class that accepted different types of input data class ctrl_InputHandler public virtual void HandleJoy ctrl_Joypad aJoy Other controller types handled similarly. The idea is that the client writes their own input handler to do whatever they require it to do. However there are a couple of things we needed to specify something about who was using the controller and something about what was being controlled. This was done by using two Strawman classes class ctrl_User public ctrl_User virtual ctrl_User class ctrl_Target public ctrl_Target virtual ctrl_Target The handler class now has member functions of the form void HandleJoy ctrl_Joy aData ctrl_User pUser ctrl_Target pTarget Object-oriented design for games 107 At the game level we had a player owning a controller and using it to move a cursor to drive it around the screen Figure . The game s input handler code looked something like this include controller class GameInputHandler public ctrl_InputHandler public void HandleJoy ctrl_Joy aData ctrl_User pUser ctrl_Target pTarget include include include void GameInputHandler HandleJoy ctrl_Joy aData ctrl_User pUser ctrl_Target pTarget This upcast is fine because we know what the final user type is at the game level. Player pPlayer static_cast Player pUser Similarly at this level that target is always the cursor. Cursor pCursor static_cast Cursor pTarget Code to do things with players and cursors Cursor Figure The game subclasses of the abstract component classes. 108 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
2    490    1    21-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.