Skip to content
Snippets Groups Projects
Commit 029c4e8b authored by sailyts's avatar sailyts
Browse files

harjoitustyön vienti

parent 310b808e
No related branches found
No related tags found
No related merge requests found
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Harjoitustyö", "Harjoitustyö\Harjoitustyö.csproj", "{DAA6A487-FEF6-4491-BC7F-B32CE58D745F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAA6A487-FEF6-4491-BC7F-B32CE58D745F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAA6A487-FEF6-4491-BC7F-B32CE58D745F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAA6A487-FEF6-4491-BC7F-B32CE58D745F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAA6A487-FEF6-4491-BC7F-B32CE58D745F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F44E8F41-FDB5-42D3-9C8E-B324559A45C9}
EndGlobalSection
EndGlobal
k k
p p p p v
llllllllllllllllllll
p p p p v
llllllllllllllllllll
p p p p v
llllllllllllllllllll
p p p p v
llllllllllllllllllll
p p p p v
\ No newline at end of file
Harjoitustyö/Harjoitustyö/Content/kentanLattia.png

1.07 KiB

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Diagnostics;
using System.Timers;
using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;
public class Vihollinen : PlatformCharacter
{
private int Osumat;
public Vihollinen(double leveys, double korkeus)
: base(leveys, korkeus)
{
Osumat = 0;
}
public void OtaVastaanOsuma()
{
Osumat++;
if (Osumat > 2)
{
this.Destroy();
}
}
}
public class Harjoitustyo : PhysicsGame
{
PhysicsObject tykki;
private static System.Timers.Timer aika;
private int koko = 80;
private Vector[] vihuSpawnit = new Vector[5];
private Vector[] tykkiSpawnit = new Vector[20];
private int vihuTaulukkoPaikka = 0;
private int tykkiTaulukkoPaikka = 0;
public override void Begin()
{
TeeKenttä();
AloitaAjastin();
//for (int i = 0; i < 5; i++)
//{
// Palikka palikka = new Palikka(50, 50);
// palikka.Position = RandomGen.NextVector(Level.BoundingRect);
// Add(palikka);
//}
//AddCollisionHandler<PhysicsObject, Vihollinen>(tykki, TormattiinViholliseen);
Mouse.Listen(MouseButton.Left, ButtonState.Released, LisaaTykki, "Lisää peliin tykin");
Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
}
public void LisaaTykki()
{
tykki = new PhysicsObject(koko, koko, Shape.Rectangle);
tykki.Position = LahinTykkiSpawn();
Vector paikka = tykki.Position;
tykki.Color = Color.ForestGreen;
tykki.CollisionIgnoreGroup = 2;
Add(tykki);
AmmuTykillä(paikka);
}
public void AmmuTykillä(Vector paikka)
{
Vihollinen panos = new Vihollinen(koko / 5, koko / 5);
panos.IgnoresGravity = true;
panos.Shape = Shape.Circle;
panos.CollisionIgnoreGroup = 2;
panos.Position = paikka;
panos.LinearDamping = 0.1;
Add(panos);
panos.Push(new Vector(0, 400));
}
public void TormattiinViholliseen(PhysicsObject tormaaja, Vihollinen kohde)
{
kohde.OtaVastaanOsuma();
}
public Vector LahinTykkiSpawn()
{
Vector lahin = tykkiSpawnit[0];
foreach (Vector spawn in tykkiSpawnit)
{
if (Vector.Distance(Mouse.PositionOnWorld, spawn) < Vector.Distance(Mouse.PositionOnWorld, lahin))
{
lahin = spawn;
}
}
return lahin;
}
public void TeeKenttä()
{
TileMap kentta = TileMap.FromLevelAsset("Leveli");
kentta.SetTileMethod('l', LuoLattia, "lattia");
kentta.SetTileMethod('v', LuoSpawni, "vihujen spawnpisteet", 'v');
kentta.SetTileMethod('p', LuoSpawni, "tykkien spawnipisteet", 'p');
kentta.Execute(koko, koko);
kentta.Optimize('l');
Level.CreateBorders();
Level.Size = new Vector(1000, 800);
SetWindowSize(1000, 800);
Camera.ZoomToAllObjects();
Gravity = new Vector(0, -200);
}
public void LuoLattia(Vector paikka, double korkeus, double leveys, string kuvanNimi)
{
PhysicsObject lattia = new PhysicsObject(koko, koko);
lattia.Position = paikka;
lattia.Image = LoadImage("kentanLattia");
lattia.MakeStatic();
lattia.CollisionIgnoreGroup = 1;
Add(lattia);
}
public void LuoSpawni(Vector paikka, double korkeus, double leveys, string kuvanNimi, char tunniste)
{
PhysicsObject spawn = new PhysicsObject(koko, koko);
spawn.IgnoresCollisionResponse = true;
spawn.IgnoresGravity = true;
spawn.Position = paikka;
spawn.IsVisible = false;
if (tunniste == 'v')
{
vihuSpawnit[vihuTaulukkoPaikka] = spawn.Position;
vihuTaulukkoPaikka++;
}
else
{
tykkiSpawnit[tykkiTaulukkoPaikka] = spawn.Position;
tykkiTaulukkoPaikka++;
}
Add(spawn);
}
private void AloitaAjastin()
{
aika = new System.Timers.Timer(2000);
aika.Elapsed += AjastettuToiminto;
aika.AutoReset = true;
aika.Enabled = true;
}
private void AjastettuToiminto(Object source, ElapsedEventArgs e)
{
LuoVihu();
}
private void LuoVihu()
{
Vihollinen vihu = new Vihollinen(koko, koko);
vihu.Color = Color.BloodRed;
vihu.Shape = Shape.Rectangle;
vihu.Position = vihuSpawnit[RandomGen.NextInt(5)];
//vihu.StaticFriction = 0.1;
//vihu.KineticFriction = 0;
//vihu.MaxVelocity = 400;
//vihu.Acceleration = new Vector(-400, 0);
Add(vihu);
//vihu.Push(new Vector(-400, 0));
vihu.Hit(new Vector(-400, 0));
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>netcoreapp3.1;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
<ItemGroup>
<PackageReference Include="Jypeli.Core" Version="8.*" />
<PackageReference Include="Jypeli.Physics2d.Core" Version="1.4.*" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\" />
</ItemGroup>
<ItemGroup>
<None Update="Content\kentanLattia.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Content\Leveli.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Harjoitustyö/Harjoitustyö/Icon.ico

29.1 KiB

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Program
{
/// <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 Harjoitustyo())
game.Run();
}
}
}
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