Code Monkey home page Code Monkey logo

Comments (8)

cxong avatar cxong commented on July 24, 2024

Vehicles can pose a new problem. Right now there are no entities that are bigger than a single tile, although barely (players are 2 pixels narrower/shorter than the tiles, i.e. 1px leeway on all 4 sides). Small vehicles are definitely easy, but vehicles bigger than a single tile will require changes in the collision logic.

This is because currently, collisions are checked (GetItemOnTileInCollision) by looking for all entities in the current tile as well as surrounding tiles. This is so that items on adjacent tiles can still collide with each other. With entities larger than a single tile, We'd need to check around the current tile in a range that is at least one row/column larger than the size of the largest entity.

Same goes for rendering too; if things can collide they also need to be drawn in the right Z order. Now we'd need to sort rendering not just based on items in the current tile, but in a perimeter.

from cdogs-sdl.

cxong avatar cxong commented on July 24, 2024

There's a related issue: go to a proper spacial partitioning system (quadtree etc). That's a lot of work and the benefit is unclear.

from cdogs-sdl.

cxong avatar cxong commented on July 24, 2024

Instead of increasing the search perimeter, one alternative is to use "pseudo references" that indicate the presence, but not the location of an entity inside a tile. This idea may make collision detection faster as well.

Tiles currently have a collection of references to entities that are in that tile. This is a one-to-one relationship; entities can only exist in one tile at a time. This complicates collision detection a bit though, because entities at tile boundaries can collide with entities in the neighbouring tile, so the collision search is done on all 8 surrounding tiles as well. This works as long as no entities exceed one tile in size.

Instead, in addition to the regular references, we store "pseudo references" as well, and as long as an entity overlaps a tile, it also has a pseudo reference in that tile.

  • This makes collision easier, as one simply checks the current tile for references and pseudo references
  • It can handle entities larger than one tile, as those entities will simply have pseudo references in every tile it overlaps
  • Drawing/Z order is still based on regular references

There are some caveats though:

  • Checking for collision for a single entity may require searches in multiple tiles anyway, as that entity may exist in multiple tiles. In this case, duplicate detection needs to be done as well
  • Moving entities becomes a bit harder as the multiple pseudo references need to be updated

from cdogs-sdl.

cxong avatar cxong commented on July 24, 2024

C-Dogs is an 8-directional shooter, which is about movement as much as shooting. The 8-directions creates significant blind spots, which is compensated by moving around a lot.

Turrets (and vehicles to a lesser extent) worsens this limitation, so to compensate we can:

  • Use auto-aim #264
  • Moving/rotating crosshair (which would require laser sight #267)
  • Allow analog movement #272

from cdogs-sdl.

 avatar commented on July 24, 2024

Turrets could be implemented like this, for maximal flexibility:

  • bullets optionally can place static map objects instead of doing damage
  • static map objects optionally can fire weapons, with an optional auto-aim tag and ammo limit

You could maybe even implement a half-life style health dispenser this way, if you set the bullet damage to -1.

from cdogs-sdl.

 avatar commented on July 24, 2024

And, if you at the same time allow bullets to be static map objecs, you could implement shooting drones.

from cdogs-sdl.

cxong avatar cxong commented on July 24, 2024

This feature should probably be split as we built it out in parts. Initially we could build it on top of the custom gun system. E.g.

MG emplacement

  • Makes you immobile (speed = 0)
  • Drops when you switch away from it; doesn't stay in your inventory
  • Fixed muzzle position (have a map object as its parent?)

Turret emplacement
In addition to the above:

  • Can "enter" the turret (hide player, disable collisions)
  • Destructible (map object parent is destructible; need to eject player on destruction)

Jetpack

  • Does not change player's gun; they can fire the gun they were holding when they "entered" the vehicle
  • Change player physics (more speed, inertia)
  • Disable sliding (or custom action when pressing move + switch?)

Hoverbike
In addition to the Jetpack:

  • Destructible (movable map objects?)
  • Mass (can be knocked back, knocks back actors on collision)

Motorbike

  • Basic vehicle physics: has a heading, accelerates while moving towards heading, decelerates and turns while moving to a different heading, brakes while moving opposite to the heading. Need to add the following properties:
    • heading
    • vehicle rotation (directional sprites for map objects?)
    • deceleration
    • braking
    • acceleration angle threshold
    • braking angle threshold

...

from cdogs-sdl.

cxong avatar cxong commented on July 24, 2024

Went with a different design - vehicles are a special type of actor, and added two references to actors: pilot and vehicle
For the pilot, it controls the vehicle instead of itself, doesn't get drawn and doesn't react to collisions - instead it always follows the vehicle
For the vehicle, it doesn't control itself, and when drawn, will draw the pilot's head instead (if being piloted)

Having vehicles act as actors means minimal changes to other parts of the code.

from cdogs-sdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.