Skip to content

Instantly share code, notes, and snippets.

View dacharya64's full-sized avatar

Devi Acharya dacharya64

View GitHub Profile
@dacharya64
dacharya64 / BaseProvider.java
Created August 12, 2018 19:14
[GSoC Light and Shadow] Creates a region from defined coordinates to create base
return Region3i.createFromMinMax(new Vector3i(centerBasePosition.x() - LASUtils.BASE_EXTENT, centerBasePosition.y(), centerBasePosition.z() - LASUtils.BASE_EXTENT),
new Vector3i(centerBasePosition.x() + LASUtils.BASE_EXTENT, centerBasePosition.y(), centerBasePosition.z() + LASUtils.BASE_EXTENT));
@dacharya64
dacharya64 / BaseRasterizer.java
Created August 12, 2018 19:11
[GSoC Light and Shadow] Sets blocks in world for each block in the defined region
for (Vector3i baseBlockPosition : baseRegion) {
if (chunkRegion.getRegion().encompasses(baseBlockPosition) && baseBlockPosition.x > 0) {
chunk.setBlock(ChunkMath.calcBlockPos(baseBlockPosition), redBaseStone);
} else if (chunkRegion.getRegion().encompasses(baseBlockPosition)) {
chunk.setBlock(ChunkMath.calcBlockPos(baseBlockPosition), blackBaseStone);
}
}
@dacharya64
dacharya64 / TeleporterSystem.java
Created August 12, 2018 19:06
[GSoC Light and Shadow] Setting team of player based on team selection via teleporter
private String setPlayerTeamToTeleporterTeam(EntityRef player, EntityRef teleporter) {
LASTeamComponent teleporterTeamComponent = teleporter.getComponent(LASTeamComponent.class);
LASTeamComponent playerTeamComponent = player.getComponent(LASTeamComponent.class);
playerTeamComponent.team = teleporterTeamComponent.team;
player.saveComponent(playerTeamComponent);
return playerTeamComponent.team;
}
@dacharya64
dacharya64 / TakeBlockOnActivationSystem.java
Created August 12, 2018 19:04
[GSoC Light and Shadow] Giving flag to player on activating flag
private void giveFlagToPlayer(EntityRef flag, EntityRef player) {
BlockComponent blockComponent = flag.getComponent(BlockComponent.class);
LASTeamComponent flagTeamComponent = flag.getComponent(LASTeamComponent.class);
BlockItemFactory blockFactory = new BlockItemFactory(entityManager);
inventoryManager.giveItem(player, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily(LASUtils.getFlagURI(flagTeamComponent.team))));
worldProvider.setBlock(blockComponent.getPosition(), blockManager.getBlock(BlockManager.AIR_ID));
flag.destroy();
}
@dacharya64
dacharya64 / AttackSystem.java
Created August 12, 2018 19:02
[GSoC Light and Shadow] Checking player inventory for flag
int inventorySize = inventoryManager.getNumSlots(targetPlayer);
for (int slotNumber = 0; slotNumber <= inventorySize; slotNumber++) {
EntityRef inventorySlot = inventoryManager.getItemInSlot(targetPlayer, slotNumber);
if (inventorySlot.hasComponent(BlockItemComponent.class)) {
if (inventorySlot.getComponent(BlockItemComponent.class).blockFamily.getURI().toString().equals(flagTeam)) {
flagSlot = inventorySlot;
}
}
}
@dacharya64
dacharya64 / ScoreSystem.java
Created August 12, 2018 19:00
[GSoC Light and Shadow] Incrementing Score and Sending Event on Authority System
private void incrementScore(LASTeamComponent baseTeamComponent) {
if (baseTeamComponent.team.equals(LASUtils.RED_TEAM)) {
redScore++;
// Send event to clients to update their Score UI
sendEventToClients(new ScoreUpdateFromServerEvent(LASUtils.RED_TEAM, redScore));
return;
}
if (baseTeamComponent.team.equals(LASUtils.BLACK_TEAM)) {
blackScore++;
// Send event to clients to update their Score UI
@dacharya64
dacharya64 / ClientScoreSystem.java
Created August 12, 2018 18:57
[GSoC Light and Shadow] Updating Score on Receiving Event from Authorty System
@ReceiveEvent
public void onScoreUpdateFromServer(ScoreUpdateFromServerEvent event, EntityRef entity) {
String team = event.team;
if (team.equals(LASUtils.RED_TEAM)) {
redScore = event.score;
return;
}
if (team.equals(LASUtils.BLACK_TEAM)) {
blackScore = event.score;
return;
@dacharya64
dacharya64 / PlayerMovement.cs
Created February 7, 2018 03:47
Learning Unity: Player Movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float speed; //how fast the player moves
public float jumpForce; //how high the player jumps
//Private Vars
@dacharya64
dacharya64 / CameraMovement.cs
Created February 7, 2018 03:08
A Unity script for getting the camera to follow the player
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CameraMovement : MonoBehaviour
{
public GameObject player; //Public variable to store a reference to the player game object
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Devi/LambertShader"
{
Properties
{
_Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader
{