Skip to content
Snippets Groups Projects
Commit 98ba92cc authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

live14 alku

parent 33eabcc8
No related branches found
No related tags found
No related merge requests found
Showing
with 359 additions and 0 deletions
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/modules.xml
/.idea.live14.iml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
using Jypeli;
namespace AngryLego;
/// @author vesal
/// @version 16.10.2023
/// <summary>
///
/// </summary>
public class AngryLego : PhysicsGame
{
private static readonly string[] lines = {
" ",
" ",
" ",
" ",
"/ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ======= ",
" Y Y Y ",
" X* X X ",
" * X X X * ",
" X X X ",
" X *X *X ",
};
private static readonly int tileWidth = 800 / lines[0].Length;
private static readonly int tileHeight = 480 / lines.Length;
public override void Begin()
{
ClearGameObjects();
ClearControls();
Gravity = new Vector(0, -500);
Level.Background.CreateGradient(Color.Blue, Color.White);
TileMap tiles = TileMap.FromStringArray(lines);
tiles.SetTileMethod('Y', LuoYlaSeina, Color.Wheat); // Aliohjelmien pitää itse lisätä, enemmän param
tiles.SetTileMethod('X', LuoSeina, Color.Wheat); // Aliohjelmien pitää itse lisätä, enemmän param
tiles.SetTileMethod('=', LuoKatto, Color.Red);
tiles.SetTileMethod('/', LuoMaila, Color.Black);
tiles.SetTileMethod('*', LuoVihollinen, Color.Pink);
tiles.Execute(tileWidth, tileHeight);
Level.CreateBorders();
Camera.ZoomToLevel();
PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
}
/// <summary>
/// Luodaan seinäelementti
/// </summary>
private void LuoSeina(Vector paikka, double leveys, double korkeus, Color vari)
{
PhysicsObject seina = new PhysicsObject(leveys-1, korkeus-1);
seina.Position = paikka;
seina.Color = Color.Wheat;
seina.Tag = "rakenne";
// seina.Image = LoadImage("tiili");
Add(seina);
}
/// <summary>
/// Luodaan isompi yläseinäelementti
/// </summary>
private void LuoYlaSeina(Vector paikka, double leveys, double korkeus, Color vari)
{
PhysicsObject seina = new PhysicsObject(leveys*1.8, korkeus-1);
seina.Position = paikka;
seina.Color = Color.Wheat;
seina.Tag = "rakenne";
// seina.Image = LoadImage("tiili");
Add(seina);
}
/// <summary>
/// Luodaan kattoelementti. Luodaan hieman ylisuureksi, jolloin liimautuu
/// naapuriin kiinni.
/// </summary>
private void LuoKatto(Vector paikka, double leveys, double korkeus, Color vari)
{
PhysicsObject katto = new PhysicsObject(leveys-1, korkeus-1);
katto.Position = paikka;
katto.Color = vari;
katto.Tag = "rakenne";
Add(katto);
}
/// <summary>
/// Luodaan maila, jolla palloja lyödään
/// </summary>
private void LuoMaila(Vector paikka, double leveys, double korkeus, Color vari)
{
PhysicsObject maila = PhysicsObject.CreateStaticObject(leveys * 6, korkeus);
maila.Position = paikka;
maila.Color = vari;
// maila.Image = LoadImage("maila3");
Add(maila);
}
/// <summary>
/// Luodaan vihollinen, joka hajoaa osuessaan rekenteeseen
/// </summary>
private void LuoVihollinen(Vector paikka, double leveys, double korkeus, Color vari)
{
PhysicsObject vihu = new PhysicsObject(leveys / 2, leveys / 2, Shape.Circle);
vihu.Position = paikka;
vihu.Color = vari;
// vihu.Collided += new NewCollisionHandler(VihuunOsui);
vihu.Tag = "vihu";
// vihu.Image = LoadImage("Baby");
Add(vihu);
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jypeli.NET" Version="11.*"/>
<PackageReference Include="Jypeli.FarseerPhysics.NET" Version="2.*"/>
</ItemGroup>
</Project>
luennot/live14/AngryLego/Content/Baby.png

19.4 KiB

luennot/live14/AngryLego/Content/Igor.png

43.4 KiB

luennot/live14/AngryLego/Content/maila.png

32.8 KiB

luennot/live14/AngryLego/Content/maila2.png

178 KiB

luennot/live14/AngryLego/Content/maila3.png

54.1 KiB

luennot/live14/AngryLego/Content/symbian.png

14.8 KiB

luennot/live14/AngryLego/Content/tiili.png

335 B

luennot/live14/AngryLego/Content/tiili1.png

499 B

luennot/live14/AngryLego/Content/tiili2.png

721 B

luennot/live14/AngryLego/Content/tiili3.png

1001 B

luennot/live14/AngryLego/Content/tiiliseina.png

837 B

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace AngryLego
{
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using var game = new AngryLego();
game.Run();
}
}
}
\ No newline at end of file
using Jypeli;
namespace LaskeMatka;
/// @author Vesa Lappalainen
/// @version 20.10.2020
///
/// <summary>
/// Piirretään näyttöön pisteitä ja lasketaan niiden välisiä etäisyyksiä
/// </summary>
public class LaskeMatka : PhysicsGame
{
/// <summary>Koordinaatistoakselit</summary>
private Axis akselit; // Atribuutti
private const double x1 = -5;
private const double x2 = 20;
private const double y1 = -5;
private const double y2 = 20;
private const double pallonKoko = (y2 - y1) / 300;
public override void Begin()
{
Level.Background.Color = Color.White;
akselit = new Axis(x1, y1, x2, y2);
Camera.ZoomTo(x1, y1, x2, y2);
AsetaOhjaimet();
}
/// <summary>
/// Asetetaan ohjaimet peliä varten. F1 ja ESC.
/// Kuunnellaan hiiren paikkaa ja siirretään merkkipisteen sen mukaan mihin klikattu
/// Samoin kuunnellaan puhelimelta sormella tökkäisyä.
/// </summary>
private void AsetaOhjaimet()
{
Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
Mouse.IsCursorVisible = true;
// Keyboard.Listen(Key.Delete, ButtonState.Pressed, PoistaPisteet, "Poistaa kaikki pisteet");
Mouse.Listen(MouseButton.Left, ButtonState.Pressed, delegate { LisaaPiste(Mouse.PositionOnWorld); }, "Laita piste");
// Mouse.Listen(MouseButton.Right, ButtonState.Pressed, PoistaPisteet, "Laita piste");
// TouchPanel.Listen(ButtonState.Pressed, delegate(Touch kosketus) { SiirraMerkkipisteet(kosketus.PositionOnWorld); }, null);
// TouchPanel.ListenGesture(GestureType.VerticalDrag, delegate(Touch touch) { KysyKoordinaatti(); }, "Kysy");
PhoneBackButton.Listen(Exit, "Lopeta peli");
}
/// <summary>
/// Lisätään piste näyttöön ja listaan
/// </summary>
/// <param name="piste">paikka johon sininen piste</param>
private void LisaaPiste(Vector piste)
{
}
/// <summary>
/// Lisätään peliin pallo
/// </summary>
/// <param name="game">peli johon pallo lisätään</param>
/// <param name="p">pallon keskipiste</param>
/// <param name="r">pallon säde</param>
/// <param name="color">pallon väri</param>
/// <returns>lisätyn pallon viite</returns>
public static PhysicsObject LuoPallo(PhysicsGame game, Vector p, double r, Color color)
{
PhysicsObject pallo = new PhysicsObject(r * 2, r * 2, Shape.Circle);
pallo.Position = p;
pallo.Color = color;
game.Add(pallo);
return pallo;
}
/// <summary>
/// Tämä tehdään aina kun ruutua pitää päivittää
/// </summary>
/// <param name="canvas">Piirtoalue, johon voi piirtää</param>
protected override void Paint(Canvas canvas)
{
akselit.Draw(canvas);
}
}
/// <summary>
/// Luokka koordinaatiston piirtämistä varten
/// </summary>
public class Axis
{
private readonly double x1, x2, y1, y2;
public Color Color { set; get; }
/// <summary>
/// Alustetaan koordinaatisto haluttuihin rajoihin
/// </summary>
/// <param name="x1">alueen vasemman alakulman x</param>
/// <param name="y1">alueen vasemman alakulman y</param>
/// <param name="x2">alueen vasemman yläkulman x</param>
/// <param name="y2">alueen vasemman yläkulman y</param>
public Axis(double x1, double y1, double x2, double y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
Color = Color.Black;
}
/// <summary>
/// Piirretään koordinaatisto niin, että tulee x ja y akselit ja niihin
/// yhden välein pikkutikkuja.
/// </summary>
/// <param name="canvas">Canvas-olio, johon piirto tehdään</param>
public void Draw(Canvas canvas)
{
canvas.BrushColor = Color;
double t = (y2 - y1) / 200; // tikkujen koko
// X-akseli
canvas.DrawLine(new Vector(x1, 0), new Vector(x2, 0));
// Tikut X-akselille 0:sta lähtien kumpaankin suuntaan
for (double x = 0; x >= x1; x -= 1.0) canvas.DrawLine(new Vector(x, -t), new Vector(x, t));
for (double x = 0; x <= x2; x += 1.0) canvas.DrawLine(new Vector(x, -t), new Vector(x, t));
// Y -akseli
canvas.DrawLine(new Vector(0, y1), new Vector(0, y2));
// Tikut Y-akselille 0:sta lähtien kumpaankin suuntaan
for (double y = 0; y >= y1; y -= 1.0) canvas.DrawLine(new Vector(-t, y), new Vector(t, y));
for (double y = 0; y <= y2; y += 1.0) canvas.DrawLine(new Vector(-t, y), new Vector(t, y));
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jypeli.NET" Version="11.*"/>
<PackageReference Include="Jypeli.FarseerPhysics.NET" Version="2.*"/>
</ItemGroup>
</Project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment