Skip to content
Snippets Groups Projects
Forked from tie / ohj1 / 2024k / ohj1ht
5 commits ahead of the upstream repository.
pomppu possu.cs 2.37 KiB
using System;
using System.Collections.Generic;
using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;

namespace pomppu_possu;

/// @author suvitoivanen
/// @version 14.02.2025
/// <summary>
/// Eeppinen tasohyppely peli
/// </summary>
public class pomppu_possu : PhysicsGame
{
    public override void Begin()
    {Level.Size = new Vector(1920, 1080);
        SetWindowSize(1920, 1080);
        CenterWindow();
        Camera.ZoomToAllObjects(100);
        Level.CreateBorders();
        Level.Background.Color = Color.SpringGreen;

        PhysicsObject pomppuPossu = new PhysicsObject(30, 80, Shape.Rectangle);
        Add(pomppuPossu);

        Keyboard.Listen(Key.Up, ButtonState.Down, Liikuta, "Liikuttaa pelaajaa ylös", pomppuPossu, new Vector(0,1000));
        Keyboard.Listen(Key.Down, ButtonState.Down, Liikuta, "Liikuttaa pelaajaa alas", pomppuPossu, new Vector(0,-1000));
        Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikuttaa pelaajaa vasemmalle", pomppuPossu, new Vector(-1000,0));
        Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikuttaa pelaajaa oikealle", pomppuPossu, new Vector(1000,0));

        for (int i = 0; i < 10; i++)
        {
            Color[] varit = { Color.Black, Color.White };
            Megaporkkanat ympyra = new Megaporkkanat(60, 60, varit);
            ympyra.Shape = Shape.Circle;
            ympyra.Position = RandomGen.NextVector(Level.BoundingRect);
            AddCollisionHandler<PhysicsObject, Megaporkkanat>(pomppuPossu, ympyra, TormattiinEsineeseen);
            Add(ympyra);
        }
        
        for (int i = 0; i < 5; i++)
        {
            Tasot paikallaan = new Tasot(150, 20);
            paikallaan.MakeStatic();
            paikallaan.Position = RandomGen.NextVector(Level.BoundingRect);
            Add(paikallaan);
        }
        
        
        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
    }

    public void TormattiinEsineeseen(PhysicsObject tormaaja, Megaporkkanat kohde)
    {
        kohde.OtaVastaanOsuma();
    }

    /// <summary>
    /// Liikuttaa fysiikkaoliota.
    /// </summary>
    /// <param name="liikuteltava">Liikutettava</param>
    /// <param name="suunta">Suunta</param>
    public void Liikuta(PhysicsObject liikuteltava, Vector suunta)
    {
        liikuteltava.Push(suunta);
    }
        // Pomppu possun megamaailma
        
}