One of two high school students accused of opening fire at STEM School Highlands Ranch near Denver in May, killing an 18-year-old, allegedly told police he targeted students who made fun of his gender identity and had been planning the shooting for a few weeks.

Court documents released Thursday shed new details on the May 7 shooting that killed Kendrick Castillo, 18, who has been called a hero for acting with others to stop one of the shooters at the STEM school, which is in a community south of Denver.

Alec McKinney, 16, was arrested after a shooting at the STEM School Highlands Ranch in Colorado. McKinney has been charged as an adult. Obtained by NBC News

Devon Erickson, 18, and Alec McKinney, 16, who according to the documents told police he was transitioning and whose attorney says prefers male pronouns, have been charged with more than 40 counts including murder and attempted murder. Prosecutors have said both are being tried as adults.

Probable cause documents released Thursday are redacted and include only Erickson's name, but officials have said Erickson and McKinney are the only people charged in the shooting.

The documents portray the second suspect, not Erickson, as the person who planned the attack.

The documents say that suspect in interviews with police "said he wanted the kids at the school to experience bad things, have to suffer from trauma like he has had to in his life,” and that “he wanted everyone in that school to suffer and realize that the world is a bad place.”

That suspect allegedly said he got Erickson involved in the plan. He also told police that students were targeted and that they made fun of him, "called him names and said he was disgusting for trying to be a guy" as well as referring to him as "a she," according to the probable cause documents.

McKinney has been charged as an adult, and his attorneys have said they plan to ask a judge to move the case to juvenile court, the Associated Press reported. Neither suspect has entered a plea yet, and their attorneys opposed the unsealing of records associated with the criminal cases.

Devon Michael Erickson appears at the Douglas County Courthouse for his advisement hearing on May 8, 2019 in Castle Rock, Colorado. Joe Amon / Pool via Getty Images

A judge sealed both court records after Erickson and McKinney made their initial court appearances, preventing police or prosecutors from discussing almost anything about the case.

Both suspects allegedly told police they talked on Snapchat the night before the shooting. Erickson told police the other suspect said he was suicidal and wanted revenge, according to the documents.

Both suspects allegedly told police that they went to Erickson's home during lunch and broke into a parent’s gun safe with an ax and a crowbar and got three handguns and a rifle as well as ammunition and magazines from the safe.

Download the NBC News app for breaking news and politics

They both took cocaine, although Erickson said he was threatened into doing so, according to the documents. They allegedly put the guns in a guitar case and a backpack and went back to school.

The accounts of the two suspects in the probable cause documents differ, including who had which guns and where they were kept.

Erickson told police he pulled out the Glock handgun out of a guitar case and told everyone to get down, that the gun went off when he was rushed by two students in the classroom, and that he surrendered the gun and heard more shooting and yelling, according to the documents. He also claimed that he pulled out the gun after seeing the other suspect go for his gun, and that after being taken down he tried to warn people.

The other suspect told police that Erickson "pulled the magnetic strip and shut the door to prevent it from being opened from the outside," that they both pulled out their guns and said "nobody move," and he believes Erickson shot first.

The other suspect claimed he then started shooting his own two handguns and was also tackled by students and a teacher, but got away and grabbed a third handgun from his backpack and fled with the intention of killing himself but couldn’t work the gun's safety, according to the documents.

That suspect was confronted by an armed security guard and was ordered to the ground and taken into custody.

Erickson was being held down by another student who had been shot in the leg and was arrested, according to the documents. Police found a rifle, identified as a Ruger 22, in the guitar case, the documents say.

The police documents released Thursday also allege that a security guard at the school, who has not been identified, fired a shot that wounded a female student in another room. The security guard "stated he saw a muzzle come around the corner," according to the documents.

Robert Burk, attorney for the unnamed guard, said he had no comment.

The private security guard is under investigation, NBC affiliate KUSA of Denver reported, and the owner of the company he worked for told the station that he had not heard of the allegations in the court documents.

Aside from Castillo, the student who was killed, eight others were wounded in the shooting, authorities have said. All survived.

Police said in the affidavit that while Erickson repeatedly claimed he was going to stop McKinney he "couldn't articulate how or why he never told an adult."