Topics - p3lb0x [ switch to compact view ]

Pages: [1] 2 3 4 5 6 7next
1
General Software Discussion / Fruits of my gamejam labour
« on: October 17, 2017, 12:58 AM »
At the behest of Mouser I am gonna post the results of a small local gamejam I joined by the Organization Coding Pirates here in Denmark.

Coding Pirates are a volunteer organization that does community work with kids and young adults to get them interested in technology, programming and mixing these with more artistic endeavors (Like game making or visual arts). I hadn't actually heard of them before, but I saw the event through facebook and decided to join in.

The theme of the gamejam was mirrored from what they had helped the kids in their program work on for the last half year, but we were only afforded 12 hours (actually only 11 hours since the last hour was for a presentation). That theme being "feelings", completely open to interpretation.

The group I was in decided on "The feeling of confusion" as our interpretation, resulting in a maze game that tried to confuse the player through the use of rotating the playing field and teleporters. The game was made in Unity, something I've been dabbling in recently and hopefully can produce a small game in for my NANY. Lots of corners were cut, due to a mixture of us not being the most proficient at Unity, the other programmer in the group never having written any C# and time constraints. We did however produce a fully functional game with well defined gameplay elements and no bugs (as far as I know anyway).

bacon.png

The goal of Squared? (Stylized as "?²") we made is to find 4 keys and reach the treasure behind the locked door.

1.jpg

Gameplay is really simple, you walk around the maze with limited vision, only being able to see neighboring rooms. Compass rooms reorient the gameworld and teleporters move you to another place in the maze, there's also glyph rooms that help you create a mental map (that the rotations hopefully messes with).

We ended up being tied for last place however, because the game wasn't eye catching compared to the other games (that you can also download here)

2
Community Giveaways / Shadow of Mordor and Neon Chrome
« on: September 20, 2017, 05:40 PM »
I have a spare copy of these two games from a recent Humble Bundle, anyone want them?
Middle-earth: Shadow of Mordor Game of the Year Edition
Neon Chrome


3
N.A.N.Y. 2018 / NANY 2018 Pledge: Some kind of unity game
« on: September 10, 2017, 09:44 AM »
I have been messing around in unity and I think I can churn out a small game. Which I am gonna do!

4
Community Giveaways / TIS-100, a programming game
« on: December 06, 2016, 05:39 PM »
Hey! I got an extra copy of TIS-100 due once more, to bundle overlap. If anyone is interested in solving some programming problems with something that can be be described as multithreaded assembly, give me a shout.

5
General Software Discussion / Looking back (Some of your first code)
« on: January 20, 2016, 08:02 PM »
So, I recently stumbled on my first real C project, back from high school. It is pretty bad. And I thought it would be fun to share with you guys and maybe get to see some of the first code you guys did in whatever capacity you can find. I also have code from the first major Lua project I did. Both were written around the same time.

C code:
The below code is for a master microcontroller that calculates game of life and sends the "game" field to another microcontroller that had a charlieplexed 8x7 led display that displayed it. A video of it in action can be found here
comments are translated from danish and I have commented on the comments in parentheses (pastebin link)
Spoiler
#include <htc.h> //PIC hardware mapping
#include <delay.c>
#include <I2CMaster.h>
#include <stdlib.h>
//config bits

__CONFIG(HS & PWRTDIS & WDTDIS & LVPDIS);

/////////// Constants ///////////
#define LEDPLADE8PIN 1 // Defines how many light plates with 8pins that's attached (Not ever actually used, was supposed to be able to handle more than one)

/////////// Bit manipulation functions ///////////

void clear_bit(unsigned char *x, char bitNum){
*x &= ~(1 << bitNum);
}
void set_bit(unsigned char *x, char bitNum) {
*x |= (1 << bitNum);
}
unsigned char get_bit(unsigned char x, char bitNum) {
return x & (1 << bitNum);
}

/////////////// Function prototypes for patterns //////////////////

void glider(void);
void lwss(void);
void toad(void);
void kasse(void);
void blinker(void);
void randompat(void);

/////////// Variables ///////////

////////// GAME OF LIFE ///////////

char LifeGameBuf[2][7];
char LiveCount;
char FirstEvol;
char Pattern;
char NewPattern;

///////////////////////////////////

char i; // Indexes
char j;

char I2C_Address; // Defines the i2c address we want to write to
char I2C_i; // Defines what type of byte we want to send (I don't remember what this is, and it is apparently unused)

/////////// Main program ///////////
void main(void){ // Start

srand(70);

/////////// Opsætning ///////////

/////////// Opsætning af SSP modul ///////////

TRISC = 0b00011000; // Sets port C pin 3 and 4 to be inputs
SSPADD = 39; // Defines the baudrate of the i2c communications
SSPCON = 0b00101000; // Configuration and start of SSP module
SSPCON2 = 0b00000000;
SSPSTAT = 0b11000000;
SSPIE = 1; // Enable interrupt on i2c communication start
SSPIF = 0;

/////////// Setup of interrupts ///////////

PEIE = 1;
GIE = 1; // Global interrupt enable

/////////// GAME OF LIFE ///////////

LiveCount = 0;
Pattern = 0;
NewPattern = 0;

glider();

/////////// Runs in a loop from here (Obviously not) ///////////

/////////// Pattern change ///////////
TRISD = 0b00000010; // Set pins on port D as input and output
while(!0){
PORTD = 0b00001000; // Drive current to RD3 pin
if(RD3 == 0){ // I HAVE NO IDEA WHY THIS WORKS (Basically, the code here sets a pin, then checks if it is set. It worked, I still have no idea why)
Pattern = Pattern + 1;
NewPattern = 1;
DelayMs(255);
}
if(NewPattern){
if(Pattern > 5) Pattern = 0;
if(Pattern == 0) glider();
else if(Pattern == 1) lwss();
else if(Pattern == 2) toad();
else if(Pattern == 3) kasse();
else if(Pattern == 4) blinker();
else if(Pattern == 5) randompat();
NewPattern = 0;
}

//////////////// Blink light to indicate when the next generations of game of life is calculated /////////////////
PORTD = 0;
DelayMs(50);
PORTD = 1;

//////////////// Game of Life /////////////////
if(!FirstEvol){
for(i=0; i<7; i++){
for(j=0; j<8; j++){
if(i == 0){
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
}
else if(i == 6){
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j-1)) LiveCount = LiveCount + 1;
}
}
else{
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
}

if(LiveCount < 2){clear_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 2 && get_bit(LifeGameBuf[1][i],j) == 1){set_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 2 && get_bit(LifeGameBuf[1][i],j) == 0){clear_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 3){set_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount > 3){clear_bit(&LifeGameBuf[1][i],j);}
LiveCount = 0;

}
}
for(i=0; i<7; i++){
LifeGameBuf[0][i] = LifeGameBuf[1][i];
}
}
FirstEvol = 0; // No longer first generation

////////////// SEND TO DISPLAY /////////////////

i2c_Start();
i2c_Address(15,0);
i2c_Write(LifeGameBuf[0][0]);
i2c_Write(LifeGameBuf[0][1]);
i2c_Write(LifeGameBuf[0][2]);
i2c_Write(LifeGameBuf[0][3]);
i2c_Write(LifeGameBuf[0][4]);
i2c_Write(LifeGameBuf[0][5]);
i2c_Write(LifeGameBuf[0][6]);
i2c_Stop();
}
} // End

static void interrupt isr(void)
{

if(SSPIF){ // Was it a i2c interrupt?
SSPIF = 0; // Clear SSP interrupt flag
}
}

/////////// Game of Life pattern funftions ///////////

void glider() {

LifeGameBuf[0][0] = 0b00100000;
LifeGameBuf[0][1] = 0b10100000;
LifeGameBuf[0][2] = 0b01100000;
LifeGameBuf[0][3] = 0b00000000;
LifeGameBuf[0][4] = 0b00000000;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}


void lwss() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00000000;
LifeGameBuf[0][2] = 0b00110000;
LifeGameBuf[0][3] = 0b11011000;
LifeGameBuf[0][4] = 0b11110000;
LifeGameBuf[0][5] = 0b01100000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void toad() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00000000;
LifeGameBuf[0][2] = 0b00000000;
LifeGameBuf[0][3] = 0b00111000;
LifeGameBuf[0][4] = 0b00011100;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void kasse() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00110000;
LifeGameBuf[0][2] = 0b01001000;
LifeGameBuf[0][3] = 0b01001000;
LifeGameBuf[0][4] = 0b00110000;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void blinker() {

LifeGameBuf[0][0] = 0b01000000;
LifeGameBuf[0][1] = 0b01000000;
LifeGameBuf[0][2] = 0b01000000;
LifeGameBuf[0][3] = 0b00001000;
LifeGameBuf[0][4] = 0b00001000;
LifeGameBuf[0][5] = 0b00001000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void randompat() {

LifeGameBuf[0][0] = (char)rand();
LifeGameBuf[0][1] = (char)rand();
LifeGameBuf[0][2] = (char)rand();
LifeGameBuf[0][3] = (char)rand();
LifeGameBuf[0][4] = (char)rand();
LifeGameBuf[0][5] = (char)rand();
LifeGameBuf[0][6] = (char)rand();

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

Fun things:
while(!0)
The "I HAVE NO IDEA WHY THIS WORKS" comment

Lua code:
The below code is for a randomized gun generation thing for the game Cortex Command, a video of which can be found here. If I recall correctly, it was also my first NANY.
removed a few new lines, otherwise did nothing (pastebin link)
Spoiler
function Create(self)

-- Initialize variables and timers

self.smgbodylist = {};
self.smgbarrellist = {};
self.smgmaglist = {};
self.smgbulletlist = {};
self.smgsoundlist = {};
self.smgsoundlist["fire"] = {};
self.smgsoundlist["reload"] = {};
self.smgmuzzlelist = {};

self.projectileteam = -1;
self.allmodulesfound = false;
self.ammocounter = 0;
self.reloading = false;

self.Body = {};
self.Mag = {};
self.Barrel = {};
self.Bullet = {};
self.FireSound = nil;
self.ReloadSound = nil;
self.MuzzleFlash = nil;

self.firingtimer = Timer();

-- Initial stats
-- Basic stats
self.rateoffire = 700;
self.ammocapacity = 20;
self.accuracy = 25;

-- Initial modifiers
self.rofmod = 0.8 + math.random()*0.4;
self.magmod = 0.8 + math.random()*0.4;
self.accmod = 0.8 + math.random()*0.4;
self.firevelmod = 0.8 + math.random()*0.4;
self.massmod = 0.8 + math.random()*0.4;
self.sharpnessmod = 0.8 + math.random()*0.4;

-- Load body modules
dofile("Brolands.rte/smg/bodymodules.lua");
BrolandsBodies(self);

-- Load barrel modules
dofile("Brolands.rte/smg/barrelmodules.lua");
BrolandsBarrels(self);

-- Load magazines modules
dofile("Brolands.rte/smg/magazinemodules.lua");
BrolandsMagazines(self);

-- Load bullets
dofile("Brolands.rte/smg/bulletmodules.lua");
BrolandsBullets(self);

-- Load muzzleflashes
dofile("Brolands.rte/smg/muzzleflashmodules.lua");
BrolandsMuzzleflashes(self);

-- Load sounds
dofile("Brolands.rte/smg/soundmodules.lua");
BrolandsSounds(self);

end

function Update(self)

-- Generate gun
if self.allmodulesfound ~= true then
-- Find the attachments
for i=1,MovableMan:GetMOIDCount()-1 do
local mo = MovableMan:GetMOFromID(i);
if mo.PresetName == "SmgBody" and mo.RootID == self.RootID then
self.Body["pointer"] = ToAttachable(mo);
self.Body["pointer"].GetsHitByMOs = false;
elseif mo.PresetName == "SmgMag" and mo.RootID == self.RootID then
self.Mag["pointer"] = ToAttachable(mo);
self.Mag["pointer"].GetsHitByMOs = false;
elseif mo.PresetName == "SmgBarrel" and mo.RootID == self.RootID then
self.Barrel["pointer"] = ToAttachable(mo);
self.Barrel["pointer"].GetsHitByMOs = false;
end
if self.Body["pointer"] and self.Mag["pointer"] and self.Barrel["pointer"] then
self.allmodulesfound = true;
break;
end
end

-- Body
for k,v in pairs(self.smgbodylist[math.random(1,#self.smgbodylist)]) do self.Body[k] = v end
-- for k,v in pairs(self.smgbodylist[15]) do self.Body[k] = v end
self.Body["pointer"].Frame = self.Body["sprite"];

-- Modify stat modifier with module modifier
self.rofmod = self.rofmod * self.Body["rofmod"];
self.magmod = self.magmod * self.Body["magmod"];
self.accmod = self.accmod * self.Body["accmod"];
self.firevelmod = self.firevelmod * self.Body["firevelmod"];
self.massmod = self.massmod * self.Body["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Body["sharpnessmod"];

-- Mag
for k,v in pairs(self.smgmaglist[math.random(1,#self.smgmaglist)]) do self.Mag[k] = v end
-- for k,v in pairs(self.smgmaglist[16]) do self.Mag[k] = v end
self.Mag["pointer"].Frame = self.Mag["sprite"];
self.Mag["offset"] = self.Body["magoffset"];

-- Modify stat modifier with module modifier
self.rofmod = self.rofmod * self.Mag["rofmod"];
self.magmod = self.magmod * self.Mag["magmod"];
self.accmod = self.accmod * self.Mag["accmod"];
self.firevelmod = self.firevelmod * self.Mag["firevelmod"];
self.massmod = self.massmod * self.Mag["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Mag["sharpnessmod"];

-- Barrel
for k,v in pairs(self.smgbarrellist[math.random(1,#self.smgbarrellist)]) do self.Barrel[k] = v end
-- for k,v in pairs(self.smgbarrellist[18]) do self.Barrel[k] = v end
self.Barrel["pointer"].Frame = self.Barrel["sprite"];
self.Barrel["offset"] = self.Body["barreloffset"];

-- Modify gun stat modifier with module modifier
self.rofmod = self.rofmod * self.Barrel["rofmod"];
self.magmod = self.magmod * self.Barrel["magmod"];
self.accmod = self.accmod * self.Barrel["accmod"];
self.firevelmod = self.firevelmod * self.Barrel["firevelmod"];
self.massmod = self.massmod * self.Barrel["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Barrel["sharpnessmod"];

-- Bullet
for k,v in pairs(self.smgbulletlist[math.random(1,#self.smgbulletlist)]) do self.Bullet[k] = v end
-- for k,v in pairs(self.smgbulletlist[3]) do self.Bullet[k] = v end

-- Modify gun stat modifier with module modifier
self.rofmod = self.rofmod * self.Bullet["rofmod"];
self.magmod = self.magmod * self.Bullet["magmod"];
self.accmod = self.accmod * self.Bullet["accmod"];
self.firevelmod = self.firevelmod * self.Bullet["firevelmod"];
self.massmod = self.massmod * self.Bullet["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Bullet["sharpnessmod"];

-- Fire sound

self.FireSound = self.smgsoundlist["fire"][self.Bullet["firesounds"][math.random(1,#self.Bullet["firesounds"])]];

-- Reload sound

self.ReloadSound = self.smgsoundlist["reload"][self.Mag["reloadsounds"][math.random(1,#self.Mag["reloadsounds"])]];

-- Muzzle flash

self.MuzzleFlash = self.smgmuzzlelist[self.Bullet["muzzleflash"][math.random(1,#self.Bullet["muzzleflash"])]];

-- Done generating gun, apply gun stat modifiers
self.rateoffire = Round(self.rateoffire * self.rofmod);
self.ammocapacity = Round(self.ammocapacity * self.magmod);

-- You can't be more precise than 100%
if self.accuracy > 100 then
self.accuracy = 100;
else
self.accuracy = Round(self.accuracy * self.accmod);
end

self.Bullet["firevel"] = Round(self.Bullet["firevel"] * self.firevelmod);
self.Bullet["mass"] = self.Bullet["mass"] * self.massmod;
self.Bullet["sharpness"] = Round(self.Bullet["sharpness"] * self.sharpnessmod);


-- Output gun stats to console
-- print("\nRate of fire: "..self.rateoffire.." Rounds Per Minute\nMagazine capacity: "..self.ammocapacity.." Rounds\nAccuracy: "..self.accuracy.."%\nProjectile type: "..self.Bullet["particle"].."\nProjectile mass: "..self.Bullet["mass"].."\nProjectile speed: "..self.Bullet["firevel"].."\nProjectile sharpness: "..self.Bullet["sharpness"].."\n");

self.ammocounter = self.ammocapacity;

-- Clear unneeded tables and variables
self.smgbodylist = nil;
self.smgbarrellist = nil;
self.smgmaglist = nil;
self.smgbulletlist = nil;
self.smgsoundlist = nil;
self.rofmod = nil;
self.magmod = nil;
self.accmod = nil;
self.firevelmod = nil;
self.massmod = nil;
self.sharpnessmod = nil;
end

-- Figure out what team is currently holding the gun
self.projectileteam = MovableMan:GetMOFromID(self.RootID).Team;

-- Move around attachables
if self.Body["pointer"].ToDelete ~= true and self.Body["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X * -1,self.Body["offset"].Y):RadRotate(self.RotAngle);
else
self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X,self.Body["offset"].Y):RadRotate(self.RotAngle);
end
self.Body["pointer"].RotAngle = self.RotAngle;
self.Body["pointer"].HFlipped = self.HFlipped;
end

if self.Mag["pointer"].ToDelete ~= true and self.Mag["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X * -1,self.Mag["offset"].Y):RadRotate(self.RotAngle);
else
self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X,self.Mag["offset"].Y):RadRotate(self.RotAngle);
end
self.Mag["pointer"].RotAngle = self.RotAngle;
self.Mag["pointer"].HFlipped = self.HFlipped;
end

if self.Barrel["pointer"].ToDelete ~= true and self.Barrel["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X * -1,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
else
self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
end
self.Barrel["pointer"].RotAngle = self.RotAngle;
self.Barrel["pointer"].HFlipped = self.HFlipped;
end

if self:IsActivated() and self.firingtimer:IsPastSimMS(60000 / self.rateoffire) and self.ammocounter > 0 and self.Magazine ~= nil then
self.ammocounter = self.ammocounter - 1;
self.firingtimer:Reset()

-- Decide which kind of particle to create depending on the bullets particle type
if self.Bullet["particletype"] == "MOPixel" then
self.particle = CreateMOPixel(self.Bullet["particle"],"Brolands.rte");
elseif self.Bullet["particletype"] == "MOSRotating" then
self.particle = CreateMOSRotating(self.Bullet["particle"],"Brolands.rte");
elseif self.Bullet["particletype"] == "MOSParticle" then
self.particle = CreateMOSParticle(self.Bullet["particle"],"Brolands.rte");
end

-- Decide which kind of particle to create depending on the muzzleflashs particle type
if self.MuzzleFlash["particletype"] == "MOPixel" then
self.particle2 = CreateMOPixel(self.MuzzleFlash["particle"],"Brolands.rte");
elseif self.MuzzleFlash["particletype"] == "MOSRotating" then
self.particle2 = CreateMOSRotating(self.MuzzleFlash["particle"],"Brolands.rte");
elseif self.MuzzleFlash["particletype"] == "MOSParticle" then
self.particle2 = CreateMOSParticle(self.MuzzleFlash["particle"],"Brolands.rte");
end

-- Figure out if the actor is sharpaiming or not.
local MO = MovableMan:GetMOFromID(self.RootID)
local Aiming = 1;
if MO then
local Actor = ToActor(MO)
if Actor:GetController():IsState(Controller.AIM_SHARP) then
Aiming = 0.5;
else
Aiming = 1;
end
end

-- Create a direction vector for the projectile depending on if the gun is HFlipped or not
if self.HFlipped == true then
self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
if math.random() > 0.5 then
self.firingvector = Vector(-1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
else
self.firingvector = Vector(-1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
end
else
self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
if math.random() > 0.5 then
self.firingvector = Vector(1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
else
self.firingvector = Vector(1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
end
end
self.particle.Mass = self.Bullet["mass"]
self.particle.Sharpness = self.Bullet["sharpness"];
self.particle.Vel = self.firingvector * self.Bullet["firevel"];
self.particle.LifeTime = 1500;
self.particle.Team = self.projectileteam;
self.particle.IgnoresTeamHits = true;
MovableMan:AddParticle(self.particle);

-- Create firing sound emitter.
self.particle = CreateAEmitter(self.FireSound,"Brolands.rte");
self.particle.Pos = self.Pos;
MovableMan:AddParticle(self.particle);

-- Create muzzleflash
self.particle2.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
self.particle2.Vel = self.Vel;
MovableMan:AddParticle(self.particle2);
end

-- Keeps track of the magazine
if self.Magazine == nil then
self.Mag["pointer"].Scale = 0;
self.ammocounter = self.ammocapacity;
self.reloading = true;
else
self.Mag["pointer"].Scale = 1;
self.Magazine.RoundCount = self.ammocounter;
end

if self.reloading == true and self.Magazine ~= nil then
self.reloading = false;
-- When the gun is done reloading, play reload sound
self.particle = CreateAEmitter(self.ReloadSound,"Brolands.rte");
self.particle.Pos = self.Pos;
MovableMan:AddParticle(self.particle);
end

end

function Destroy(self)
end

function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end

Fun things:
"pointers" in lua

Pages: [1] 2 3 4 5 6 7next
Go to full version