Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Player
- {
- update()
- {
- // ...
- if ( bumped into a solid )
- {
- velocity = 0;
- if ( bumped into CratePlaceholderBlock )
- {
- CratePlaceholderBlock crate = ( CratePlaceholderBlock ) tile bumped into;
- crate.crate.bump( side bumped into );
- }
- }
- // ...
- }
- }
- CratePlaceholderBlock
- {
- CrateEntity crate;
- isSolid() { return true; }
- }
- CrateEntity
- {
- Map< Position, Block > oldBlocks;
- update()
- {
- // ...
- // Similar code to what player has - Maybe common entity code?
- for ( every tile the crate overlaps right now )
- {
- Block block = level.getBlockAt( ... );
- if ( !( block instanceof CratePlaceholderBlock ) )
- {
- level.setBlockAt( ..., new CratePlaceholderBlock( this ) );
- oldBlocks.put( ..., block );
- }
- }
- for ( everything in oldBlocks )
- {
- Block block = ...;
- if ( no longer overlapping that block )
- {
- level.setBlockAt( ..., block );
- }
- }
- // ...
- }
- draw()
- {
- // Draw everything in oldBlocks so things don't flicker
- }
- bump( Side side )
- {
- if ( opposite side does not have solid tile )
- {
- velocity = ...;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement