Compare commits

...

3 Commits

Author SHA1 Message Date
djelalb
51404e5cc6
docs(class-diagram): complete class diagram (#35)
Co-authored-by: Djelal Boudji <dboudji@unistra.fr>
2025-02-03 16:56:26 +01:00
M VINCENT PETT
af64c2e0f4
fix: jump issues (#36) 2025-02-03 16:30:19 +01:00
c6be884024
docs(uml): class diagram (#34) 2025-02-03 15:35:36 +01:00
2 changed files with 108 additions and 50 deletions

View File

@ -5,44 +5,40 @@ public class PlayerScript : MonoBehaviour
{
public Rigidbody2D rigidBody;
public GameObject playerObject;
public ParticleSystem particle;
private bool wantsToJump = false;
public bool isColliding = true;
public AudioSource audioSource;
private bool hasStarted = false;
private bool canJump = true;
public void Start()
{
var mainModule = particle.main;
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
particle.transform.parent = null;
Invoke(nameof(EnableInput), 0.1f);
}
private void EnableInput()
{
hasStarted = true;
}
public void Update()
{
transform.position += Time.deltaTime * 8.6f * Vector3.right;
rigidBody.linearVelocity = new Vector2(8.6f, rigidBody.linearVelocity.y);
if (Input.GetKey(KeyCode.Space))
if (hasStarted && isColliding && Input.GetKey(KeyCode.Space) && canJump)
{
wantsToJump = true;
}
else
{
wantsToJump = false;
Jump();
}
if (!IsJumping())
{
AlignRotation();
if (wantsToJump)
{
Jump();
wantsToJump = false;
}
particle.gameObject.SetActive(true);
}
else
@ -88,13 +84,14 @@ public class PlayerScript : MonoBehaviour
public void OnCollisionEnter2D(Collision2D collision)
{
isColliding = true;
canJump = true;
if (collision.gameObject.tag == "Kill")
if (collision.gameObject.CompareTag("Kill"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
if (collision.gameObject.tag == "Win")
if (collision.gameObject.CompareTag("Win"))
{
SceneManager.LoadScene("HomeScene");
}

View File

@ -5,46 +5,107 @@ skinparam classAttributeIconSize 0
skinparam classFontStyle Bold
hide enum methods
class Position {
{field} + column: Integer
{field} + row: Integer
{method} + Position(column: Integer, row: Integer)
{method} + equals(position: Position)
class GameManager {
- score: int
- isPaused: Boolean
+ StartGame()
+ RestartLevel()
+ PauseGame()
+ ResumeGame()
+ UpdateScore(points: int)
}
class Level {
{field} + songPath: String
{field} + backgroundPath: String
{field} + speed: Double
{method} + Level()
- name: String
- musicPath: String
+ StartLevel()
+ EndLevel()
+ CheckCompletion(): Boolean
}
Level *--> "*\n- grid" GameObject : <<Is made up of>>
abstract class GameObject {
{method} + getImagePath(): String {abstract}
{method} + safeSides(): List<PositionSide> {abstract}
abstract class LevelElement {
- x: Float
- y: Float
}
GameObject o--> "1\n- " Position : <<Has>>
GameObject ..> PositionSide : <<Uses>>
class Spike extends GameObject {}
class Game {
{field} - score: Integer
{method} + start(): void
{method} + restart(): void
{method} + end(): void
abstract class Obstacle extends LevelElement {
+ TriggerEffect(player: Player)
}
Game o--> "1\n- currentLevel" Level : <<Has>>
enum PositionSide <<enumeration>> {
TOP
RIGHT
BOTTOM
LEFT
class Platform extends LevelElement {
}
class Spike extends Obstacle {
+ TriggerEffect(player: Player)
}
class Portal extends LevelElement {
- destination: Vector2
- type: PortalType
+ Teleport(player: Player)
}
enum PortalType {
Normal, Gravity, Speed
}
class Bumper extends LevelElement {
- bounceForce: Float
+ Bounce(player: Player)
}
class LevelEnd extends LevelElement {
+ TriggerEndGame()
}
class Collectible extends LevelElement {
- points: int
+ Collect(player: Player)
}
class Player {
- JUMP_FORCE: static const Float = 26.6581
- SPEED: static const Float = 8.6
- rigidBody: Rigidbody2D
- isColliding: Boolean
- isGrounded: Boolean
- gravityScale: Float
+ Jump()
+ IsJumping(): Boolean
+ OnCollisionEnter2D(collision: Collision2D)
+ OnCollisionExit2D(collision: Collision2D)
+ ChangeGravity()
+ Die()
+ Respawn()
+ CollectItem(item: Collectible)
}
class LevelLoader {
+ LoadLevel(jsonPath: String): Level
+ UnloadLevel(level: Level)
}
class LevelParser {
+ ParseJSON(jsonData: String): Level
}
class MusicManager {
- currentTrack: String
- volume: Float
+ PlayMusic(musicPath: String)
+ StopMusic()
+ SetVolume(level: Float)
}
GameManager *--> Level : <<Manages>>
GameManager --> LevelLoader : <<Uses>>
LevelLoader --> LevelParser : <<Uses>>
Level *--> LevelElement : <<Contains>>
GameManager *--> Player : <<Owns>>
GameManager --> MusicManager : <<Controls>>
Player --> LevelEnd : <<Triggers>>
Player --> Portal : <<Interacts>>
Player --> Collectible : <<Collects>>
Obstacle --> Player : <<Affects>>
@enduml