week07
加入teams 疫情時可使用
--------------------------------------------------------------------------------------------------------------------------
今天教指標
指標進階-1
///重點: Pointer指標/// ///// ->
#include <stdio.h>
int main(){
int a=100;
int b=200;
int c=300;
int *p;///(1)指標宣告: p是一個指標, 要指到一個整數
p = &a;///(2)指標的設值: &符號(and)叫 address住址
printf(" %d \n", *p);///(3)指標指到的東西,拿來用
p = &b;///(2)指標的設值: &符號(and)叫 address住址
printf(" %d \n", *p);///(3)指標指到的東西,拿來用
p = &c;///(2)指標的設值: &符號(and)叫 address住址
printf(" %d \n", *p);///(3)指標指到的東西,拿來用
}
指標進階-2
///重點: Pointer指標/// ///// ->
#include <stdio.h>
char s1[30]="hello world I love you";
char s2[30]="I am a book and he is not";
int main(){
char *p;///(1)指標宣告: p是一個指標, 要指到一個整數
char a[10];
p = s1;///(2)指標的設值: &符號(and)叫 address住址
printf(" %s \n", p);///(3)指標指到的東西,拿來用
p = s2;
printf(" %s \n", p);
}
-----------------------------------------------------------
今天遊戲程式碼:
PImage img1;//有圖,向右PImage img2;//有圖,向左
PImage img3;//有圖,向正
PImage img;//最後用這張圖來秀
void setup(){
size(300,300);//記得把圖,放進程式碼裡喔!
img1=loadImage("img1.png");
img2=loadImage("img2.png");
img3=loadImage("img3.png");
img=img3;//先立正
}
void draw(){
background(255);//背景清白色
image(img, 100, 100);//畫圖
}
void keyPressed(){
if(keyCode==LEFT) img=img2;
if(keyCode==RIGHT) img=img1;
}
void keyReleased(){
img=img3;//放開,就立正站好
}
--------------------------------------------------------------------------------------------------------------------------圖片:
PImage img1, img2, img3;//有圖,向右,向左,向正
PImage img;//最後用這張圖來秀
float x=100, y=100, vx=0;//TODO: 用變數,讓程式有變化
void setup(){
size(300,300);//記得把圖,放進程式碼裡喔!
//fullScreen() ;
img1=loadImage("right.png");
img2=loadImage("left.png");
img3=loadImage("up.png");
img=img3;//先立正
}
void draw(){
background(255);//背景清白色
image(img, 100, 100);//畫圖
x += vx;//TODO: Q: 為什麼會走?因為x被改!
}
void keyPressed(){
if(keyCode==LEFT){
img=img2; vx= -1;
}else if(keyCode==RIGHT){
img=img1; vx= +1;
}
}
void keyReleased(){
img=img3; vx=0;//放開,就立正站好
}
--------------------------------------------------------------------------------------------------------------------------
圖片:
---------------------------------------------------------------------------------
程式碼:
PImage img;
float x=100, y=100, vx=3, vy=0;
void setup(){
size(500,500);
img=loadImage("trump.png");
}
void draw(){
background(255);
image(img, x, y, 100, 100);
x +=vx;
y +=vy;
vy += 0.98;
if(x>400) vx = -3;
if(x<0) vx = +3;
if(y>400) vy = -vy*0.8;
}
---------------------------------------------------------------------------------圖片:









沒有留言:
張貼留言