Three police officers and a state trooper were shot and wounded Sunday afternoon and the alleged gunman died of an apparent self-inflicted gunshot wound, ending a standoff that lasted more than eight hours, police said.

Police said the siege began when officers were called to an apartment complex because of a report of a broken window. They determined it was shot out, and when they went to the apartment where the gunfire appeared to have come from, someone opened fire on them.

Trooper Rick Smith was shot as he responded to the report of three officers being wounded, said Lisa Block, a Texas Department of Public Safety spokeswoman.

Midlothian police spokesman Britt Snipes identified the dead gunman as Richard Wayne Miles, 25, of Midlothian, about 25 miles southwest of Dallas. Officers don't know the motive for the shootings, Block said.

Hundreds of people gathered around the two-story brick building, which was illuminated after nightfall by high powered lights, and bursts of gunfire punctuated the air throughout the evening.

Midlothian police Sgt. Brian Woolery was in serious condition at Methodist Dallas Medical Center Hospital, spokeswoman Kathleen Beathard said. Officer Dustin Compton was in good condition and Smith and Officer Cody McKinney were in fair condition.

A woman who has lived across the street from Miles' parents for the past 12 years said he had been having trouble keeping a job.

"This surely is a shock," said Teresa Colvin, whose children grew up playing with Miles. "I knew he's been having some problems, but I didn't think it would go this far."