<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CubaGames &#187; C#</title>
	<atom:link href="http://www.cubagames.com.br/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cubagames.com.br</link>
	<description>Notícias sobre o mundo dos games, artigos sobre gamedev, reflexões, tutoriais, games e jogos online</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:40:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 7 &#8211; Final</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-7-final/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-7-final/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 03:01:39 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1587</guid>
		<description><![CDATA[<p style="text-align: center;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/02/winformslander.jpg"><img class="size-full wp-image-1590   alignnone" title="winformslander" src="http://www.cubagames.com.br/wp-content/uploads/2010/02/winformslander.jpg" alt="winformslander" width="462" height="336" /></a><br />
<em>Clique para ampliar</em></p>
<p style="text-align: justify;">Depois de algum tempo, termino esta série. A idéia desde o início era simplesmente explicar o básico sobre desenvolvimento de games conforme eu fosse aprendendo. Desde o primeiro post, o jogo <strong>WinForms Lander</strong> já estava praticamente completo. E claro, como nem todos gostam de ler posts técnicos, fui alternando os posts com posts padrão deste blog. Por isso a série demorou para acabar. Mesmo assim, recomendo muitíssimo a todos a leitura dos posts anteriores, pois eu tentei ser bastante didático e teórico, não se prendendo somente em códigos. Acredito que os textos tenham ficados bem agradáveis e com conteúdo interessante. Mesmo se você não quer desenvolver.</p>
<p style="text-align: justify;">Leiam o restante para acessar os downloads:</p>
<p style="text-align: justify;"><!--more-->Ao longo do desenvolvimento, fui tomando algumas decisões de design e alterando coisas. A principal alteração foi o uso de código 100% nativo para leitura de teclas. Agora não é mais necessário usar aquela dll do XNA para isso. O código eu achei na internet e mantive intacto, junto com o comentário que identifica o autor.</p>
<p style="text-align: justify;">Outra coisa foi o uso de código nativo para tocar arquivos de áudio multimídia. Também peguei da internet. A biblioteca original do Windows Forms/.Net só permitia tocar um som por vez, e ainda somente .WAV. Agora o game toca mp3.</p>
<p style="text-align: justify;">Algo que descobri desenvolvendo o game é que a parte audiovisual é um grande limitador para quem desenvolve sozinho. Fazer um game sem uma equipe multi-talentosa requer um criador multi-talentoso. Criar gráficos 2D estáticos é fácil. Mas criar sons, músicas, animações, backgrounds sem copiar tudo de outras fontes é extremamente difícil para um simples programador.</p>
<p style="text-align: justify;">E aí vem o problema. Encontrar bons efeitos sonoros é muito mais difícil que encontrar músicas. Acredite.</p>
<p style="text-align: justify;">Um dos grandes problemas para desenvolver este jogo foi tentar incluir cenários. O Windows Forms aceita inserir imagens de background, mas qualquer animação fica meio quebrada. A detecção de transparência não é muito boa. Por isso, e também por falta de habilidades de minha parte, não foi possível colocar backgrounds, muito menos obstáculos nas fases, como montanhas, relevos e etc.</p>
<p style="text-align: justify;">Isso levou a algumas idéias interessantes para aumentar o desafio de pousar as naves. Eu fiz com que em cada fase a plataforma se movesse de variadas velocidades e direções para dificultar um pouco e diferenciar as áreas mais avançadas. Algumas áreas possuem ventos. Outra coisa que inseri nas últimas fases foram asteróides que ficam caindo em velocidades e direções variadas, para atrapalhar um pouco.</p>
<p style="text-align: justify;">No geral, acho que o game ficou bem completo.</p>
<p style="text-align: justify;">Tentei neste game incluir um pouco das coisas que sinto falta em alguns games, como fases variadas, prêmios e incentivos para continuar a jogar. Tudo isso na escala do jogo, claro.</p>
<p style="text-align: justify;">Bom, depois de tudo isso, vamos aos downloads:</p>
<p style="text-align: justify;"><a href="http://www.4shared.com/file/231239952/3923be76/WinFormsLander_Source.html">Aqui</a> tem os fontes.</p>
<p style="text-align: justify;">Para codificar, adotei por padrão o idioma inglês. Acho mais fácil em inglês porque assim evitamos estrangeirismos, acentuações ou traduções grosseiras geralmente vistas no código em &#8220;português&#8221;. Se for codificar em português e usar &#8220;GetValor&#8221; para nomear alguma função, então que se adote o inglês de uma vez! Ou usa &#8220;PegaValor&#8221;. Os comentários estão todos em português, no entanto.</p>
<p style="text-align: justify;"><a href="http://www.4shared.com/file/231237363/88412fc6/WinFormsLander_Game.html">Aqui</a> tem o executável.</p>
<p style="text-align: justify;"><a href="http://www.4shared.com/file/232452167/d387c3a3/WinFormsLander_Game_NO_SOUND.html&lt;br &gt;&lt;/a&gt;">Aqui</a> tem o executável sem o áudio, para quem tiver problemas.</p>
<p style="text-align: justify;">Para rodar o game, é necessário ter o .Net 2.0 instalado. Talvez precise de alguma outra biblioteca, mas não consegui testar em uma grande variedade de PCs para me certificar se está tudo ok. Qualquer problema, deixe um comentário.</p>
<p style="text-align: justify;"><em>Edit:</em></p>
<p style="text-align: justify;"><em>PROBLEMA &#8211; a biblioteca de audio que usei pode não funcionar corretamente em alguns sistemas (foi o caso do Kazuma). Como a biblioteca não é minha, não sei porque não funciona. Vou investigar. Enquanto isso, estou disponibilizando uma versão sem áudio do game.</em></p>
<p style="text-align: justify;"><em>VISUAL &#8211; Como utilizei controles visuais usados em formulários de sistemas, como barras, botões, painéis e etc., as imagens ficarão melhores se o jogo rodar no modo visual clássico, e não com o tema do XP (ou mesmo Aero). Cliquem com o botão direito no WinFormsLander.exe e em Propriedades &gt;&gt; Compatibilidade, marquem &#8220;Desabilitar temas visuais&#8221;.</em></p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windowsforms-parte-1/">Parte 1 &#8211; Início</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-7-final/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 6 &#8211; Colisão De Borda</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-6-colisao-de-borda/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-6-colisao-de-borda/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 13:22:17 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Colisão]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1532</guid>
		<description><![CDATA[<p style="text-align: justify;">Neste post, vou mostrar algo bem simples. É a colisão de borda.</p>
<p style="text-align: justify;">A borda nada mais é que um delimitador da área do jogo, que pode ser os extremos da tela, por exemplo.</p>
<p style="text-align: justify;">Esta detecção é importante caso seja necessário manter um sprite dentro da tela. Por exemplo, nos jogos de tiro em scroll vertical como a série Sonic Wings, você não consegue movimentar o avião além da própria tela. Quando o aviãozinho atinge o limite da tela, ele simplesmente não se locomove mais naquela direção.</p>
<p style="text-align: justify;"><!--more--></p>
<p style="text-align: justify;">Utilizando a classe Sprite criada no post anterior, podemos chamar uma função que retorne um booleano para detecção de colisão para uma determinada borda. Quando o retorno for <span style="text-decoration: underline;">true</span>, o que podemos fazer é zerar a velocidade naquela direção, e talvez voltar um pixel para que o sprite saia do estado de colisão e não fique "preso".</p>
<p style="text-align: center;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/02/super-mario-sprite.gif"><img class="size-full wp-image-1540  aligncenter" title="super-mario-sprite" src="http://www.cubagames.com.br/wp-content/uploads/2010/02/super-mario-sprite.gif" alt="super-mario-sprite" width="124" height="120" /></a></p>
<p style="text-align: justify;">Uma coisa que eu esqueci de mencionar no post anterior é que para que possa ser detectado com facilidade as colisões, o ideal é usarmos sprites retangulares. O problema é que um Super Mario quadradinho não venderia tão bem...</p>
<p style="text-align: justify;">Para contornar este problema, devemos sempre usar, associado à imagem do sprite, um retângulo invisível que servirá de zona de detecção. Quando mais ajustado ao tamanho da imagem, melhor.</p>
<p style="text-align: justify;">A classe Sprite possui um objeto pictureBox dentro dela, e esse pictureBox possui a imagem do sprite, e além disso, ela é um retângulo cujas dimensões podem ser facilmente obtidas. Ou seja, o próprio pictureBox serve tanto como imagem quanto zona de detecção. Se fosse no XNA puro, teríamos que renderizar a imagem em cima de uma retângulo invisível e usar a imagem para exibição, e o retângulo para detecção.</p>
<p style="text-align: justify;">Fugindo um pouco, mas nem tanto... Vocês já perceberam que nos primeiros Resident Evil as imagens que formam os cenários são navegáveis pelos personagens como se fossem 3D? Como o jogo sabe numa imagem onde começa o corredor ou onde está a porta? É simples. O jogo não sabe. Os programadores posicionam em cada imagem do cenário um cubo de detecção exatamente com as dimensões das áreas "caminháveis" de cada imagem. E é por este cubo invisível que a engine do jogo se enxerga para deslocar os personagens. A foto não influencia em nada.</p>
<p style="text-align: center;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/02/resident_evil_2_possible_borders.png"><img class="size-full wp-image-1536  aligncenter" title="resident_evil_2_possible_borders" src="http://www.cubagames.com.br/wp-content/uploads/2010/02/resident_evil_2_possible_borders.png" alt="resident_evil_2_possible_borders" width="300" height="225" /></a><br />
<em>Possíveis bordas feitas por mim</em></p>
<p style="text-align: justify;">No caso do nosso sprite, até seria possível ficar testando a sobreposição de imagens, pixel a pixel, para proporcionar uma colisão perfeita. Mas se fizessem isso com Mario, ele nunca rodaria nos consoles antigos. Lembram que eu mencionei sobre uma detecção de colisão que eu fiz comparando pixel a pixel os retângulos? Nem usei os pixels da imagem, que certamente pesaria mais ainda, e ainda assim o jogo ficou com uns 5 quadros.</p>
<p style="text-align: justify;">Em imagens mais complexas, são utilizados mais retângulos por sprite, e as colisões são testadas individualmente. Um exemplo disso são os jogos de luta 2D. Quem já fuçou no MUGEN já deve ter visto isso.</p>
<p style="text-align: justify;">Voltando à colisão de borda, temos que testar a colisão de cada borda individualmente. Para isso, basta chamar a função para cada borda que deve ser testada, passando o limite dela, o sprite, e a direção.</p>
<p style="text-align: justify;">Para criar a função, eu criei também um enumerador com as quatro direções, e assim fica mais fácil passar a direção como parâmetro.</p>
<p style="text-align: justify;">Para cada direção, eu uso um dos vértices do retângulo do sprite para testar a colisão. Eu criei para a classe Sprite quatro propriedades para retornar cada vértice do retângulo, começando a partir do superior esquerdo (0,0) e girando no sentido horário:</p>
<p style="text-align: justify;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/02/vertices.png"><img class="size-full wp-image-1537    aligncenter" title="vertices" src="http://www.cubagames.com.br/wp-content/uploads/2010/02/vertices.png" alt="vertices" width="163" height="185" /></a></p>
<p style="text-align: justify;">Para testar uma colisão do lado esquerdo, preciso usar o vértice 1 ou o 4.</p>
<p style="text-align: justify;">Para testar uma colisão em cima, preciso usar o vértice 1 ou o 2.</p>
<p style="text-align: justify;">Para testar uma colisão do lado direito, preciso usar o vértice 2 ou 3.</p>
<p style="text-align: justify;">Para testar uma colisão embaixo, preciso usar o vértice 4 ou 3.</p>
<p style="text-align: justify;">Todos os sprites ocupam uma posição absoluta na tela. A tela nada mais é que uma grade de pixels, que começa no canto superior esquerdo como 0,0, e termina no canto inferior direito como 640,480 (caso esteja usando esta resolução).</p>
<p style="text-align: justify;">Então, se o vértice 1 estiver na posição do eixo X=0 ou menos, houve uma colisão do lado esquerdo. Se não pararmos o sprite neste momento, nada impede que ele saia da área visível da tela. É perfeitamente possível um sprite ocupar coordenadas de valores negativos (-52,300).</p>
<p style="text-align: justify;">Vamos à função:</p>
<div class="igBar"><span id="lc-1"><a href="#" onclick="javascript:showPlainTxt('c-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-1">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">static</span> bool DetectBorderCollision<span style="color: #66cc66;">&#40;</span>Sprite sprite, <span style="color: #000000; font-weight: bold;">Enum</span>.<span style="color: #202020;">Direction</span> direction, <span style="color: #993333;">int</span> collisionPoint<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bool collided = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>direction == <span style="color: #000000; font-weight: bold;">Enum</span>.<span style="color: #202020;">Direction</span>.<span style="color: #202020;">Down</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite.<span style="color: #202020;">Vertex3</span>.<span style="color: #202020;">Y</span>&amp;gt;= collisionPoint<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">collided = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>direction == <span style="color: #000000; font-weight: bold;">Enum</span>.<span style="color: #202020;">Direction</span>.<span style="color: #202020;">Up</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">Y</span> &amp;lt;= collisionPoint<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">collided = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>direction == <span style="color: #000000; font-weight: bold;">Enum</span>.<span style="color: #202020;">Direction</span>.<span style="color: #202020;">Left</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">X</span> &amp;lt;= collisionPoint<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">collided = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>direction == <span style="color: #000000; font-weight: bold;">Enum</span>.<span style="color: #202020;">Direction</span>.<span style="color: #202020;">Right</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite.<span style="color: #202020;">Vertex2</span>.<span style="color: #202020;">X</span>&amp;gt;= collisionPoint<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">collided = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> collided;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p style="text-align: justify;">Uma função extremamente simples e leve. Se quisermos testar a colisão nos quatros lados da tela, teremos que chamar a função 4 vezes. Para cada vez, passamos uma das direções e o limite da borda, em pixels. Na colisão à esquerda, o collisionPoint deve ser 0. Para a colisão à direita, o collisionPoint deve ser 640.</p>
<p style="text-align: justify;">O que será feito com o retorno da função depende de cada game ou situação. No WinForms Lander, só testo a colisão na parte de baixo. Caso haja colisão, a nave quebra, o jogador perde uma vida, e o estágio é reiniciado. Só passa de fase se o jogador pousar na plataforma.</p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-7-final/">Parte 7 - Final</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-6-colisao-de-borda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 5 &#8211; Colisão Simples</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-5-colisao-simples/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-5-colisao-simples/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 16:26:37 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Colisão]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1506</guid>
		<description><![CDATA[<p>Uma das coisas mais importantes em um jogo é a colisão. Isso não significa que deva haver uma explosão ao colidir sprites, mas simplesmente fazer com que o Super Mario possa caminhar sobre o chão sem atravessá-lo.</p>
<p>Existem muitas implementações para colisão. Desde implementações simples até das mais complexas. Por exemplo, a colisão usada nos jogos do Mario para coletar as moedas só precisa informar se Mario tocou a moeda. Mas para testar a colisão em um koopa, é necessário verificar se Mario está acima ou no lado ao tocar o inimigo. Caso esteja em cima, Mario sai ileso e elimina o inimigo. Caso esteja no lado, Mario perde uma vida.</p>
<p>Para testar uma colisão dessas, é bem mais complicado. Principalmente se os sprites se movem com mais velocidade.</p>
<p>O que vou mostrar agora é a colisão simples (aquela da moeda). Até porque a minha colisão que detecta a direção do toque não é 100% confiável em altas velocidades (parece até coisa de mecânica quântica). Eu digo "minha" colisão porque fiz questão de tentar criar uma solução por conta própria, sem pesquisar nada na internet. É claro que futuramente terei que ir atrás disso, pois não sou um bom programador de jogos e nem um bom matemático.</p>
<p>Para detectar uma colisão simples, o ideal é usar cálculos e algoritmos que usem poucos ciclos de CPU. É bem difícil saber o quanto um cálculo usa de CPU. Mas podemos deduzir a complexidade dele pela quantidade de linhas de códigos e quantidade de loops usados.</p>
<p>Uma das minhas idéias iniciais para detectar colisão deixou o jogo com uns 5 quadros de animação por segundo. Enquanto as outras duas mantinham a velocidade de 50. Aí podemos ver que não daria certo usá-la <img src='http://www.cubagames.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Mas porque ficou tão pesado? Porque o que eu fazia era comparar pixel por pixel a área utilizada por cada um dos sprites que eu estava testando a colisão. Quando eu vi a degradação da performance, logo busquei outra alternativa, bem mais leve.</p>
<p>Vamos a elas:</p>
<p><!--more--></p>
<p>Mas para fins didáticos, vou mostrar minha idéia dos 5 FPS:</p>
<p>Comparando colisão entre sprite1 com sprite2:</p>
<p>1 - gerar lista com todos os pixels do sprite1</p>
<p>2 - gerar lista com todos os pixels do sprite2</p>
<p>3 - comparar cada pixel com sprite1 com cada pixel do sprite2</p>
<p>Este método é bastante lento, mas 100% confiável. O problema é que se um sprite com 50x50 pixels for comparado com outro sprite 50x50, estaremos comparando 2500 pixels contra outros 2500. Isso tudo 50 vezes por segundo.</p>
<p>O método mais simples e igualmente preciso que eu usei no jogo foi este:</p>
<p>1 - Verificação Horizontal (Eixo X):</p>
<p><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/squaresx1.png"><img class="size-full wp-image-1511 alignleft" title="squaresx1" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/squaresx1.png" alt="squaresx1" width="156" height="119" /></a></p>
<p>1.1 - Subtrair a distância (sempre em pixels) da extremidade da direita do sprite mais à direita com a extremidade esquerda do sprite mais à esquerda;</p>
<p>1.2 - Somar a largura do sprite1 com a largura do sprite2;</p>
<p>1.3 - se a distância for menor ou igual à soma das larguras, realizar a verificação Vertical.</p>
<p>2 - Verificação Vertical (Eixo Y):</p>
<p><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/squaresy.png"><img class="size-full wp-image-1512 alignleft" title="squaresy" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/squaresy.png" alt="squaresy" width="119" height="156" /></a></p>
<p>2.1 - Subtrair a distância (sempre em pixels) do topo do sprite mais acima com o fundo do sprite mais abaixo;</p>
<p>2.2 - Somar a altura do sprite1 com a altura do sprite2;</p>
<p>2.3 - se a distância for menor ou igual à soma das alturas, a colisão<span style="text-decoration: underline;"> foi confirmada</span>.</p>
<p>No passo 1.3, vejam que há condição para continuar. Se uma colisão em uma das dimensões não tiver sido detectada, não há necessidade de testar na outra dimensão.</p>
<p>Colidir em uma dimensão parece coisa de doido, mas o que quero dizer é o seguinte:</p>
<p><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/colisionx.png"><img class="size-full wp-image-1510 alignleft" title="colisionx" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/colisionx.png" alt="colisionx" width="162" height="119" /></a></p>
<p>Na figura acima, houve uma colisão no eixo Y, mas não no eixo X. Portanto, para um jogo 2D, não houve colisão. Veja que os dois quadrados ocupam as mesmas posições referentes a altura.</p>
<p><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/colisiony.png"><img class="size-full wp-image-1513 alignleft" title="colisiony" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/colisiony.png" alt="colisiony" width="119" height="156" /></a></p>
<p>Já nesta figura acima, houve uma colisão no eixo X, mas não no eixo Y.</p>
<p><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/squarescolision1.png"><img class="size-full wp-image-1515 alignleft" title="squarescolision1" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/squarescolision1.png" alt="squarescolision1" width="136" height="133" /></a></p>
<p>E aqui, finalmente ocorreu uma colisão nos dois eixos.</p>
<p>Segue o código abaixo.</p>
<div class="igBar"><span id="lc-2"><a href="#" onclick="javascript:showPlainTxt('c-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-2">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">static</span> bool DetectCollision<span style="color: #66cc66;">&#40;</span>Sprite sprite1, Sprite sprite2<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bool partial1 = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bool partial2 = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> xDistance = sprite2.<span style="color: #202020;">Vertex2</span>.<span style="color: #202020;">X</span> - sprite1.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">X</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> yDistance = sprite2.<span style="color: #202020;">Vertex4</span>.<span style="color: #202020;">Y</span> - sprite1.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">Y</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Verifica se sprite2 está mais à esquerda que sprite1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite2.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">X</span> &amp;lt;sprite1.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">X</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">xDistance = sprite1.<span style="color: #202020;">Vertex2</span>.<span style="color: #202020;">X</span> - sprite2.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">X</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Verifica se sprite2 está mais ao topo que sprite1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sprite2.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">Y</span> &amp;lt;sprite1.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">yDistance = sprite1.<span style="color: #202020;">Vertex4</span>.<span style="color: #202020;">Y</span> - sprite2.<span style="color: #202020;">Vertex1</span>.<span style="color: #202020;">Y</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> xSize = sprite1.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Width</span> + sprite2.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Width</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> ySize = sprite1.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Height</span> + sprite2.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Height</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>xDistance &amp;lt;= xSize<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">partial1 = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>partial1<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>yDistance &amp;lt;= ySize<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">partial2 = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> partial2;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Vocês devem ter visto que existe uma classe chamada <strong>Sprite</strong>. Esta classe é uma implementação minha para facilitar as coisas. Uma das facilidades é poder retornar o X/Y de cada um dos vértices do pictureBox, obtido através do Location e do Size. A implementação da classe Sprite segue abaixo:</p>
<div class="igBar"><span id="lc-3"><a href="#" onclick="javascript:showPlainTxt('c-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-3">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">using System;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">using System.<span style="color: #202020;">Collections</span>.<span style="color: #202020;">Generic</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">using System.<span style="color: #202020;">Text</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">using System.<span style="color: #202020;">Windows</span>.<span style="color: #202020;">Forms</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">using System.<span style="color: #202020;">Drawing</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">namespace WinFormsLander.<span style="color: #202020;">Classes</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public class Sprite</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*&nbsp; 1------2</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*&nbsp; |&nbsp; &nbsp; &nbsp; |</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*&nbsp; |&nbsp; &nbsp; &nbsp; |</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*&nbsp; |&nbsp; &nbsp; &nbsp; |</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*&nbsp; 4------3</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">* */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Point Vertex1</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">get</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span>, this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Point Vertex2</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">get</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span> + this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Width</span>, this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Point Vertex3</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">get</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span> + this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Width</span>, this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span> + this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Height</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Point Vertex4</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">get</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">return</span> new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span>, this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span> + this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Height</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public PictureBox PictureBoxMain;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">string</span> ID;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Image ImageDefault;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">int</span> FlipVCounter;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">int</span> FlipHCounter;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public bool FlipV;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public bool FlipH;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> VerticalVelocity;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> HorizontalVelocity;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> TotalVelocity;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> Y;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> X;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> StretchedY;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> StretchedX;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">int</span> DefaultHeight;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">int</span> DefaultWidth;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> VerticalVelocityLimit;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> HorizontalVelocityLimit;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> Drag;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> GForce;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public bool vBouncingZone;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public bool hBouncingZone;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">int</span> FlickCount;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> Accel;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public <span style="color: #993333;">float</span> AccelMpS;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public Sprite<span style="color: #66cc66;">&#40;</span>PictureBox pictureBoxMain<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">PictureBoxMain</span> = pictureBoxMain;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">BackColor</span> = Color.<span style="color: #202020;">Transparent</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">ID</span> = <span style="color: #ff0000;">""</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">ImageDefault</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">FlipVCounter</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">FlipHCounter</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">FlipV</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">FlipH</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">VerticalVelocity</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">HorizontalVelocity</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">TotalVelocity</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">Y</span> = PictureBoxMain.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">X</span> = PictureBoxMain.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">StretchedY</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">StretchedX</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">DefaultHeight</span> = this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Height</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">DefaultWidth</span> = this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">Size</span>.<span style="color: #202020;">Width</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">VerticalVelocityLimit</span> = <span style="color: #cc66cc;color:#800000;">50</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">HorizontalVelocityLimit</span> = <span style="color: #cc66cc;color:#800000;">50</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">Drag</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">GForce</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">vBouncingZone</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">hBouncingZone</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">FlickCount</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">Accel</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">AccelMpS</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">PictureBoxMain</span>.<span style="color: #202020;">BackgroundImage</span> = this.<span style="color: #202020;">ImageDefault</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-6-colisao-de-borda/">Parte 6 - Colisão de Borda</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-5-colisao-simples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 4 &#8211; Física</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-4-fisica/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-4-fisica/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 22:53:09 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1468</guid>
		<description><![CDATA[<p>Aqui serei mais teórico.</p>
<p>Como aplicar física em jogos?<br />
1 - Usando uma boa engine que já faça isso;<br />
2 - Usando boas bibliotecas que façam isso;<br />
3 - Manifestando um pouco do Newton que há dentro de nós;</p>
<p>Como a idéia toda desta série é entender como tudo funciona, e não simplesmente criar um jogo o mais rápido possível, ficaremos com a terceira opção. Apesar de eu gostar de física, nunca estudei muito tal disciplina, e hoje sinto bastante dificuldade com vários cálculos básicos. Graças ao jogo em si, eu consegui redescobrir muitas coisas, pois na prática é mais fácil de entender um conceito.</p>
<p>Vamos:</p>
<p><!--more--></p>
<p>A Física, entendida por muitos estudantes como a abreviação da disciplina "Educação Física", não é chutar uma bola e marcar um gol, e sim calcular sua tragetória, peso, velocidade, aceleração e etc.</p>
<p>Para quem quer criar jogos de RPG, ignorem tudo isso. Para os demais, vamos analisar algumas coisas:</p>
<p>Num fluxo de jogo, não basta aplicar uma fórmula para deslocar um objeto para outro lugar. É preciso MOVER o objeto um pouco a cada update.</p>
<p>Como o fluxo é contínuo, você não deve prever onde os objetos estarão, e sim mover os objetos na direção que a fórmula deve prever. Complicado?</p>
<p>Quando aplicamos uma fórmula para descobrir a aceleração ou velocidade de um corpo, o que obtemos é o valor em distância/tempo (km/h, m/s, mph, etc...). Se temos a velocidade e multiplicarmos pelo tempo, obteremos a posição onde o corpo estará.</p>
<p>Mas para um sprite se mover, temos que reposicioná-lo a cada Update. Como num jogo 2D comum temos pixels, e aqui temos nosso Update() disparado por Timer.Tick() a cada 20 milisegundos, nossa velocidade é medida em pixels por tick.</p>
<p>Ou seja, se um sprite se desloca com uma velocidade de 1 p/t (pixel por tick), e um tick é disparado a cada 20 milisegundos (resultando em 50 ticks por segundos), temos a velocidade de 50 pixels por segundo.</p>
<p>Numa tela de jogo de 640 pixels de largura, o sprite demoraria 13 segundos para atravessá-la completamente.</p>
<p>Definindo um pouco as coisas:</p>
<p>Velocidade: é a taxa mudança de posição de um corpo ao longo do tempo. Se a cada tick temos a mudança de posição em 1 pixel, nossa velocidade é 1 p/t (não existe essa medida, e nem adianta sugerir à <a href="http://www.bipm.org/en/si/">SI</a>).</p>
<p>Aceleração: é a taxa de aumento de velocidade num determinado período de tempo. Se no primeiro tick temos 1 p/t, e no próximo temos 2 p/t, no terceiro estaremos com a velocidade acumulada do primeiro somado do segundo (1 + 2).</p>
<p>A cada tick o sprite pulará mais pixels de uma vez:</p>
<p>Ticks:    |<br />
Pixels:   +</p>
<p>|+|++|+++|++++|+++++|++++++|</p>
<p>Como representar isso?</p>
<p>Simples. É só criarmos uma variável para acumular a velocidade e somá-la aos pixels que representam a localização dos sprites.</p>
<p>No exemplo da bola na parte 3, nós movíamos a bola em um pixel a cada tick quando o jogador mantinha uma seta pressionda. Agora vamos acrescentando unidades em uma variável e transferiremos o valor total dela no Location do sprite:</p>
<div class="igBar"><span id="lc-4"><a href="#" onclick="javascript:showPlainTxt('c-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-4">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Declarar como global</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333;">int</span> vel = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Left</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; vel = vel - <span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Right</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; vel = vel + <span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span> = </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span> + vel, this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>o que estamos fazendo acima é:</p>
<p>1 - Criar uma variável para armazenar velocidade;<br />
2 - Adicionar ou subtrair unidades a ela dependendo da direção esquerda/direita (velocidade na direção oposta é negativa)<br />
3 - reposicionar o pictureBox acrescentando a velocidade à sua posição no eixo X atual;</p>
<p>Execute e veja como para os lados a bola possui aceleração, velocidade e inércia. Enquanto para cima e para baixo ainda se move do jeito antigo.</p>
<p style="text-align: left;">Aqui vai o código completo da tela: <a href="http://www.4shared.com/file/196349286/9323faf5/Ler_Teclas.html">link</a></p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-5-colisao-simples/">Parte 5 - Colisão Simples</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-4-fisica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 3 &#8211; Lendo Teclas</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-3-lendo-teclas/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-3-lendo-teclas/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 17:53:22 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1439</guid>
		<description><![CDATA[<p style="text-align: justify;">Nesta terceira parte, já vamos avançar para a parte prática. O foco desta série não é ensinar programação C#, nem Windows Forms. Portanto, vou partir do princípio que quem me acompanha aqui já possui conhecimento básico sobre estas tecnologias. Para quem quer aprender um pouco, <a href="http://msdn.microsoft.com/pt-br/library/b201w61t.aspx">aqui</a> tem um tutorial básico da Microsoft sobre Windows Forms. <a href="http://msdn.microsoft.com/pt-br/vbasic/ms789117.aspx">Aqui</a> tem mais coisas.</p>
<p style="text-align: justify;">Para começarmos, será necessário criar um novo projeto do tipo <strong>Windows Application</strong> no Visual Studio 2008. Ao criar um novo projeto, cria-se uma Solution que abriga este projeto.</p>
<p style="text-align: justify;">Uma solução recém criada já apresenta um formulário chamado Form1. Podemos utilizar ele mesmo.</p>
<p style="text-align: justify;"><!--more--></p>
<p style="text-align: justify;">Com o XNA 3.1 devidamente instalado, vamos importar a DLL <span style="text-decoration: underline;">Microsoft.XNA.Framework</span> e <span style="text-decoration: underline;">Microsoft.XNA.Framework.Game</span>.</p>
<p style="text-align: justify;">Para isso, clique com o botão direito na pasta <strong>References</strong> no menu <span style="text-decoration: underline;">Solution Explorer</span> e selecione <strong>Add Reference</strong>. Aguarde a janela aparecer (demora!) e na aba <span style="text-decoration: underline;">.Net</span>, selecione as DLLs <span style="text-decoration: underline;">Microsoft.XNA.Framework</span> e <span style="text-decoration: underline;">Microsoft.XNA.Framework.Game</span> nas versões 3.1.0.0.</p>
<p style="text-align: justify;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/add_reference.png"><img class="aligncenter size-full wp-image-1456" title="add_reference" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/add_reference.png" alt="add_reference" width="234" height="184" /></a></p>
<p style="text-align: justify;">Abra o ToolBox (CTRL + W + X) e, na entrada <span style="text-decoration: underline;">All Windows Forms</span>, procure e arraste para o formulário o controle chamado <span style="text-decoration: underline;">PictureBox</span> e outro chamado <span style="text-decoration: underline;">Timer</span>.</p>
<p style="text-align: justify;">Selecione o PictureBox e na aba <strong>Properties</strong> (F4), mude a propriedade <span style="text-decoration: underline;">Size</span> para 32;32. Na propriedade <span style="text-decoration: underline;">BackgroundImage</span>, clique e em Local Resource, navegue nos diretórios e selecione uma imagem qualquer. Sugiro salvar e usar esta aqui:</p>
<p><img class="size-full wp-image-1441 alignleft" title="ball" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/ball.png" alt="ball" width="32" height="32" /></p>
<p>Agora vamos mexer no Timer. Selecione lá embaixo o timer1, que foi criado ao arrastar o Timer. Em <strong>Properties</strong> (F4), mude o <span style="text-decoration: underline;">Interval</span> para 20 (50Hz). Mude também o <span style="text-decoration: underline;">Enabled</span> para<strong> true</strong>;</p>
<p>Agora vamos implementar o evento <span style="text-decoration: underline;">Timer.Tick</span>. Ainda em <strong>Properties</strong>, no topo da aba existe uma figurinha em forma de raio. Clique nela. Aqui temos os eventos disponíveis para o Timer. O único disponível é o Tick. Clique duas vezes na célula vazia e o Visual Studio vai criar o evento e a função associada ao evento (event handler), chamada timer1_Tick().</p>
<p>Todo o código fica neste arquivo.</p>
<p>Vamos escrever algumas coisas por aqui. Primeiramente, vamos criar um objeto do tipo KeyboardState. Logo acima da linha<span style="color: #800000;"> public Form1()</span>, escreva:</p>
<div class="igBar"><span id="lc-5"><a href="#" onclick="javascript:showPlainTxt('c-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-5">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">KeyboardState</span> ks; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Agora, dentro do bloco timer1_Tick(), escreva:</p>
<div class="igBar"><span id="lc-6"><a href="#" onclick="javascript:showPlainTxt('c-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-6">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">this.<span style="color: #202020;">ks</span> = Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keyboard</span>.<span style="color: #202020;">GetState</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Up</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span> =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span>, this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span> - <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</span></pre>
<p style="text-align: left;">O que estou fazendo acima é a cada 20 milisegundos:</p>
<p style="text-align: left;">1 - Capturar o estado do teclado (teclas pressionadas);</p>
<p style="text-align: left;">2 - Verificar se a tecla pressionda é a Seta Para Cima;</p>
<p style="text-align: left;">2.1 - Se sim, a localização do pictureBox1 muda para um novo ponto cartesiano, onde o eixo X mantém o mesmo  valor, e o Y é decrescido de um pixel.</p>
<p style="text-align: left;">
<p style="text-align: left;">O problema desses controles é que a posição é definida por um objeto Point que une o X e o Y. Então eu não posso simplesmente decrementar diretamente o Y,  e sim recriar o Point, repassando o X e o Y do jeito que eu quero.</p>
<p style="text-align: left;">O interessante é que quanto mais para cima, menor é o Y. Ou seja, o ponto X=0 e Y=0 é o canto superior esquerdo do formulário. Isso vale para qualquer aplicação baseada em pixels na tela. Até o paint.</p>
<p>Agora vamos rodar o programa. Pressione F5 para compilar e rodar. Se tudo deu certo, o formulario e a figura aparecerão na tela. E ainda se moverá para cima enquanto a tecla <strong>Seta Para Cima</strong> estiver pressionada.</p>
<p>Podemos fechar a janela e continuar o programa.</p>
<p>Ainda dentro do timer1_Tick(), vamos aplicar todas as direções.</p>
<p>Basta escrever o restante:</p>
<div class="igBar"><span id="lc-7"><a href="#" onclick="javascript:showPlainTxt('c-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C:</span>
<div id="c-7">
<div class="c">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Down</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span> =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span>, this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span> + <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Left</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span> =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span> - <span style="color: #cc66cc;color:#800000;">1</span>, this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">ks</span>.<span style="color: #202020;">IsKeyDown</span><span style="color: #66cc66;">&#40;</span>Microsoft.<span style="color: #202020;">Xna</span>.<span style="color: #202020;">Framework</span>.<span style="color: #202020;">Input</span>.<span style="color: #202020;">Keys</span>.<span style="color: #202020;">Right</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span> =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">new Point<span style="color: #66cc66;">&#40;</span>this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">X</span> + <span style="color: #cc66cc;color:#800000;">1</span>, this.<span style="color: #202020;">pictureBox1</span>.<span style="color: #202020;">Location</span>.<span style="color: #202020;">Y</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Agora rode novamente e experimente mover a bola para todas as direções.</p>
<p>Por enquanto é isso. No proximo post, vamos aplicar aceleração e outras coisas a mais.</p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-4-fisica/">Parte 4 - Física</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-3-lendo-teclas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 2 &#8211; Fluxo e Update</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-2-fluxo-e-update/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-2-fluxo-e-update/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 17:30:31 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1430</guid>
		<description><![CDATA[<p style="text-align: justify;">Aqui, eu tratarei um pouco sobre o fluxo de jogo.</p>
<p style="text-align: justify;">Qualquer jogo possui uma estrutura genérica que geralmente segue o mesmo padrão. Aqui, o principal é mostrar o básico, e sem utilizar ferramentas que escondem alguns dos passos básicos do fluxo.</p>
<p style="text-align: justify;">Como eu havia falado, o Windows Forms atualiza as figuras na tela automaticamente quando detecta uma mudança, e isso é bem difícil de controlar manualmente. Então, a parte de fazer as imagens ser renderizadas fica oculta para nós.</p>
<p style="text-align: justify;">Abaixo está a figura com o fluxo básico do <strong>WinForms Lander</strong>. Vejam:</p>
<p style="text-align: justify;"><!--more--></p>
<p style="text-align: justify;"><a href="http://www.cubagames.com.br/wp-content/uploads/2010/01/fluxo.png"><img class="aligncenter size-full wp-image-1434" title="fluxo" src="http://www.cubagames.com.br/wp-content/uploads/2010/01/fluxo.png" alt="fluxo" width="452" height="733" /></a></p>
<p style="text-align: justify;">Como podem ver, não é nada muito complicado. Dos 3 blocos, o mais importante é o <strong>Update</strong>. Nele todas as coisas que fazem a partida funcionar são continuamente executadas num loop infinito. Bom, só não é infinito porque se o jogador vencer ou perder, o loop se quebra e o jogo segue para o terceiro bloco.</p>
<p style="text-align: justify;">No caso do WinForms Lander, e muito povavelmente para qualquer engine, o update é disparado automaticamente. Geralmente é utilizado um temporizador (timer para os íntimos) que dispara uma função a cada X milisegundos. Em Windows Forms, eu utilizo o controle <span style="text-decoration: underline;">Timer</span>. No evento <span style="text-decoration: underline;">Timer.Tick</span> eu chamo a minha função <strong>Update()</strong>.</p>
<p style="text-align: justify;">O padrão para os jogos é rodar a 60 quadros por segundo, e isso conta também os updates, e não somente a atualização dos gráficos. Na verdade, como os videogames são feitos para ligar na TV, e a TV atualiza as imagens 60 vezes por segundo, o video dos consoles gera e envia imagens nesta taxa também. E como o processo de update e geração de imagens são síncronas, o update acaba rodando nesta velocidade.</p>
<p style="text-align: justify;">Muito provavelmente, até os jogos de PC com taxa de quadros variável deve rodar seus updates 60 vezes por segundo. Ou seja, mesmo que o jogo esteja exibindo 20 frames por segundo, a captura de teclas, detecção de colisão, movimentos e toda a lógica do jogo está executando a cada 16,66 milisegundos (60Hz).  Isso se deve ao fato dos jogos modernos serem assíncronos. Ou seja, a geração das imagens não bate com a atualização delas, nem com a lógica de jogo. Isso quer dizer que é possível jogar Quake 3 com a lógica rodando a 60Hz, taxa de atualização do monitor à 85Hz, e 70 FPS. Num console, principalmente os antigos, é tudo síncrono. Acredito que nos consoles antigos, disparar o update seja uma implementação de hardware, com o uso de algum temporizador baseado num chip.</p>
<p style="text-align: justify;">Mas isso é só suposição. Imagino que seja assim porque ao usar um jogo NTSC (60Hz) num console PAL (50Hz), o jogo roda mais lento. O inverso também ocorre.</p>
<p style="text-align: justify;">Usando o Timer do Windows Forms, é possível informar o intervalo de tempo em que o evento Timer.Tick será disparado. Com isso, podemos fazer com que a lógica do jogo seja executada no tempo que quiser. E o melhor é que o intervalo pode ser alterado a qualquer momento. O legal é que diminuindo o intervalo, todo o jogo se acelera. Não sei se é possível alterar o intervalo em qualquer ferramenta.</p>
<p style="text-align: justify;">Por enquanto é isso.</p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-3-lendo-teclas/">Parte 3 - Lendo Teclas</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-2-fluxo-e-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criando Um Jogo em Windows Forms &#8211; Parte 1</title>
		<link>http://www.cubagames.com.br/criando-um-jogo-em-windowsforms-parte-1/</link>
		<comments>http://www.cubagames.com.br/criando-um-jogo-em-windowsforms-parte-1/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 20:07:38 +0000</pubDate>
		<dc:creator>Fernando Lorenzon</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Jogos]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WinForms Lander]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.cubagames.com.br/?p=1416</guid>
		<description><![CDATA[<p style="text-align: center;"><a href="http://www.cubagames.com.br/wp-content/uploads/2009/12/forms_game1.png"><img class="size-full wp-image-1426  aligncenter" title="forms_game1" src="http://www.cubagames.com.br/wp-content/uploads/2009/12/forms_game1.png" alt="forms_game1" width="248" height="123" /></a></p>
<p style="text-align: justify;">De todos os colaboradores da Cubagames, eu sou o menos familiarizado com desenvolvimento de jogos. Não tenho muita familiaridade nem com Web, que geralmente possui ferramentas muito boas para implementar um jogo, como é o caso do Flash.</p>
<p style="text-align: justify;">Mas tenho bastante familiaridade com programação de sistemas e um pouco de conceito sobre criação de jogos. A plataforma de desenvolvimento que possuo mais experiência é Windows Forms, e a linguagem que mais domino é o C#. Há alguns anos venho pensando (filosofando) como os jogos antigos de 8 e 16 bits eram criados. Hoje temos muitas ferramentas visuais, frameworks, engines, todos equipados com temporizadores automáticos, eventos, gerenciamento de memória, threads e o escambal. Com isso, criar um jogo pode ser bem rápido, mas talvez não tão didático.</p>
<p style="text-align: justify;">Acompanhem-me:</p>
<p style="text-align: justify;"><!--more--></p>
<p style="text-align: justify;">Aventurar-se numa ferramenta dessas pode ser bastante confuso. Até eu tive dificuldades de compreender o funcionamento do XNA. E olha que ele usa C# e o Visual Studio. É claro que agora, fazendo quase tudo no braço usando Forms, já consigo entender como o XNA funciona. É por isso que quero compartilhar este conhecimento aqui. Claro que "no braço" é um termo relativo, pois com C# e o Visual Studio muita coisa já vem pronta. Só que nada vem pronto para ser utilizado em jogos. Comparando com engines como a Unity, ou ferramentas como o Flash, C# e WindowsForms é bem cru. Se eu tivesse paciência para aprender C++, com certeza usaria ele aqui.</p>
<p style="text-align: justify;">Por um lado, ferramentas completas são úteis e muito produtivas, mas para quem está interessado em conceitos, isso pode atrapalhar mais no aprendizado do que ensinar.</p>
<p style="text-align: justify;">Muito antes de bolar meu próprio MMO para concorrer com WoW, eu quero entender como tratar uma <span style="text-decoration: underline;">colisão</span> "no muque". Ou ainda, como trabalhar os <span style="text-decoration: underline;">updates por segundo</span> de jogos mais rústicos, como os antigões. Essas novas engines mascaram tudo isso. (Recomendo ler um texto muito bom do Rômulo sobre isso: <a href="http://www.cubagames.com.br/comentario-cubagames-sobre-design-inchado/">Design Inchado</a>)</p>
<p style="text-align: justify;">Então, por causa dessa minha curiosidade e também falta de compromisso para criar um jogo propriamente dito, comecei a fuçar um pouco no Windows Forms com C#, usando a ferramenta Visual Studio 2008. Aqui eu me sinto em casa. Porém, O WindowsForms já é todo otimizado e "fechado" para uso em programas com telas estáticas, com botões, campos de texto, barras, grids etc. Traduzindo, Windows Forms não foi feito para criar jogos. Então pensei: "Perfeito!".</p>
<p style="text-align: justify;">O problema do Windows Forms é que o programa fica esperando o usuário interagir com as telas, pronto para capturar teclas pressionadas e cliques de mouse. Num jogo, o que ocorre é o contrário. Ele funciona continuamente, mesmo sem a intervenção do jogador. Ou seja, se você largar o controle por um tempo, morre.</p>
<p style="text-align: justify;">Para poder quebrar essa primeira e talvez a única barreira que o WindowsForms oferece ao criar jogos, eu tive que usar uma biblioteca em que eu determinasse quando pegar as teclas pressionadas pelo jogador e aplicar a lógica de jogo. Ou seja, o programa não ficaria esperando as teclas serem pressionadas para disparar os eventos.</p>
<p style="text-align: justify;">Comecei a procurar por uma biblioteca que fizesse leitura de teclas com intervenção do programador, e logo descobri que o próprio XNA possui a dita cuja.</p>
<p style="text-align: justify;">A biblioteca usada foi justamente uma que acompanha o XNA. O resto foi WindowsForms puro.</p>
<p style="text-align: justify;">No início, fiquei apenas fazendo uma esfera deslizar pela tela conforme o uso das setas. Logo depois eu comecei a criar mais e mais funções para fazer diversas coisas, como gravidade, arrasto, colisão, leitura do teclado, aplicação dos comando para a esfera, esticamentos,  etc. No processo, acabei até adquirindo alguns conhecimentos sobre física. Afinal, criar jogos é uma boa oportunidade de aplicar teorias da física.</p>
<p style="text-align: justify;">Tudo utilizando imagens carregadas num "botão". No WindowsForms, essa é a melhor (ou única) maneira de representar sprites.</p>
<p style="text-align: justify;">Quando percebi, já tinha um bom começo para criar um jogo. E foi o que fiz. Com o que eu já tinha, daria para criar sem grandes problemas uma versão simples do jogo clássico <strong>Lunar Lander</strong>. E assim nasceu o projeto <strong>WinForms Lander</strong>. Com este game, acabei juntando coisas que me interesso, como física, astronomia, games e desenvolvimento. Só assim para sentirmos motivados a criar algo.</p>
<p style="text-align: justify;">Logo no início, ficou óbvio o quanto o WindowsForms é limitado para trabalhar com imagens. Quanto mais sprites e backgrounds existir, menos fluentes ficam os sprites. Isso se deve ao fato do WindowsForms atualizar as imagens na tela por conta própria. Você desloca uma figura, e a imagem se move sem você dizer quando isso deve ocorrer. O resultado não é tão ruim quanto parece, desde que se use pouquíssimos sprites numa tela.</p>
<p style="text-align: justify;">Conforme fui desenvolvendo, fui aprimorando os códigos e arrumando a estrutura das funções. Posso dizer que o resultado ficou muito bom.Para contornar as limitações tecnológicas, fui adicionando conteúdo para tornar o jogo mais divertido, e atualmente o jogo já conta com várias "navinhas" e estágios, com variáveis diversas para aumentar o limitado desafio.</p>
<p style="text-align: justify;">Inclusive, todas as naves foram desenhadas por mim num criador de ícones, e foi bastante divertido bolar as naves e os poderes especiais de cada uma (sim, eu fiz isso). Como se trata de um jogo de pousar corretamente, os poderes se limitam a auxiliar o pouso, como anti-gravidade, estabilização, etc.</p>
<p style="text-align: justify;">Estou incluindo alguns efeitos sonoros também. E não tenho nenhuma biblioteca avançada em mãos para tocar os sons paralelamente e de qualquer jeito. Estou usando a biblioteca padrão para tocar sons em WindowsForms. É bem fácil de carregar um som e tocar, mas não é possível tocar áudios paralelamente. Portanto, tudo tem que ser feito controlando manualmente se o áudio está tocando, se deve trocar de áudio, etc. Difícil, mas recompensadoramente didático.</p>
<p style="text-align: justify;">Posso dizer que o jogo está uns 70% pronto, faltando apenas aprimoramentos na jogabilidade e algum polimento no código. O jogo já salva e carrega, possui naves e fases secretas, e terá alguns desafios extras.</p>
<p style="text-align: justify;">Quando terminar, ainda vou migrar o jogo para o XNA, que atualmente nem parece mais o bicho de sete cabeças de antes. E com certeza melhorarei o que o WindowsForms não permitiu.</p>
<p style="text-align: justify;">Bom, este texto foi somente uma introdução. No próximo post, eu explico um pouco o que aprendi e aos poucos vou esclarecendo sobre <span style="text-decoration: underline;">lógica de jogo</span> em geral e algumas decisões tomadas por mim durante o desenvolvimento.</p>
<p style="text-align: justify;">Esta série não tem o intuito de ensinar a programar C#, nem mesmo de ensinar a criar jogos a torto e direito. Tenho a intenção de explicar mais coisas teóricas, que serão úteis mais para frente,  conforme eu for mostrando os códigos.</p>
<p style="text-align: justify;">Você talvez deva estar se perguntando: "Se Windows Forms é ruim pra jogos, por que perder tempo com ele?"</p>
<p style="text-align: justify;">Volto a salientar: isso tem <span style="text-decoration: underline;">somente</span> fins didáticos. Eu ainda vou converter o jogo para XNA daqui alguns meses, e aí sim teremos um jogo decente (ou não).</p>
<p style="text-align: justify;">Mas na verdade, se for analisar a simplicidade de alguns games antigos, o <strong>WinForms Lander</strong> até que não está indo mal.</p>
<p style="text-align: justify;">Para quem já conhece C# e tem interesse em acompanhar a série, será necessário o Visual Studio 2008 ou o <a href="http://www.microsoft.com/express/vcsharp/">Visual C# Express Edition</a> para programar. Ah, e instale o <a href="http://creators.xna.com/en-US/downloads">XNA 3.1</a> para utilizar a biblioteca. O C# Express e o XNA são gratuitos.</p>
<p style="text-align: justify;">Após a conclusão do game, me aventurarei com o XNA. E com certeza criarei uma série de tutoriais sobre XNA.</p>
<p><a href="http://www.cubagames.com.br/criando-um-jogo-em-windows-forms-parte-2-fluxo-e-update/">Parte 2 - Fluxo e Update</a></p>
]]></description>
		<wfw:commentRss>http://www.cubagames.com.br/criando-um-jogo-em-windowsforms-parte-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

