如果你是零基础入门 Python 的话,建议初学者至少达到两个目标: 会用,理解。

会用

通过 Python 入门教程,学习 Python 的语法,熟悉 Python 标准库的使用。

目前 Python 官方已经发布了中文版的官方教程,降低了学习 Python 的门槛。建议初学者一开始直接从 Python 官方教程开始学习 Python。

通过 Python 官方教程,学习 Python 的语法,熟悉 Python 标准库的使用。

目前 Python 官方已经发布了中文版的官方教程,降低了学习 Python 的门槛。建议初学者一开始直接从 Python 官方教程开始学习 Python。

理解

程序这个东西,即使你一知半解,也是可以跑的通的。但是这样的学习效果不是我们想要的。程序能运行,不代表你学会了。所以,不管是学习 Python,还是其他语言,理解程序是最重要的,理解了程序,才能学会。

初学者可以通过 Python Tutor ,直接在 Web 浏览器中编写 Python 代码,可视化地运行程序。

通过可视化的程序运行步骤,来帮助初学者理解程序,加深对代码的思考。

如果你觉得看文章学习枯燥无味,还可以找 Python 的视频教程来学习。

我这里积累了很多的python干货资料,需要的可以找我来拿

参考下图找我

var GameLayer = cc.Layer.extend({

touchStartX:0,

touchStartY:0,

bullets:[],

enemies:[],

tools:[],

ctor: function () {

this._super();

this.touchStartX = 0;

this.touchStartY = 0;

this.bullets = [];

this.enemies = [];

this.tools = [];

// 播放背景音乐

cc.audioEngine.playMusic("res/sound/game_music.mp3",true);

// 加载plist

cc.spriteFrameCache.addSpriteFrames(res.shoot_background_plist);

cc.spriteFrameCache.addSpriteFrames(res.shoot_plist);

// 添加背景图

var bg = new Background(false);

bg.setPosition(0,0);

this.addChild(bg);

// 添加飞机

var player = new Player(this);

player.setPosition(cc.winSize.width / 2, -player.height / 2);

this.addChild(player);

player.setTag(1);

// 产生敌机

this.schedule(function(){

this.createEnemy(1);

},Global.createEnemySpeed(1));

this.schedule(function(){

this.createEnemy(2);

},Global.createEnemySpeed(2));

this.schedule(function(){

this.createEnemy(3);

},Global.createEnemySpeed(3));

// 产生道具

this.schedule(function(){

this.createTool(1);

},Global.createToolSpeed(1));

this.schedule(function(){

this.createTool(2);

},Global.createToolSpeed(2));

// 添加爆炸道具

var bombNor = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("bomb.png"));

var bombSelected = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("bomb.png"));

bombSelected.setPosition(-bombSelected.width/4,-bombSelected.height/4);

bombSelected.setScale(1.5);

var bombBtn = new cc.MenuItemSprite(

bombNor,

bombSelected,

function () {

var bombNum = this.getChildByTag(3);

if(parseInt(bombNum.getString().slice(1))==0){

return;

}

// 全屏爆炸

var blowEnemy = [];

for(var i in this.enemies){

var enemy = this.enemies[i];

blowEnemy.push(enemy);

}

for(var j in blowEnemy){

blowEnemy[j].blowUp();

}

// 数量减一

bombNum.setString("X"+(parseInt(bombNum.getString().slice(1))-1));

}, this);

bombBtn.setPosition(50+bombBtn.width/2,50+bombBtn.height/2);

var bombMenu = new cc.Menu(bombBtn);

bombMenu.setPosition(0,0);

bombMenu.setAnchorPoint(0,0);

this.addChild(bombMenu);

// 爆炸道具数量

var bombNum = new cc.LabelBMFont("X2",res.font);

bombNum.setAnchorPoint(0,0.5);

bombNum.setPosition(bombBtn.getPositionX()+bombBtn.width/2+50,bombBtn.getPositionY());

bombNum.setTag(3);

this.addChild(bombNum);

// 暂停开始按钮

var pauseBtn = new cc.MenuItemSprite(

new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("game_pause_nor.png")),

new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("game_pause_pressed.png")),

function () {

// 暂停音乐音效

cc.audioEngine.pauseAllEffects();

cc.audioEngine.pauseMusic();

pauseBtn.setEnabled(false);

cc.director.pause();

this.addChild(new PauseLayer(pauseBtn),10);

}, this);

var pauseMenu = new cc.Menu(pauseBtn);

pauseMenu.setPosition(20+pauseBtn.width/2,cc.winSize.height-pauseBtn.height/2-20);

pauseMenu.setAnchorPoint(0,0);

this.addChild(pauseMenu);

// 分数

var score = new cc.LabelBMFont("0",res.font);

score.setAnchorPoint(0,0.5);

score.setPosition(pauseMenu.getPositionX()+pauseBtn.width/2+50,pauseMenu.getPositionY());

score.setTag(2);

this.addChild(score);

// 碰撞检测

this.schedule(this.collision);

return true;

},

collision:function(){

var bullets = this.bullets;

var enemies = this.enemies;

var tools = this.tools;

var score = parseInt(this.getChildByTag(2).getString());

for(var i in enemies){

var enemy = enemies[i];

// 检测是否与玩家碰撞

var player = this.getChildByTag(1);

if(cc.rectIntersectsRect(enemy.getBoundingBox(),player.getBoundingBox())){

// 游戏结束

this.unschedule(this.collision);

player.blowUp();

// 停止背景音乐

cc.audioEngine.stopMusic("res/sound/game_music.mp3");

cc.audioEngine.playEffect("res/sound/game_over.mp3");

this.scheduleOnce(function() {

cc.director.runScene(new cc.TransitionFade(1,new OverScene(score)));

},2);

}

// 检测是否吃到道具

for(var m in tools){

var tool = tools[m];

if(cc.rectIntersectsRect(tool.getBoundingBox(),player.getBoundingBox())){

switch(tool.type){

case 1:

// 双排子弹道具

cc.audioEngine.playEffect("res/sound/get_double_laser.mp3");

player.shootDoubleBegin();

break;

case 2:

// 清屏道具

cc.audioEngine.playEffect("res/sound/get_bomb.mp3");

var bomb = this.getChildByTag(3);

bomb.setString("X"+(parseInt(bomb.getString().slice(1))+1));

bomb.runAction(cc.sequence(cc.scaleTo(0.1,1.2),cc.scaleTo(0.1,1)));

break;

}

tool.remove();

}

}

for(var j in bullets){

var bullet = bullets[j];

// 检测是否与子弹碰撞

if(cc.rectIntersectsRect(enemy.getBoundingBox(),bullet.getBoundingBox())){

enemy.hit();

bullet.remove();

}

}

}

},

addScore:function(type){

var score = this.getChildByTag(2);

var addScore = 0;

var curScore = parseInt(score.getString());

switch(type){

case 1:

addScore = 100 + Math.ceil(Math.random()*(curScore/1000));

break;

case 2:

addScore = 200 + Math.ceil(Math.random()*(curScore/1000));

break;

case 3:

addScore = 500 + Math.ceil(Math.random()*(curScore/1000));

break;

}

score.setString(curScore+addScore);

},

createEnemy:function(type){

var enemy = new Enemy(type,this);

var randomX = Math.random()*(cc.winSize.width-enemy.width/2-enemy.width/2)+enemy.width/2;

enemy.setPosition(randomX,cc.winSize.height+enemy.height/2);

this.addChild(enemy);

this.enemies.push(enemy);

},

createTool:function(type){

var tool = new Tool(type,this);

var randomX = Math.random()*(cc.winSize.width-tool.width/2-tool.width/2)+tool.width/2;

tool.setPosition(randomX,cc.winSize.height+tool.height/2);

this.addChild(tool);

this.tools.push(tool);

},

onEnter:function(){

this._super();

// 添加触摸事件

cc.eventManager.addListener({

event:cc.EventListener.TOUCH_ONE_BY_ONE,

swallowTouches:true,

onTouchBegan:this.touchbegan,

onTouchMoved:this.touchmoved,

onTouchEnded:this.touchended

},this);

return true;

},

touchbegan:function(touch,event){

event.getCurrentTarget().touchStartX = touch.getLocation().x;

event.getCurrentTarget().touchStartY = touch.getLocation().y;

return true;

},

touchmoved:function(touch,event){

var touchX = touch.getLocation().x;

var touchY = touch.getLocation().y;

var touchStartX = event.getCurrentTarget().touchStartX;

var touchStartY = event.getCurrentTarget().touchStartY;

var player = event.getCurrentTarget().getChildByTag(1);

if(player!=null){

player.moveBy(touchX-touchStartX,touchY-touchStartY);

event.getCurrentTarget().touchStartX = touchX;

event.getCurrentTarget().touchStartY = touchY;

}

return true;

},

touchended:function(touch,event){

return true;

}

});

更多推荐

高中python教程标准_高中应该怎样自学Python?