반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
 
        int randnumber = 0;
        // 볼 사이즈와 컬러 구조체 선언
        Point[] colorPoint = new Point[100];
        Point[] sizePoint = new Point[100];
 
        // 비행기컬러 , 비행기 사이즈 구조체 선언
        int ship_x = 300;
        int ship_y = 300;
       // int shipsize = 10;
 
        int count = 0;
        // 볼 속도 선언
        int[] x_speed = new int[100];
        int[] y_speed = new int[100];
 
       
        public Form1()
        {
            InitializeComponent();
 
            // x,y 속도를 랜덤하게 출력하게 하는 함수
            // 속도가 0 일경우 1로 설정됨.
            
            for (int i = 0; i < 100; i++)
            {
                x_speed[i]= rs.Next(-3,3);
                y_speed[i] = rs.Next(-33);
                if (x_speed[i] == 0)
                    x_speed[i] = 1;
                else if (y_speed[i] == 0)
                    y_speed[i] = 1;
            }
        }
 
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            
            randnumber = rs.Next(520); // 랜덤수 출력
            // 마우스 클릭시 해당 좌표값 읽어오는 소스
            //textBox1.Text = e.X.ToString() + "," + e.Y.ToString() + "(" + randnumber.ToString() + ")";
 
            colorPoint[count].X = e.X;
            colorPoint[count].Y = e.Y;
 
            
 
            //볼 사이즈를 랜덤하게 설정 
            sizePoint[count].X = randnumber; 
            sizePoint[count].Y = randnumber;
 
            count++;
            pictureBox1.Invalidate(); // 화면 갱신
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            //비행기 그리는 소스
            Image ship = Bitmap.FromFile("ship.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(ship, ship_x, ship_y,25,25);
            //e.Graphics.FillEllipse(Brushes.Purple, ship_x, ship_y, shipsize, shipsize);
 
            for (int i = 0; i < count; i++)
            {
                //원을 그려주는 소스
                SolidBrush mybrush = new SolidBrush(Color.FromArgb(i + 10025500));
                e.Graphics.FillEllipse(mybrush, colorPoint[i].X - (sizePoint[i].X/2), colorPoint[i].Y-(sizePoint[i].Y/2), sizePoint[i].X, sizePoint[i].Y);
 
                
 
                for (int j =0; j<count; j++)
                {
                    // 선을 그려주는 소스
                   // Pen mypen = new Pen(Color.FromArgb(i + 5,255,255,255),0.1f) ;
                  //  e.Graphics.DrawLine(mypen, colorPoint[i], colorPoint[j]);
                    
                }
            }
            
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i<count; i++)
            {
                // 볼을 이동시키는 소스
                colorPoint[i].X += x_speed[i]; 
                colorPoint[i].Y += y_speed[i];
                pictureBox1.Invalidate(); // 화면 갱신
                // 벽을 만나면 튕기는 소스
                if (colorPoint[i].X < 0) x_speed[i] *=-1;
                if (colorPoint[i].X > pictureBox1.Width) x_speed[i] *= -1;
                if (colorPoint[i].Y < 0) y_speed[i] *= -1;
                if (colorPoint[i].Y > pictureBox1.Height) y_speed[i] *= -1;
            }
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            // 키코드를 누를 때 입력 받는 함수
            if (e.KeyCode == Keys.Right) bright = true;
            if (e.KeyCode == Keys.Left) bleft = true;
            if (e.KeyCode == Keys.Down) bdown = true;
            if (e.KeyCode == Keys.Up) bup = true;
           
             
        }
        // 키보드 이동용 bool변수
        bool bleft = false,bright=false, bup =false,bdown =false;
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            // 비행기 움직임
            if (bright) { if (ship_x < pictureBox1.Width-35) ship_x +=5; }
            if (bleft) { if (ship_x > 0) ship_x -=5; }
            if (bup) {if (ship_y > 0) ship_y -=5; }
            if (bdown) { if (ship_y < pictureBox1.Height -35)  ship_y +=5; }
 
            pictureBox1.Invalidate();
        }
 
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //키코드를 뗄 때 입력받는 함수
            if (e.KeyCode == Keys.Right)bright = false;
            if (e.KeyCode == Keys.Left)bleft = false;
            if (e.KeyCode == Keys.Down)bdown = false;
            if (e.KeyCode == Keys.Up)bup = false;
            
        }
    }
}
 
cs

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
C# - 계산기 만들기2  (0) 2018.08.30

+ Recent posts