Help with creating a player entity for a 2D Side-scrolling Shooter


(N00B_IN_N33D) #1

So I’m trying to create a relatively simple 2D side-scrolling shooter, however, it isn’t turning out to be quite so simple… My problem is with determining how to structure the player entity. You see, the player should be comprised of two main parts: an arm with a gun, and a body. The arm with a gun is to rotate (aim) on a specified point (the player’s shoulder), meanwhile the body will have a hitbox for taking damage from enemy entities as well as displaying running or jumping animations (the player will always be in motion). On a side note I’ve already created a projectile system for my game, with a Bullet class designed to take x & y coordinates + a direction to travel in, so no need to worry about coding that.

My first attempt at creating my player was to create both a Player and PlayerGun class, a Player object would then store an instance of a PlayerGun object, from which the update() method would be used to track input and adjust the PlayerGun object accordingly (i.e. rotate it based on mouse x & y coordinates)… Although I’m not sure whether or not this is the way to go or not… How should I structure an entity whom has a rotating arm with a gun? Is this somehow accomplishable with a spritemap?

Any and all help would be greatly appreciated. Thanks.


(John Andersson) #2

I have to go out in 30 seconds, so this is a super fast and maybe not so helpful answer:

I know spritemaps can rotate by using “spritemapvarnamehere.angle” and you can set “spritemapvarnamehere.originX” (and Y) to compensate for the offset.

If I were you, I’d make an entity with a graphics list with both the main player model and the arm. If you check one of my thousand previous threads, you’ll see an answer I received which explained how to use a graphics list

Gotta go now, best of luck!