Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PlatoformerTut
- {
- public partial class Platformer : Form
- {
- bool isJumping = false;
- List<Coin> cList = new List<Coin>();
- int score = 0;
- public Platformer()
- {
- InitializeComponent();
- }
- private void tmrGravity_Tick(object sender, EventArgs e)
- {
- if(!pbPlayer.Bounds.IntersectsWith(pbGround.Bounds) && isJumping == false)
- {
- pbPlayer.Top += 10;
- }
- }
- private void tmrUp_Tick(object sender, EventArgs e)
- {
- pbPlayer.Top -= 10;
- isJumping = true;
- }
- private void tmrRight_Tick(object sender, EventArgs e)
- {
- pbPlayer.Left += 10;
- }
- private void tmrLeft_Tick(object sender, EventArgs e)
- {
- pbPlayer.Left -= 10;
- }
- private void Platformer_KeyDown(object sender, KeyEventArgs e)
- {
- if(e.KeyCode == Keys.Up)
- {
- tmrUp.Start();
- }
- else if (e.KeyCode == Keys.Right)
- {
- tmrRight.Start();
- }
- else if (e.KeyCode == Keys.Left)
- {
- tmrLeft.Start();
- }
- }
- private void Platformer_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Up)
- {
- tmrUp.Stop();
- isJumping = false;
- }
- else if (e.KeyCode == Keys.Right)
- {
- tmrRight.Stop();
- }
- else if (e.KeyCode == Keys.Left)
- {
- tmrLeft.Stop();
- }
- }
- private void Platformer_Load(object sender, EventArgs e)
- {
- Coin c1 = new Coin();
- Coin c2 = new Coin();
- c1.drawTo(this);
- cList.Add(c1);
- c1.setPos(100, 200);
- c2.drawTo(this);
- cList.Add(c2);
- c2.setPos(200, 200);
- }
- private void tmrGameLoop_Tick(object sender, EventArgs e)
- {
- foreach(Coin c in cList)
- {
- if (pbPlayer.Bounds.IntersectsWith(c.getBounds()))
- {
- c.setPos(1001, 1001);
- score++;
- lblScore.Text = "Score: " + score;
- }
- }
- }
- }
- }
- ///////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing;
- namespace PlatoformerTut
- {
- class Coin
- {
- private PictureBox pbCoin = new PictureBox();
- public Coin()
- {
- pbCoin.Width = 10;
- pbCoin.Height = 10;
- pbCoin.BackColor = Color.Yellow;
- }
- public void drawTo(Form f)
- {
- f.Controls.Add(pbCoin);
- }
- public Rectangle getBounds()
- {
- return pbCoin.Bounds;
- }
- public void setPos(int x, int y)
- {
- pbCoin.Location = new Point(x, y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement